blob: 03ae7006075d9ea7c3665130b1e2e6c4e0291e45 [file] [log] [blame]
Andrew Morgan2c9c0532007-07-10 20:50:21 -07001#
Andrew Morgan2c9c0532007-07-10 20:50:21 -07002## Optional prefixes:
3#
4
Rolf Eike Beer6f8b1202016-05-10 17:57:11 +02005# common 'packaging' directory
Andrew Morgan2c9c0532007-07-10 20:50:21 -07006
Mike Frysinger76f6f0a2008-02-16 16:52:31 -05007FAKEROOT=$(DESTDIR)
Andrew Morgan2c9c0532007-07-10 20:50:21 -07008
9# Autoconf-style prefixes are activated when $(prefix) is defined.
Andrew G Morgan93308182013-12-24 10:08:05 -080010# Otherwise binaries and libraries are installed in /{lib,sbin}/,
Andrew Morgan2c9c0532007-07-10 20:50:21 -070011# header files in /usr/include/ and documentation in /usr/man/man?/.
Andrew G. Morgan85748f42010-08-08 17:42:11 -070012# These choices are motivated by the fact that getcap and setcap are
13# administrative operations that could be needed to recover a system.
Andrew Morgan2c9c0532007-07-10 20:50:21 -070014
Andrew Morgan5216fff2007-07-10 22:38:22 -070015ifndef lib
Andrew G Morgan93308182013-12-24 10:08:05 -080016lib=$(shell ldd /usr/bin/ld|egrep "ld-linux|ld.so"|cut -d/ -f2)
Andrew Morgan5216fff2007-07-10 22:38:22 -070017endif
18
Andrew Morgan2c9c0532007-07-10 20:50:21 -070019ifdef prefix
20exec_prefix=$(prefix)
21lib_prefix=$(exec_prefix)
22inc_prefix=$(lib_prefix)
Andrew Morgan5216fff2007-07-10 22:38:22 -070023man_prefix=$(prefix)/share
Andrew Morgan2c9c0532007-07-10 20:50:21 -070024else
25prefix=/usr
26exec_prefix=
27lib_prefix=$(exec_prefix)
28inc_prefix=$(prefix)
Andrew Morgan5216fff2007-07-10 22:38:22 -070029man_prefix=$(prefix)/share
Andrew Morgan2c9c0532007-07-10 20:50:21 -070030endif
31
32# Target directories
33
Benedikt Morbach0ee94212014-05-20 23:30:53 +020034MANDIR=$(man_prefix)/man
35SBINDIR=$(exec_prefix)/sbin
36INCDIR=$(inc_prefix)/include
37LIBDIR=$(lib_prefix)/$(lib)
Rolf Eike Beer48f44c62016-05-10 17:55:17 +020038PKGCONFIGDIR=$(LIBDIR)/pkgconfig
Andrew G. Morgan1a61e6f2019-12-07 17:23:41 -080039GOPKGDIR=$(prefix)/share/gocode/src
Andrew Morgan2c9c0532007-07-10 20:50:21 -070040
Andrew G. Morgan19eebc52020-07-05 14:07:52 -070041# Common version number defines for libcap
Andrew Morgan370a70f2007-07-17 21:50:12 -070042LIBTITLE=libcap
Andrew Morganf782a972007-11-07 22:14:24 -080043VERSION=2
Andrew G. Morgan7ad50362020-07-24 19:39:35 -070044MINOR=41
Andrew G. Morgan876ac712020-07-02 21:36:16 -070045
Andrew G. Morgan19eebc52020-07-05 14:07:52 -070046# Go modules have their own semantics. I plan to leave this value at 0
47# and keep it there. The Go packages should always remain backwardly
48# compatible, but I may have to up it if Go's syntax changes in a
49# backwards incompatible manner. (Let's hope not.)
Andrew G. Morgan876ac712020-07-02 21:36:16 -070050GOMAJOR=0
Andrew Morgan2c9c0532007-07-10 20:50:21 -070051
52# Compilation specifics
53
Andrew G Morganc3290662014-01-01 17:56:31 -080054KERNEL_HEADERS := $(topdir)/libcap/include/uapi
55IPATH += -fPIC -I$(KERNEL_HEADERS) -I$(topdir)/libcap/include
Andrew G. Morgan8bdd0ef2008-09-10 19:50:50 -070056
Rolf Eike Beerad120c12016-05-10 18:06:55 +020057CC := $(CROSS_COMPILE)gcc
Rolf Eike Beer44a15c12016-05-10 18:01:22 +020058DEFINES := -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
59CFLAGS := -O2 $(DEFINES)
Andrew G. Morgan953e7f12008-06-02 22:02:01 -070060BUILD_CC := $(CC)
Rolf Eike Beer44a15c12016-05-10 18:01:22 +020061BUILD_CFLAGS := -O2 $(DEFINES) $(IPATH)
Rolf Eike Beerad120c12016-05-10 18:06:55 +020062AR := $(CROSS_COMPILE)ar
63RANLIB := $(CROSS_COMPILE)ranlib
Andrew G. Morgan953e7f12008-06-02 22:02:01 -070064DEBUG = -g #-DDEBUG
Torsten Werner7ebd7c52009-09-30 21:23:15 +020065WARNINGS=-Wall -Wwrite-strings \
Andrew Morgan2c9c0532007-07-10 20:50:21 -070066 -Wpointer-arith -Wcast-qual -Wcast-align \
Andrew Morgan5216fff2007-07-10 22:38:22 -070067 -Wstrict-prototypes -Wmissing-prototypes \
68 -Wnested-externs -Winline -Wshadow
Andrew Morgancd45c572007-08-13 23:16:50 -070069LD=$(CC) -Wl,-x -shared
Andrew G. Morgan953e7f12008-06-02 22:02:01 -070070LDFLAGS := #-g
Andrew G. Morgane9f55d92019-12-02 20:48:13 -080071LIBCAPLIB := -L$(topdir)/libcap -lcap
72LIBPSXLIB := -L$(topdir)/libcap -lpsx -lpthread
73
Matthieu Crapet3c228702014-03-28 14:11:15 +010074BUILD_GPERF := $(shell which gperf >/dev/null 2>/dev/null && echo yes)
Andrew Morgan2c9c0532007-07-10 20:50:21 -070075
Andrew Morgan54f055e2007-07-21 22:18:02 -070076SYSTEM_HEADERS = /usr/include
Andrew Morgan2c9c0532007-07-10 20:50:21 -070077INCS=$(topdir)/libcap/include/sys/capability.h
Andrew G. Morgan953e7f12008-06-02 22:02:01 -070078LDFLAGS += -L$(topdir)/libcap
Torsten Werner7ebd7c52009-09-30 21:23:15 +020079CFLAGS += -Dlinux $(WARNINGS) $(DEBUG)
Andrew G. Morgan953e7f12008-06-02 22:02:01 -070080PAM_CAP := $(shell if [ -f /usr/include/security/pam_modules.h ]; then echo yes ; else echo no ; fi)
Matthieu Crapet3c228702014-03-28 14:11:15 +010081INDENT := $(shell if [ -n "$$(which indent 2>/dev/null)" ]; then echo "| indent -kr" ; fi)
Andrew G. Morgan0a42b492008-10-19 19:37:28 -070082DYNAMIC := $(shell if [ ! -d "$(topdir)/.git" ]; then echo yes; fi)
83
Andrew G. Morganb0d13e82020-07-03 10:47:42 -070084GO := go
85GOLANG := $(shell if [ -n "$(shell $(GO) version 2>/dev/null)" ]; then echo yes ; else echo no ; fi)
Andrew G. Morgan0615d992019-05-19 14:57:20 -070086ifeq ($(GOLANG),yes)
Andrew G. Morganb0d13e82020-07-03 10:47:42 -070087GOROOT := $(shell $(GO) env GOROOT)
88GOCGO := $(shell if [ "$(shell $(GO) env CGO_ENABLED)" = 1 ]; then echo yes ; else echo no ; fi)
89GOOSARCH := $(shell $(GO) env GOHOSTOS)_$(shell $(GO) env GOHOSTARCH)
Andrew G. Morganb2b267e2019-11-30 18:33:42 -080090CGO_CFLAGS := -I$(topdir)/libcap/include
91CGO_LDFLAGS := -L$(topdir)/libcap
Andrew G. Morgana3e844a2020-07-02 16:39:24 -070092CGO_LDFLAGS_ALLOW := -Wl,-?-wrap[=,][^-.@][^,]*
Andrew G. Morgane305dd22019-12-07 08:04:58 -080093CGO_REQUIRED=$(shell $(topdir)/go/cgo-required.sh)
Andrew G. Morgan876ac712020-07-02 21:36:16 -070094ifeq ($(CGO_REQUIRED),0)
95# Hopefully this will not be needed at some point.
96GOBUILDTAG=-tags allthreadssyscall
97endif
Andrew G. Morgan0615d992019-05-19 14:57:20 -070098endif
99
Andrew G. Morgancbca9ab2020-04-05 19:31:19 -0700100# If you want capsh to launch with something other than /bin/bash
101# build like this:
102#
103# make CAPSH_SHELL='-DSHELL=\"/bin/sh\"'
104#
105# or undefine the following:
106#CAPSH_SHELL := '-DSHELL="/bin/sh"'
107
Andrew G. Morgan2b5f5632019-12-13 17:30:23 -0800108# When installing setcap, you can arrange for the installation process
109# to set its inheritable bit to be able to place capabilities on files.
110# It can be used in conjunction with pam_cap (associated with su and
111# certain users say) to make it useful for specially blessed users.
Andrew G. Morgan85748f42010-08-08 17:42:11 -0700112#
Andrew G. Morgan2b5f5632019-12-13 17:30:23 -0800113# make RAISE_SETFCAP=yes install
Andrew G. Morgan85748f42010-08-08 17:42:11 -0700114#
Andrew G. Morgan2b5f5632019-12-13 17:30:23 -0800115# This is now defaulted to no because some distributions have started
116# shipping with all users blessed with full inheritable sets which makes
117# no sense whatsoever!
118#
119# Indeed, it looks alarmingly like these distributions are recreating
120# the environment for what became known as the sendmail-capabilities
121# bug from 2000:
122#
123# https://sites.google.com/site/fullycapable/Home/thesendmailcapabilitiesissue
124#
125# they are also nullifying the difference between a p-bit and an i-bit.
126#
127# Folk really should read this document, which explains there is a really
128# important difference being lost here:
129#
130# https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/33528.pdf
131#
132# In the context of this tree, on such such systems, a yes setting will
133# guarantee that every user, by default, is able to bless any binary with
134# any capability - a ready made local exploit machanism.
135RAISE_SETFCAP := no
136
137# If set to yes, this will cause the go "web" demo app to force the needed p
138# bit to be able to bind to port 80 without running as root.
139RAISE_GO_FILECAP := no
Andrew G. Morgan85748f42010-08-08 17:42:11 -0700140
Andrew Morgan2c9c0532007-07-10 20:50:21 -0700141# Global cleanup stuff
142
143LOCALCLEAN=rm -f *~ core
144DISTCLEAN=@find . \( -name '*.orig' -o -name '*.rej' \) | xargs rm -f