#!/usr/bin/make -f
# Made with the aid of debmake, by Christoph Lameter,
# based on the sample debian/rules file for GNU hello by Ian Jackson.

package=arpack

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

build:
	$(checkdir)

	-mkdir shared static
#
# First build the shared library
#
	cd shared ; \
	    $(MAKE) -f ../SRC/Makefile VPATH="../SRC" srcdir="../SRC" FFLAGS="-O2 -fPIC -pipe" single double complex complex16; \
	    $(MAKE) -f ../UTIL/Makefile VPATH="../UTIL" srcdir="../UTIL" FFLAGS="-O2 -fPIC -pipe" single double complex complex16; \
	    gcc -shared -Wl,-soname,lib$(package).so.$(version_major) -o lib$(package).so.$(version) `ls *.o`

# Build the static library (it does not need Position Independent Code,
# which reserves one register; thus, without -fPIC we get more efficient
# code).
#
	cd static ; \
	$(MAKE) -f ../SRC/Makefile VPATH="../SRC" srcdir="../SRC" FFLAGS="-O2 -pipe" LDFLAGS="-s" all; \
	$(MAKE) -f ../UTIL/Makefile VPATH="../UTIL" srcdir="../UTIL" FFLAGS="-O2 -pipe" LDFLAGS="-s" all; \
	ar rv lib$(package).a `ls *.o`; \
	ranlib lib$(package).a 
	touch build

clean:
	$(checkdir)
	-rm -rf static shared
	-rm -f build
	-$(MAKE) clean
	-rm -f `find . -name "*~"`
	-rm -rf debian/tmp `find debian/* -type d ! -name CVS` debian/files* core
	-rm -f debian/*substvars

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

binary-arch: checkroot build
	$(checkdir)
	-rm -rf debian/tmp `find debian/* -type d ! -name CVS`
	install -d debian/tmp
	cd debian/tmp && install -d `cat ../dirs`

	install -m644 static/lib$(package).a debian/tmp/usr/lib/
	install -m644 shared/lib$(package).so.$(version) debian/tmp/usr/lib
	( cd debian/tmp/usr/lib && ln -sf lib$(package).so.$(version) lib$(package).so.$(version_major) )
	( cd debian/tmp/usr/lib && ln -sf lib$(package).so.$(version) lib$(package).so )

	$(MAKE) install DESTDIR=`pwd`/debian/tmp
#	debstd -m README debian/copyright EXAMPLES/
	dh_installdocs -parpack2
	dh_movefiles -a
	dh_installdocs -parpack2-dev DOCUMENTS/* ug.ps
	dh_installexamples -parpack2-dev EXAMPLES/* 
	dh_installchangelogs 
	dh_link
	dh_strip
	dh_compress -Xpdf
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

define checkdir
	test -f debian/rules
endef

binary: binary-indep binary-arch

checkroot:
	$(checkdir)
	test root = "`whoami`"

.PHONY: binary binary-arch binary-indep clean checkroot
