#!/usr/bin/make -f
# 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

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

DEB_HOST_ARCH := $(shell dpkg-architecture -qDEB_HOST_ARCH)
ifeq ($(DEB_HOST_ARCH),alpha)
CFLAGS := -pipe -Wall -W -O0 -mieee -DNO_DEBUG
else
CFLAGS := -pipe -Wall -W -O3 -funroll-loops -g # -DNO_DEBUG
endif

CC := gcc
CXX := g++

configure: patch configure-stamp
configure-stamp:
	dh_testdir
	# Add here commands to configure the package.
	qmake gutenbrowser.pro -o Makefile
	make CC="$(CC)" CXX="$(CXX)" LINK="$(CXX)" CFLAGS="$(CFLAGS)" CXXFLAGS="$(CFLAGS)" MOC="/usr/bin/moc-qt3" UIC="/usr/bin/uic-qt3"

	touch configure-stamp

build: configure build-stamp
build-stamp:
	dh_testdir

	# Add here commands to compile the package.
	$(MAKE)
	#/usr/bin/docbook-to-man gutenbrowser.sgml > gutenbrowser.1

	touch build-stamp

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

	# Add here commands to clean up after the build process.
	-$(MAKE) clean

	dh_clean
patch: patch-stamp
patch-stamp:
	dpatch apply-all > patch-stamp

unpatch:
	dpatch deapply-all
	rm -rf patch-stamp debian/patched

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	# Add here commands to install the package into debian/gutenbrowser.
	INSTALL=install DESTDIR=$(CURDIR)/debian/gutenbrowser sh ./Install.sh

# 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_testdir
	dh_testroot
	dh_installdocs
	dh_installmenu
	dh_installman docs/gutenbrowser.1
	dh_installchangelogs CHANGES
	dh_link
	dh_strip
	dh_compress
	# make sure /usr/share/doc/gutenbrowser/PGWHOLE.TXT stays uncompressed
	gunzip $(CURDIR)/debian/gutenbrowser/usr/share/doc/gutenbrowser/PGWHOLE.TXT.gz
	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 configure
