#!/usr/bin/make -f

export DH_VERBOSE=1

DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
LIBDIR=/usr/lib/$(DEB_HOST_MULTIARCH)
AUTOGENERATED:= pmix-mca-params.conf
CFLAGS:=$(shell dpkg-buildflags --get CFLAGS)  -fPIC

PSM_ARCH= amd64 i386
PSM2_ARCH= amd64 
PSM2:= $(if $(filter $(DEB_TARGET_ARCH),$(PSM2_ARCH)), --with-psm2, )

ifneq (,$(filter $(DEB_HOST_ARCH), armel mipsel sh4 m68k ))
  export DEB_LDFLAGS_MAINT_APPEND += -Wl,--no-as-needed -latomic -Wl,--as-needed
endif

%:
	dh $@ 

override_dh_auto_clean:
	dh_auto_clean
	rm -f $(patsubst %, debian/%, ${AUTOGENERATED})
	rm -rf debian/static-build debian/shared-build

override_dh_autoreconf:
	./autogen.pl --force
	for f in ${AUTOGENERATED} ; do \
                sed -e 's%@DEB_HOST_MULTIARCH@%${DEB_HOST_MULTIARCH}%g' < debian/$$f.in  > debian/$$f ; \
                done

override_dh_auto_configure:
	dh_auto_configure --builddirectory=debian/static-build -- $(PSM2) \
		--enable-static --sysconfdir=$(LIBDIR)/pmix2/share --disable-man-pages
	dh_auto_configure --builddirectory=debian/shared-build -- $(PSM2) \
		--enable-shared --sysconfdir=$(LIBDIR)/pmix2/share --disable-man-pages

override_dh_auto_build:
	dh_auto_build  --builddirectory=debian/static-build
	dh_auto_build  --builddirectory=debian/shared-build

override_dh_auto_install:
	dh_auto_install --builddirectory=debian/static-build
	dh_auto_install --builddirectory=debian/shared-build
	find debian/tmp -name '*.la' -delete

