#!/usr/bin/make -f

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

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

CXXFLAGS := $(shell dpkg-buildflags --get CXXFLAGS)
CPPFLAGS := $(shell dpkg-buildflags --get CPPFLAGS)
LDFLAGS := $(shell dpkg-buildflags --get LDFLAGS)
CXXFLAGS += -Wall
CPPFLAGS += "-DCONFIG_NEW_WINDOW_COMMAND=\"x-terminal-emulator\""
LDFLAGS += -Wl,-z,defs

build-arch: build-arch-stamp
build-indep:
build: build-arch-stamp

build-arch-stamp:
	dh_testdir
	# it's a C++ program, but it uses CFLAGS instead of CXXFLAGS
	$(MAKE) CFLAGS='$(CXXFLAGS)' LDFLAGS='$(LDFLAGS)' \
		LIBS="-lXext -lX11" INCS='$(CPPFLAGS)'
	touch build-arch-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-arch-stamp
	-rm -f Makefile.bak
	$(MAKE) distclean
	dh_clean

# Build architecture-independent files
binary-indep:
# We have nothing to do

# Build architecture-dependent files
binary-arch: build-arch-stamp
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs
	dh_install
	dh_installchangelogs
	dh_installdocs
	dh_installmenu
	dh_installman debian/wm2.1
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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