#!/usr/bin/make -f

export FC_DEFAULT=gfortran
export FC_OPTIONAL=flang lfortran

export DH_NO_ORIG_LIBS=1

# Necessary to build shared libraries
export DEB_LDFLAGS_MAINT_APPEND=-fPIC

export DH_VERBOSE=1

export DEB_BUILD_PROFILES=stage1

# Need a bootstrap version for fpm full build
ifneq ($(filter stage1,$(DEB_BUILD_PROFILES)),)
execute_before_dh_auto_clean:
	- mv fpm.toml.orig fpm.toml

execute_before_dh_auto_configure:
	cp fpm.toml fpm.toml.orig
	cp debian/fpm.toml.bootstrap fpm.toml
endif

# The magic debhelper  rule
%:
	dh $@ --with fortran --buildsystem=fortran 

execute_after_dh_auto_clean:
	rm -rf obj-* docs/man3 docs/cat3 docs/*gz

execute_after_dh_auto_build:
	(cd docs; unzip manpages.zip)

execute_after_dh_fixperms:
	chmod 644 debian/libfortran-cli2-dev/usr/share/doc/libfortran-cli2-dev/examples/demos/*.f90
	chmod 644 debian/libfortran-cli2-dev/usr/share/doc/libfortran-cli2-dev/examples/*.f90
	chmod 644 debian/libfortran-cli2-dev/usr/share/doc/libfortran-cli2-dev/examples/one.rsp
