diff options
author | David Seifert <soap@gentoo.org> | 2021-09-01 16:53:17 +0200 |
---|---|---|
committer | Andrew G. Morgan <morgan@kernel.org> | 2021-09-01 19:17:05 -0700 |
commit | 2762c2c1a8c98d9012fcd40f20d133493a0b3219 (patch) | |
tree | 7b72d2b1c2660fed4549bc843d8fca58c530627d | |
parent | 41f065cdc95f8bbe79ccba94cff20cd5434f7d2a (diff) | |
download | libcap2-2762c2c1a8c98d9012fcd40f20d133493a0b3219.tar.gz |
Canonicalize build system
* Respect user's CFLAGS/CPPFLAGS/LDFLAGS
* Respect $(MAKE)
* Remove CPPFLAGS from link rules
Note: for in-tree built test binaries, where we build --static,
we do not apply LDFLAGS: we want to limit external
dependencies in general; and users' LDFLAGS have a strong
tendency to conflict with --static for linking.
Work in collaboration with David Seifert (ie, he wrote most of it).
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
-rw-r--r-- | contrib/bug400591/Makefile | 4 | ||||
-rw-r--r-- | contrib/sucap/Makefile | 2 | ||||
-rw-r--r-- | kdebug/Makefile | 2 | ||||
-rw-r--r-- | libcap/Makefile | 5 | ||||
-rw-r--r-- | pam_cap/Makefile | 10 | ||||
-rw-r--r-- | tests/Makefile | 9 |
6 files changed, 12 insertions, 20 deletions
diff --git a/contrib/bug400591/Makefile b/contrib/bug400591/Makefile index 320610c..bb2e59d 100644 --- a/contrib/bug400591/Makefile +++ b/contrib/bug400591/Makefile @@ -1,8 +1,8 @@ all: bug bug: bug.c ../../libcap Makefile - make -C ../../libcap - cc -g -I../../libcap/include --static -o $@ $< -L../../libcap -lcap + $(MAKE) -C ../../libcap + $(CC) $(CFLAGS) $(CPPFLAGS) -g -I../../libcap/include --static -o $@ $< -L../../libcap -lcap ./bug clean: diff --git a/contrib/sucap/Makefile b/contrib/sucap/Makefile index 91947af..8cd4cef 100644 --- a/contrib/sucap/Makefile +++ b/contrib/sucap/Makefile @@ -1,7 +1,7 @@ all: su su: su.c - $(CC) -DPAM_APP_NAME=\"sucap\" -o $@ $< -lpam -lpam_misc -lcap + $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -DPAM_APP_NAME=\"sucap\" -o $@ $< -lpam -lpam_misc -lcap # to permit all ambient capabilities, this needs all permitted. sudo setcap =p ./su diff --git a/kdebug/Makefile b/kdebug/Makefile index 0e8c11f..35a16d0 100644 --- a/kdebug/Makefile +++ b/kdebug/Makefile @@ -10,7 +10,7 @@ shell: exit ./test-kernel.sh exit: exit.c - $(CC) -O2 $< -o $@ --static + $(CC) $(CFLAGS) $(CPPFLAGS) $< -o $@ --static all: @echo cd to kdebug to test a kernel build diff --git a/libcap/Makefile b/libcap/Makefile index 399aa66..4b96a0c 100644 --- a/libcap/Makefile +++ b/libcap/Makefile @@ -104,9 +104,6 @@ $(STAPSXLIBNAME): $(PSXOBJS) include/sys/psx_syscall.h ifeq ($(SHARED),yes) -empty: empty.c - $(CC) -o $@ $< - loader.txt: empty $(OBJCOPY) --dump-section .interp=$@ $< /dev/null @@ -134,7 +131,7 @@ cap_text.o: cap_text.c $(USE_GPERF_OUTPUT) $(INCLS) $(CC) $(CFLAGS) $(CPPFLAGS) $(INCLUDE_GPERF_OUTPUT) -c $< -o $@ cap_test: cap_test.c libcap.h $(CAPOBJS) - $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CAPOBJS) -o $@ + $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $< $(CAPOBJS) -o $@ libcapsotest: $(CAPLIBNAME) ./$(CAPLIBNAME) diff --git a/pam_cap/Makefile b/pam_cap/Makefile index 09083ea..b245307 100644 --- a/pam_cap/Makefile +++ b/pam_cap/Makefile @@ -55,20 +55,18 @@ lazylink.so: lazylink.c ../libcap/execable.h ../libcap/loader.txt endif endif -pam_cap.o: pam_cap.c - $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@ - ../libcap/libcap.a: $(MAKE) -C ../libcap libcap.a +# Avoid $(LDFLAGS) here to avoid conflicts with --static for a in-tree +# test binary. test_pam_cap: test_pam_cap.c pam_cap.c ../libcap/libcap.a - $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ test_pam_cap.c $(LIBCAPLIB) --static + $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ test_pam_cap.c $(LIBCAPLIB) --static -testlink: test.c pam_cap.o +testlink: test.o pam_cap.o $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $+ -lpam -ldl $(LIBCAPLIB) test: testlink test_pam_cap pam_cap.so - $(MAKE) testlink ./test_pam_cap LD_LIBRARY_PATH=../libcap ./pam_cap.so LD_LIBRARY_PATH=../libcap ./pam_cap.so --help diff --git a/tests/Makefile b/tests/Makefile index 770cffa..dd78432 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -105,20 +105,17 @@ run_exploit_test: exploit noexploit @echo exploit should fail $(SUDO) ./noexploit ; if [ $$? -eq 0 ]; then exit 0; else exit 1 ; fi -exploit.o: exploit.c - $(CC) $(CFLAGS) $(CPPFLAGS) -c $< - exploit: exploit.o $(DEPS) - $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $< -o $@ $(LINKEXTRA) $(LIBCAPLIB) -lpthread + $(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ $(LINKEXTRA) $(LIBCAPLIB) -lpthread # Note, for some reason, the order of libraries is important to avoid # the exploit working for dynamic linking. noexploit: exploit.o $(DEPS) - $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $< -o $@ $(LINKEXTRA) $(LIBPSXLIB) $(LIBCAPLIB) + $(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ $(LINKEXTRA) $(LIBPSXLIB) $(LIBCAPLIB) # This one runs in a chroot with no shared library files. noop: noop.c - $(CC) $(CFLAGS) $< -o $@ --static + $(CC) $(CFLAGS) $(CPPFLAGS) $< -o $@ --static clean: rm -f psx_test libcap_psx_test libcap_launch_test uns_test *~ |