#!/usr/bin/make -f

package=cln

version=$(shell expr `pwd` : '.*-\([0-9.]*\)')
version_major=$(shell expr `pwd` : '.*-\([0-9]*\).[0-9.]*')

ifneq (,$(filter $(ARCH), arm armel))
    export CFLAGS = -mfpu=vfp -mfloat-abi=softfp
    export CPPFLAGS = -mfpu=vfp -mfloat-abi=softfp
    export CXXFLAGS = -mfpu=vfp -mfloat-abi=softfp
endif

build:
	dh_testdir
	./configure --prefix=/usr `dpkg-architecture -qDEB_HOST_GNU_TYPE`
	# * ARM: CLN's assembler support is not working properly (it was only
	#   'theoretically' ported by copying from code that had once worked in
	#   CLISP under BSD). Same for armel.
	# * HPPA: Assembler support is not working properly.  Somebody needs to
	#   investigate but currently I don't have the inspiration for fixing
	#   things on exotic architectures.
	# * SPARC: With some versions of GCC, there are apparently problems in
	#   passing return values in %g1.
	case `dpkg-architecture -qDEB_HOST_ARCH` in \
	  arm|armel|hppa|sparc) \
	    ${MAKE} CPPFLAGS="-DNO_ASM" CXXFLAGS="-O2";; \
	  *) \
	    ${MAKE} CXXFLAGS="-O2";; \
	esac
	touch build

clean:
	dh_testdir
	dh_clean
	-rm -f build
	-${MAKE} distclean
	-rm -f `find . -name "*~"`
	-rm -rf debian/tmp `find debian/* -type d ! -name CVS` debian/files* core
	-rm -rf debian/.libs debian/*.o
	-rm -f debian/*substvars

binary-indep: build
	dh_testdir
	dh_testroot
# There are no architecture-independent files to be uploaded
# generated by this package.  If there were any they would be
# made here.

binary-arch: build
	dh_testdir
	dh_testroot
	dh_installdirs
	# Let's see what the buildd logs say...
	-${MAKE} check
	${MAKE} install prefix=$(CURDIR)/debian/tmp/usr includedir=$(CURDIR)/debian/libcln-dev/usr/include bindir=$(CURDIR)/debian/libcln-dev/usr/bin mandir=$(CURDIR)/debian/libcln-dev/usr/share/man infodir=$(CURDIR)/debian/libcln-dev/usr/share/info datadir=$(CURDIR)/debian/libcln-dev/usr/share htmldir=$(CURDIR)/debian/libcln-dev/usr/share/doc/libcln-dev/html dvidir=$(CURDIR)/debian/libcln-dev/usr/share/doc/libcln-dev
	# This installs into libdir, but we must not set libdir because it affects the .la file:
	mv $(CURDIR)/debian/tmp/usr/lib/pkgconfig/* $(CURDIR)/debian/libcln-dev/usr/lib/pkgconfig/
	dh_installdocs ChangeLog NEWS README TODO
	dh_installexamples -plibcln-dev $(CURDIR)/examples/contfrac.cc $(CURDIR)/examples/e.cc $(CURDIR)/examples/fibonacci.cc $(CURDIR)/examples/legendre.cc $(CURDIR)/examples/lucaslehmer.cc $(CURDIR)/examples/nextprime.cc $(CURDIR)/examples/perfnum.cc
	/bin/sh libtool  --mode=install /usr/bin/install -c examples/pi $(CURDIR)/debian/pi/usr/bin/pi
	/usr/bin/install -m 644 examples/pi.1 $(CURDIR)/debian/pi/usr/share/man/man1/pi.1
	/usr/bin/install -m 644 debian/libcln-dev.doc-base $(CURDIR)/debian/libcln-dev/usr/share/doc-base/libcln-dev
	# Note: CLN's doc/Makefile should honor psdir, just as it does honor dvidir:
	/usr/bin/install -m 644 doc/cln.ps $(CURDIR)/debian/libcln-dev/usr/share/doc/libcln-dev
	dh_installchangelogs
	dh_install --sourcedir=debian/tmp
	dh_strip
	dh_compress
	dh_fixperms
	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch

.PHONY: binary binary-arch binary-indep clean
