#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

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

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

	touch configure-stamp

build: build-stamp

build-stamp: configure-stamp  
	dh_testdir

	# Add here commands to compile the package.
	#docbook-to-man debian/qmc2.sgml > qmc2.1

	touch $@

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

	# Add here commands to clean up after the build process.

	dh_clean 

install: build

qmc2-sdlume:
	${MAKE} DISTCFG=1 EMULATOR=SDLUME PREFIX=/usr/
	${MAKE} DISTCFG=1 EMULATOR=SDLUME PREFIX=/usr/ DESTDIR=${CURDIR}/debian/qmc2-sdlume install
	${MAKE} DISTCFG=1 EMULATOR=SDLUME PREFIX=/usr/ man

	# Remove shared resources and runonce application
	rm -rf $(CURDIR)/debian/qmc2-sdlume/usr/bin/qmc2
	rm -rf $(CURDIR)/debian/qmc2-sdlume/usr/bin/runonce
	rm -rf $(CURDIR)/debian/qmc2-sdlume/usr/share/qmc2
	rm -rf $(CURDIR)/debian/qmc2-sdlume/etc
	rm -rf $(CURDIR)/debian/qmc2-sdlume/usr/bin/runonce

	# install manpage
	mkdir -p $(CURDIR)/debian/qmc2-sdlume/usr/share/man/man6
	cp -d $(CURDIR)/data/doc/man/qmc2-sdlume.6.gz $(CURDIR)/debian/qmc2-sdlume/usr/share/man/man6/

	dh_testdir
	dh_testroot
	dh_installdirs -p$@
	dh_installdocs -p$@
	dh_installchangelogs -p$@
	dh_installexamples -p$@
	dh_installman -p$@
	dh_link -p$@
	dh_strip -p$@
	dh_compress -p$@
	dh_fixperms -p$@
	dh_installdeb -p$@
	dh_shlibdeps -p$@
	dh_gencontrol -p$@
	dh_md5sums -p$@
	dh_builddeb -p$@

qmc2-sdlmess:
	$(MAKE) DISTCFG=1 clean
	$(MAKE) DISTCFG=1 man-clean
	$(MAKE) DISTCFG=1 EMULATOR=SDLMESS PREFIX=/usr/
	$(MAKE) DISTCFG=1 EMULATOR=SDLMESS PREFIX=/usr/ DESTDIR=$(CURDIR)/debian/qmc2-sdlmess install
	$(MAKE) DISTCFG=1 EMULATOR=SDLMESS PREFIX=/usr/ man

	# Remove shared resources and runonce application
	rm -rf $(CURDIR)/debian/qmc2-sdlmess/usr/bin/qmc2
	rm -rf $(CURDIR)/debian/qmc2-sdlmess/usr/bin/runonce
	rm -rf $(CURDIR)/debian/qmc2-sdlmess/usr/share/qmc2
	rm -rf $(CURDIR)/debian/qmc2-sdlmess/etc
	rm -rf $(CURDIR)/debian/qmc2-sdlmess/usr/bin/runonce
	
	# install manpage
	mkdir -p $(CURDIR)/debian/qmc2-sdlmess/usr/share/man/man6
	cp -d $(CURDIR)/data/doc/man/qmc2-sdlmess.6.gz $(CURDIR)/debian/qmc2-sdlmess/usr/share/man/man6/

	dh_testdir
	dh_testroot
	dh_installdirs -p$@
	dh_installdocs -p$@
	dh_installchangelogs -p$@
	dh_installexamples -p$@
	dh_installman -p$@
	dh_link -p$@
	dh_strip -p$@
	dh_compress -p$@
	dh_fixperms -p$@
	dh_installdeb -p$@
	dh_shlibdeps -p$@
	dh_gencontrol -p$@
	dh_md5sums -p$@
	dh_builddeb -p$@

