#!/usr/bin/make -f
# GNU copyright 1997 to 1999 by Joey Hess.

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

DEB_BUILD_MAINT_OPTIONS = hardening=+all future=+lfs
DEB_CFLAGS_MAINT_APPEND = -Wall

include /usr/share/dpkg/default.mk

DESTDIR = $(CURDIR)/debian/arj

INSTALL = install
INSTALL_DATA = $(INSTALL) -m 644

# XXX: The upstream build system does not support cross-building...
ifeq ($(DEB_BUILD_GNU_TYPE), $(DEB_HOST_GNU_TYPE))
  conf_gnu_type += --build $(DEB_HOST_GNU_TYPE)
else
  conf_gnu_type += --build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE)
endif

ifneq (,$(filter debug,$(DEB_BUILD_OPTIONS)))
	DEBUG = "DEBUG=1"
endif

ifeq (,$(filter nostrip,$(DEB_BUILD_OPTIONS)))
	STRIP = "BUILD_STRIP=1"
endif

gnu/configure: gnu/configure.in
	dh_testdir
	
	cd gnu && autoconf -f -i

gnu/config.status: gnu/configure
	dh_testdir
	dh_update_autotools_config
	
	cd gnu && ./configure \
	  $(conf_gnu_type) \
	  --prefix=/usr \
	  --mandir=\$${prefix}/share/man

build-indep:

build-arch: gnu/config.status
	dh_testdir
	
	$(MAKE) $(DEBUG) $(STRIP)\
	  CPPFLAGS="$(CPPFLAGS)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)"

build: build-arch build-indep

clean:
	dh_testdir
	dh_testroot
	
	[ ! -f GNUmakefile ] || $(MAKE) clean
	
	-rm -f gnu/configure
	-rm -f gnu/config.status gnu/config.log gnu/config.cache
	-rm -rf gnu/autom4te.cache
	-rm -f c_defs.h GNUmakefile
	
	dh_clean

install-arch: build-arch
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs
	
	$(MAKE) install DESTDIR=$(DESTDIR)
	$(INSTALL_DATA) $(CURDIR)/resource/rearj.cfg.example \
			$(DESTDIR)/etc/rearj.cfg

binary-indep:

binary-arch: install-arch
	dh_testdir
	dh_testroot
	dh_installdocs -a
	dh_installexamples -a
	dh_installmenu -a
	dh_installcron -a
	dh_installman -a
	dh_installinfo -a
	dh_installchangelogs -a ChangeLog
	dh_link -a
	# NOTE: Do not strip here, it is currently done in the upstream build
	# system, after the linker stage and before preprocessing the binary
	# files. Otherwise when stripping the self-extracting modules and the
	# help text are removed.
#	dh_strip -a
	dh_compress -a
	dh_fixperms -a
	dh_installdeb -a
	dh_shlibdeps -a
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a

binary: binary-arch binary-indep

.PHONY: clean configure build build-indep build-arch install-arch
.PHONY: binary-indep binary-arch binary
