#!/usr/bin/make -f

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/autotools.mk


DEB_CONFIGURE_SYSCONFDIR 	:= /etc/X11/fluxbox
DEB_STYLE_DIR 			:= /usr/share/fluxbox/styles/
VENDOR_THEME			:= $(shell \
	if dpkg-vendor --derives-from Ubuntu; then \
		echo Ubuntu-light; \
	else \
		echo Debian-dark; \
	fi \
)

VERSION	= $(shell dpkg-parsechangelog|grep ^Version|awk '{print $$2}' \
	|sed 's/-[[:digit:]]\+$$//')

# additional themes source images
BACKGROUND_IMAGES	= ubuntu-dark.png debian-blue.png debian-dark.png

DEB_CONFIGURE_EXTRA_FLAGS 	:= \
	--enable-xinerama \
	--enable-nls \
	--enable-xft \
	--with-apps=$(DEB_CONFIGURE_SYSCONFDIR)/apps \
	--with-keys=$(DEB_CONFIGURE_SYSCONFDIR)/keys \
	--with-init=$(DEB_CONFIGURE_SYSCONFDIR)/init \
	--with-overlay=$(DEB_CONFIGURE_SYSCONFDIR)/overlay \
	--with-menu=$(DEB_CONFIGURE_SYSCONFDIR)/fluxbox.menu-user \
	--with-windowmenu=$(DEB_CONFIGURE_SYSCONFDIR)/window.menu \
	--with-locale=/usr/share/fluxbox/nls \
	--with-style=$(DEB_STYLE_DIR)/$(VENDOR_THEME) \
	--enable-shape \
	--enable-fribidi


CXXFLAGS := -O2 -ffunction-sections

#fix FTBFS with binutils-gold
LDFLAGS=-lfontconfig


# rules to build background images
%-dark.png: additional-themes/wallpapers-source/%-dark.xcf
	convert $<  -layers merge $@
debian-blue.png: additional-themes/wallpapers-source/debian-blue.svg
	convert $< $@

configure/fluxbox:: $(BACKGROUND_IMAGES)

clean::
	rm -f *.cdbs-config_list
	rm -f src/defaults.cc
	# find nls -type f -name generated-\*.m -delete
	rm -f $(BACKGROUND_IMAGES)
	rm -fr .pc/

install/fluxbox::
	# We use the menu file generated by the 'menu' package.
	rm -f ./debian/fluxbox/usr/bin/fluxbox-generate_menu
	perl debian/update-init.pl \
		debian/fluxbox$(DEB_CONFIGURE_SYSCONFDIR)/init


# creates both tarballs
tarball: clean ../fluxbox_$(VERSION).orig.tar.gz \
	../fluxbox_$(VERSION).orig-additional-themes.tar.gz


# current tree must have no applied patсhes
../fluxbox_$(VERSION).orig.tar.gz:
	tar -C.. --exclude=.git \
			--exclude=debian \
			--exclude=additional-themes \
			--exclude=.gitignore \
			-czvf $@ fluxbox-$(VERSION)

../fluxbox_$(VERSION).orig-additional-themes.tar.gz:
	tar -czvf $@ additional-themes
