#!/usr/bin/make -f

CFLAGS = -g -Wall

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

LDFLAGS += -Wl,--as-needed

DESTDIR=$(CURDIR)/debian/tmp

conf_args = --prefix=/usr --disable-rpath-install --disable-rpath --bundled-libraries=NONE
conf_args += --build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE)

configure: configure-stamp
configure-stamp:
	dh_testdir
	CFLAGS="$(CFLAGS)" ./configure $(conf_args)
	touch configure-stamp

build: configure build-stamp
build-stamp:
	dh_testdir
	$(MAKE) all
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	LD_LIBRARY_PATH=bin/shared ./bin/talloc_testsuite
endif
	touch build-stamp

get-orig-source:
	./debian/build-orig.sh

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp
	[ ! -f Makefile ] || $(MAKE) distclean
	rm -f buildtools/wafsamba/*.pyc
	rm -rf buildtools/bin/.waf*
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs
	mkdir -p $(DESTDIR)`swig -swiglib`
	$(MAKE) install DESTDIR=$(DESTDIR)
	# Waf really should be doing this:
	ar -rc libtalloc.a bin/default/talloc_*.o
	cp libtalloc.a $(DESTDIR)/usr/lib
	dh_install --list-missing --fail-missing --sourcedir=$(DESTDIR)

# Build architecture-dependent files here.
# Pass -a to all debhelper commands in this target to reduce clutter.
binary-arch: DH_OPTIONS=-a
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installdocs
	dh_installchangelogs 
	dh_strip
	dh_link
	dh_compress
	dh_fixperms
	dh_makeshlibs -- -c4
	dh_pysupport
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary-indep:

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