#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.

#export DH_VERBOSE=1


DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
DEB_BUILD_ARCH      ?= $(shell dpkg-architecture -qDEB_BUILD_ARCH)

CFLAGS = -Wall -g

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

configure: configure-stamp
configure-stamp:
	dh_testdir

	./autogen.sh
	./configure --enable-maintainer-mode --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) CFLAGS="$(CFLAGS)" LDFLAGS="-Wl,-z,defs"

	touch $@

build: build-stamp

build-stamp: configure-stamp
	dh_testdir

	$(MAKE)

	touch $@

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

	-./antigen.sh
	-$(MAKE) clean
	#I'm a lazy ass cunt, I know.
	-./generatepot.sh

	dh_clean 

install: build
	dh_testdir
	dh_testroot
	dh_clean -k 
	dh_installdirs

	$(MAKE) DESTDIR=$(CURDIR)/debian/simple-brightness-applet install
	find $(CURDIR)/debian/simple-brightness-applet -name "*.la" | xargs rm -f

binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs
	dh_installdocs
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	-sed -i "s/libhildon1 (>= 2.2.10)/libhildon1/" simple-brightness-applet.substvars #Oh, God, please forgive me. Then again, WHY THE FUCK WAS THE PR 1.2 SDK DEPLOYED BEFORE WE FUCKING GOT THE UPDATE?
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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