#!/usr/bin/make -f
# -*- makefile -*-
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# See lintian-override
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_BUILD_MAINT_OPTIONS = hardening=+all,-PIE
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

# 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 noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
else
	CFLAGS += -O2
endif

CFLAGS += $(CPPFLAGS)
CXXFLAGS += $(CPPFLAGS)

build: build-arch build-indep
build-arch: build-stamp
build-indep: build-stamp

build-stamp: 
	dh_testdir
	./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) \
		--prefix=/usr --mandir=\$${prefix}/share/man \
		--infodir=\$${prefix}/share/info \
		--libexecdir=\$${prefix}/lib/fbpanel \
		--datadir=\$${prefix}/share \
		--ldflagsx="$(LDFLAGS) -lglib-2.0 -pthread -lgtk-x11-2.0 -lgdk-x11-2.0 \
					-lgdk_pixbuf-2.0 -lm -lgobject-2.0 -lgmodule-2.0 \
					-lglib-2.0 -lX11" 
	$(MAKE)
	touch $@

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp
	[ ! -f Makefile ] || $(MAKE) distclean
	rm -f config.sub config.guess
	dh_clean 

install: build
	dh_testdir
	dh_testroot
	dh_clean -k 
	dh_installdirs usr/bin usr/share/fbpanel/images
	dh_install debian/terminal_color.svg debian/terminal_sketch.svg \
		usr/share/fbpanel/images
	
	# Yeah, do it properly you bastard!
	$(MAKE) DESTDIR=$(CURDIR)/debian/fbpanel install

binary-indep: build install
# Nothing to see, keep walking :)

binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs CHANGELOG
	dh_installdocs
	dh_installmenu
	dh_installman data/man/fbpanel.1
	dh_link
	dh_strip
	dh_lintian
	dh_compress
	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 instal
