# Building
# ========
# 
# To build this you need bmake and mk files from
# http://www.crufty.net/ftp/pub/sjg/
# 
# On some platforms you may need to set ``PICFLAG=-fPIC``
# Otherwise building is simply a matter of::
#
# 	export MAKEOBJDIRPREFIX=/tmp
# 	bmake -m ~/share/mk obj
# 	bmake -m ~/share/mk install
#
# Note: if ``swig`` or ``cython`` are available they will be used, otherwise
# pre-generated files in ``./gen`` will be used.
#
# By default the Cython based module will be built appropriate to 
# PYTHON_VERSION (default is 2.7).
#
# If you want to build the swig based module (does not support Python
# 3.x) use::
#
# 	bmake -m ~/share/mk install-signer
#  
# You can also build a standalone signed (mainly suitable for testing)
# with::
#
# 	bmake -m ~/share/mk signer
# 
#

# RCSid:
#	$Id: Makefile,v 1.17 2014/08/30 01:01:08 sjg Exp $
#
#	@(#) Copyright (c) 2012 Simon J. Gerraty
#
#	This file is provided in the hope that it will
#	be of use.  There is absolutely NO WARRANTY.
#	Permission to copy, redistribute or otherwise
#	use this file is hereby granted provided that 
#	the above copyright notice and this notice are
#	left intact. 
#      
#	Please send copies of changes and bug-fixes to:
#	sjg@crufty.net

.MAIN: all

SRCS= signer.c

.-include "Makefile.local.inc"

CYTHON_MODULE_NAME= ossl

.include "cython.mk"

.if make(signer)
PROG= signer

CFLAGS+= -DMAIN

.elif make(*signer*)
# swig does not handle python3
all: _signer.so

SRCS+= signer_wrap.c

SWIG?= swig

.if ${type ${SWIG} 2> /dev/null || echo:L:sh:M/*} != ""
signer_wrap.c: signer.i
	${SWIG} -python -o $@ ${.ALLSRC}

signer.py: signer_wrap.c
.else
.PATH: ${.CURDIR}/gen
.endif

.else
all: build-cython-module

.if ${type ${CYTHON} 2> /dev/null || echo:L:sh:M/*} == ""
.PATH: ${.CURDIR}/gen
.endif

install: install-cython-module
.endif

CFLAGS_MD=
CFLAGS_MF=

_signer.so:	${SRCS:S,.c,.So,}
	${CC} -shared -o $@ ${.ALLSRC:M*.So} ${LDADD}

install-signer:	_signer.so signer.py
	test -d ${DESTDIR}${MODULE_BINDIR} || \
	${INSTALL} -d ${DESTDIR}${MODULE_BINDIR}
	${INSTALL} -m 755 ${.ALLSRC:M*signer*} ${DESTDIR}${MODULE_BINDIR}

savegen-signer:	signer_wrap.c signer.py
	cp ${.ALLSRC} ${.CURDIR}/gen

LDADD+= -lcrypto

NOMAN=
NO_MAN=
NO_AUTODEP=

.include <prog.mk>

#CFLAGS+= -g -O0
#LDFLAGS+= -static
