#!/usr/bin/make -f
# Holger Levsen, 2006-12, based on 
# -*- 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

# plugins to be build (not build per default are: powerinfo pgraph mini quagga)
# 	(fixme?: if you add them here, they are build but their README is not 
# 	copied to /usr/share/doc/olsrd-plugins/)
#
# you dont need to edit this file. export PLUGIS=foo ; fakeroot ./debian/rules binary
# is enough for a rebuild :)
PLUGINS ?= dyn_gw httpinfo dot_draw nameservice secure txtinfo bmf quagga
#hack: - also needs debian/patches/240-plugin-install-targets.patch - this has been reported to upstream...
PLUGINS_INSTALL ?= dyn_gw_install httpinfo_install dot_draw_install nameservice_install secure_install txtinfo_install bmf_install quagga_install

CFLAGS = -Wall -g

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

configure: configure-stamp
configure-stamp:
	dh_testdir
	# Add here commands to configure the package.
	QUILT_PATCHES=debian/patches quilt push -a || test $$? = 2
	
	touch configure-stamp

build: build-stamp

build-stamp: configure-stamp 
	dh_testdir

	# Add here commands to compile the package.
	$(MAKE)
	$(MAKE) $(PLUGINS)

	touch $@

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

	# Add here commands to clean up after the build process.
	-$(MAKE) clean_all
	rm -f $(CURDIR)/lib/*/src/*.o $(CURDIR)/lib/*/*.so.?.?
	QUILT_PATCHES=debian/patches quilt pop -a -R || test $$? = 2

	dh_clean 

install: build
	dh_testdir
	dh_testroot
	dh_clean -k 
	dh_installdirs

	# Add here commands to install the package into debian/olsrd.
	$(MAKE) DESTDIR=$(CURDIR)/debian/olsrd install STRIP=: 
	$(MAKE) DESTDIR=$(CURDIR)/debian/olsrd-plugins LIBDIR=$(CURDIR)/debian/olsrd-plugins/usr/lib/olsrd $(PLUGINS_INSTALL) STRIP=:

# 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 -polsrd CHANGELOG -polsrd-plugins
	dh_installdocs
	dh_installinit
	dh_installman
	dh_link
	dh_strip
	# compress, but don't compress README_NAMESERVICE, for consistency reasons
	dh_compress -XREADME_NAMESERVICE -XREADME_BMF
	# provide better default config
	rm $(CURDIR)/debian/olsrd/etc/olsrd.conf
	cp $(CURDIR)/debian/olsrd.conf $(CURDIR)/debian/olsrd/etc/olsrd/olsrd.conf
	cp  $(CURDIR)/debian/olsrd-default $(CURDIR)/debian/olsrd/etc/default/olsrd
	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
