#!/usr/bin/make -f

#export DH_VERBOSE=1

SHELL=/bin/bash
CDIR=$(CURDIR)/debian/apt-cacher-ng/etc/apt-cacher-ng/

CFLAGS = -Wall -g

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
else
	CFLAGS += -O2
endif

CXXFLAGS=$(CFLAGS)
export CXXFLAGS

configure: configure-stamp
configure-stamp:
	dh_testdir
	# Add here commands to configure the package.

	touch configure-stamp


build: build-stamp

build-stamp: configure-stamp 
	dh_testdir

	# Add here commands to compile the package.
	$(MAKE) all
	# may fail if halibut is not installed, doesn't matter
	-$(MAKE) doc
	#docbook-to-man debian/apt-cacher-ng.sgml > apt-cacher-ng.1

	touch $@

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

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

	dh_clean 

install: build
	dh_testdir
	dh_testroot
	dh_clean -k 
	dh_installdirs

	# Add here commands to install the package into debian/apt-cacher-ng.
	#$(MAKE) DESTDIR=$(CURDIR)/debian/apt-cacher-ng install
	install apt-cacher-ng $(CURDIR)/debian/apt-cacher-ng/usr/sbin/apt-cacher-ng
	#install acngfs $(CURDIR)/debian/apt-cacher-ng/usr/sbin/
	install acngfs in.acng expire-caller.pl urlencode-fixer.pl distkill.pl $(CURDIR)/debian/apt-cacher-ng/usr/lib/apt-cacher-ng/
	cp -a conf/{*mirror*,*.html,*.css} $(CURDIR)/debian/apt-cacher-ng/usr/lib/apt-cacher-ng
	cp -a conf/*.conf $(CDIR)
	> $(CDIR)/backends_debian
	> $(CDIR)/backends_debvol
	> $(CDIR)/backends_ubuntu
	cd $(CDIR) && cp -s ../../usr/lib/apt-cacher-ng/{*mirror*,*.html,*.css} .

# 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_installchangelogs ChangeLog
	dh_installdocs
	dh_installexamples conf/*.conf
#	dh_install
#	dh_installmenu
	dh_installdebconf	
	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
#	dh_python
	dh_installinit
	dh_installcron
#	dh_installinfo
	dh_installman doc/man/*.8
	#dh_installman doc/man/apt-cacher-ng.8
	dh_link
	dh_strip
	dh_compress -X.pdf
	dh_fixperms
#	dh_perl
#	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 configure
