#!/usr/bin/make -f

include /usr/share/quilt/quilt.make

$(foreach x,$(shell dpkg-architecture | sed -e 's/=/?=/'),$(eval $x))
ifeq ($(DEB_HOST_ARCH),alpha)
  LDFLAGS := -Wl,--no-relax
endif

configure: configure-stamp
configure-stamp: patch
	dh_testdir
	LDFLAGS='$(LDFLAGS)' CXXFLAGS='-g -O2' \
		cmake -DCMAKE_INSTALL_PREFIX='/usr' .
	touch $@

build: build-stamp
build-stamp: configure-stamp
	dh_testdir
	$(MAKE) VERBOSE=1
	touch $@

clean: unpatch
	dh_testdir
	dh_testroot
	[ ! -f Makefile ] || $(MAKE) clean
	$(MAKE) -f debian/Makefile distclean
	find . -type f -name "a.out" -or -name "*.bin" | xargs rm -f
	rm -f configure-stamp build-stamp
	dh_clean

install: build
	dh_testdir
	dh_prep
	$(MAKE) install DESTDIR="$(CURDIR)/debian/ldc"

binary-arch: build

binary-arch: build install
	dh_testdir
	dh_testroot
	dh_install
	dh_installdocs
	dh_installman debian/ldc.1 debian/ldmd.1
	dh_installchangelogs
	dh_link
	dh_strip --exclude=debug.a
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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