#!/usr/bin/make -f

export CFLAGS := -Wall -g -O$(if $(findstring noopt,$(DEB_BUILD_OPTIONS)),0,2)

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

libwmf_pkg := libwmf0.2-7

confflags := --prefix=/usr \
	     --with-docdir=/usr/share/doc/$(libwmf_pkg) \
	     --with-fontdir=/var/lib/defoma/$(libwmf_pkg).d \
	     --with-gsfontdir=/var/lib/defoma/$(libwmf_pkg).d \
	     --with-sysfontmap=/var/lib/defoma/$(libwmf_pkg).d/fontmap \
	     --with-gsfontmap=/var/lib/defoma/$(libwmf_pkg).d/fontmap.gs \
	     --with-xtrafontmap=/etc/libwmf.fontmap
ifeq ($(DEB_BUILD_GNU_TYPE), $(DEB_HOST_GNU_TYPE))
	confflags += --build=$(DEB_HOST_GNU_TYPE)
else
	confflags += --build=$(DEB_BUILD_GNU_TYPE) --host=$(DEB_HOST_GNU_TYPE)
endif

build: build-stamp
build-stamp:
	dh_testdir
	ln -sf /usr/share/misc/config.sub /usr/share/misc/config.guess .
	./configure $(confflags)
	$(MAKE)
	> $@

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

export DH_OPTIONS

install: DH_OPTIONS =
install: build
	dh_testdir
	dh_testroot
	dh_clean
	$(MAKE) DESTDIR=$(CURDIR)/debian/tmp font_DATA= install

binary-arch: DH_OPTIONS = -a
binary-indep: DH_OPTIONS = -i
binary-%: DH_OPTIONS = -p$*
binary binary-%: install
	dh_installdirs
	dh_link
	dh_installchangelogs ChangeLog
	dh_installdocs
	dh_installdefoma
	dh_install
	#LD_LIBRARY_PATH=debian/$(libwmf_pkg)/usr/lib:$(LD_LIBRARY_PATH) \
	#	dh_gtkmodules
	dh_strip
	dh_compress
	dh_fixperms
	dh_makeshlibs -V
	dh_installdeb
	dh_shlibdeps -ldebian/$(libwmf_pkg)/usr/lib -Xusr/lib/gtk
	dh_gencontrol
	dh_md5sums
	dh_builddeb

.PHONY: build clean install binary
