#!/usr/bin/make -f

#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)
DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
DEB_ARCH_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_BUILD_ARCH)

ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
	INSTALL_PROGRAM += -s
endif

%:
	dh $@  --with autotools-dev

override_dh_auto_configure:
	dh_auto_configure -- CFLAGS="-O2 -g -Wall -D_GNU_SOURCE" ./configure \
		--host=$(DEB_HOST_GNU_TYPE) \
		--build=$(DEB_BUILD_GNU_TYPE) \
		--prefix=/usr \
		--mandir=\$${prefix}/share/man \
		--infodir=\$${prefix}/share/info \
		--enable-textport=yes \
		--disable-ssl

override_dh_auto_install:
	dh_auto_install
	convert -geometry 32x32 $(CURDIR)/debian/tmp/usr/share/pixmaps/gftp.png $(CURDIR)/debian/tmp/usr/share/pixmaps/gftp.xpm
	# Add translation domain to .desktop and .server files
	for d in $$(find debian/tmp -type f -name "*.desktop" ); do \
	    echo "Adding translation domain to $$d..."; \
	    echo "X-Ubuntu-Gettext-Domain=gftp" >> $$d; \
	done;
	install -m 755 $(CURDIR)/docs/parse-netrc.pl $(CURDIR)/debian/gftp-common/usr/share/doc/gftp-common/examples
	mv $(CURDIR)/debian/tmp/usr/share/gftp/gftprc $(CURDIR)/debian/gftp-common/etc/gftp
	mv $(CURDIR)/debian/tmp/usr/share/gftp/bookmarks $(CURDIR)/debian/gftp-common/etc/gftp
	ln -s /etc/gftp/gftprc $(CURDIR)/debian/tmp/usr/share/gftp/gftprc
	ln -s /etc/gftp/bookmarks $(CURDIR)/debian/tmp/usr/share/gftp/bookmarks
