#!/usr/bin/make -f

DESTDIR=$$(pwd)/debian/tmp
LIBDIR=/usr/lib/intel-ipsec-mb
HDRDIR=/usr/include/intel-ipsec-mb
MANDIR=/usr/share/man/man7

VERSION_MAJOR=$(shell grep "^VERSION = " Makefile | tr '.' ' ' | cut -d' ' -f3)
VERSION_MINOR=$(shell grep "^VERSION = " Makefile | tr '.' ' ' | cut -d' ' -f4)

MAN1 = libipsec-mb.7
MAN2 = libipsec-mb-dev.7

#
# DOCDIR is the same path as the library copyright file
#
DOCDIR=/usr/share/doc/libipsec-mb

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

override_dh_auto_build:
	$(shell dpkg-buildflags --export=sh); SHARED=y dh_auto_build
	rm obj/*.o
	$(shell dpkg-buildflags --export=sh); SHARED=n dh_auto_build

override_dh_auto_install:
	# Documentation
	install -d ${DESTDIR}${DOCDIR}
	install -m 0644 $$(pwd)/LICENSE ${DESTDIR}${DOCDIR}

	# Install the library
	install -d ${DESTDIR}${LIBDIR}
	install -m 0644 -s $$(pwd)/libIPSec_MB.a ${DESTDIR}${LIBDIR}
	install -m 0644 -s $$(pwd)/libIPSec_MB.so.${VERSION_MAJOR}.${VERSION_MINOR} ${DESTDIR}${LIBDIR}
	ln -s ${LIBDIR}/libIPSec_MB.so.${VERSION_MAJOR}.${VERSION_MINOR} ${DESTDIR}${LIBDIR}/libIPSec_MB.so.${VERSION_MAJOR}
	ln -s ${LIBDIR}/libIPSec_MB.so.${VERSION_MAJOR} ${DESTDIR}${LIBDIR}/libIPSec_MB.so

	#dpkg-shlibdeps ${DESTDIR}${LIBDIR}/libIPSec_MB.so.${VERSION_MAJOR}.${VERSION_MINOR}

	# Install the header files
	install -d ${DESTDIR}${HDRDIR}
	install -m 0644 $$(pwd)/include/types.h ${DESTDIR}${HDRDIR}
	install -m 0644 $$(pwd)/constants.h ${DESTDIR}${HDRDIR}
	install -m 0644 $$(pwd)/job_aes_hmac.h ${DESTDIR}${HDRDIR}
	install -m 0644 $$(pwd)/asm_types.h ${DESTDIR}${HDRDIR}
	install -m 0644 $$(pwd)/mb_mgr.h ${DESTDIR}${HDRDIR}
	install -m 0644 $$(pwd)/gcm_defines.h ${DESTDIR}${HDRDIR}

	# Install man pages
	install -d ${DESTDIR}${MANDIR}
	install -m 0444 $$(pwd)/${MAN1} ${DESTDIR}${MANDIR}
	install -m 0444 $$(pwd)/${MAN2} ${DESTDIR}${MANDIR}

%:
	dh $@
	dh_makeshlibs
	dh_shlibdeps
