aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew G. Morgan <morgan@kernel.org>2021-12-04 09:51:07 -0800
committerAndrew G. Morgan <morgan@kernel.org>2021-12-04 10:18:50 -0800
commit1fe7dbe984adef5cf9d0f58b02acd6f2b72c6993 (patch)
tree99b2da4a9f542d0be3da2816ae367a7ba323dde9
parent9d3c75818196802bb5bc3c43bb4a52fb89a83e8c (diff)
downloadlibcap-1fe7dbe984adef5cf9d0f58b02acd6f2b72c6993.tar.gz
Drop perl from the build requirements.
David Seifert at Gentoo made a request to not require perl for the libcap build since their distribution wants to build it prior to building perl and so requiring it requires they maintain some extra patches. We previously introduced the need for perl in response to some apparent incompatibilities between various versions of sed: https://git.kernel.org/pub/scm/libs/libcap/libcap.git/commit/?id=9494a1fab59ac0b6e4f0bfc536fa482c6d6490b6 However, it has been 13 years since that time so we're optimistic those problems are no longer present for anyone and we've also added a make variable abstraction in case some builder wants to override their system default 'sed' as make BUILD_SED=... etc. We've also done something similar with make uses of grep, egrep and fgrep. Finally, for make variable naming consistency, we've replaced use of BUILD_GPERF with USE_GPERF. Since folk may be using BUILD_GPERF in their package building scripts, we error out if it is set. The expectation is that people will update their package defs. (Eventually, we plan to reuse BUILD_GPERF as an alias for 'gperf'.) Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
-rw-r--r--Make.Rules14
-rw-r--r--Makefile2
-rw-r--r--doc/Makefile2
-rw-r--r--libcap/Makefile20
-rw-r--r--libcap/cap_names.header5
5 files changed, 32 insertions, 11 deletions
diff --git a/Make.Rules b/Make.Rules
index 70d5829..eaaf3d6 100644
--- a/Make.Rules
+++ b/Make.Rules
@@ -92,7 +92,19 @@ BUILD_COPTS ?= $(COPTS)
BUILD_CFLAGS ?= $(BUILD_COPTS)
BUILD_CPPFLAGS += -Dlinux $(WARNINGS) $(DEBUG) $(DEFINES) $(LIBCAP_INCLUDES)
BUILD_LDFLAGS ?= $(LDFLAGS)
-BUILD_GPERF := $(shell which gperf >/dev/null 2>/dev/null && echo yes)
+BUILD_SED ?= sed
+BUILD_GREP ?= grep
+BUILD_EGREP ?= $(BUILD_GREP) -E
+BUILD_FGREP ?= $(BUILD_GREP) -F
+
+# Plan to eventually redefine BUILD_GPERF to be the actual gperf tool
+# alias as per above. Typical distributions are upto a year behind
+# HEAD so we'll not do that before 2023-01-01.
+ifdef BUILD_GPERF
+$(error BUILD_GPERF is now reserved, please use USE_GPERF=yes or no instead)
+endif
+
+USE_GPERF ?= $(shell which gperf >/dev/null 2>/dev/null && echo yes)
LIBCAPLIB := -L$(topdir)/libcap -lcap
PSXLINKFLAGS := -lpthread -Wl,-wrap,pthread_create
diff --git a/Makefile b/Makefile
index 9ee11c8..256c339 100644
--- a/Makefile
+++ b/Makefile
@@ -35,7 +35,7 @@ clean-here:
distclean: clean
$(DISTCLEAN)
@echo "CONFIRM Go package cap has right version dependency on cap/psx:"
- for x in $$(find . -name go.mod); do grep -F -v "module" $$x | fgrep "kernel.org/pub/linux/libs/security/libcap" > /dev/null || continue ; grep -F "v$(GOMAJOR).$(VERSION).$(MINOR)" $$x > /dev/null && continue ; echo "$$x is not updated. Try running: ./gomods.sh v$(GOMAJOR).$(VERSION).$(MINOR)" ; exit 1 ; done
+ for x in $$(find . -name go.mod); do $(BUILD_FGREP) -v "module" $$x | $(BUILD_FGREP) "kernel.org/pub/linux/libs/security/libcap" > /dev/null || continue ; $(BUILD_FGREP) "v$(GOMAJOR).$(VERSION).$(MINOR)" $$x > /dev/null && continue ; echo "$$x is not updated. Try running: ./gomods.sh v$(GOMAJOR).$(VERSION).$(MINOR)" ; exit 1 ; done
@echo "ALL go.mod files updated"
@echo "Now validate that everything is checked in to a clean tree.."
test -z "$$(git status --ignored -s)"
diff --git a/doc/Makefile b/doc/Makefile
index 11b9370..e78eb6e 100644
--- a/doc/Makefile
+++ b/doc/Makefile
@@ -44,7 +44,7 @@ html:
mkdir -p html
for man in $(MANS) ; \
do \
- egrep '^\.so man' $$man > /dev/null || \
+ $(BUILD_EGREP) '^\.so man' $$man > /dev/null || \
groff -man -Thtml $$man > html/$$man.html ; \
done
diff --git a/libcap/Makefile b/libcap/Makefile
index df1267a..7a38fe9 100644
--- a/libcap/Makefile
+++ b/libcap/Makefile
@@ -52,13 +52,13 @@ ifeq ($(PTHREADS),yes)
$(MAKE) $(PSXTITLE).pc
endif
-ifeq ($(BUILD_GPERF),yes)
+ifeq ($(USE_GPERF),yes)
USE_GPERF_OUTPUT = $(GPERF_OUTPUT)
INCLUDE_GPERF_OUTPUT = -DINCLUDE_GPERF_OUTPUT='"$(GPERF_OUTPUT)"'
endif
$(LIBTITLE).pc: $(LIBTITLE).pc.in
- sed -e 's,@prefix@,$(prefix),' \
+ $(BUILD_SED) -e 's,@prefix@,$(prefix),' \
-e 's,@exec_prefix@,$(exec_prefix),' \
-e 's,@libdir@,$(LIBDIR),' \
-e 's,@includedir@,$(inc_prefix)/include,' \
@@ -67,7 +67,7 @@ $(LIBTITLE).pc: $(LIBTITLE).pc.in
$< >$@
$(PSXTITLE).pc: $(PSXTITLE).pc.in
- sed -e 's,@prefix@,$(prefix),' \
+ $(BUILD_SED) -e 's,@prefix@,$(prefix),' \
-e 's,@exec_prefix@,$(exec_prefix),' \
-e 's,@libdir@,$(LIBDIR),' \
-e 's,@includedir@,$(inc_prefix)/include,' \
@@ -81,18 +81,22 @@ _makenames: _makenames.c cap_names.list.h
cap_names.h: _makenames
./_makenames > cap_names.h
-$(GPERF_OUTPUT): cap_names.list.h
- perl -e 'print "struct __cap_token_s { const char *name; int index; };\n%{\nconst struct __cap_token_s *__cap_lookup_name(const char *, size_t);\n%}\n%%\n"; while ($$l = <>) { $$l =~ s/[\{\"]//g; $$l =~ s/\}.*// ; print $$l; }' < $< | gperf --ignore-case --language=ANSI-C --readonly --null-strings --global-table --hash-function-name=__cap_hash_name --lookup-function-name="__cap_lookup_name" -c -t -m20 $(INDENT) > $@
- sed -e 's/unsigned int len/size_t len/' -i $@
+$(GPERF_OUTPUT): cap_names.list.h cap_names.header Makefile
+ (cat cap_names.header ; $(BUILD_SED) -e 's/[\{\}"]//g' -e 's/,$$//' cap_names.list.h) | gperf --ignore-case --language=ANSI-C --readonly --null-strings --global-table --hash-function-name=__cap_hash_name --lookup-function-name="__cap_lookup_name" -c -t -m20 $(INDENT) > $@
+ $(BUILD_SED) -e 's/unsigned int len/size_t len/' -i $@
# Intention is that libcap keeps up with torvalds' tree, as reflected
# by this maintained version of the kernel header. libcap dynamically
# trims the meaning of "all" capabilities down to that of the running
-# kernel as of 2.30.
+# kernel as of 2.30. That is, all production kernels should be equal
+# to or behind libcap.
+#
+# Note "./libcap.so --summary" should explain how the built libcap.so
+# compares to the running kernel.
UAPI_HEADER := $(topdir)/libcap/include/uapi/linux/capability.h
cap_names.list.h: Makefile $(UAPI_HEADER)
@echo "=> making $@ from $(UAPI_HEADER)"
- perl -e 'while ($$l=<>) { if ($$l =~ /^\#define[ \t](CAP[_A-Z]+)[ \t]+([0-9]+)\s+$$/) { $$tok=$$1; $$val=$$2; $$tok =~ tr/A-Z/a-z/; print "{\"$$tok\",$$val},\n"; } }' $(UAPI_HEADER) | fgrep -v 0x > $@
+ $(BUILD_EGREP) '^#define\s+CAP_([^\s]+)\s+[0-9]+\s*$$' include/uapi/linux/capability.h | $(BUILD_SED) -e 's/^#define\s\+/{"/' -e 's/\s*$$/},/' -e 's/\s\+/",/' -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/' > $@
$(STACAPLIBNAME): $(CAPOBJS)
$(AR) rcs $@ $^
diff --git a/libcap/cap_names.header b/libcap/cap_names.header
new file mode 100644
index 0000000..8d64f64
--- /dev/null
+++ b/libcap/cap_names.header
@@ -0,0 +1,5 @@
+struct __cap_token_s { const char *name; int index; };
+%{
+const struct __cap_token_s *__cap_lookup_name(const char *, size_t);
+%}
+%%