#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# These are used for cross-compiling and for saving the configure script
# from having to guess our platform (since we know it already)
include /usr/share/dpkg/architecture.mk
ifneq ($(DEB_HOST_GNU_TYPE),$(DEB_BUILD_GNU_TYPE))
CROSS= --build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE)
else
CROSS= --build $(DEB_BUILD_GNU_TYPE)
endif

CPPFLAGS:=$(shell dpkg-buildflags --get CPPFLAGS)
CFLAGS:=$(shell dpkg-buildflags --get CFLAGS) -fpermissive
CXXFLAGS:=$(shell dpkg-buildflags --get CXXFLAGS) -fpermissive
LDFLAGS:=$(shell dpkg-buildflags --get LDFLAGS)

%:
	dh $@

override_dh_auto_configure:
	dh_auto_configure -- $(CROSS) \
		--prefix=/usr \
		--datarootdir=\$${prefix}/share \
		--mandir=\$${prefix}/share/man \
		--infodir=\$${prefix}/share/info \
		--with-wx-config=/usr/bin/wx-config \
		CFLAGS="$(CFLAGS) $(CPPFLAGS)" \
		CXXFLAGS="$(CXXFLAGS) $(CPPFLAGS)" \
		LDFLAGS="$(LDFLAGS) -Wl,-z,defs -Wl,--as-needed -Wl,--no-undefined"


override_dh_clean:
	rm -f config.sub config.guess config.cache config.log
	rm -f configure aclocal.m4 compile depcomp ltmain.sh missing install-sh
	rm -f Makefile.in data/Makefile.in src/Makefile.in
	rm -f m4/Makefile.in m4/libtool.m4 m4/ltoptions.m4 m4/ltsugar.m4 m4/ltversion.m4 m4/lt~obsolete.m4
	rm -f src/help/xmlcopyeditor.chm
	dh_clean

override_dh_install:
	dh_install
	rm -rf $(CURDIR)/debian/xmlcopyeditor/usr/share/xmlcopyeditor/copying
	rm -rf $(CURDIR)/debian/xmlcopyeditor/usr/share/xmlcopyeditor/po/.intltool-merge-cache
	sed -i 's/\r//g' $(CURDIR)/debian/xmlcopyeditor/usr/share/applications/xmlcopyeditor.desktop
