#!/usr/bin/make -f
# 
# GNU copyright 1997 by Joey Hess.
#
# $Id: rules.in,v 1.7 2003/08/25 13:26:41 rdm Exp $
#
# Rules file for ROOT packages for Debian GNU/Linux 
#

# Uncomment this to turn on verbose mode. 
#export DH_VERBOSE=0

# This is the debhelper compatability version to use.
export DH_COMPAT=4

# This has to be exported to make some magic below work.
export DH_OPTIONS

# These are used for cross-compiling and for saving the configure script
# from having to guess our platform (since we know it already)
DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
ARCH		    =  $(shell case $(DEB_BUILD_GNU_TYPE) in \
			  *-linux) echo "linuxdeb" ;; \
			  *-hurd)  echo "hurddeb" ;; esac)
#
# Some utility variables 
#
# The packages:
#
# Order of the packages are important for when we move files around
#
BUILDPREFIX = $(shell pwd)/debian/tmp
ALLPKGS	    = @pkgs@
#
# Some notes about this target:
#
# * We build the full ROOT system here. 
# * See README.Debian for thoughts about the configure options. 
# * I've got a dual-processor machine, so I use -j3 for make
# * Uncomment the lines with "make changleog" to install the full
#   upstream changelog. This is only possible if you have CVS access
#   to the main repository at :pserver:cvs@root.cern.ch:/user/cvs 
#   (password is "cvs")
# 
build: build-stamp
build-stamp:
	dh_testdir

	case $(DEB_BUILD_GNU_TYPE) in \
	*-linux) arch="linuxdeb" ;; *-hurd) arch="hurddeb" ;; esac ; \
	    ./configure $$arch 					\
		--prefix=@prefix@				\
		--etcdir=@etcdir@ 				\
		--docdir=@docdir@				\
		--cintincdir=@prefix@/lib/root/cint		\
		--enable-table					\
		--enable-thread 				\
		--enable-shared 				\
		--enable-soversion 				\
		--disable-rpath                                 \
		--disable-afs 					\
		--disable-srp 					\
		--with-sys-iconpath=/usr/share/pixmaps		\
		--fontdir=/usr/share/fonts/truetype

	$(MAKE)
	$(MAKE) cintdlls
	#
	# If you have access to the CVS repository, you may want to 
	# uncomment the next line to make an upstream changelog
	#
	#$(MAKE) changelog

	touch build-stamp

#
# Some notes about this target:
#
# * We use the maintainer-clean target rather then the clean target,
#   since this is much more thourogh, and we really need a clean
#   source directory for the patches
# * We remove the Changelog file if it was created
#
clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp 

	-$(MAKE) distclean
	rm -rf bin lib include system.rootrc config/Makefile.config \
	   test/Makefile README/Changelog etc/system.rootrc

	dh_clean

#
# Some notes about this target:
#
# * We use the DESTDIR mechanism to install into the default build
#   directory debian/tmp 
# * If the Changelog file was generated, we install that along with
#   the rest of the documentation. This could be moved to main
#   Makefile 
# * We install INSTALL file along with the rest of the documentation,
#   'cause it contains some useful infromation on third party
#   software.  
# * We remove all the sub-directories CVS from the build directory, so
#   that we may have a clean installation. 
# * Particular in the CINT sub-package there are some problems with
#   file permissions, which we fix. This is things like header files
#   being executable, scripts not executable, and so on
# * A CINT source file has an interpretor line, puting to some
#   directory on Masa's own machine. This is removed.
# * Finally, we move the files into appropiate sub-package
#   directories. The order in which the fiels are moved is very
#   important, since in the base packages, we use wildcards and full
#   directories. 
#
install: DH_OPTIONS=
install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	$(MAKE) install DESTDIR=$(BUILDPREFIX)

	@if [ -f README/Changelog ] ; then \
	   cp README/Changelog $(BUILDPREFIX)@docdir@/ ; \
	fi

	# Remove, as Lintian complains about it. I used to install it, 
	# but since it was one of the few warnings left from Lintian, 
	# I thought I might as well remove it. 
	# cp README/INSTALL $(BUILDPREFIX)@docdir@/

	# Remove since lintian comlpains about dual license files
	rm $(BUILDPREFIX)@docdir@/LICENSE

	# Move the PROOF README file to a proper directory 
	mv $(BUILDPREFIX)@docdir@/README.PROOF \
		debian/root-daemon.README.Debian

	# Remove the CVS directories if present 
	find debian/tmp -name "CVS" | xargs rm -fr 
	find debian/tmp -name ".cvsignore" | xargs rm -fr 

	# Remove a bad magic line in CINT code. 
	sed 's|^#!.*||' \
	  < $(BUILDPREFIX)@prefix@/lib/root/cint/lib/snstream/length.cxx > foo
	mv foo $(BUILDPREFIX)@prefix@/lib/root/cint/lib/snstream/length.cxx

	# Fix some errouneous permissions 
	chmod 644 $(BUILDPREFIX)@prefix@/include/root/TFileIter.h \
		$(BUILDPREFIX)@prefix@/include/root/TDsKey.h
	chmod 755 $(BUILDPREFIX)@prefix@/lib/root/cint/lib/pthread/setup

	for i in $(ALLPKGS) ;    do dh_movefiles -p $$i ; done
	# First move for the arch-dependent packages, then for the 
	# arch-independet packages
	# dh_movefiles -a -i 

	# This is for alternatives registration, if one want's to install 
	# Richard Kreckels cint package next to ROOT
	mv debian/root-cint@prefix@/bin/cint \
		debian/root-cint@prefix@/bin/cint.root
	mv debian/root-cint@prefix@/bin/makecint \
		debian/root-cint@prefix@/bin/makecint.root
	mv debian/root-cint@prefix@/share/man/man1/cint.1 \
		debian/root-cint@prefix@/share/man/man1/cint.root.1
	mv debian/root-cint@prefix@/share/man/man1/makecint.1 \
		debian/root-cint@prefix@/share/man/man1/makecint.root.1

