2 # $Id: cython.mk,v 1.8 2020/08/19 17:51:53 sjg Exp $
4 # @(#) Copyright (c) 2014, Simon J. Gerraty
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
13 # Please send copies of changes and bug-fixes to:
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)
25 PYTHON_H?= ${pyprefix}/include/python${PYTHON_VERSION}/Python.h
26 PYVERSION:= ${PYTHON_VERSION:C,\..*,,}
28 CFLAGS+= -I${PYTHON_H:H}
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},}
36 COMPILE.c?= ${CC} -c ${CFLAGS}
42 ${COMPILE.c} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}
44 # this is what we build
45 .if !empty(CYTHON_MODULE_NAME)
46 CYTHON_MODULE = ${CYTHON_MODULE_NAME}${CYTHON_PYVERSION}.so
48 CYTHON_SRCS?= ${CYTHON_MODULE_NAME}.pyx
50 # this is where we save generated src
51 CYTHON_SAVEGENDIR?= ${.CURDIR}/gen
53 # set this empty if you don't want to handle multiple versions
54 .if !defined(CYTHON_PYVERSION)
55 CYTHON_PYVERSION:= ${PYVERSION}
58 CYTHON_GENSRCS= ${CYTHON_SRCS:R:S,$,${CYTHON_PYVERSION}.c,}
59 SRCS+= ${CYTHON_GENSRCS}
61 .SUFFIXES: .pyx .c .So
63 CYTHON?= ${pyprefix}/bin/cython
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}
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}
78 ${CYTHON} ${CYTHON_FLAGS} -${PYVERSION} -o ${.TARGET} ${.IMPSRC}
81 save-gen: ${CYTHON_GENSRCS}
82 mkdir -p ${CYTHON_SAVEGENDIR}
83 cp -p ${.ALLSRC} ${CYTHON_SAVEGENDIR}
87 ${CYTHON_MODULE}: ${SRCS:S,.c,${PICO},}
88 ${CC} ${CC_SHARED:U-shared} -o ${.TARGET} ${.ALLSRC:M*${PICO}} ${LDADD}
90 MODULE_BINDIR?= ${.CURDIR:H}/${PY_HOST_TARGET:U${HOST_TARGET}}
92 build-cython-module: ${CYTHON_MODULE}
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}
99 CLEANFILES+= *${PICO} ${CYTHON_MODULE}