#!/usr/bin/make -f

PACKAGE = wcd
EXE	= .exec

export DEB_BUILD_MAINT_OPTIONS	= hardening=+all
export DEB_CFLAGS_MAINT_APPEND	= -Wall -pedantic
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

#  UCS; Activate unicode UTF-8 support
#  NLS; Enable international support
#  DOTWCD; Use ~/.wcd/ configuration directory
#  UNINORM; Enable Unicode normalization

MAKE_OPTIONS =	EXT=$(EXE) \
		UCS=1 \
		NLS=1 \
		DOTWCD=1 \
		UNINORM=1 \
		CPP_FLAGS_POD=-Dunix

# Original files chnaged by the build process
KEEP_FILES = \
 src/po/wcd.pot

include debian/debian-vars.mk

override_dh_auto_build:
	for f in $(KEEP_FILES) ; do cp -a $$f $$f.o ; done
	$(MAKE) -C src \
		$(MAKE_OPTIONS) \
		CC="$(CC) $(CFLAGS) $(CPPFLAGS)" \
		LDFLAGS_EXTRA="$(LDFLAGS)" \
		man pod all

override_dh_auto_clean:
	for f in $(KEEP_FILES) ; do [ ! -f $$f.o ] || mv $$f.o $$ ; done
	$(MAKE) -C src $(MAKE_OPTIONS) clean
	rm -f doc/wcd.txt doc/wcd.htm doc/wcd.html
	# This is a generated file. The developer may have forgot to update it,
	# and debuild says "it's modified" and aborts.
	rm -f src/man/man1/wcd1.pod

override_dh_auto_install:
	$(MAKE) -C src \
		DESTDIR=$(PKGDIR) \
		prefix=/usr \
		BINDIR=$(LIBDIR) \
		DOCDIR=$(PKGDOCDIR) \
		MANDIR1=$(MAN7DIR) \
		INSTALL_OBJS_DOC_INSTALL= \
		INSTALL_OBJS_DOC_COPYING= \
		$(MAKE_OPTIONS) \
		install install-profile

	# Remove /usr/share/doc/wcd-VERSION
	# Not used in Debian

	rm -rf $(PKGDOCDIR)-*/

	# Relocate scripts

	install -d -m 755 $(SHAREDIR)

	install -m 644 \
		$(PKGDIR)/etc/profile.d/wcd.csh \
		$(SHAREDIR)/wcd-include.csh

	install -m 644 \
		debian/wcd-include.sh \
		$(SHAREDIR)/wcd-include.sh

	rm -rf	debian/$(PACKAGE)/etc

man:
	# target: man
	install -d -m 755 $(MAN1DIR)

	# Create manual page redirection file
	man=$(MAN1DIR)/$(PACKAGE)$(EXE).1 ; \
	echo ".so man1/wcd.1.gz" > $$man ; \
	gzip --best $$man

override_dh_installchangelogs:
	dh_installchangelogs doc/whatsnew.txt

override_dh_installman: man
	dh_installman
	rm $(PKGDOCDIR)/wcd.txt*

%:
	dh $@

.PHONY: man

# End of file
