1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
  
     | 
    
      #!/usr/bin/make -f
# Exports DEB_{BUILD,HOST}_* flags
include /usr/share/dpkg/architecture.mk
# Pass this as version-info to dh_makeshlibs
SHLIBS_MINVER = 1:2.63
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
# Support cross-compiling
ifneq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE))
CC := $(DEB_HOST_GNU_TYPE)-gcc
endif
# One upstream target, "_makenames", requires the BUILD compiler instead of HOST
BUILD_CC ?= cc
export BUILD_LDFLAGS = $(shell dpkg-architecture -a$(DEB_BUILD_ARCH) -c dpkg-buildflags --get LDFLAGS)
export BUILD_CPPFLAGS = $(shell dpkg-architecture -a$(DEB_BUILD_ARCH) -c dpkg-buildflags --get CPPFLAGS)
# Upstream's way of setting optimization
ifneq (,$(filter noopt, $(DEB_BUILD_OPTIONS)))
COPTS = COPTS=-O0
endif
# See pam_cap/Makefile for FORCELINKPAM
MAKE_ASSIGNMENTS = \
	prefix=/usr \
	FORCELINKPAM=yes \
	GOLANG=no
%:
	dh ${@}
override_dh_auto_clean:
	dh_auto_clean -- $(MAKE_ASSIGNMENTS)
	# The Golang build system does not appear to fully honor -B, so we need
	# two cleans
	set -e; if test -d _build; then \
		dh_auto_clean -B_build -O--buildsystem=golang; \
		dh_auto_clean O--buildsystem=golang; \
	fi
	# Undo change of lookup (see override_dh_auto_build)
	sed -i -e 's,\./tcapsh-static,../progs/tcapsh-static,g' tests/libcap_launch_test.c
override_dh_auto_build:
	# See pam_cap/Makefile for FORCELINKPAM
	dh_auto_build -- \
		$(MAKE_ASSIGNMENTS) \
		BUILD_CC=$(BUILD_CC) \
		CROSS_COMPILE=$(DEB_HOST_GNU_TYPE)- \
		$(COPTS) \
		DYNAMIC=yes \
		SUDO=$(DEB_GAIN_ROOT_CMD)
	# Some of test suite is only invoked when run as real root. Explicitly
	# build all binaries so we can include them in the autopkgtest.	
	dh_auto_build -D libcap -- $(MAKE_ASSIGNMENTS) cap_test
	dh_auto_build -D pam_cap -- $(MAKE_ASSIGNMENTS) test_pam_cap
	# Change lookup from sibling dir to current dir
	sed -i -e 's,\.\./progs/tcapsh-static,./tcapsh-static,g' tests/libcap_launch_test.c
	dh_auto_build -D tests -- $(MAKE_ASSIGNMENTS) \
		psx_test \
		libcap_psx_test \
		uns_test \
		libcap_launch_test \
		libcap_psx_launch_test \
		noop \
		exploit \
		noexploit
	dh_auto_build -D progs -- $(MAKE_ASSIGNMENTS) tcapsh-static
override_dh_installdirs:
	dh_installdirs
	# While the PAM module and the library are in /lib, according to the
	# FHS, development files must go into usr/lib/<triplet>.
	mkdir -p debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)
override_dh_auto_install:
	# Unfortunately, RPATH seems to be needed for the build-time tests
	# (avoiding it and going through LD_LIBRARY_PATH didn't work in all
	# cases)
	# List is identical to build above, minus noop (no RPATH)
	cd tests && patchelf --remove-rpath \
		psx_test \
		libcap_psx_test \
		uns_test \
		libcap_launch_test \
		libcap_psx_launch_test \
		exploit \
		noexploit
	dh_auto_install -- \
		$(MAKE_ASSIGNMENTS) \
		lib=lib/$(DEB_HOST_MULTIARCH) \
		PKGCONFIGDIR=/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig \
		RAISE_SETFCAP=no
override_dh_auto_test:
	dh_auto_test -- $(MAKE_ASSIGNMENTS)
override_dh_makeshlibs:
	dh_makeshlibs -V'libcap2 (>= $(SHLIBS_MINVER))' -plibcap2 \
		--add-udeb=libcap2-udeb -- -c4
	dh_makeshlibs --remaining-packages -- -c4
export DH_GOLANG_BUILDPKG := \
	kernel.org/pub/linux/libs/security/libcap/cap \
	kernel.org/pub/linux/libs/security/libcap/psx
execute_after_dh_auto_configure-indep:
	dh_auto_configure -B_build -O--buildsystem=golang
execute_after_dh_auto_install-indep:
	dh_auto_install -B_build -O--buildsystem=golang
execute_after_dh_auto_build-indep:
	dh_auto_build -B_build -O--buildsystem=golang
 
     |