xref: /dragonfly/contrib/bmake/mk/cython.mk (revision a34d5fb1)
16a91b982SJohn Marino# RCSid:
2a34d5fb1SAntonio Huete Jimenez#	$Id: cython.mk,v 1.8 2020/08/19 17:51:53 sjg Exp $
36a91b982SJohn Marino#
46a91b982SJohn Marino#	@(#) Copyright (c) 2014, Simon J. Gerraty
56a91b982SJohn Marino#
66a91b982SJohn Marino#	This file is provided in the hope that it will
76a91b982SJohn Marino#	be of use.  There is absolutely NO WARRANTY.
86a91b982SJohn Marino#	Permission to copy, redistribute or otherwise
96a91b982SJohn Marino#	use this file is hereby granted provided that
106a91b982SJohn Marino#	the above copyright notice and this notice are
116a91b982SJohn Marino#	left intact.
126a91b982SJohn Marino#
136a91b982SJohn Marino#	Please send copies of changes and bug-fixes to:
146a91b982SJohn Marino#	sjg@crufty.net
156a91b982SJohn Marino#
166a91b982SJohn Marino
176a91b982SJohn Marino# pyprefix is where python bits are
186a91b982SJohn Marino# which may not be where we want to put ours (prefix)
196a91b982SJohn Marino.if exists(/usr/pkg/include)
206a91b982SJohn Marinopyprefix?= /usr/pkg
216a91b982SJohn Marino.endif
226a91b982SJohn Marinopyprefix?= /usr/local
236a91b982SJohn Marino
246a91b982SJohn MarinoPYTHON_VERSION?= 2.7
256a91b982SJohn MarinoPYTHON_H?= ${pyprefix}/include/python${PYTHON_VERSION}/Python.h
266a91b982SJohn MarinoPYVERSION:= ${PYTHON_VERSION:C,\..*,,}
276a91b982SJohn Marino
28ca58f742SDaniel FojtCFLAGS+= -I${PYTHON_H:H}
29ca58f742SDaniel Fojt
30ca58f742SDaniel Fojt# conf.host_target() is limited to uname -m rather than uname -p
31ca58f742SDaniel Fojt_HOST_MACHINE!= uname -m
32ca58f742SDaniel Fojt.if ${HOST_TARGET:M*${_HOST_MACHINE}} == ""
33ca58f742SDaniel FojtPY_HOST_TARGET:= ${HOST_TARGET:S,${_HOST_ARCH:U${uname -p:L:sh}}$,${_HOST_MACHINE},}
34ca58f742SDaniel Fojt.endif
35ca58f742SDaniel Fojt
36ca58f742SDaniel FojtCOMPILE.c?= ${CC} -c ${CFLAGS}
37ca58f742SDaniel FojtPICO?= .pico
38ca58f742SDaniel Fojt
39ca58f742SDaniel Fojt.SUFFIXES: ${PICO} .c
40ca58f742SDaniel Fojt
41ca58f742SDaniel Fojt.c${PICO}:
42ca58f742SDaniel Fojt	${COMPILE.c} ${PICFLAG} ${CC_PIC} ${.IMPSRC} -o ${.TARGET}
43ca58f742SDaniel Fojt
44ca58f742SDaniel Fojt# this is what we build
45ca58f742SDaniel Fojt.if !empty(CYTHON_MODULE_NAME)
46ca58f742SDaniel FojtCYTHON_MODULE = ${CYTHON_MODULE_NAME}${CYTHON_PYVERSION}.so
47ca58f742SDaniel Fojt
48ca58f742SDaniel FojtCYTHON_SRCS?= ${CYTHON_MODULE_NAME}.pyx
49ca58f742SDaniel Fojt
50ca58f742SDaniel Fojt# this is where we save generated src
51ca58f742SDaniel FojtCYTHON_SAVEGENDIR?= ${.CURDIR}/gen
52ca58f742SDaniel Fojt
536a91b982SJohn Marino# set this empty if you don't want to handle multiple versions
546a91b982SJohn Marino.if !defined(CYTHON_PYVERSION)
556a91b982SJohn MarinoCYTHON_PYVERSION:= ${PYVERSION}
566a91b982SJohn Marino.endif
576a91b982SJohn Marino
586a91b982SJohn MarinoCYTHON_GENSRCS= ${CYTHON_SRCS:R:S,$,${CYTHON_PYVERSION}.c,}
596a91b982SJohn MarinoSRCS+= ${CYTHON_GENSRCS}
606a91b982SJohn Marino
616a91b982SJohn Marino.SUFFIXES: .pyx .c .So
626a91b982SJohn Marino
636a91b982SJohn MarinoCYTHON?= ${pyprefix}/bin/cython
646a91b982SJohn Marino
656a91b982SJohn Marino# if we don't have cython we can use pre-generated srcs
666a91b982SJohn Marino.if ${type ${CYTHON} 2> /dev/null || echo:L:sh:M/*} == ""
676a91b982SJohn Marino.PATH: ${CYTHON_SAVEGENDIR}
686a91b982SJohn Marino.else
696a91b982SJohn Marino
706a91b982SJohn Marino.if !empty(CYTHON_PYVERSION)
716a91b982SJohn Marino.for c in ${CYTHON_SRCS}
726a91b982SJohn Marino${c:R}${CYTHON_PYVERSION}.${c:E}: $c
736a91b982SJohn Marino	ln -sf ${.ALLSRC:M*pyx} ${.TARGET}
746a91b982SJohn Marino.endfor
756a91b982SJohn Marino.endif
766a91b982SJohn Marino
776a91b982SJohn Marino.pyx.c:
786a91b982SJohn Marino	${CYTHON} ${CYTHON_FLAGS} -${PYVERSION} -o ${.TARGET} ${.IMPSRC}
796a91b982SJohn Marino
806a91b982SJohn Marino
816a91b982SJohn Marinosave-gen: ${CYTHON_GENSRCS}
826a91b982SJohn Marino	mkdir -p ${CYTHON_SAVEGENDIR}
836a91b982SJohn Marino	cp -p ${.ALLSRC} ${CYTHON_SAVEGENDIR}
846a91b982SJohn Marino
856a91b982SJohn Marino.endif
866a91b982SJohn Marino
87ca58f742SDaniel Fojt${CYTHON_MODULE}: ${SRCS:S,.c,${PICO},}
88ca58f742SDaniel Fojt	${CC} ${CC_SHARED:U-shared} -o ${.TARGET} ${.ALLSRC:M*${PICO}} ${LDADD}
896a91b982SJohn Marino
906a91b982SJohn MarinoMODULE_BINDIR?= ${.CURDIR:H}/${PY_HOST_TARGET:U${HOST_TARGET}}
916a91b982SJohn Marino
926a91b982SJohn Marinobuild-cython-module: ${CYTHON_MODULE}
936a91b982SJohn Marino
946a91b982SJohn Marinoinstall-cython-module: ${CYTHON_MODULE}
956a91b982SJohn Marino	test -d ${DESTDIR}${MODULE_BINDIR} || \
966a91b982SJohn Marino	${INSTALL} -d ${DESTDIR}${MODULE_BINDIR}
976a91b982SJohn Marino	${INSTALL} -m 755 ${.ALLSRC} ${DESTDIR}${MODULE_BINDIR}
986a91b982SJohn Marino
99ca58f742SDaniel FojtCLEANFILES+= *${PICO} ${CYTHON_MODULE}
100ca58f742SDaniel Fojt
101ca58f742SDaniel Fojt.endif
102