#!/usr/bin/make -f

include /usr/share/cdbs/1/rules/debhelper.mk
# include /usr/share/cdbs/1/rules/simple-patchsys.mk
# include /usr/share/cdbs/1/rules/patchsys-quilt.mk

CFLAGS += -fPIC

DEB_MAKE_CHECK_TARGET := check
DEB_MAKE_CLEAN_TARGET := clean distclean maintainer-clean

# Compile into the shlib all but certain duplicated object files

clean::
	$(MAKE) ARCH=linux CNAME=_gfortran clean
	rm -f libemos.a libemosR64.a debian/libemos*.so.* 
	rm -f .r64 .emos 
	rm -f bufrdc/*.o
	find bufrtables -type l -exec rm {} \;

build:
	autoreconf -if
	./configure
	( cd gribex && ln -sf ../config.h config.h )
	# FIXME: Need to edit TABLE_PATH as per build_library
	echo debian/libemos1/usr/share > .emos
	# First build libemos.a
	$(MAKE) ARCH=linux CNAME=_gfortran R64= clean all
	# Then rebuild pic for objects ...
	$(MAKE) ARCH=linux CNAME=_gfortran+pic R64= clean all
	# Link them into libemos.so
	$(MAKE) -f debian/build-shlib R64=
	# And repeat for 64-bit reals.
	$(MAKE) ARCH=linux CNAME=_gfortran R64=R64 clean all 
	$(MAKE) ARCH=linux CNAME=_gfortran+pic  R64=R64 clean all 
	$(MAKE) -f debian/build-shlib R64=R64

binary-install/libemos-data::
	echo "" > .r64
	echo "debian/libemos-data/usr/share/emos" > .emos
	./install
	find debian/libemos-data/usr/share -type f -exec chmod 644 {} \;
	rm debian/libemos-data/usr/share/emos/libemos.a

binary-install/libemos-dev::
	make -C pkgconfig install
	chmod a-x debian/libemos-dev/usr/share/doc/libemos-dev/examples/*/*

# Store build information
common-binary-post-install-arch common-binary-post-install-indep::
	dh_buildinfo
