#!/usr/bin/make -f
#
# ELinks 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 compatibility version to use.
#export DH_COMPAT=2   # this should work if your debhelper is older!
export DH_COMPAT=4


# This adds the values the variable is set to to the -X options of all commands
# that support the -X option
# XXX: The last _has_ to be `Makefil', since find chokes on `Makefile'
export DH_ALWAYS_EXCLUDE=CVS:.cvsignore:.vimrc:MT:.mt-attrs:Makefil


## Handling of DEB_BUILD_OPTIONS
#
# debug		- turn on all the built-in debugging
# nostrip	- dh_strip will take care of this
# noopt		- compiled with a minimum of optimization

ifneq (,$(findstring debug, $(DEB_BUILD_OPTIONS)))
CONFIGURE_MODE	= --enable-debug
endif

ifneq (,$(findstring noopt, $(DEB_BUILD_OPTIONS)))
# Export it so configure can grab it
export CFLAGS  += -O0 -Wall
else
ifeq (,$(CONFIGURE_MODE))
CONFIGURE_MODE	= --enable-fastmem
endif
endif


## Compile Configuration
#
# with GNUTLS	- due to license restictions
# without X	- since it only needed for RESETTING the xterm title and
#		  resizing xterm windows
CONFIGURE_OPTIONS = \
 --prefix=/usr \
 --mandir=\$${prefix}/share/man \
 --sysconfdir=/etc/elinks \
 --with-xterm="x-terminal-emulator -e" \
 --without-openssl \
 --without-x \
 --with-gnutls=/usr \
 --with-perl --enable-nntp --enable-256-colors --enable-leds  \
 --without-spidermonkey
# spidermonkey: libsmjs-dev
# perl libperl-dev


# The .deb file packaging root directory
DEB_ROOT = `pwd`/debian/elinks


build: debian/build-stamp
debian/build-stamp:
	dh_testdir
	./configure $(CONFIGURE_MODE) $(CONFIGURE_OPTIONS)
	$(MAKE)
	touch debian/build-stamp

clean:
	dh_testdir
	dh_testroot
	
	# Add here commands to clean up after the build process.
	-$(MAKE) distclean
	
	# handle non-linux archs, patch by Robert Millan <rmh@debian.org>, bug#262350
	cat debian/control.in \
	| sed "s/@linux-gnu@/`type-handling any linux-gnu`/g" \
	> debian/control
	
#	-find . -name ".#*" -exec rm -rf "{}" \;
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs
	
	# Add here commands to install the package into debian/elinks.
	$(MAKE) install DESTDIR=$(DEB_ROOT)
	
	mkdir -p $(DEB_ROOT)/etc/elinks
	install -o root -g root -m 644 contrib/elinks.conf $(DEB_ROOT)/etc/elinks/elinks.conf
	# KDE and Gnome menu integration (freedesktop.org)
	dh_install debian/elinks.desktop usr/share/applications/
	# upstream CVS bug hack: remove double contrib dirs
	-rm -rf contrib/lua/lua contrib/conv/conv contrib/guile/guile
	# locale.alias causes conflicts and I believe it's not necessary
	-rm -f $(DEB_ROOT)/usr/share/locale/locale.alias

# 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_installdebconf	
	dh_installdocs
	dh_installexamples \
		-X colws.diff -X elinks.spec -X hooks.lua.in -X links_wps.zip \
		-X wipe-out-ssl -X LinksOS2Icon.zip -X js-1.5-rc6a contrib/
	dh_installmime
	dh_installmenu
	dh_installman
	
# comment out for slink:
##	dh_installinfo
	
	dh_installchangelogs ChangeLog
	
# comment out for slink:
##	dh_link
	
	dh_strip
	dh_compress
	dh_fixperms
#	dh_makeshlibs
	dh_installdeb
#	dh_perl
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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