Andrew G. Morgan | dbeb06b | 2020-08-15 11:17:55 -0700 | [diff] [blame] | 1 | # Common version number defines for libcap |
| 2 | LIBTITLE=libcap |
| 3 | VERSION=2 |
Andrew G. Morgan | 797050c | 2021-08-15 19:06:35 -0700 | [diff] [blame] | 4 | MINOR=53 |
Andrew G. Morgan | dbeb06b | 2020-08-15 11:17:55 -0700 | [diff] [blame] | 5 | |
Andrew Morgan | 2c9c053 | 2007-07-10 20:50:21 -0700 | [diff] [blame] | 6 | # |
Andrew Morgan | 2c9c053 | 2007-07-10 20:50:21 -0700 | [diff] [blame] | 7 | ## Optional prefixes: |
| 8 | # |
| 9 | |
Rolf Eike Beer | 6f8b120 | 2016-05-10 17:57:11 +0200 | [diff] [blame] | 10 | # common 'packaging' directory |
Andrew Morgan | 2c9c053 | 2007-07-10 20:50:21 -0700 | [diff] [blame] | 11 | |
Mike Frysinger | 76f6f0a | 2008-02-16 16:52:31 -0500 | [diff] [blame] | 12 | FAKEROOT=$(DESTDIR) |
Andrew Morgan | 2c9c053 | 2007-07-10 20:50:21 -0700 | [diff] [blame] | 13 | |
| 14 | # Autoconf-style prefixes are activated when $(prefix) is defined. |
Andrew G Morgan | 9330818 | 2013-12-24 10:08:05 -0800 | [diff] [blame] | 15 | # Otherwise binaries and libraries are installed in /{lib,sbin}/, |
Andrew Morgan | 2c9c053 | 2007-07-10 20:50:21 -0700 | [diff] [blame] | 16 | # header files in /usr/include/ and documentation in /usr/man/man?/. |
Andrew G. Morgan | 85748f4 | 2010-08-08 17:42:11 -0700 | [diff] [blame] | 17 | # These choices are motivated by the fact that getcap and setcap are |
| 18 | # administrative operations that could be needed to recover a system. |
Andrew Morgan | 2c9c053 | 2007-07-10 20:50:21 -0700 | [diff] [blame] | 19 | |
Andrew Morgan | 5216fff | 2007-07-10 22:38:22 -0700 | [diff] [blame] | 20 | ifndef lib |
Andrew G Morgan | 9330818 | 2013-12-24 10:08:05 -0800 | [diff] [blame] | 21 | 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] | 22 | endif |
| 23 | |
Andrew Morgan | 2c9c053 | 2007-07-10 20:50:21 -0700 | [diff] [blame] | 24 | ifdef prefix |
| 25 | exec_prefix=$(prefix) |
| 26 | lib_prefix=$(exec_prefix) |
| 27 | inc_prefix=$(lib_prefix) |
Andrew Morgan | 5216fff | 2007-07-10 22:38:22 -0700 | [diff] [blame] | 28 | man_prefix=$(prefix)/share |
Andrew Morgan | 2c9c053 | 2007-07-10 20:50:21 -0700 | [diff] [blame] | 29 | else |
| 30 | prefix=/usr |
| 31 | exec_prefix= |
| 32 | lib_prefix=$(exec_prefix) |
| 33 | inc_prefix=$(prefix) |
Andrew Morgan | 5216fff | 2007-07-10 22:38:22 -0700 | [diff] [blame] | 34 | man_prefix=$(prefix)/share |
Andrew Morgan | 2c9c053 | 2007-07-10 20:50:21 -0700 | [diff] [blame] | 35 | endif |
| 36 | |
| 37 | # Target directories |
| 38 | |
Benedikt Morbach | 0ee9421 | 2014-05-20 23:30:53 +0200 | [diff] [blame] | 39 | MANDIR=$(man_prefix)/man |
| 40 | SBINDIR=$(exec_prefix)/sbin |
| 41 | INCDIR=$(inc_prefix)/include |
| 42 | LIBDIR=$(lib_prefix)/$(lib) |
Rolf Eike Beer | 48f44c6 | 2016-05-10 17:55:17 +0200 | [diff] [blame] | 43 | PKGCONFIGDIR=$(LIBDIR)/pkgconfig |
Andrew G. Morgan | 1a61e6f | 2019-12-07 17:23:41 -0800 | [diff] [blame] | 44 | GOPKGDIR=$(prefix)/share/gocode/src |
Andrew Morgan | 2c9c053 | 2007-07-10 20:50:21 -0700 | [diff] [blame] | 45 | |
Andrew G. Morgan | 75a5a9e | 2021-02-04 22:15:03 -0800 | [diff] [blame] | 46 | # From here on out, the Go module packages should always remain |
| 47 | # backwardly compatible. I will only resort to using major version 2 |
| 48 | # etc if Go's syntax dramatically changes in a backwards incompatible |
| 49 | # manner. (Let's hope not.) |
| 50 | GOMAJOR=1 |
Andrew Morgan | 2c9c053 | 2007-07-10 20:50:21 -0700 | [diff] [blame] | 51 | |
| 52 | # Compilation specifics |
| 53 | |
Andrew G Morgan | c329066 | 2014-01-01 17:56:31 -0800 | [diff] [blame] | 54 | KERNEL_HEADERS := $(topdir)/libcap/include/uapi |
| 55 | IPATH += -fPIC -I$(KERNEL_HEADERS) -I$(topdir)/libcap/include |
Andrew G. Morgan | 8bdd0ef | 2008-09-10 19:50:50 -0700 | [diff] [blame] | 56 | |
Rolf Eike Beer | de3dbde | 2020-09-30 09:17:02 +0200 | [diff] [blame] | 57 | CC := $(CROSS_COMPILE)gcc |
Rolf Eike Beer | 44a15c1 | 2016-05-10 18:01:22 +0200 | [diff] [blame] | 58 | DEFINES := -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 |
Rolf Eike Beer | bbe2115 | 2020-09-30 09:02:45 +0200 | [diff] [blame] | 59 | COPTS ?= -O2 |
| 60 | CFLAGS ?= $(COPTS) $(DEFINES) |
Fabrice Fontaine | 22f2e20 | 2020-07-30 09:48:44 +0200 | [diff] [blame] | 61 | BUILD_CC ?= $(CC) |
Rolf Eike Beer | bbe2115 | 2020-09-30 09:02:45 +0200 | [diff] [blame] | 62 | BUILD_COPTS ?= -O2 |
| 63 | BUILD_CFLAGS ?= $(BUILD_COPTS) $(DEFINES) $(IPATH) |
Rolf Eike Beer | de3dbde | 2020-09-30 09:17:02 +0200 | [diff] [blame] | 64 | AR := $(CROSS_COMPILE)ar |
| 65 | RANLIB := $(CROSS_COMPILE)ranlib |
Andrew G. Morgan | ee3b25c | 2021-07-12 16:32:56 -0700 | [diff] [blame] | 66 | OBJCOPY := $(CROSS_COMPILE)objcopy |
Andrew G. Morgan | 953e7f1 | 2008-06-02 22:02:01 -0700 | [diff] [blame] | 67 | DEBUG = -g #-DDEBUG |
Torsten Werner | 7ebd7c5 | 2009-09-30 21:23:15 +0200 | [diff] [blame] | 68 | WARNINGS=-Wall -Wwrite-strings \ |
Andrew Morgan | 2c9c053 | 2007-07-10 20:50:21 -0700 | [diff] [blame] | 69 | -Wpointer-arith -Wcast-qual -Wcast-align \ |
Andrew Morgan | 5216fff | 2007-07-10 22:38:22 -0700 | [diff] [blame] | 70 | -Wstrict-prototypes -Wmissing-prototypes \ |
| 71 | -Wnested-externs -Winline -Wshadow |
Andrew Morgan | cd45c57 | 2007-08-13 23:16:50 -0700 | [diff] [blame] | 72 | LD=$(CC) -Wl,-x -shared |
Fabrice Fontaine | 22f2e20 | 2020-07-30 09:48:44 +0200 | [diff] [blame] | 73 | LDFLAGS ?= #-g |
Andrew G. Morgan | e9f55d9 | 2019-12-02 20:48:13 -0800 | [diff] [blame] | 74 | LIBCAPLIB := -L$(topdir)/libcap -lcap |
Andrew G. Morgan | 6b1d98b | 2020-10-13 06:21:55 -0700 | [diff] [blame] | 75 | PSXLINKFLAGS := -lpthread -Wl,-wrap,pthread_create |
| 76 | LIBPSXLIB := -L$(topdir)/libcap -lpsx $(PSXLINKFLAGS) |
Andrew G. Morgan | e9f55d9 | 2019-12-02 20:48:13 -0800 | [diff] [blame] | 77 | |
Matthieu Crapet | 3c22870 | 2014-03-28 14:11:15 +0100 | [diff] [blame] | 78 | BUILD_GPERF := $(shell which gperf >/dev/null 2>/dev/null && echo yes) |
Andrew Morgan | 2c9c053 | 2007-07-10 20:50:21 -0700 | [diff] [blame] | 79 | |
Andrew Morgan | 54f055e | 2007-07-21 22:18:02 -0700 | [diff] [blame] | 80 | SYSTEM_HEADERS = /usr/include |
Andrew Morgan | 2c9c053 | 2007-07-10 20:50:21 -0700 | [diff] [blame] | 81 | INCS=$(topdir)/libcap/include/sys/capability.h |
Torsten Werner | 7ebd7c5 | 2009-09-30 21:23:15 +0200 | [diff] [blame] | 82 | CFLAGS += -Dlinux $(WARNINGS) $(DEBUG) |
Matthieu Crapet | 3c22870 | 2014-03-28 14:11:15 +0100 | [diff] [blame] | 83 | INDENT := $(shell if [ -n "$$(which indent 2>/dev/null)" ]; then echo "| indent -kr" ; fi) |
Andrew G. Morgan | f025e2f | 2020-11-01 15:00:02 -0800 | [diff] [blame] | 84 | |
| 85 | # SHARED tracks whether or not the SHARED libraries (libcap.so, |
| 86 | # libpsx.so and pam_cap.so) are built. (Some environments don't |
| 87 | # support shared libraries.) |
| 88 | SHARED ?= yes |
| 89 | # DYNAMIC controls how capsh etc are linked - to shared or static libraries |
| 90 | DYNAMIC := $(shell if [ ! -d "$(topdir)/.git" ]; then echo $(SHARED); else echo no ; fi) |
| 91 | |
| 92 | PAM_CAP ?= $(shell if [ -f /usr/include/security/pam_modules.h ]; then echo $(SHARED) ; else echo no ; fi) |
Andrew G. Morgan | 0a42b49 | 2008-10-19 19:37:28 -0700 | [diff] [blame] | 93 | |
Andrew G. Morgan | 24375fb | 2020-10-27 20:20:47 -0700 | [diff] [blame] | 94 | # If your system does not support pthreads, override this as "no". |
| 95 | # |
| 96 | # make PTHREADS=no ... |
| 97 | # |
| 98 | # This implies no Go support and no C/C++ libpsx build. Why might you |
| 99 | # need libpsx for non-Go use? Tl;dr for POSIX semantics security: |
| 100 | # |
| 101 | # https://sites.google.com/site/fullycapable/who-ordered-libpsx |
| 102 | # |
| 103 | PTHREADS ?= yes |
| 104 | |
| 105 | ifeq ($(PTHREADS),yes) |
Andrew G. Morgan | 068edb7 | 2021-02-04 21:13:27 -0800 | [diff] [blame] | 106 | GO ?= go |
| 107 | GOLANG ?= $(shell if [ -n "$(shell $(GO) version 2>/dev/null)" ]; then echo yes ; else echo no ; fi) |
Andrew G. Morgan | 0615d99 | 2019-05-19 14:57:20 -0700 | [diff] [blame] | 108 | ifeq ($(GOLANG),yes) |
Andrew G. Morgan | 068edb7 | 2021-02-04 21:13:27 -0800 | [diff] [blame] | 109 | GOROOT ?= $(shell $(GO) env GOROOT) |
| 110 | GOCGO ?= $(shell if [ "$(shell $(GO) env CGO_ENABLED)" = 1 ]; then echo yes ; else echo no ; fi) |
| 111 | GOOSARCH ?= $(shell $(GO) env GOHOSTOS)_$(shell $(GO) env GOHOSTARCH) |
| 112 | CGO_REQUIRED=$(shell $(topdir)/go/cgo-required.sh $(GO)) |
| 113 | ifeq ($(CGO_REQUIRED),1) |
| 114 | # Strictly speaking go1.15 doesn't need this, but 1.16 is when the |
| 115 | # real golang support arrives for non-cgo support, so drop the last |
| 116 | # vestige of legacy workarounds then. |
Andrew G. Morgan | 1b59ff9 | 2021-06-20 15:40:15 -0700 | [diff] [blame] | 117 | CGO_LDFLAGS_ALLOW := CGO_LDFLAGS_ALLOW="-Wl,-?-wrap[=,][^-.@][^,]*" |
Andrew G. Morgan | 068edb7 | 2021-02-04 21:13:27 -0800 | [diff] [blame] | 118 | endif |
Andrew G. Morgan | b2b267e | 2019-11-30 18:33:42 -0800 | [diff] [blame] | 119 | CGO_CFLAGS := -I$(topdir)/libcap/include |
| 120 | CGO_LDFLAGS := -L$(topdir)/libcap |
Andrew G. Morgan | 0615d99 | 2019-05-19 14:57:20 -0700 | [diff] [blame] | 121 | endif |
Andrew G. Morgan | 24375fb | 2020-10-27 20:20:47 -0700 | [diff] [blame] | 122 | endif |
Andrew G. Morgan | 0615d99 | 2019-05-19 14:57:20 -0700 | [diff] [blame] | 123 | |
Andrew G. Morgan | cbca9ab | 2020-04-05 19:31:19 -0700 | [diff] [blame] | 124 | # If you want capsh to launch with something other than /bin/bash |
| 125 | # build like this: |
| 126 | # |
| 127 | # make CAPSH_SHELL='-DSHELL=\"/bin/sh\"' |
| 128 | # |
| 129 | # or undefine the following: |
| 130 | #CAPSH_SHELL := '-DSHELL="/bin/sh"' |
| 131 | |
Andrew G. Morgan | 2b5f563 | 2019-12-13 17:30:23 -0800 | [diff] [blame] | 132 | # When installing setcap, you can arrange for the installation process |
| 133 | # to set its inheritable bit to be able to place capabilities on files. |
| 134 | # It can be used in conjunction with pam_cap (associated with su and |
| 135 | # certain users say) to make it useful for specially blessed users. |
Andrew G. Morgan | 85748f4 | 2010-08-08 17:42:11 -0700 | [diff] [blame] | 136 | # |
Andrew G. Morgan | 2b5f563 | 2019-12-13 17:30:23 -0800 | [diff] [blame] | 137 | # make RAISE_SETFCAP=yes install |
Andrew G. Morgan | 85748f4 | 2010-08-08 17:42:11 -0700 | [diff] [blame] | 138 | # |
Andrew G. Morgan | 2b5f563 | 2019-12-13 17:30:23 -0800 | [diff] [blame] | 139 | # This is now defaulted to no because some distributions have started |
| 140 | # shipping with all users blessed with full inheritable sets which makes |
| 141 | # no sense whatsoever! |
| 142 | # |
| 143 | # Indeed, it looks alarmingly like these distributions are recreating |
| 144 | # the environment for what became known as the sendmail-capabilities |
| 145 | # bug from 2000: |
| 146 | # |
| 147 | # https://sites.google.com/site/fullycapable/Home/thesendmailcapabilitiesissue |
| 148 | # |
| 149 | # they are also nullifying the difference between a p-bit and an i-bit. |
| 150 | # |
| 151 | # Folk really should read this document, which explains there is a really |
| 152 | # important difference being lost here: |
| 153 | # |
| 154 | # https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/33528.pdf |
| 155 | # |
| 156 | # In the context of this tree, on such such systems, a yes setting will |
| 157 | # guarantee that every user, by default, is able to bless any binary with |
Samanta Navarro | e721aff | 2021-08-14 12:08:22 +0000 | [diff] [blame] | 158 | # any capability - a ready made local exploit mechanism. |
Andrew G. Morgan | 2b5f563 | 2019-12-13 17:30:23 -0800 | [diff] [blame] | 159 | RAISE_SETFCAP := no |
| 160 | |
| 161 | # If set to yes, this will cause the go "web" demo app to force the needed p |
| 162 | # bit to be able to bind to port 80 without running as root. |
| 163 | RAISE_GO_FILECAP := no |
Andrew G. Morgan | 85748f4 | 2010-08-08 17:42:11 -0700 | [diff] [blame] | 164 | |
Andrew Morgan | 2c9c053 | 2007-07-10 20:50:21 -0700 | [diff] [blame] | 165 | # Global cleanup stuff |
| 166 | |
| 167 | LOCALCLEAN=rm -f *~ core |
| 168 | DISTCLEAN=@find . \( -name '*.orig' -o -name '*.rej' \) | xargs rm -f |