xref: /aosp_15_r20/external/libcap/Make.Rules (revision 2810ac1b38eead2603277920c78344c84ddf3aff)
1*2810ac1bSKiyoung Kim# Common version number defines for libcap
2*2810ac1bSKiyoung KimLIBTITLE=libcap
3*2810ac1bSKiyoung KimVERSION=2
4*2810ac1bSKiyoung KimMINOR=69
5*2810ac1bSKiyoung Kim
6*2810ac1bSKiyoung Kim#
7*2810ac1bSKiyoung Kim## Optional prefixes:
8*2810ac1bSKiyoung Kim#
9*2810ac1bSKiyoung Kim
10*2810ac1bSKiyoung Kim# common 'packaging' directory
11*2810ac1bSKiyoung Kim
12*2810ac1bSKiyoung KimFAKEROOT=$(DESTDIR)
13*2810ac1bSKiyoung Kim
14*2810ac1bSKiyoung Kim# Autoconf-style prefixes are activated when $(prefix) is defined.
15*2810ac1bSKiyoung Kim# Otherwise binaries and libraries are installed in /{lib,sbin}/,
16*2810ac1bSKiyoung Kim# header files in /usr/include/ and documentation in /usr/man/man?/.
17*2810ac1bSKiyoung Kim# These choices are motivated by the fact that getcap and setcap are
18*2810ac1bSKiyoung Kim# administrative operations that could be needed to recover a system.
19*2810ac1bSKiyoung Kim
20*2810ac1bSKiyoung Kimifndef lib
21*2810ac1bSKiyoung Kimlib=$(shell ldd /usr/bin/ld|grep -E "ld-linux|ld.so"|cut -d/ -f2)
22*2810ac1bSKiyoung Kimendif
23*2810ac1bSKiyoung Kim
24*2810ac1bSKiyoung Kimifndef sbin
25*2810ac1bSKiyoung Kimsbin=sbin
26*2810ac1bSKiyoung Kimendif
27*2810ac1bSKiyoung Kim
28*2810ac1bSKiyoung Kimifdef sbindir
29*2810ac1bSKiyoung Kimsbin=$(sbindir)
30*2810ac1bSKiyoung Kimendif
31*2810ac1bSKiyoung Kim
32*2810ac1bSKiyoung Kimifdef prefix
33*2810ac1bSKiyoung Kimexec_prefix=$(prefix)
34*2810ac1bSKiyoung Kimlib_prefix=$(exec_prefix)
35*2810ac1bSKiyoung Kiminc_prefix=$(lib_prefix)
36*2810ac1bSKiyoung Kimman_prefix=$(prefix)/share
37*2810ac1bSKiyoung Kimelse
38*2810ac1bSKiyoung Kimprefix=/usr
39*2810ac1bSKiyoung Kimexec_prefix=
40*2810ac1bSKiyoung Kimlib_prefix=$(exec_prefix)
41*2810ac1bSKiyoung Kiminc_prefix=$(prefix)
42*2810ac1bSKiyoung Kimman_prefix=$(prefix)/share
43*2810ac1bSKiyoung Kimendif
44*2810ac1bSKiyoung Kim
45*2810ac1bSKiyoung Kim# Target directories
46*2810ac1bSKiyoung Kim
47*2810ac1bSKiyoung KimMANDIR=$(man_prefix)/man
48*2810ac1bSKiyoung KimSBINDIR=$(exec_prefix)/$(sbin)
49*2810ac1bSKiyoung KimINCDIR=$(inc_prefix)/include
50*2810ac1bSKiyoung KimLIBDIR=$(lib_prefix)/$(lib)
51*2810ac1bSKiyoung KimPKGCONFIGDIR=$(LIBDIR)/pkgconfig
52*2810ac1bSKiyoung KimGOPKGDIR=$(prefix)/share/gocode/src
53*2810ac1bSKiyoung Kim
54*2810ac1bSKiyoung Kim# From here on out, the Go module packages should always remain
55*2810ac1bSKiyoung Kim# backwardly compatible. I will only resort to using major version 2
56*2810ac1bSKiyoung Kim# etc if Go's syntax dramatically changes in a backwards incompatible
57*2810ac1bSKiyoung Kim# manner. (Let's hope not. If that happens, I'll also drop deprecated
58*2810ac1bSKiyoung Kim# API functions.)
59*2810ac1bSKiyoung KimGOMAJOR=1
60*2810ac1bSKiyoung Kim
61*2810ac1bSKiyoung Kim# Compilation specifics
62*2810ac1bSKiyoung Kim
63*2810ac1bSKiyoung KimKERNEL_HEADERS := $(topdir)/libcap/include/uapi
64*2810ac1bSKiyoung KimLIBCAP_INCLUDES = -I$(KERNEL_HEADERS) -I$(topdir)/libcap/include
65*2810ac1bSKiyoung KimDEFINES := -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
66*2810ac1bSKiyoung KimSYSTEM_HEADERS = /usr/include
67*2810ac1bSKiyoung Kim
68*2810ac1bSKiyoung KimSUDO := sudo
69*2810ac1bSKiyoung KimCC := $(CROSS_COMPILE)gcc
70*2810ac1bSKiyoung KimLD := $(CC) -Wl,-x -shared
71*2810ac1bSKiyoung KimAR := $(CROSS_COMPILE)ar
72*2810ac1bSKiyoung KimRANLIB := $(CROSS_COMPILE)ranlib
73*2810ac1bSKiyoung KimOBJCOPY := $(CROSS_COMPILE)objcopy
74*2810ac1bSKiyoung Kim
75*2810ac1bSKiyoung Kim# Reference:
76*2810ac1bSKiyoung Kim#   CPPFLAGS used for building .o files from .c & .h files
77*2810ac1bSKiyoung Kim#   CFLAGS used when building libraries from .o, .c and .h files
78*2810ac1bSKiyoung Kim
79*2810ac1bSKiyoung KimDEBUG = # -g -DDEBUG
80*2810ac1bSKiyoung KimWARNINGS=-Wall -Wwrite-strings -Wpointer-arith -Wcast-qual -Wcast-align \
81*2810ac1bSKiyoung Kim	-Wstrict-prototypes -Wmissing-prototypes -Wnested-externs       \
82*2810ac1bSKiyoung Kim	-Winline -Wshadow -Wunreachable-code
83*2810ac1bSKiyoung KimCOPTS ?= -O2
84*2810ac1bSKiyoung KimCFLAGS ?= $(COPTS) $(DEBUG)
85*2810ac1bSKiyoung KimCFLAGS += $(WARNINGS)
86*2810ac1bSKiyoung KimCPPFLAGS += -Dlinux $(DEFINES) $(LIBCAP_INCLUDES)
87*2810ac1bSKiyoung KimLDFLAGS ?= # -g
88*2810ac1bSKiyoung Kim
89*2810ac1bSKiyoung KimBUILD_CC ?= $(CC)
90*2810ac1bSKiyoung KimBUILD_LD ?= $(BUILD_CC) -Wl,-x -shared
91*2810ac1bSKiyoung KimBUILD_COPTS ?= $(COPTS)
92*2810ac1bSKiyoung KimBUILD_CFLAGS ?= $(BUILD_COPTS)
93*2810ac1bSKiyoung KimBUILD_CPPFLAGS += -Dlinux $(WARNINGS) $(DEBUG) $(DEFINES) $(LIBCAP_INCLUDES)
94*2810ac1bSKiyoung KimBUILD_LDFLAGS ?= $(LDFLAGS)
95*2810ac1bSKiyoung KimBUILD_SED ?= sed
96*2810ac1bSKiyoung KimBUILD_GREP ?= grep
97*2810ac1bSKiyoung KimBUILD_EGREP ?= $(BUILD_GREP) -E
98*2810ac1bSKiyoung KimBUILD_FGREP ?= $(BUILD_GREP) -F
99*2810ac1bSKiyoung Kim
100*2810ac1bSKiyoung Kim# Plan to eventually redefine BUILD_GPERF to be the actual gperf tool
101*2810ac1bSKiyoung Kim# alias as per above. Typical distributions are upto a year behind
102*2810ac1bSKiyoung Kim# HEAD so we'll not do that before 2023-01-01.
103*2810ac1bSKiyoung Kimifdef BUILD_GPERF
104*2810ac1bSKiyoung Kim$(error BUILD_GPERF is now reserved, please use USE_GPERF=yes or no instead)
105*2810ac1bSKiyoung Kimendif
106*2810ac1bSKiyoung Kim
107*2810ac1bSKiyoung KimUSE_GPERF ?= $(shell which gperf >/dev/null 2>/dev/null && echo yes)
108*2810ac1bSKiyoung Kim
109*2810ac1bSKiyoung KimLIBCAPLIB := -L$(topdir)/libcap -lcap
110*2810ac1bSKiyoung KimPSXLINKFLAGS :=  -lpthread -Wl,-wrap,pthread_create
111*2810ac1bSKiyoung KimLIBPSXLIB := -L$(topdir)/libcap -lpsx $(PSXLINKFLAGS)
112*2810ac1bSKiyoung Kim
113*2810ac1bSKiyoung KimINCS=$(topdir)/libcap/include/sys/capability.h
114*2810ac1bSKiyoung KimINDENT := $(shell if [ -n "$$(which indent 2>/dev/null)" ]; then echo "| indent -kr" ; fi)
115*2810ac1bSKiyoung Kim
116*2810ac1bSKiyoung Kim# SHARED tracks whether or not the SHARED libraries (libcap.so,
117*2810ac1bSKiyoung Kim# libpsx.so and pam_cap.so) are built. (Some environments don't
118*2810ac1bSKiyoung Kim# support shared libraries.)
119*2810ac1bSKiyoung KimSHARED ?= yes
120*2810ac1bSKiyoung Kim# DYNAMIC controls how capsh etc are linked - to shared or static libraries
121*2810ac1bSKiyoung Kim# Force enabled with "make DYNAMIC=yes ...".
122*2810ac1bSKiyoung KimDYNAMIC := $(shell if [ ! -d "$(topdir)/.git" ]; then echo $(SHARED); else echo no ; fi)
123*2810ac1bSKiyoung Kim
124*2810ac1bSKiyoung KimPAM_CAP ?= $(shell if [ -f /usr/include/security/pam_modules.h ]; then echo $(SHARED) ; else echo no ; fi)
125*2810ac1bSKiyoung Kim
126*2810ac1bSKiyoung Kim# If your system does not support pthreads, override this as "no".
127*2810ac1bSKiyoung Kim#
128*2810ac1bSKiyoung Kim#    make PTHREADS=no ...
129*2810ac1bSKiyoung Kim#
130*2810ac1bSKiyoung Kim# This implies no Go support and no C/C++ libpsx build. Why might you
131*2810ac1bSKiyoung Kim# need libpsx for non-Go use? Tl;dr for POSIX semantics security:
132*2810ac1bSKiyoung Kim#
133*2810ac1bSKiyoung Kim#    https://sites.google.com/site/fullycapable/who-ordered-libpsx
134*2810ac1bSKiyoung Kim#
135*2810ac1bSKiyoung KimPTHREADS ?= yes
136*2810ac1bSKiyoung Kim
137*2810ac1bSKiyoung Kimifeq ($(PTHREADS),yes)
138*2810ac1bSKiyoung KimGO ?= go
139*2810ac1bSKiyoung KimGOLANG ?= $(shell if [ -n "$(shell $(GO) version 2>/dev/null)" ]; then echo yes ; else echo no ; fi)
140*2810ac1bSKiyoung Kimifeq ($(GOLANG),yes)
141*2810ac1bSKiyoung KimGOROOT ?= $(shell $(GO) env GOROOT)
142*2810ac1bSKiyoung KimGOCGO ?= $(shell if [ "$(shell $(GO) env CGO_ENABLED)" = 1 ]; then echo yes ; else echo no ; fi)
143*2810ac1bSKiyoung KimGOOSARCH ?= $(shell $(GO) env GOHOSTOS)_$(shell $(GO) env GOHOSTARCH)
144*2810ac1bSKiyoung KimCGO_REQUIRED := $(shell $(topdir)/go/cgo-required.sh $(GO))
145*2810ac1bSKiyoung Kimifeq ($(CGO_REQUIRED),1)
146*2810ac1bSKiyoung Kim# Strictly speaking go1.15 doesn't need this, but 1.16 is when the
147*2810ac1bSKiyoung Kim# real golang support arrives for non-cgo support, so drop the last
148*2810ac1bSKiyoung Kim# vestige of legacy workarounds then.
149*2810ac1bSKiyoung KimCGO_LDFLAGS_ALLOW := CGO_LDFLAGS_ALLOW="-Wl,-?-wrap[=,][^-.@][^,]*"
150*2810ac1bSKiyoung Kimendif
151*2810ac1bSKiyoung KimCGO_CFLAGS := $(LIBCAP_INCLUDES)
152*2810ac1bSKiyoung KimCGO_LDFLAGS := -L$(topdir)/libcap
153*2810ac1bSKiyoung KimGO_BUILD_FLAGS :=
154*2810ac1bSKiyoung Kimendif
155*2810ac1bSKiyoung Kimendif
156*2810ac1bSKiyoung Kim
157*2810ac1bSKiyoung Kim# If you want capsh to launch with something other than /bin/bash
158*2810ac1bSKiyoung Kim# build like this:
159*2810ac1bSKiyoung Kim#
160*2810ac1bSKiyoung Kim#   make CAPSH_SHELL='-DSHELL=\"/bin/sh\"'
161*2810ac1bSKiyoung Kim#
162*2810ac1bSKiyoung Kim# or undefine the following:
163*2810ac1bSKiyoung Kim#CAPSH_SHELL := '-DSHELL="/bin/sh"'
164*2810ac1bSKiyoung Kim
165*2810ac1bSKiyoung Kim# When installing setcap, you can arrange for the installation process
166*2810ac1bSKiyoung Kim# to set its inheritable bit to be able to place capabilities on files.
167*2810ac1bSKiyoung Kim# It can be used in conjunction with pam_cap (associated with su and
168*2810ac1bSKiyoung Kim# certain users say) to make it useful for specially blessed users.
169*2810ac1bSKiyoung Kim#
170*2810ac1bSKiyoung Kim#    make RAISE_SETFCAP=yes install
171*2810ac1bSKiyoung Kim#
172*2810ac1bSKiyoung Kim# This is now defaulted to no because some distributions started
173*2810ac1bSKiyoung Kim# shipping with all users blessed with full inheritable sets which
174*2810ac1bSKiyoung Kim# makes no sense whatsoever!
175*2810ac1bSKiyoung Kim#
176*2810ac1bSKiyoung Kim# Indeed, it looked alarmingly like these distributions were recreating
177*2810ac1bSKiyoung Kim# the environment for what became known as the sendmail-capabilities
178*2810ac1bSKiyoung Kim# bug from 2000:
179*2810ac1bSKiyoung Kim#
180*2810ac1bSKiyoung Kim#  https://sites.google.com/site/fullycapable/Home/thesendmailcapabilitiesissue
181*2810ac1bSKiyoung Kim#
182*2810ac1bSKiyoung Kim# they are also nullifying the difference between a p-bit and an i-bit.
183*2810ac1bSKiyoung Kim#
184*2810ac1bSKiyoung Kim# Folk really should read this document, which explains there is a really
185*2810ac1bSKiyoung Kim# important difference being lost here:
186*2810ac1bSKiyoung Kim#
187*2810ac1bSKiyoung Kim#  https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/33528.pdf
188*2810ac1bSKiyoung Kim#
189*2810ac1bSKiyoung Kim# In the context of this tree, on such such systems, a yes setting will
190*2810ac1bSKiyoung Kim# guarantee that every user, by default, is able to bless any binary with
191*2810ac1bSKiyoung Kim# any capability - a ready made local exploit mechanism.
192*2810ac1bSKiyoung KimRAISE_SETFCAP := no
193*2810ac1bSKiyoung Kim
194*2810ac1bSKiyoung Kim# If set to yes, this will cause the go "web" demo app to force the needed p
195*2810ac1bSKiyoung Kim# bit to be able to bind to port 80 without running as root.
196*2810ac1bSKiyoung KimRAISE_GO_FILECAP := no
197*2810ac1bSKiyoung Kim
198*2810ac1bSKiyoung Kim# Global cleanup stuff
199*2810ac1bSKiyoung Kim
200*2810ac1bSKiyoung KimLOCALCLEAN=rm -f *~ core
201*2810ac1bSKiyoung KimDISTCLEAN=@find . \( -name '*.orig' -o -name '*.rej' \) | xargs rm -f
202