#!/usr/bin/make -f
# -*- makefile -*-

DEB_BUILD_MAINT_OPTIONS=hardening=+all
DEB_LDFLAGS_MAINT_APPEND=-Wl,-z,defs
include /usr/share/dpkg/default.mk

libdir = /usr/lib/$(DEB_HOST_MULTIARCH)
libpkg = libserf-1-1

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

silent =
ifneq (,$(filter terse,$(DEB_BUILD_OPTIONS)))
    silent = --silent
endif

%:
	dh $@

.PHONY: build
build: build-arch build-indep
override_dh_auto_build:
	scons $(parallel) $(silent) GSSAPI=/usr CFLAGS="$(CFLAGS)" CPPFLAGS="$(CPPFLAGS)" LINKFLAGS="$(LDFLAGS)" PREFIX=/usr LIBDIR=$(libdir) CC="$(CC)"

override_dh_auto_test:
	scons $(silent) check CFLAGS="$(CFLAGS)" CPPFLAGS="$(CPPFLAGS)" LINKFLAGS="$(LDFLAGS)" CC="$(CC)"

override_dh_auto_clean:
	scons -c

override_dh_auto_install:
	scons $(silent) install PREFIX=$(CURDIR)/debian/tmp/usr LIBDIR=debian/tmp$(libdir)
	chrpath -d $(CURDIR)/debian/tmp/$(libdir)/*.so.*

override_dh_installchangelogs:
	dh_installchangelogs CHANGES

override_dh_shlibdeps:
	dh_shlibdeps
	sed -i 's:libserf-private\(, *\)\?::' debian/*.substvars
