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


# These are used for cross-compiling and for saving the configure script
# from having to guess our platform (since we know it already)
DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)


config.status: configure
	dh_testdir
	# Add here commands to configure the package.
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
	./configure --prefix=/usr

build: build-stamp

build-stamp:  config.status
	dh_testdir

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

	touch $@

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp
	# Add here commands to clean up after the build process.
	[ ! -f Makefile ] || $(MAKE) distclean
	dh_clean
	rm -f other-licenses/ply/ply/lex.pyc \
	      other-licenses/ply/ply/yacc.pyc \
	      other-licenses/ply/ply/__init__.pyc
	rm -f config/configobj.pyc \
	      js/src/js \
	      xpcom/idl-parser/xpidl.pyc \
	      xpcom/idl-parser/header.pyc
	rm -rf security/dbm/src/Linux2.6_*
#	rm -f confdefs.h config.cache config.guess config.log config.status config.sub
	rm -f .hgignore .hgtags
#	rm -rf .pc
#	rm -rf dist _leaktest _profile

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs

	# Add here commands to install the package into debian/icecat.
	$(MAKE) prefix=$(CURDIR)/debian/icecat/usr install
	rm $(CURDIR)/debian/icecat/usr/bin/icecat

	rm -rf $(CURDIR)/debian/icecat/usr/share/idl
	rm -rf $(CURDIR)/debian/icecat/usr/include

	mkdir -p $(CURDIR)/debian/icecat/usr/share/applications/
	mkdir -p $(CURDIR)/debian/icecat/usr/share/pixmaps/

	rm -rf $(CURDIR)/debian/icecat/usr/lib/icecat-devel-*
	# Dirty hack to remove version number from the directory
	mv $(CURDIR)/debian/icecat/usr/lib/icecat-*  $(CURDIR)/debian/icecat/usr/lib/icecat

	cp $(CURDIR)/debian/desktop/icecat.desktop $(CURDIR)/debian/icecat/usr/share/applications/ 
	cp $(CURDIR)/debian/desktop/icecat.png $(CURDIR)/debian/icecat/usr/share/pixmaps/

	ln -s /`(cd $(CURDIR)/debian/icecat; find usr/lib -type f -iname icecat)` $(CURDIR)/debian/icecat/usr/bin/icecat
	ln -s /usr/lib/gnash/libgnashplugin.so `find $(CURDIR)/debian/icecat -type d -iname plugins`/
	ln -s /usr/lib/swfdec-mozilla/libswfdecmozilla.so `find $(CURDIR)/debian/icecat -type d -iname plugins`/
	ln -s /usr/lib/mozilla/plugins/mozplugger.so `find $(CURDIR)/debian/icecat -type d -iname plugins`/

# 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
	mkdir -p $(CURDIR)/debian/icecat/usr/share/doc/icecat/
	cp $(CURDIR)/debian/copyright $(CURDIR)/debian/icecat/usr/share/doc/icecat/
	dh_installman
	dh_installchangelogs ChangeLog
	dh_lintian
	dh_link
	dh_strip
	dh_shlibdeps
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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