#!/usr/bin/make -f

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk
CFLAGS += -fPIC

%:
	dh $@

override_dh_auto_configure:
	dh_auto_configure -- --prefix=/usr

override_dh_auto_install:
	mkdir -p $(CURDIR)/debian/tmp/usr
	dh_auto_install -- prefix=$(CURDIR)/debian/tmp/usr
	find $(CURDIR)/debian/tmp/usr/bin/ -type f \
	  ! -name "*dclps*" \
	  ! -name "cdclcc"  \
	  ! -name "cdclconfig*" \
	  | xargs chrpath -d
	$(CC) $(LDFLAGS) -shared -Wl,-soname,libf2c4dcl.so.6 \
	  -o $(CURDIR)/debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/libf2c4dcl.so.6.0.2 \
	  `find $(CURDIR)/f2csrc -name \*.o`
	$(CC) $(LDFLAGS) -shared -Wl,-soname,libcdcl.so.6 \
	  -o $(CURDIR)/debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/libcdcl.so.6.0.2 \
	  `find $(CURDIR)/src -name \*.o`
	( cd $(CURDIR)/debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH) ; ln -s libcdcl.so.6.0.2 libcdcl.so.6 )
	( cd $(CURDIR)/debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH) ; ln -s libcdcl.so.6.0.2 libcdcl.so )
	( cd $(CURDIR)/debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH) ; ln -s libf2c4dcl.so.6.0.2 libf2c4dcl.so.6 )
	( cd $(CURDIR)/debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH) ; ln -s libf2c4dcl.so.6.0.2 libf2c4dcl.so )


override_dh_install:
	dh_install --sourcedir=debian/tmp

override_dh_auto_clean:
	dh_auto_clean

.PHONY: override_dh_strip
override_dh_strip:
	dh_strip --dbg-package=libcdcl6-dbg

override_dh_installchangelogs:
	dh_installchangelogs --all --keep HISTORY