#	for i in $(METAPKGS) ;    do dh_movefiles -p $$i ; done
#	for i in $(FEATUREPKGS) ; do dh_movefiles -p $$i ; done
#	for i in $(CINTPKGS) ;    do dh_movefiles -p $$i ; done
#	for i in $(BASEPKGS) ;    do dh_movefiles -p $$i ; done

#
# Some notes about this target:
#
# * Build architecture-independent files here.
# * Pass -i to all debhelper commands in this target to reduce
#   clutter. 
# * Note that we really don't need that many things here. 
#
binary-indep: DH_OPTIONS=-i
binary-indep: build install
	dh_testdir
	dh_testroot
	dh_installdocs
	# dh_installexamples
	dh_installmenu
	# dh_installemacsen
	# dh_installpam
	dh_installmime 
	# dh_installinit
	dh_installman
	# dh_installinfo
	dh_undocumented
	dh_installchangelogs 
	dh_link
	dh_compress
	dh_fixperms
	dh_makeshlibs
	dh_installdeb
	# dh_perl
	dh_gencontrol
	dh_md5sums
	dh_builddeb

#
# Some notes about this target:
#
# * Build architecture-dependent files here.
# * Pass -a to all debhelper commands in this target to reduce
#   clutter. 
# * Please notice that we make the shared library dependency with the
#   --exclude=bin/cint flag. This is because the root-cint package both
#   provides and uses the libCint.so library. Hence, if we let the
#   cint program from generating shared library dependencies we would
#   end up with root-cint depending on it self, which ofcourse is bad. 
#
binary-arch: DH_OPTIONS=-a
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installdocs
	# dh_installexamples
	dh_installmenu
	# dh_installlogrotate
	# dh_installemacsen
	# dh_installpam
	dh_installmime
	# dh_installinit
	# dh_installcron
	dh_installman
	# dh_installinfo
	dh_undocumented
	dh_installchangelogs 
	dh_strip
	dh_link
	dh_compress
	dh_fixperms
	dh_makeshlibs
	dh_installdeb
	# dh_perl
	dh_shlibdeps 			\
	  --exclude=bin/cint 	\
	  -ldebian/libroot/@prefix@/lib/root:debian/root-cint/@prefix@/lib/root
	dh_gencontrol
	dh_md5sums
	dh_builddeb

#
# Some notes about this target:
#
binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install

#
# $Log: rules.in,v $
# Revision 1.7  2003/08/25 13:26:41  rdm
# fix cintddls to cintdlls and remove -j2 option.
#
# Revision 1.6  2003/08/19 09:56:56  rdm
# some corrections in package build files and install and readme notes. By
# Christian Holm and Denis Stepanov.
#
# Revision 1.5  2003/02/24 11:32:27  rdm
# change --with-ttf-fontdir to --fontdir.
#
# Revision 1.4  2002/07/31 20:45:10  rdm
# modified files for Debian and RedHat packaging. By Christian Holm.
#
# Revision 1.3  2002/05/14 15:45:28  rdm
# several Debian related packaging and build changes. By Christian Holm.
#
# Revision 1.2  2002/01/20 14:23:52  rdm
# Mega patch by Christian Holm concerning the configure, build and
# Debian and RedHat packaging scripts. The configure script has been
# rationalized (introduction of two shell functions to find package
# headers and libraries). Extensive update of the INSTALL writeup,
# including description of all new packages (SapDB, PgSql, etc.).
# More options to the root-config script. Man page for memprobe.
# Big overhaul of the Debian and RedHat packaging scripts, supporting
# the new libraries.
#
# Revision 1.1  2001/04/23 14:09:55  rdm
# part of the debian ad redhat package system.
#
#
