#! /usr/bin/make -f
# -*- makefile -*-
package=whitedune
#export DH_VERBOSE=1

DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

CFLAGS?=-Wall -g

tmpdir = $(CURDIR)/debian/tmp
DESTDIR?=$(CURDIR)/debian/${package}/usr

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
else
	CFLAGS += -O2
endif

config.status: configure
	dh_testdir
	CFLAGS="$(CFLAGS)" LDFLAGS="-Wl,-z,defs" \
	 ./configure \
 --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) \
 --prefix=/usr --mandir=/usr/share/man  --infodir=/usr/share/info \
 --without-usrlocalinclude \
 --without-usrlocallib \


configure:
	-${MAKE} bootstrap
	autoconf
ifneq "$(wildcard /usr/share/misc/config.sub)" ""
	cp -f /usr/share/misc/config.sub config.sub
endif
ifneq "$(wildcard /usr/share/misc/config.guess)" ""
	cp -f /usr/share/misc/config.guess config.guess
endif



build: build-stamp

build-stamp:  config.status
	dh_testdir
	$(MAKE)
#	cp man/dune.1 debian/
	sed -e 's/dune/${package}/g' < ./man/dune.1 \
	 | sed -e 's/DUNE/WHITEDUNE/g' > debian/${package}.1
	cd debian && ln -fs ${package}.1 dune.1
	touch $@

generated_files?=\
 lex.yy.c \
 debian/dune.1 debian/${package}.1 debian/dune \
 configure \
 docs/export_example_c++/Makefile docs/export_example_c/Makefile \
 docs/export_example_java/Makefile \
 src/Makefile \
 src/SDLjoystick/Makefile \
 src/config.h \
 src/resource.c \
 src/swt/motif/Makefile src/swt/rc/Makefile src/swt/tests/Makefile \
 #}

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp 
	$(MAKE) clean realclean distclean  || echo "# $@"
	rm -f ${generated_files}
	dh_clean 

install: build
	dh_testdir
	dh_testroot
	dh_clean -k 
	dh_installdirs 
	install -d ${DESTDIR}/bin
	install -s bin/dune ${DESTDIR}/bin/${package}
	install -d ${DESTDIR}/share/pixmaps/
	install -m 644 ./desktop/fvwm2/mini-dune.xpm \
	  ${DESTDIR}/share/pixmaps/${package}.xpm

# Build architecture-independent files here.
install-indep:
	echo "$@"
#	mkdir -p ${CURDIR}/debian/${package}-doc/usr/share/doc/${package}-doc/
#	cp -rf docs/* \
#	 ${CURDIR}/debian/${package}-doc/usr/share/doc/${package}-doc/

# find docs -type f > debian/${package}-doc.docs
binary-indep: install-indep
	dh_testdir -i
	dh_testroot -i
	dh_install -i  # --sourcedir=$(tmpdir)
	dh_installdocs -i
	dh_installexamples -i
	dh_installchangelogs -i 
	dh_link -i
	dh_compress -i
	dh_fixperms -i
	dh_installdeb -i
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i

binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs 
	dh_installdocs
	dh_installexamples
	dh_install
	dh_installmenu
	dh_installmime
	dh_installman ./man/dune.1 ./debian/${package}.1
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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

#eof "$Id: rules -- rzr $"
