]> CyberLeo.Net >> Repos - FreeBSD/releng/10.3.git/blob - contrib/bmake/mk/cython.mk
- Copy stable/10@296371 to releng/10.3 in preparation for 10.3-RC1
[FreeBSD/releng/10.3.git] / contrib / bmake / mk / cython.mk
1 # RCSid:
2 #       $Id: cython.mk,v 1.6 2014/10/15 06:23:51 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 # this is what we build
18 CYTHON_MODULE = ${CYTHON_MODULE_NAME}${CYTHON_PYVERSION}.so
19
20 CYTHON_MODULE_NAME?= it
21 CYTHON_SRCS?= ${CYTHON_MODULE_NAME}.pyx
22
23 # this is where we save generated src
24 CYTHON_SAVEGENDIR?= ${.CURDIR}/gen
25
26 # pyprefix is where python bits are
27 # which may not be where we want to put ours (prefix)
28 .if exists(/usr/pkg/include)
29 pyprefix?= /usr/pkg
30 .endif
31 pyprefix?= /usr/local
32
33 PYTHON_VERSION?= 2.7
34 PYTHON_H?= ${pyprefix}/include/python${PYTHON_VERSION}/Python.h
35 PYVERSION:= ${PYTHON_VERSION:C,\..*,,}
36
37 # set this empty if you don't want to handle multiple versions
38 .if !defined(CYTHON_PYVERSION)
39 CYTHON_PYVERSION:= ${PYVERSION}
40 .endif
41
42 CFLAGS+= -I${PYTHON_H:H}
43
44 CYTHON_GENSRCS= ${CYTHON_SRCS:R:S,$,${CYTHON_PYVERSION}.c,}
45 SRCS+= ${CYTHON_GENSRCS}
46
47 .SUFFIXES: .pyx .c .So
48
49 CYTHON?= ${pyprefix}/bin/cython
50
51 # if we don't have cython we can use pre-generated srcs
52 .if ${type ${CYTHON} 2> /dev/null || echo:L:sh:M/*} == ""
53 .PATH: ${CYTHON_SAVEGENDIR}
54 .else
55
56 .if !empty(CYTHON_PYVERSION)
57 .for c in ${CYTHON_SRCS}
58 ${c:R}${CYTHON_PYVERSION}.${c:E}: $c
59         ln -sf ${.ALLSRC:M*pyx} ${.TARGET}
60 .endfor
61 .endif
62
63 .pyx.c:
64         ${CYTHON} ${CYTHON_FLAGS} -${PYVERSION} -o ${.TARGET} ${.IMPSRC}
65
66
67 save-gen: ${CYTHON_GENSRCS}
68         mkdir -p ${CYTHON_SAVEGENDIR}
69         cp -p ${.ALLSRC} ${CYTHON_SAVEGENDIR}
70
71 .endif
72
73 COMPILE.c?= ${CC} -c ${CFLAGS}
74
75 .c.So:
76         ${COMPILE.c} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}
77
78 ${CYTHON_MODULE}: ${SRCS:S,.c,.So,}
79         ${CC} ${CC_SHARED:U-shared} -o ${.TARGET} ${.ALLSRC:M*.So} ${LDADD}
80
81 # conf.host_target() is limited to uname -m rather than uname -p
82 _HOST_MACHINE!= uname -m
83 .if ${HOST_TARGET:M*${_HOST_MACHINE}} == ""
84 PY_HOST_TARGET:= ${HOST_TARGET:S,${_HOST_ARCH:U${uname -p:L:sh}}$,${_HOST_MACHINE},}
85 .endif
86
87 MODULE_BINDIR?= ${.CURDIR:H}/${PY_HOST_TARGET:U${HOST_TARGET}}
88
89 build-cython-module: ${CYTHON_MODULE}
90
91 install-cython-module: ${CYTHON_MODULE}
92         test -d ${DESTDIR}${MODULE_BINDIR} || \
93         ${INSTALL} -d ${DESTDIR}${MODULE_BINDIR}
94         ${INSTALL} -m 755 ${.ALLSRC} ${DESTDIR}${MODULE_BINDIR}
95
96 CLEANFILES+= *.So ${CYTHON_MODULE}