#!/usr/bin/make -f

# Build with gfortran only this release
export FC_DEFAULT=gfortran-15
export FC_OPTIONAL=


export DH_VERBOSE=1

# Hack until dh-dfortran fix in 0.70 
FPM_FFLAGS=$(shell dh_fortran get_env | grep FPM_FFLAGS | sed -e s/FPM_FFLAGS=// )
export FPM_FFLAGS

# Necessary to build shared libraries
export DEB_LDFLAGS_MAINT_APPEND=-fPIC

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

execute_after_dh_auto_clean:
	rm -fr doc/html

override_dh_auto_build:
	fpm build --compiler gfortran --profile release	
	ford ford.md

override_dh_auto_test:
	fpm test --compiler gfortran --profile release	

override_dh_fortran_lib:
	:

override_dh_auto_install:
	fpm install --compiler gfortran --profile release  --prefix debian/tmp/usr
	patchelf --set-soname libfortran-julienne.so.0 debian/tmp/usr/lib/libjulienne.so
	mv debian/tmp/usr/lib/libjulienne.so debian/tmp/usr/lib/libjulienne.so.0
	# Need to rename to avoid conflict
	mv debian/tmp/usr/bin/scaffold debian/tmp/usr/bin/fpm-scaffold
