# 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.22 2024/09/20 06:19:24 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= \
	libcrypto-compat.c \
	signer.c

.-include "Makefile.local.inc"

CYTHON_MODULE_NAME= ossl

.if !make(signer)
.include "cython.mk"
.endif

.if make(signer)
PROG= signer

CFLAGS+= -DMAIN -g -O0

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

SRCS+= signer_wrap.c

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

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

.else
all: build-cython-module

install: install-cython-module
.endif

CFLAGS_MD=
CFLAGS_MF=

_signer.so:	${SRCS:S,.c,${PICO},}
	${CC} -shared -o $@ ${.ALLSRC:M*${PICO}} ${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>

#LDFLAGS+= -static
CLEANFILES+= signer signer.o
