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 | 7f51955 | 2020-06-02 21:07:49 -0700 | [diff] [blame] | 44 | MINOR=36 |
Andrew G. Morgan | a3e844a | 2020-07-02 16:39:24 -0700 | [diff] [blame^] | 45 | PATCH=0 |
Andrew Morgan | 2c9c053 | 2007-07-10 20:50:21 -0700 | [diff] [blame] | 46 | # |
| 47 | |
| 48 | # Compilation specifics |
| 49 | |
Andrew G Morgan | c329066 | 2014-01-01 17:56:31 -0800 | [diff] [blame] | 50 | KERNEL_HEADERS := $(topdir)/libcap/include/uapi |
| 51 | IPATH += -fPIC -I$(KERNEL_HEADERS) -I$(topdir)/libcap/include |
Andrew G. Morgan | 8bdd0ef | 2008-09-10 19:50:50 -0700 | [diff] [blame] | 52 | |
Rolf Eike Beer | ad120c1 | 2016-05-10 18:06:55 +0200 | [diff] [blame] | 53 | CC := $(CROSS_COMPILE)gcc |
Rolf Eike Beer | 44a15c1 | 2016-05-10 18:01:22 +0200 | [diff] [blame] | 54 | DEFINES := -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 |
| 55 | CFLAGS := -O2 $(DEFINES) |
Andrew G. Morgan | 953e7f1 | 2008-06-02 22:02:01 -0700 | [diff] [blame] | 56 | BUILD_CC := $(CC) |
Rolf Eike Beer | 44a15c1 | 2016-05-10 18:01:22 +0200 | [diff] [blame] | 57 | BUILD_CFLAGS := -O2 $(DEFINES) $(IPATH) |
Rolf Eike Beer | ad120c1 | 2016-05-10 18:06:55 +0200 | [diff] [blame] | 58 | AR := $(CROSS_COMPILE)ar |
| 59 | RANLIB := $(CROSS_COMPILE)ranlib |
Andrew G. Morgan | 953e7f1 | 2008-06-02 22:02:01 -0700 | [diff] [blame] | 60 | DEBUG = -g #-DDEBUG |
Torsten Werner | 7ebd7c5 | 2009-09-30 21:23:15 +0200 | [diff] [blame] | 61 | WARNINGS=-Wall -Wwrite-strings \ |
Andrew Morgan | 2c9c053 | 2007-07-10 20:50:21 -0700 | [diff] [blame] | 62 | -Wpointer-arith -Wcast-qual -Wcast-align \ |
Andrew Morgan | 5216fff | 2007-07-10 22:38:22 -0700 | [diff] [blame] | 63 | -Wstrict-prototypes -Wmissing-prototypes \ |
| 64 | -Wnested-externs -Winline -Wshadow |
Andrew Morgan | cd45c57 | 2007-08-13 23:16:50 -0700 | [diff] [blame] | 65 | LD=$(CC) -Wl,-x -shared |
Andrew G. Morgan | 953e7f1 | 2008-06-02 22:02:01 -0700 | [diff] [blame] | 66 | LDFLAGS := #-g |
Andrew G. Morgan | e9f55d9 | 2019-12-02 20:48:13 -0800 | [diff] [blame] | 67 | LIBCAPLIB := -L$(topdir)/libcap -lcap |
| 68 | LIBPSXLIB := -L$(topdir)/libcap -lpsx -lpthread |
| 69 | |
Matthieu Crapet | 3c22870 | 2014-03-28 14:11:15 +0100 | [diff] [blame] | 70 | BUILD_GPERF := $(shell which gperf >/dev/null 2>/dev/null && echo yes) |
Andrew Morgan | 2c9c053 | 2007-07-10 20:50:21 -0700 | [diff] [blame] | 71 | |
Andrew Morgan | 54f055e | 2007-07-21 22:18:02 -0700 | [diff] [blame] | 72 | SYSTEM_HEADERS = /usr/include |
Andrew Morgan | 2c9c053 | 2007-07-10 20:50:21 -0700 | [diff] [blame] | 73 | INCS=$(topdir)/libcap/include/sys/capability.h |
Andrew G. Morgan | 953e7f1 | 2008-06-02 22:02:01 -0700 | [diff] [blame] | 74 | LDFLAGS += -L$(topdir)/libcap |
Torsten Werner | 7ebd7c5 | 2009-09-30 21:23:15 +0200 | [diff] [blame] | 75 | CFLAGS += -Dlinux $(WARNINGS) $(DEBUG) |
Andrew G. Morgan | 953e7f1 | 2008-06-02 22:02:01 -0700 | [diff] [blame] | 76 | 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] | 77 | 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] | 78 | DYNAMIC := $(shell if [ ! -d "$(topdir)/.git" ]; then echo yes; fi) |
| 79 | |
Andrew G. Morgan | 0615d99 | 2019-05-19 14:57:20 -0700 | [diff] [blame] | 80 | GOLANG := $(shell if [ -n "$(shell go version 2>/dev/null)" ]; then echo yes ; else echo no ; fi) |
| 81 | ifeq ($(GOLANG),yes) |
| 82 | GOROOT := $(shell go env GOROOT) |
Andrew G. Morgan | 2d2b702 | 2019-11-16 09:14:22 -0800 | [diff] [blame] | 83 | 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] | 84 | GOOSARCH := $(shell go env GOHOSTOS)_$(shell go env GOHOSTARCH) |
Andrew G. Morgan | b2b267e | 2019-11-30 18:33:42 -0800 | [diff] [blame] | 85 | CGO_CFLAGS := -I$(topdir)/libcap/include |
| 86 | CGO_LDFLAGS := -L$(topdir)/libcap |
Andrew G. Morgan | a3e844a | 2020-07-02 16:39:24 -0700 | [diff] [blame^] | 87 | CGO_LDFLAGS_ALLOW := -Wl,-?-wrap[=,][^-.@][^,]* |
Andrew G. Morgan | e305dd2 | 2019-12-07 08:04:58 -0800 | [diff] [blame] | 88 | CGO_REQUIRED=$(shell $(topdir)/go/cgo-required.sh) |
Andrew G. Morgan | 0615d99 | 2019-05-19 14:57:20 -0700 | [diff] [blame] | 89 | endif |
| 90 | |
Andrew G. Morgan | cbca9ab | 2020-04-05 19:31:19 -0700 | [diff] [blame] | 91 | # If you want capsh to launch with something other than /bin/bash |
| 92 | # build like this: |
| 93 | # |
| 94 | # make CAPSH_SHELL='-DSHELL=\"/bin/sh\"' |
| 95 | # |
| 96 | # or undefine the following: |
| 97 | #CAPSH_SHELL := '-DSHELL="/bin/sh"' |
| 98 | |
Andrew G. Morgan | 2b5f563 | 2019-12-13 17:30:23 -0800 | [diff] [blame] | 99 | # When installing setcap, you can arrange for the installation process |
| 100 | # to set its inheritable bit to be able to place capabilities on files. |
| 101 | # It can be used in conjunction with pam_cap (associated with su and |
| 102 | # certain users say) to make it useful for specially blessed users. |
Andrew G. Morgan | 85748f4 | 2010-08-08 17:42:11 -0700 | [diff] [blame] | 103 | # |
Andrew G. Morgan | 2b5f563 | 2019-12-13 17:30:23 -0800 | [diff] [blame] | 104 | # make RAISE_SETFCAP=yes install |
Andrew G. Morgan | 85748f4 | 2010-08-08 17:42:11 -0700 | [diff] [blame] | 105 | # |
Andrew G. Morgan | 2b5f563 | 2019-12-13 17:30:23 -0800 | [diff] [blame] | 106 | # This is now defaulted to no because some distributions have started |
| 107 | # shipping with all users blessed with full inheritable sets which makes |
| 108 | # no sense whatsoever! |
| 109 | # |
| 110 | # Indeed, it looks alarmingly like these distributions are recreating |
| 111 | # the environment for what became known as the sendmail-capabilities |
| 112 | # bug from 2000: |
| 113 | # |
| 114 | # https://sites.google.com/site/fullycapable/Home/thesendmailcapabilitiesissue |
| 115 | # |
| 116 | # they are also nullifying the difference between a p-bit and an i-bit. |
| 117 | # |
| 118 | # Folk really should read this document, which explains there is a really |
| 119 | # important difference being lost here: |
| 120 | # |
| 121 | # https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/33528.pdf |
| 122 | # |
| 123 | # In the context of this tree, on such such systems, a yes setting will |
| 124 | # guarantee that every user, by default, is able to bless any binary with |
| 125 | # any capability - a ready made local exploit machanism. |
| 126 | RAISE_SETFCAP := no |
| 127 | |
| 128 | # If set to yes, this will cause the go "web" demo app to force the needed p |
| 129 | # bit to be able to bind to port 80 without running as root. |
| 130 | RAISE_GO_FILECAP := no |
Andrew G. Morgan | 85748f4 | 2010-08-08 17:42:11 -0700 | [diff] [blame] | 131 | |
Andrew Morgan | 2c9c053 | 2007-07-10 20:50:21 -0700 | [diff] [blame] | 132 | # Global cleanup stuff |
| 133 | |
| 134 | LOCALCLEAN=rm -f *~ core |
| 135 | DISTCLEAN=@find . \( -name '*.orig' -o -name '*.rej' \) | xargs rm -f |