#! /usr/bin/make -f 

tmp:=$(shell pwd)/debian/tmp

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

build: build-stamp
build-stamp:
	dh_testdir
	CFLAGS="$(CFLAGS)" ./configure \
	            --prefix=/usr --sysconfdir=/etc --mandir=/usr/share/man \
	            --with-freedesktop_org-menu=/usr/share/applications \
	            --with-freedesktop_org-mime=/usr/share/mime \
	            --without-gnome2_4-mime \
	            --without-gnome2_4-appreg \
	            --with-icon-path=/usr/share/pixmaps \
	            --disable-update-databases
	$(MAKE)
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	-test -r /usr/share/misc/config.sub && \
	  cp -f /usr/share/misc/config.sub $(CURDIR)/config.sub
	-test -r /usr/share/misc/config.guess && \
	  cp -f /usr/share/misc/config.guess $(CURDIR)/config.guess
	[ ! -f Makefile ] || $(MAKE) distclean
	rm -f build-stamp
	rm -f po/*.gmo po/stamp-cat-id po/bluefish.pot po/cat-id-tbl.c data/Makefile
	rm -rf $(tmp)
	dh_clean

binary-indep:

binary-arch: build 
	dh_testdir
	dh_testroot
	$(MAKE) install prefix=$(tmp)/usr sysconfdir=$(tmp)/etc mandir=$(tmp)/usr/share/man pixmapsdir=$(tmp)/usr/share/pixmaps
	install -d -o root -g root -m 755 $(tmp)/usr/share/pixmaps
	install -o root -g root -m 644 debian/bluefish_icon1.xpm $(tmp)/usr/share/pixmaps/bluefish_icon.xpm
	install -o root -g root -m 644 inline_images/bluefish_icon1.png $(tmp)/usr/share/pixmaps/bluefish-icon.png
	install -d -o root -g root -m 755 $(tmp)/usr/share/applications
	install -o root -g root -m 644 data/bluefish.desktop $(tmp)/usr/share/applications/
	dh_installdocs
	dh_installman
	dh_installmenu
	dh_installchangelogs
ifeq "$(findstring nostrip,$(DEB_BUILD_OPTIONS))" ""	
	dh_strip
endif
	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
