#!/usr/bin/make -f
# Makefile for Debian dpkg-buildpackage(1)
# Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; exactly version 2 of June 1991 is required
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


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

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

# This has to be exported to make some magic below work.
export DH_OPTIONS

ifeq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
OPTFLAGS := -O2
else
OPTFLAGS := -O0
endif

# 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)


#ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
#	CFLAGS += -g
#endif
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
	INSTALL_PROGRAM += -s
endif

config.status: configure
	dh_testdir
	./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var \
		--enable-shared --disable-static \
		--with-readline \
		--disable-bug-replay \
		--enable-lufs \
		--enable-install-pkg \
		--enable-sandbox-setuid=captive \
		--enable-sandbox-setgid=captive \
		--enable-sandbox-chroot=/var/lib/captive \
		--enable-man-pages \
		--enable-sbin-mountdir=/sbin \
		--enable-sbin-mount-fs=ntfs:fastfat:cdfs:ext2fsd \
		--disable-gtk-doc \
		--with-orbit-line=link

build-arch:  config.status build-arch-stamp
build-arch-stamp:
	dh_testdir
	$(MAKE)
	touch build-arch-stamp

build: build-arch

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp 
	# Do not: -$(MAKE) distclean
	# as we are run in clean distribution archive by AutoGen.pm
	dh_clean

install: DH_OPTIONS=
install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	$(MAKE) DESTDIR=$(CURDIR)/debian/tmp install-strip
	dh_movefiles
	#FIXME: dh_movefiles(1) ignores any directories
	#       and dh_installdirs(1) creates them in debian/tmp/
	mkdir -p   $(CURDIR)/debian/captive/var/lib/captive
	chmod  755 $(CURDIR)/debian/captive/var/lib/captive
	mkdir -p   $(CURDIR)/debian/captive/var/lib/captive/tmp
	chmod 1777 $(CURDIR)/debian/captive/var/lib/captive/tmp

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir -a
	dh_testroot -a
#	dh_installdebconf -a
	dh_installdocs -a
#	dh_installinit -a
#	dh_installman -a
#	dh_installchangelogs ChangeLog -a
	dh_link -a
	dh_compress -a
	dh_fixperms -a -X/usr/sbin/captive-sandbox-server -X/var/lib/captive/tmp
	dh_makeshlibs -a
	dh_installdeb -a
	# FIXME: warning: could not find path for libcaptive-0.9cvs.so
	#dh_shlibdeps -a
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a

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