#!/usr/bin/make -f
# Sample debian/rules that uses debhelper. 
# GNU copyright 1997 by Joey Hess.
#
# This version is for a hypothetical package that builds an
# architecture-dependant package, as well as an architecture-independent
# package.

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

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

configure: configure-stamp
configure-stamp:
	dh_testdir
	# Add here commands to configure the package.

	touch configure-stamp

build: configure-stamp build-stamp
build-stamp:
	dh_testdir

	# Add here commands to compile the package.

        # Extract the programs, libs and manpages from the tar files
	# Note, that a openmosix patched kernel is kept in /tmp/linux before
	# compilation, so that the correct header files are found.
	$(MAKE) -C src DESTDIR=$(CURDIR)/debian/openmosix

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp

	# Add here commands to clean up after the build process.
	$(MAKE) -C src clean

	# Clean the copies of manpages 
	rm -f src/mosrun/*.1

	dh_clean

install: DH_OPTIONS=
install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs 

	# Add here commands to install the package into debian/openmosix.
	$(MAKE) -C src install DESTDIR=$(CURDIR)/debian/openmosix

	# Install /etc/default/openmosix
	install -m 0644 ./etc_default_openmosix $(CURDIR)/debian/openmosix/etc/default/openmosix

	# Copy a template openmosix.map
	install -m 0644 ./openmosix.map $(CURDIR)/debian/openmosix/etc/openmosix.map 

	# Remove all manpages. They are handled with dh_installman
	rm -fr $(CURDIR)/debian/openmosix/man

	# Copy the missing manpages to mosrun.
	( cd ./src/mosrun && \
	  for i in cpujob fastdecay iojob nodecay nomig \
                   runhome runon slowdecay; \
                do cp mosrun.1 $$i.1; \
          done  )

	# Install include files and static library in correct place
	mv $(CURDIR)/debian/openmosix/lib/libmos.* $(CURDIR)/debian/openmosix/usr/lib/
	(cd $(CURDIR)/debian/openmosix/usr/lib && ln libmos.so libmos.so.0 -s)
	mv $(CURDIR)/debian/openmosix/include $(CURDIR)/debian/openmosix/usr/include/openmosix/

        # Install an update-cluster file.
	# install -m 0744 openmosix.updatelist $(CURDIR)/debian/openmosix/usr/lib/update-cluster/openmosix.updatelist

# Build architecture-independent files here.
# Pass -i to all debhelper commands in this target to reduce clutter.
binary-indep: 

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir 
	dh_testroot 
	dh_movefiles -popenmosix-dev --sourcedir=./debian/openmosix 
	dh_installdebconf 
	dh_installdocs 
	dh_installinit -r -- defaults 90 10
#	dh_installcron 
	dh_installman  
	dh_installkpatches 
#	dh_installinfo 
	dh_undocumented -a fixvfork.sh.1 mtune.1 prep_tune.1 tune_kernel.1 tunepass.1
	dh_installchangelogs Changelog
	dh_strip 
#	dh_link 
	dh_compress 
	dh_fixperms 
	dh_makeshlibs 
	dh_installdeb 
#	dh_perl 
	dh_shlibdeps 
	dh_gencontrol 
	dh_md5sums 
	dh_builddeb 

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install configure
