Andrew Morgan | 2c9c053 | 2007-07-10 20:50:21 -0700 | [diff] [blame] | 1 | # |
Andrew Morgan | 2c9c053 | 2007-07-10 20:50:21 -0700 | [diff] [blame] | 2 | ## Optional prefixes: |
| 3 | # |
| 4 | |
Rolf Eike Beer | 6f8b120 | 2016-05-10 17:57:11 +0200 | [diff] [blame] | 5 | # common 'packaging' directory |
Andrew Morgan | 2c9c053 | 2007-07-10 20:50:21 -0700 | [diff] [blame] | 6 | |
Mike Frysinger | 76f6f0a | 2008-02-16 16:52:31 -0500 | [diff] [blame] | 7 | FAKEROOT=$(DESTDIR) |
Andrew Morgan | 2c9c053 | 2007-07-10 20:50:21 -0700 | [diff] [blame] | 8 | |
| 9 | # Autoconf-style prefixes are activated when $(prefix) is defined. |
Andrew G Morgan | 9330818 | 2013-12-24 10:08:05 -0800 | [diff] [blame] | 10 | # Otherwise binaries and libraries are installed in /{lib,sbin}/, |
Andrew Morgan | 2c9c053 | 2007-07-10 20:50:21 -0700 | [diff] [blame] | 11 | # header files in /usr/include/ and documentation in /usr/man/man?/. |
Andrew G. Morgan | 85748f4 | 2010-08-08 17:42:11 -0700 | [diff] [blame] | 12 | # These choices are motivated by the fact that getcap and setcap are |
| 13 | # administrative operations that could be needed to recover a system. |
Andrew Morgan | 2c9c053 | 2007-07-10 20:50:21 -0700 | [diff] [blame] | 14 | |
Andrew Morgan | 5216fff | 2007-07-10 22:38:22 -0700 | [diff] [blame] | 15 | ifndef lib |
Andrew G Morgan | 9330818 | 2013-12-24 10:08:05 -0800 | [diff] [blame] | 16 | lib=$(shell ldd /usr/bin/ld|egrep "ld-linux|ld.so"|cut -d/ -f2) |
Andrew Morgan | 5216fff | 2007-07-10 22:38:22 -0700 | [diff] [blame] | 17 | endif |
| 18 | |
Andrew Morgan | 2c9c053 | 2007-07-10 20:50:21 -0700 | [diff] [blame] | 19 | ifdef prefix |
| 20 | exec_prefix=$(prefix) |
| 21 | lib_prefix=$(exec_prefix) |
| 22 | inc_prefix=$(lib_prefix) |
Andrew Morgan | 5216fff | 2007-07-10 22:38:22 -0700 | [diff] [blame] | 23 | man_prefix=$(prefix)/share |
Andrew Morgan | 2c9c053 | 2007-07-10 20:50:21 -0700 | [diff] [blame] | 24 | else |
| 25 | prefix=/usr |
| 26 | exec_prefix= |
| 27 | lib_prefix=$(exec_prefix) |
| 28 | inc_prefix=$(prefix) |
Andrew Morgan | 5216fff | 2007-07-10 22:38:22 -0700 | [diff] [blame] | 29 | man_prefix=$(prefix)/share |
Andrew Morgan | 2c9c053 | 2007-07-10 20:50:21 -0700 | [diff] [blame] | 30 | endif |
| 31 | |
| 32 | # Target directories |
| 33 | |
Benedikt Morbach | 0ee9421 | 2014-05-20 23:30:53 +0200 | [diff] [blame] | 34 | MANDIR=$(man_prefix)/man |
| 35 | SBINDIR=$(exec_prefix)/sbin |
| 36 | INCDIR=$(inc_prefix)/include |
| 37 | LIBDIR=$(lib_prefix)/$(lib) |
Rolf Eike Beer | 48f44c6 | 2016-05-10 17:55:17 +0200 | [diff] [blame] | 38 | PKGCONFIGDIR=$(LIBDIR)/pkgconfig |
Andrew G. Morgan | 1a61e6f | 2019-12-07 17:23:41 -0800 | [diff] [blame] | 39 | GOPKGDIR=$(prefix)/share/gocode/src |
Andrew Morgan | 2c9c053 | 2007-07-10 20:50:21 -0700 | [diff] [blame] | 40 | |
Andrew Morgan | 370a70f | 2007-07-17 21:50:12 -0700 | [diff] [blame] | 41 | # common defines for libcap |
| 42 | LIBTITLE=libcap |
Andrew Morgan | f782a97 | 2007-11-07 22:14:24 -0800 | [diff] [blame] | 43 | VERSION=2 |
Andrew G. Morgan | 5dcb05e | 2020-03-01 15:12:56 -0800 | [diff] [blame] | 44 | MINOR=33 |
Andrew Morgan | 2c9c053 | 2007-07-10 20:50:21 -0700 | [diff] [blame] | 45 | # |
| 46 | |
| 47 | # Compilation specifics |
| 48 | |
Andrew G Morgan | c329066 | 2014-01-01 17:56:31 -0800 | [diff] [blame] | 49 | KERNEL_HEADERS := $(topdir)/libcap/include/uapi |
| 50 | IPATH += -fPIC -I$(KERNEL_HEADERS) -I$(topdir)/libcap/include |
Andrew G. Morgan | 8bdd0ef | 2008-09-10 19:50:50 -0700 | [diff] [blame] | 51 | |
Rolf Eike Beer | ad120c1 | 2016-05-10 18:06:55 +0200 | [diff] [blame^] | 52 | CC := $(CROSS_COMPILE)gcc |
Rolf Eike Beer | 44a15c1 | 2016-05-10 18:01:22 +0200 | [diff] [blame] | 53 | DEFINES := -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 |
| 54 | CFLAGS := -O2 $(DEFINES) |
Andrew G. Morgan | 953e7f1 | 2008-06-02 22:02:01 -0700 | [diff] [blame] | 55 | BUILD_CC := $(CC) |
Rolf Eike Beer | 44a15c1 | 2016-05-10 18:01:22 +0200 | [diff] [blame] | 56 | BUILD_CFLAGS := -O2 $(DEFINES) $(IPATH) |
Rolf Eike Beer | ad120c1 | 2016-05-10 18:06:55 +0200 | [diff] [blame^] | 57 | AR := $(CROSS_COMPILE)ar |
| 58 | RANLIB := $(CROSS_COMPILE)ranlib |
Andrew G. Morgan | 953e7f1 | 2008-06-02 22:02:01 -0700 | [diff] [blame] | 59 | DEBUG = -g #-DDEBUG |
Torsten Werner | 7ebd7c5 | 2009-09-30 21:23:15 +0200 | [diff] [blame] | 60 | WARNINGS=-Wall -Wwrite-strings \ |
Andrew Morgan | 2c9c053 | 2007-07-10 20:50:21 -0700 | [diff] [blame] | 61 | -Wpointer-arith -Wcast-qual -Wcast-align \ |
Andrew Morgan | 5216fff | 2007-07-10 22:38:22 -0700 | [diff] [blame] | 62 | -Wstrict-prototypes -Wmissing-prototypes \ |
| 63 | -Wnested-externs -Winline -Wshadow |
Andrew Morgan | cd45c57 | 2007-08-13 23:16:50 -0700 | [diff] [blame] | 64 | LD=$(CC) -Wl,-x -shared |
Andrew G. Morgan | 953e7f1 | 2008-06-02 22:02:01 -0700 | [diff] [blame] | 65 | LDFLAGS := #-g |
Andrew G. Morgan | e9f55d9 | 2019-12-02 20:48:13 -0800 | [diff] [blame] | 66 | LIBCAPLIB := -L$(topdir)/libcap -lcap |
| 67 | LIBPSXLIB := -L$(topdir)/libcap -lpsx -lpthread |
| 68 | |
Matthieu Crapet | 3c22870 | 2014-03-28 14:11:15 +0100 | [diff] [blame] | 69 | BUILD_GPERF := $(shell which gperf >/dev/null 2>/dev/null && echo yes) |
Andrew Morgan | 2c9c053 | 2007-07-10 20:50:21 -0700 | [diff] [blame] | 70 | |
Andrew Morgan | 54f055e | 2007-07-21 22:18:02 -0700 | [diff] [blame] | 71 | SYSTEM_HEADERS = /usr/include |
Andrew Morgan | 2c9c053 | 2007-07-10 20:50:21 -0700 | [diff] [blame] | 72 | INCS=$(topdir)/libcap/include/sys/capability.h |
Andrew G. Morgan | 953e7f1 | 2008-06-02 22:02:01 -0700 | [diff] [blame] | 73 | LDFLAGS += -L$(topdir)/libcap |
Torsten Werner | 7ebd7c5 | 2009-09-30 21:23:15 +0200 | [diff] [blame] | 74 | CFLAGS += -Dlinux $(WARNINGS) $(DEBUG) |
Andrew G. Morgan | 953e7f1 | 2008-06-02 22:02:01 -0700 | [diff] [blame] | 75 | PAM_CAP := $(shell if [ -f /usr/include/security/pam_modules.h ]; then echo yes ; else echo no ; fi) |
Matthieu Crapet | 3c22870 | 2014-03-28 14:11:15 +0100 | [diff] [blame] | 76 | INDENT := $(shell if [ -n "$$(which indent 2>/dev/null)" ]; then echo "| indent -kr" ; fi) |
Andrew G. Morgan | 0a42b49 | 2008-10-19 19:37:28 -0700 | [diff] [blame] | 77 | DYNAMIC := $(shell if [ ! -d "$(topdir)/.git" ]; then echo yes; fi) |
| 78 | |
Andrew G. Morgan | 0615d99 | 2019-05-19 14:57:20 -0700 | [diff] [blame] | 79 | GOLANG := $(shell if [ -n "$(shell go version 2>/dev/null)" ]; then echo yes ; else echo no ; fi) |
| 80 | ifeq ($(GOLANG),yes) |
| 81 | GOROOT := $(shell go env GOROOT) |
Andrew G. Morgan | 2d2b702 | 2019-11-16 09:14:22 -0800 | [diff] [blame] | 82 | GOCGO := $(shell if [ "$(shell go env CGO_ENABLED)" = 1 ]; then echo yes ; else echo no ; fi) |
Andrew G. Morgan | 0615d99 | 2019-05-19 14:57:20 -0700 | [diff] [blame] | 83 | GOOSARCH := $(shell go env GOHOSTOS)_$(shell go env GOHOSTARCH) |
Andrew G. Morgan | b2b267e | 2019-11-30 18:33:42 -0800 | [diff] [blame] | 84 | CGO_CFLAGS := -I$(topdir)/libcap/include |
| 85 | CGO_LDFLAGS := -L$(topdir)/libcap |
| 86 | CGO_LDFLAGS_ALLOW := -Wl,-wrap,.+ |
Andrew G. Morgan | e305dd2 | 2019-12-07 08:04:58 -0800 | [diff] [blame] | 87 | CGO_REQUIRED=$(shell $(topdir)/go/cgo-required.sh) |
Andrew G. Morgan | 0615d99 | 2019-05-19 14:57:20 -0700 | [diff] [blame] | 88 | endif |
| 89 | |
Andrew G. Morgan | 2b5f563 | 2019-12-13 17:30:23 -0800 | [diff] [blame] | 90 | # When installing setcap, you can arrange for the installation process |
| 91 | # to set its inheritable bit to be able to place capabilities on files. |
| 92 | # It can be used in conjunction with pam_cap (associated with su and |
| 93 | # certain users say) to make it useful for specially blessed users. |
Andrew G. Morgan | 85748f4 | 2010-08-08 17:42:11 -0700 | [diff] [blame] | 94 | # |
Andrew G. Morgan | 2b5f563 | 2019-12-13 17:30:23 -0800 | [diff] [blame] | 95 | # make RAISE_SETFCAP=yes install |
Andrew G. Morgan | 85748f4 | 2010-08-08 17:42:11 -0700 | [diff] [blame] | 96 | # |
Andrew G. Morgan | 2b5f563 | 2019-12-13 17:30:23 -0800 | [diff] [blame] | 97 | # This is now defaulted to no because some distributions have started |
| 98 | # shipping with all users blessed with full inheritable sets which makes |
| 99 | # no sense whatsoever! |
| 100 | # |
| 101 | # Indeed, it looks alarmingly like these distributions are recreating |
| 102 | # the environment for what became known as the sendmail-capabilities |
| 103 | # bug from 2000: |
| 104 | # |
| 105 | # https://sites.google.com/site/fullycapable/Home/thesendmailcapabilitiesissue |
| 106 | # |
| 107 | # they are also nullifying the difference between a p-bit and an i-bit. |
| 108 | # |
| 109 | # Folk really should read this document, which explains there is a really |
| 110 | # important difference being lost here: |
| 111 | # |
| 112 | # https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/33528.pdf |
| 113 | # |
| 114 | # In the context of this tree, on such such systems, a yes setting will |
| 115 | # guarantee that every user, by default, is able to bless any binary with |
| 116 | # any capability - a ready made local exploit machanism. |
| 117 | RAISE_SETFCAP := no |
| 118 | |
| 119 | # If set to yes, this will cause the go "web" demo app to force the needed p |
| 120 | # bit to be able to bind to port 80 without running as root. |
| 121 | RAISE_GO_FILECAP := no |
Andrew G. Morgan | 85748f4 | 2010-08-08 17:42:11 -0700 | [diff] [blame] | 122 | |
Andrew Morgan | 2c9c053 | 2007-07-10 20:50:21 -0700 | [diff] [blame] | 123 | # Global cleanup stuff |
| 124 | |
| 125 | LOCALCLEAN=rm -f *~ core |
| 126 | DISTCLEAN=@find . \( -name '*.orig' -o -name '*.rej' \) | xargs rm -f |