#!/usr/bin/make -f

######################################################################
# BUILD NOTES
#
# ifupdown's written in litprog using noweb. noweb is written in icon.
# icon isn't as portable as one might hope (it needs to have bits recoded
# for each arch and OS it's ported to. ugh).
#
# So. The "upstream" source is made to not include any of the generated
# files. That's neat and tidy. If you want to modify anything, you edit
# the .nw file.
#
# Once you've done all the Debian changes, you run debian/rules binary,
# and get all the .c files and such updated. Once you're done, you
# run debian/rules clean, which leaves the generated .c files around
# for porters. You then generate a .diff.gz, and all should be well.
######################################################################

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

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

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

build: configure
	dh_testdir

	# Add here commands to compile the package.
	if [ -x /usr/bin/noweb ]; then \
	  $(MAKE) clobber; \
	else \
	  chmod a+rx defn2c.pl defn2man.pl makecdep.sh makenwdep.sh; \
	fi
	$(MAKE)

test: build
	dh_testdir

	# Add here commands to test the package works.
	chmod a+rx debian/testbuild
	@echo running debian/testbuild
	@if ! debian/testbuild; then \
	     echo '=================================================='; \
	     echo 'AUTOMATIC TESTS FAILED -- Something built wrong or'; \
	     echo 'there is a bug in the code!!! Either way something'; \
	     echo 'is completely screwed up!!! File a bug!'; \
	     echo ''; \
	     echo 'Aborting build.'; \
	     echo '=================================================='; \
	     exit 1; \
	fi

clean:
	dh_testdir
	dh_testroot

	# Add here commands to clean up after the build process
	rm -rf tests/
	-$(MAKE) clean

	dh_clean

install: build test
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	# Add here commands to install the package into debian/tmp.
	$(MAKE) install BASEDIR=`pwd`/debian/tmp

	for eg in examples/*; do \
	    install -o root -g root -m 644 $$eg \
		debian/tmp/usr/share/doc/ifupdown/$$eg; \
	done
	install -o root -g root -m 755 debian/upgrade-from-0.5.x.pl \
		debian/tmp/usr/share/ifupdown/

# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.

# Build architecture-dependent files here.
binary-arch: build install
#	dh_testversion
	dh_testdir
	dh_testroot
	dh_installdebconf	
	dh_installdocs
	dh_installexamples
	dh_installmenu
#	dh_installemacsen
#	dh_installpam
#	dh_installinit -r --init-script=ifupdown -- start 39 S .
#	    ^--- is a piece of junk
	install -o root -g root -m 755 debian/ifupdown.init debian/tmp/etc/init.d/ifupdown
	dh_installcron
#	dh_installmanpages
	install -o root -g root -m 644 interfaces.5 debian/tmp/usr/share/man/man5/interfaces.5
	install -o root -g root -m 644 ifup.8 debian/tmp/usr/share/man/man8/ifup.8
	ln -s ifup.8 debian/tmp/usr/share/man/man8/ifdown.8
	dh_installinfo
#	dh_undocumented
	dh_installchangelogs ChangeLog
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	# You may want to make some executables suid here.
	dh_suidregister
#	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
