#!/usr/bin/make -f
# -*- makefile -*-
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
export DPKG_EXPORT_BUILDFLAGS=1
export DEB_BUILD_MAINT_OPTIONS=hardening=+all
export LIBTOOLIZE=false
include /usr/share/dpkg/buildflags.mk
FFLAGS += -fPIC
CFLAGS += -fPIC
DCLVERNUM=7.3.3
DCLVER=733

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

override_dh_autoreconf:
	autoconf -f -i

override_dh_auto_configure-arch:
	$(shell ! grep -q jessie /etc/os-release || \
	  echo "activate-noawait ldconfig" > $(CURDIR)/debian/libf77dcl7.triggers )
	CC=gcc FC=gfortran \
	   dh_auto_configure -- $(dpkg-buildflags --export=configure) --with-gtk3

override_dh_auto_configure-indep:
#	do nothing

override_dh_auto_test:
#	do nothing

override_dh_auto_install-arch:
	dh_auto_install -- prefix=$(CURDIR)/debian/tmp/usr
	rm $(CURDIR)/debian/tmp/usr/bin/dclconfig
	mv $(CURDIR)/debian/tmp/usr/bin/dclconfig$(DCLVER) \
	  $(CURDIR)/debian/tmp/usr/bin/dclconfig
	$(FC) $(FFLAGS) $(CPPFLAGS) $(LDFLAGS) -shared -Wl,-soname,libf77dcl.so.7 \
	  -o $(CURDIR)/debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/libf77dcl.so.$(DCLVERNUM) \
	  `find $(CURDIR) -name \*.o` $(shell pkg-config gtk+-3.0 --libs)
	( cd $(CURDIR)/debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH) ; \
	  ln -s libf77dcl.so.$(DCLVERNUM) libf77dcl.so.7 )
	( cd $(CURDIR)/debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH) ; \
	  ln -s libf77dcl.so.$(DCLVERNUM) libf77dcl.so )

override_dh_auto_install-indep:
#	do nothing

override_dh_install-arch:
	dh_install -a --sourcedir=debian/tmp
	sed -i -e 's%-fdebug-prefix-map.*\.%%g ' \
	  $(CURDIR)/debian/libf77dcl-dev/usr/bin/dclconfig

override_dh_install-indep:
	dh_install -i --sourcedir=$(CURDIR)
	find $(CURDIR)/debian/dcl-f77-docs/ -name Makefile.win | xargs rm -f

override_dh_auto_clean:
	[ ! -f Mkinclude ] || $(MAKE) distclean
	dh_auto_clean
	rm -f $(CURDIR)/debian/libf77dcl*.triggers
	rm -f $(CURDIR)/lib/lib*.so
	rm -f $(CURDIR)/lib/lib*.so.*
	rm -f $(CURDIR)/src/misc1/fiolib/fcpack.f

override_dh_compress:
	dh_compress -X.png -X.f -X.dat

override_dh_installdocs:
	dh_installdocs -A README
