vendor/bmake: upgrade from 20210206 to 20210314
[dragonfly.git] / contrib / bmake / mk / cython.mk
1 # RCSid:
2 #       $Id: cython.mk,v 1.8 2020/08/19 17:51:53 sjg Exp $
3 #
4 #       @(#) Copyright (c) 2014, Simon J. Gerraty
5 #
6 #       This file is provided in the hope that it will
7 #       be of use.  There is absolutely NO WARRANTY.
8 #       Permission to copy, redistribute or otherwise
9 #       use this file is hereby granted provided that
10 #       the above copyright notice and this notice are
11 #       left intact.
12 #
13 #       Please send copies of changes and bug-fixes to:
14 #       sjg@crufty.net
15 #
16
17 # pyprefix is where python bits are
18 # which may not be where we want to put ours (prefix)
19 .if exists(/usr/pkg/include)
20 pyprefix?= /usr/pkg
21 .endif
22 pyprefix?= /usr/local
23
24 PYTHON_VERSION?= 2.7
25 PYTHON_H?= ${pyprefix}/include/python${PYTHON_VERSION}/Python.h
26 PYVERSION:= ${PYTHON_VERSION:C,\..*,,}
27
28 CFLAGS+= -I${PYTHON_H:H}
29
30 # conf.host_target() is limited to uname -m rather than uname -p
31 _HOST_MACHINE!= uname -m
32 .if ${HOST_TARGET:M*${_HOST_MACHINE}} == ""
33 PY_HOST_TARGET:= ${HOST_TARGET:S,${_HOST_ARCH:U${uname -p:L:sh}}$,${_HOST_MACHINE},}
34 .endif
35
36 COMPILE.c?= ${CC} -c ${CFLAGS}
37 PICO?= .pico
38
39 .SUFFIXES: ${PICO} .c
40
41 .c${PICO}:
42         ${COMPILE.c} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}
43
44 # this is what we build
45 .if !empty(CYTHON_MODULE_NAME)
46 CYTHON_MODULE = ${CYTHON_MODULE_NAME}${CYTHON_PYVERSION}.so
47
48 CYTHON_SRCS?= ${CYTHON_MODULE_NAME}.pyx
49
50 # this is where we save generated src
51 CYTHON_SAVEGENDIR?= ${.CURDIR}/gen
52
53 # set this empty if you don't want to handle multiple versions
54 .if !defined(CYTHON_PYVERSION)
55 CYTHON_PYVERSION:= ${PYVERSION}
56 .endif
57
58 CYTHON_GENSRCS= ${CYTHON_SRCS:R:S,$,${CYTHON_PYVERSION}.c,}
59 SRCS+= ${CYTHON_GENSRCS}
60
61 .SUFFIXES: .pyx .c .So
62
63 CYTHON?= ${pyprefix}/bin/cython
64
65 # if we don't have cython we can use pre-generated srcs
66 .if ${type ${CYTHON} 2> /dev/null || echo:L:sh:M/*} == ""
67 .PATH: ${CYTHON_SAVEGENDIR}
68 .else
69
70 .if !empty(CYTHON_PYVERSION)
71 .for c in ${CYTHON_SRCS}
72 ${c:R}${CYTHON_PYVERSION}.${c:E}: $c
73         ln -sf ${.ALLSRC:M*pyx} ${.TARGET}
74 .endfor
75 .endif
76
77 .pyx.c:
78         ${CYTHON} ${CYTHON_FLAGS} -${PYVERSION} -o ${.TARGET} ${.IMPSRC}
79
80
81 save-gen: ${CYTHON_GENSRCS}
82         mkdir -p ${CYTHON_SAVEGENDIR}
83         cp -p ${.ALLSRC} ${CYTHON_SAVEGENDIR}
84
85 .endif
86
87 ${CYTHON_MODULE}: ${SRCS:S,.c,${PICO},}
88         ${CC} ${CC_SHARED:U-shared} -o ${.TARGET} ${.ALLSRC:M*${PICO}} ${LDADD}
89
90 MODULE_BINDIR?= ${.CURDIR:H}/${PY_HOST_TARGET:U${HOST_TARGET}}
91
92 build-cython-module: ${CYTHON_MODULE}
93
94 install-cython-module: ${CYTHON_MODULE}
95         test -d ${DESTDIR}${MODULE_BINDIR} || \
96         ${INSTALL} -d ${DESTDIR}${MODULE_BINDIR}
97         ${INSTALL} -m 755 ${.ALLSRC} ${DESTDIR}${MODULE_BINDIR}
98
99 CLEANFILES+= *${PICO} ${CYTHON_MODULE}
100
101 .endif