qmc2-sdlmame:
	$(MAKE) DISTCFG=1 clean
	$(MAKE) DISTCFG=1 man-clean
	${MAKE} DISTCFG=1 EMULATOR=SDLMAME PREFIX=/usr/
	${MAKE} DISTCFG=1 EMULATOR=SDLMAME PREFIX=/usr/ DESTDIR=${CURDIR}/debian/qmc2-sdlmame install
	${MAKE} DISTCFG=1 EMULATOR=SDLMAME PREFIX=/usr/ man

	# Remove QMC2 link
	rm -rf $(CURDIR)/debian/qmc2-sdlmame/usr/bin/qmc2

	# Move shared resouces and config file to qmc2-data package
	mkdir -p $(CURDIR)/debian/qmc2-data/usr/share/
	mkdir -p $(CURDIR)/debian/qmc2-data/etc
	mv $(CURDIR)/debian/qmc2-sdlmame/usr/share/qmc2 $(CURDIR)/debian/qmc2-data/usr/share/
	mv $(CURDIR)/debian/qmc2-sdlmame/etc/qmc2 $(CURDIR)/debian/qmc2-data/etc/
	rm -rf $(CURDIR)/debian/qmc2-sdlmame/etc

	# create changelog files
	mkdir -p $(CURDIR)/debian/qmc2-data/usr/share/doc/qmc2
	w3m -dump $(CURDIR)/debian/qmc2-data/usr/share/qmc2/doc/html/us/changes.html > $(CURDIR)/debian/qmc2-data/usr/share/doc/qmc2/changelog
	gzip -9 $(CURDIR)/debian/qmc2-data/usr/share/doc/qmc2/changelog
	
	# Move runonce application to qmc2-runonce package
	#mkdir -p $(CURDIR)/debian/qmc2-runonce/usr/bin
	#mv $(CURDIR)/debian/qmc2-sdlmame/usr/bin/runonce $(CURDIR)/debian/qmc2-runonce/usr/bin/
	
	# install manpage
	mkdir -p $(CURDIR)/debian/qmc2-sdlmame/usr/share/man/man6
	cp -d $(CURDIR)/data/doc/man/qmc2-sdlmame.6.gz $(CURDIR)/debian/qmc2-sdlmame/usr/share/man/man6/

	dh_testdir
	dh_testroot
	dh_installdirs -p$@
	dh_installdocs -p$@
	dh_installchangelogs -p$@
	dh_installexamples -p$@
	dh_installman -p$@
	dh_link -p$@
	dh_strip -p$@
	dh_compress -p$@
	dh_fixperms -p$@
	dh_installdeb -p$@
	dh_shlibdeps -p$@
	dh_gencontrol -p$@
	dh_md5sums -p$@
	dh_builddeb -p$@

qmc2-arcade:
	$(MAKE) DISTCFG=1 clean
	$(MAKE) DISTCFG=1 man-clean
	${MAKE} DISTCFG=1 PREFIX=/usr/ arcade
	mkdir -p ${CURDIR}/debian/qmc2-arcade/usr/bin
	${MAKE} DISTCFG=1 PREFIX=/usr/ DESTDIR=${CURDIR}/debian/qmc2-arcade arcade-install
	$(MAKE) DISTCFG=1 PREFIX=/usr/ man

	# Remove shared resources
	rm -rf $(CURDIR)/debian/qmc2-arcade/usr/share/qmc2
	
	dh_testdir
	dh_testroot
	dh_installdirs -p$@
	dh_installdocs -p$@
	dh_installchangelogs -p$@
	dh_installexamples -p$@
	dh_installman -p$@
	dh_link -p$@
	dh_strip -p$@
	dh_compress -p$@
	dh_fixperms -p$@
	dh_installdeb -p$@
	dh_shlibdeps -p$@
	dh_gencontrol -p$@
	dh_md5sums -p$@
	dh_builddeb -p$@

qchdman:
	$(MAKE) DISTCFG=1 clean
	${MAKE} DISTCFG=1 PREFIX=/usr/ man-clean
	${MAKE} DISTCFG=1 PREFIX=/usr/ tools
	mkdir -p ${CURDIR}/debian/qchdman/usr/bin
	${MAKE} DISTCFG=1 PREFIX=/usr/ DESTDIR=${CURDIR}/debian/qchdman tools-install
	${MAKE} DISTCFG=1 PREFIX=/usr/ man

	# Remove shared resources
	rm -rf $(CURDIR)/debian/qchdman/usr/share/qmc2
	
	dh_testdir
	dh_testroot
	dh_installdirs -p$@
	dh_installdocs -p$@
	dh_installchangelogs -p$@
	dh_installexamples -p$@
	dh_installman -p$@
	dh_link -p$@
	dh_strip -p$@
	dh_compress -p$@
	dh_fixperms -p$@
	dh_installdeb -p$@
	dh_shlibdeps -p$@
	dh_gencontrol -p$@
	dh_md5sums -p$@
	dh_builddeb -p$@

qmc2-runonce:
	dh_testdir
	dh_testroot
	dh_installdirs -p$@
	dh_installdocs -p$@
	dh_installchangelogs -p$@
	dh_installexamples -p$@
	dh_installman -p$@
	dh_link -p$@
	dh_strip -p$@
	dh_compress -p$@
	dh_fixperms -p$@
	dh_installdeb -p$@
	dh_shlibdeps -p$@
	dh_gencontrol -p$@
	dh_md5sums -p$@
	dh_builddeb -p$@

qmc2-data:
	dh_testdir
	dh_testroot
	dh_installdirs -p$@
	dh_installdocs -p$@
	dh_installchangelogs -p$@
	dh_installexamples -p$@
	dh_installman -p$@
	dh_link -p$@
	dh_strip -p$@
	dh_compress -p$@
	dh_fixperms -p$@
	dh_installdeb -p$@
	dh_shlibdeps -p$@
	dh_gencontrol -p$@
	dh_md5sums -p$@
	dh_builddeb -p$@

build-indep:

build-arch:

binary-indep: qmc2-data

binary-arch: qmc2-sdlmame qmc2-arcade qchdman

binary: clean binary-arch binary-indep

.PHONY: build clean binary-indep binary-arch binary install configure qmc2-sdlmame qmc2-arcade qchdman
