#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# This has to be exported to make some magic below work.
export DH_OPTIONS

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
DEB_BUILD_ARCH     ?= $(shell dpkg-architecture -qDEB_BUILD_ARCH)

CPPFLAGS :=$(shell dpkg-buildflags --get CPPFLAGS)
CFLAGS   :=$(shell dpkg-buildflags --get CFLAGS)
CXXFLAGS :=$(shell dpkg-buildflags --get CXXFLAGS)
LDFLAGS  :=$(shell dpkg-buildflags --get LDFLAGS)

FFLAGS := -D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4

ifneq (,$(findstring $(DEB_BUILD_ARCH), hurd-i386 mips mipsel s390 armel armhf))
DEB_BUILD_OPTIONS += nocheck
endif
export DEB_BUILD_OPTIONS

export CPPFLAGS CFLAGS CXXFLAGS LDFLAGS FFLAGS

override_dh_auto_clean:
	dh_auto_clean
	rm -rf ccwrap/doxy
	rm -f octave/lhapdf.oct octave/wrapoctave.o
	rm -f pyext/lhapdf.py pyext/lhapdf_wrap.cc
	rm -f src/parmsetup.inc

override_dh_auto_configure:
	dh_auto_configure -- \
		--prefix=/usr \
		--libdir=\$${prefix}/lib/$(DEB_HOST_MULTIARCH)

# OCTDIR
include /usr/share/octave/debian/defs.make

override_dh_auto_install:
	dh_auto_install
	mkdir -p debian/octave-lhapdf$(OCTDIR)
	strip --remove-section=.comment debian/tmp/usr/share/lhapdf/lhapdf.oct
	install debian/tmp/usr/share/lhapdf/lhapdf.oct \
		debian/octave-lhapdf$(OCTDIR)
	#octave-depends -poctave-lhapdf

override_dh_auto_build-indep:
	dh_auto_build
	$(MAKE) -C ccwrap dox

%:
	dh $@ --with autoreconf --parallel
