#!/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.

#include /usr/share/dpatch/dpatch.make

INSTALL=install

build: build-arch build-indep

# extract GIT hash from changelog
GIT_SHA=$(shell head -n1 debian/changelog|sed -e "s/^cc65.*\.\([0-9a-f]*\).*$$/\1/")

build-arch: build-stamp
build-indep: build-stamp

build-stamp: # patch
	dh_testdir

	# Add here commands to compile the package.
	$(MAKE) -s PREFIX=/usr BUILD_ID="Git $(GIT_SHA)" all doc

	touch build-stamp

clean: # unpatch
	dh_testdir
	dh_testroot
	rm -f build-stamp

	$(MAKE) clean

	dh_clean

install: DH_OPTIONS=
install: build
	dh_testdir
	dh_testroot
	dh_installdirs

	# make sure to have the INFO-DIR-SECTION in the info files
	chmod 755 debian/fixinfo
	debian/fixinfo info/*.info

	$(MAKE) -C src PREFIX=/usr DESTDIR=../debian/cc65 install
	$(MAKE) -C libsrc PREFIX=/usr DESTDIR=../debian/cc65-common install
	$(MAKE) -C doc PREFIX=/usr DESTDIR=../debian/cc65-doc DESTPACKAGE_SUFFIX=-doc install

	$(INSTALL) util/ca65html debian/cc65/usr/bin
#	cp -a samples/ debian/cc65-doc/usr/share/doc/cc65-doc

#	dh_install
#	dh_movefiles

# This single target is used to build all the packages, all at once, or
# one at a time. So keep in mind: any options passed to commands here will
# affect _all_ packages. Anything you want to only affect one package
# should be put in another target, such as the install target.
binary-common:
	dh_testdir
	dh_testroot
	dh_installchangelogs
	dh_installdocs
	dh_installexamples
	dh_installmenu
#	dh_installcatalogs
#	dh_installmime
#	dh_installinit
	dh_installman
	dh_installinfo
#	dh_installwm
#	dh_lintian
#	dh_bugfiles
#	dh_undocumented
	dh_strip
	dh_link
	dh_compress
	dh_fixperms
#	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# Build architecture independant packages using the common target.
binary-indep: build install
	$(MAKE) -f debian/rules DH_OPTIONS=-i binary-common

# Build architecture dependant packages using the common target.
binary-arch: build install
	$(MAKE) -f debian/rules DH_OPTIONS=-a binary-common
# Any other binary targets build just one binary package at a time.
binary-%: build install
	make -f debian/rules binary-common DH_OPTIONS=-p$*

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

