#!/usr/bin/make -f
# Based on sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

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

CFLAGS = -Wall -Wno-deprecated -g

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
	LDFLAGS += -O0
else
	CFLAGS += -O2
	LDFLAGS += -O2
endif
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
	INSTALL_PROGRAM += -s
	IFLAGS += -s
endif
COMPILER_FLAGS= CFLAGS="$(CFLAGS)"

#configure: configure-stamp
#configure-stamp:
#	dh_testdir
#	# Nothing to do.
#	touch configure-stamp


build: build-arch build-indep

build-arch: build-arch-stamp
build-arch-stamp: # configure-stamp 
	dh_testdir
	
	# Add here commands to compile the arch part of the package.
	$(MAKE) -C ae_fspanel-1.0 CFLAGS="$(CFLAGS)" C_FLAGS="-DNOSTDLIB -DHAVE_XPM -Wall -I/usr/X11R6/include" LDFLAGS="$(LDFLAGS)" L_FLAGS="-Xlinker -L/usr/X11R6/lib -lX11 -lXpm"
	$(MAKE) -C appbar-1.0 $(COMPILER_FLAGS)
	$(MAKE) -C setrootimage-1.0 $(COMPILER_FLAGS)
	$(MAKE) -C xsession $(COMPILER_FLAGS)

	cp ae_fspanel-1.0/README README.aewm++_fspanel
	cp ae_fspanel-1.0/Changelog Changelog.aewm++_fspanel
	cp appbar-1.0/README README.aewm++_appbar
	cp appbar-1.0/Changelog Changelog.aewm++_appbar
	cp setrootimage-1.0/README README.aewm++_setrootimage
	cp setrootimage-1.0/Changelog Changelog.aewm++_setrootimage
	cp xsession/README README.aewm++_xsession

	touch build-arch-stamp

build-indep: build-indep-stamp
build-indep-stamp: # configure-stamp 
	# Nothing to do.

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

	# clean up after the build process
	$(MAKE) -C ae_fspanel-1.0 clean
	$(MAKE) -C appbar-1.0 clean
	$(MAKE) -C setrootimage-1.0 clean
	$(MAKE) -C xsession clean
	
	rm -f README.aewm++_fspanel Changelog.aewm++_fspanel
	rm -f README.aewm++_appbar Changelog.aewm++_appbar
	rm -f README.aewm++_setrootimage Changelog.aewm++_setrootimage
	rm -f README.aewm++_xsession

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs usr/bin usr/share/doc/aewm++-goodies

	# install the arch part of the package into debian/tmp.
	$(MAKE) -C ae_fspanel-1.0 install \
		DESTDIR=$(CURDIR)/debian/aewm++-goodies
	$(MAKE) -C appbar-1.0 install \
		DESTDIR=$(CURDIR)/debian/aewm++-goodies
	$(MAKE) -C setrootimage-1.0 install \
		DESTDIR=$(CURDIR)/debian/aewm++-goodies
	$(MAKE) -C xsession install \
		DESTDIR=$(CURDIR)/debian/aewm++-goodies IFLAGS=$(IFLAGS)

	dh_install

binary-indep: build install
	# Nothing to do.

# Build architecture-dependent files
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installdocs \
		README.aewm++_fspanel \
		README.aewm++_appbar \
		README.aewm++_setrootimage \
		README.aewm++_xsession
	dh_installchangelogs
	# dh_installchangelogs can't do multiple changelogs
	install -m 644 \
		Changelog.aewm++_fspanel \
		Changelog.aewm++_appbar \
		Changelog.aewm++_setrootimage \
		$(CURDIR)/debian/aewm++-goodies/usr/share/doc/aewm++-goodies
	gzip -9n $(CURDIR)/debian/aewm++-goodies/usr/share/doc/aewm++-goodies/Changelog.aewm++_fspanel
	gzip -9n $(CURDIR)/debian/aewm++-goodies/usr/share/doc/aewm++-goodies/Changelog.aewm++_appbar
	gzip -9n $(CURDIR)/debian/aewm++-goodies/usr/share/doc/aewm++-goodies/Changelog.aewm++_setrootimage
	dh_installexamples \
		appbar-1.0/appbar.rc
	dh_installmenu
	dh_installman \
		debian/aewm++_fspanel.1 \
		debian/aewm++_appbar.1 \
		debian/aewm++_setrootimage.1 \
		debian/aewm++_xsession.1
	dh_lintian
	dh_link
	dh_strip  # respects DEB_BUILD_OPTIONS "nostrip"
	dh_compress 
	dh_fixperms
	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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