#!/usr/bin/make -f
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

%:
	dh $@

override_dh_auto_clean:
	[ ! -f Mkinclude ] || $(MAKE) clean
	-rm -f Mkinclude SIGEN.htm config.cache config.log config.status
	-rm -f src/f*/charset.* chkfort.cfg
	-rm -rf tmp
	dh_clean
	rm -f src/f77/x
	rm -f src/f90/x

override_dh_auto_configure:
	FC=gfortran \
		 dh_auto_configure -- --prefix=/usr \
		 --with-dclconfig=/usr/bin/dclconfig

override_dh_auto_install:
	dh_auto_install -- prefix=$(CURDIR)/debian/tmp/usr
	mkdir -p $(CURDIR)/debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)
	$(CC) $(CFLAGS) $(LDFLAGS) --shared -Wl,-soname,libf90dcl.so.5 \
	-o $(CURDIR)/debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/libf90dcl.so.5.2 \
	  `find $(CURDIR) -name \*.o`
	( cd $(CURDIR)/debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH) ; ln -s libf90dcl.so.5.2 libf90dcl.so.5 )
	( cd $(CURDIR)/debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH) ; ln -s libf90dcl.so.5.2 libf90dcl.so )

override_dh_install:
	dh_install --sourcedir=debian/tmp

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