#!/usr/bin/make -f

# $Id: rules 5115 2012-07-07 20:07:35Z potyra $
# 
#  Copyright (C) 2008-2011 FAUmachine Team <info@faumachine.org>.
#  This program is free software, GPL-2 (or any later version). See COPYING.

CFLAGS = -g
ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
        CFLAGS += -O0
else
        CFLAGS += -O2
endif

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

clean:
	dh_testdir
	dh_testroot
	if [ -e Makefile ]; then \
		$(MAKE) mrproper; \
	fi
	dh_clean
	$(RM) build-arch-stamp
	$(RM) -r debian/tmp

configure: configure.ac autogen.sh acinclude.m4
	./autogen.sh

config.status: configure
	./configure \
		--prefix=/usr \
		--disable-Werror \
		CFLAGS="$(CFLAGS)"

build-arch-stamp: config.status
	dh_testdir
	$(MAKE) $(MAKEFLAGS)
	touch $@

install: build-arch-stamp
	dh_testdir
	dh_testroot
	$(MAKE) install DESTDIR=$(CURDIR)/debian/tmp

tests: build-arch-stamp
	dh_testdir
ifeq (,$(findstring nocheck,$(DEB_BUILD_OPTIONS)))
	$(MAKE) tests
endif

binary-arch: install tests
	dh_testdir
	dh_testroot
	dh_installchangelogs -a ChangeLog
	dh_installdocs -a
	dh_installman -a
	dh_install -a --sourcedir=debian/tmp
	dh_link -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

# no indep packages.
binary-indep:
build-indep:
build-arch: build-arch-stamp
build: build-arch build-indep
binary: binary-arch binary-indep

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