#!/usr/bin/make -f
# -*- makefile -*-

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

%:
	dh  $@  --with autotools-dev

override_dh_auto_configure:
	mailer=/usr/bin/mail ./configure $(CROSS) --prefix=/usr --sysconfdir=/etc/gnuspool --with-printers-directory=/etc/gnuspool/ptrconf \
	--with-cupspy-directory=/etc/gnuspool/cupspy --localstatedir=/var/spool \
	--libexecdir='$${exec_prefix}/lib' --datarootdir=/usr/share --pdfdir=/usr/share/doc/gnuspool CFLAGS="$(CFLAGS)" LDFLAGS="-Wl,-z,defs"

override_dh_installdirs:
	dh_installdirs -Pdebian/tmp -pgnuspool
	dh_installdirs -Ngnuspool

override_dh_auto_install:
	$(MAKE) DESTDIR=$(CURDIR)/debian/tmp SPOOLUSER=root datarootdir=/usr/share STAGED_INSTALL=true install

	# provide lpr links
	ln debian/tmp/usr/bin/gspl-lpr debian/tmp/usr/bin/lpr
	ln debian/tmp/usr/bin/gspl-lpq debian/tmp/usr/bin/lpq
	ln debian/tmp/usr/bin/gspl-lprm debian/tmp/usr/bin/lprm
	ln debian/tmp/usr/bin/gspl-lpcover debian/tmp/usr/bin/lp
	ln debian/tmp/usr/bin/gspl-lpstatc debian/tmp/usr/bin/lpstat
	ln debian/tmp/usr/bin/gspl-cancel debian/tmp/usr/bin/cancel

	# Get rid of remote CGI bins for now as they depend on separated API library.
	rm -f debian/tmp/usr/lib/gnuspool/cgi-bin/r*
	# Remove .la files for internal only
	rm -f debian/tmp/usr/lib/libgnuspool_int.la
	rm -f debian/tmp/usr/lib/libgnuspool_curs.la

override_dh_install:
	dh_install --fail-missing
