#!/usr/bin/make -f
# Based on the initial work of Joey Hess and Craig Small.

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

DEB_HOST_GNU_TYPE	?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE	?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

PACKAGE=lutefisk

BUILD_DIR = $(CURDIR)/debian/build-arch

ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
         NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
         MAKEFLAGS += -j$(NUMJOBS)
endif

$(info "---------------------------------------")
$(info NUMJOBS: $(NUMJOBS))
$(info MAKEFLAGS: $(MAKEFLAGS))
$(info DEB_BUILD_OPTIONS: $(DEB_BUILD_OPTIONS))
$(info "---------------------------------------")

# Hardening stuff, see http://wiki.debian.org/Hardening
# export DEB_BUILD_MAINT_OPTIONS = hardening=+all
# DPKG_EXPORT_BUILDFLAGS = 1
# include /usr/share/dpkg/buildflags.mk
# $(info CFLAGS: $(CFLAGS))

# Uncomment to monitor the log of package building (pdebuild log)
# .NOTPARALLEL: 

.PHONY: clean
clean:  
	dh_testdir
	dh_testroot

	dh_clean 

	rm -rf $(BUILD_DIR)


configure-stamp: 
	dh_testdir

	mkdir -p $(BUILD_DIR)

	cp -rpf src/* $(BUILD_DIR)
	ln -s $(BUILD_DIR)/Makefile.linux $(BUILD_DIR)/Makefile

	touch configure-stamp


.PHONY: build
build: build-indep build-arch


.PHONY: build-indep
build-indep:


.PHONY: build-arch
build-arch: build-arch-stamp


build-arch-stamp: configure-stamp 
	dh_testdir
	dh_prep -a

	cd $(BUILD_DIR) && $(MAKE) all

	touch build-arch-stamp


# Build architecture-independent files here.
.PHONY: binary-indep
binary-indep: 
	dh_testdir -i
	dh_testroot -i
	dh_installchangelogs HISTORY.txt -i
	dh_installdocs -i
	dh_install -i
	dh_installman -i
	dh_compress -i
	dh_fixperms -i
	dh_installdeb -i
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i


# Build architecture-dependent files here.
.PHONY: binary-arch
binary-arch: build-arch
	dh_testdir -a
	dh_testroot -a
	dh_installchangelogs HISTORY.txt -a
	dh_installdocs -a
	dh_installexamples -a
	dh_install -a
	dh_installman -a
	dh_strip -a
	dh_compress -a
	dh_fixperms -a
	dh_installdeb -a
	dh_shlibdeps -a
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a


.PHONY: binary
binary: binary-indep binary-arch

get-orig-source:
	@echo 'Getting the original source:'
	uscan --verbose || [ $$? -eq 1 ]
