Skip to contentSkip to conversation

Support static-only builds

PATCH In review Alyssa Ross 4 participants 18 messages Feb 11, 2025 – Jul 2, 2025 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 Support static-only builds

Sometimes it's useful to have a static-only toolchain. This can be due to targetting some weird embedded platform, or it can be because it ensures that no dynamic libraries are sneaking into a system that's supposed to be 100% static due to non-cooperative build systems. Most build systems support static-only builds, e.g. autoconf provides a --disable-shared configure option.

selinux's custom make-based build system did not support such an option, so here I've added one. Apart from the obvious changes, I had to make the utilities that use external libraries link against them manually, because that can't be inferred from the static selinux libraries. For downstream users of libselinux using pkg-config, this shouldn't be a problem, because libselinux.pc already includes the Requires.private line that specifies libpcre should be linked against as well.

---
Changes since v3:

• Resolve conflicts.
• Add selabel_compare to PCRE_USERS.
• Use pkg-config for libselinux in policycoreutils, so PCRE is linked.

v2: https://lore.kernel.org/selinux/[email protected]

 libselinux/src/Makefile              | 11 ++++++++---
 libselinux/utils/Makefile            |  8 +++++++-
 libsemanage/src/Makefile             |  9 +++++++--
 libsepol/src/Makefile                | 11 ++++++++---
 policycoreutils/Makefile             |  5 +++++
 policycoreutils/load_policy/Makefile |  2 +-
 policycoreutils/newrole/Makefile     |  2 +-
 policycoreutils/run_init/Makefile    |  2 +-
 policycoreutils/secon/Makefile       |  2 +-
 policycoreutils/semodule/Makefile    |  3 ++-
 policycoreutils/sestatus/Makefile    |  2 +-
 policycoreutils/setfiles/Makefile    |  2 +-
 policycoreutils/setsebool/Makefile   |  3 ++-
 policycoreutils/unsetfiles/Makefile  |  2 +-
 14 files changed, 46 insertions(+), 18 deletions(-)
libselinux/src/Makefile +8 -3
index 213c7d34..261c22d4 100644
@@ -147,7 +147,10 @@ endif
 
 SWIGRUBY = swig -Wall -ruby -o $(SWIGRUBYCOUT) -outdir ./ $(DISABLE_FLAGS)
 
-all: $(LIBA) $(LIBSO) $(LIBPC)
+all: $(LIBA) $(LIBPC)
+ifneq ($(DISABLE_SHARED),y)
+all: $(LIBSO)
+endif
 
 pywrap: all selinuxswig_python_exception.i
 	CFLAGS="$(CPPFLAGS) $(CFLAGS) $(SWIG_CFLAGS)" $(PYTHON) setup.py build_ext
@@ -186,11 +189,13 @@ $(SWIGRUBYCOUT): $(SWIGRUBYIF)
 install: all 
 	test -d $(DESTDIR)$(LIBDIR) || install -m 755 -d $(DESTDIR)$(LIBDIR)
 	install -m 644 $(LIBA) $(DESTDIR)$(LIBDIR)
-	test -d $(DESTDIR)$(SHLIBDIR) || install -m 755 -d $(DESTDIR)$(SHLIBDIR)
-	install -m 755 $(LIBSO) $(DESTDIR)$(SHLIBDIR)
 	test -d $(DESTDIR)$(LIBDIR)/pkgconfig || install -m 755 -d $(DESTDIR)$(LIBDIR)/pkgconfig
 	install -m 644 $(LIBPC) $(DESTDIR)$(LIBDIR)/pkgconfig
+ifneq ($(DISABLE_SHARED),y)
+	test -d $(DESTDIR)$(SHLIBDIR) || install -m 755 -d $(DESTDIR)$(SHLIBDIR)
+	install -m 755 $(LIBSO) $(DESTDIR)$(SHLIBDIR)
 	ln -sf --relative $(DESTDIR)$(SHLIBDIR)/$(LIBSO) $(DESTDIR)$(LIBDIR)/$(TARGET)
+endif
 
 install-pywrap: pywrap
 	CFLAGS="$(CPPFLAGS) $(CFLAGS) $(SWIG_CFLAGS)" $(PYTHON) -m pip install --prefix=$(PREFIX) `test -n "$(DESTDIR)" && echo --root $(DESTDIR) --ignore-installed --no-deps` $(PYTHON_SETUP_ARGS) .
libselinux/utils/Makefile +7 -1
index 0d7095b1..6b1dc7c9 100644
@@ -53,7 +53,13 @@ else
 TARGETS=$(patsubst %.c,%,$(sort $(wildcard *.c)))
 endif
 
-sefcontext_compile: LDLIBS += ../src/libselinux.a $(PCRE_LDLIBS) -lsepol
+sefcontext_compile: LDLIBS += ../src/libselinux.a -lsepol
+
+PCRE_USERS = matchpathcon sefcontext_compile selabel_compare \
+	selabel_digest selabel_get_digests_all_partial_matches \
+	selabel_lookup selabel_lookup_best_match \
+	selabel_partial_match
+$(PCRE_USERS): LDLIBS += $(PCRE_LDLIBS)
 
 all: $(TARGETS)
 
libsemanage/src/Makefile +7 -2
index 8dfbd762..7d60b1e9 100644
@@ -67,7 +67,10 @@ SWIG = swig -Wall -python -o $(SWIGCOUT) -outdir ./
 
 SWIGRUBY = swig -Wall -ruby -o $(SWIGRUBYCOUT) -outdir ./
 
-all: $(LIBA) $(LIBSO) $(LIBPC)
+all: $(LIBA) $(LIBPC)
+ifneq ($(DISABLE_SHARED),y)
+all: $(LIBSO)
+endif
 
 pywrap: all $(SWIGSO)
 
@@ -137,11 +140,13 @@ swigify: $(SWIGIF)
 install: all
 	test -d $(DESTDIR)$(LIBDIR) || install -m 755 -d $(DESTDIR)$(LIBDIR)
 	install -m 644 $(LIBA) $(DESTDIR)$(LIBDIR)
-	install -m 755 $(LIBSO) $(DESTDIR)$(LIBDIR)
 	test -d $(DESTDIR)$(LIBDIR)/pkgconfig || install -m 755 -d $(DESTDIR)$(LIBDIR)/pkgconfig
 	install -m 644 $(LIBPC) $(DESTDIR)$(LIBDIR)/pkgconfig
 	test -f $(DESTDIR)$(DEFAULT_SEMANAGE_CONF_LOCATION) || install -m 644 -D semanage.conf $(DESTDIR)$(DEFAULT_SEMANAGE_CONF_LOCATION)
+ifneq ($(DISABLE_SHARED),y)
+	install -m 755 $(LIBSO) $(DESTDIR)$(LIBDIR)
 	cd $(DESTDIR)$(LIBDIR) && ln -sf $(LIBSO) $(TARGET)
+endif
 
 install-pywrap: pywrap
 	test -d $(DESTDIR)$(PYTHONLIBDIR) || install -m 755 -d $(DESTDIR)$(PYTHONLIBDIR)
libsepol/src/Makefile +8 -3
index 71fa3ed7..a1aed072 100644
@@ -45,7 +45,10 @@ LDFLAGS += -undefined dynamic_lookup
 LN=gln
 endif
 
-all: $(LIBA) $(LIBSO) $(LIBPC)
+all: $(LIBA) $(LIBPC)
+ifneq ($(DISABLE_SHARED),y)
+all: $(LIBSO)
+endif
 
 
 $(LIBA):  $(OBJS)
@@ -87,11 +90,13 @@ endif
 install: all
 	test -d $(DESTDIR)$(LIBDIR) || install -m 755 -d $(DESTDIR)$(LIBDIR)
 	install -m 644 $(LIBA) $(DESTDIR)$(LIBDIR)
-	test -d $(DESTDIR)$(SHLIBDIR) || install -m 755 -d $(DESTDIR)$(SHLIBDIR)
-	install -m 755 $(LIBSO) $(DESTDIR)$(SHLIBDIR)
 	test -d $(DESTDIR)$(LIBDIR)/pkgconfig || install -m 755 -d $(DESTDIR)$(LIBDIR)/pkgconfig
 	install -m 644 $(LIBPC) $(DESTDIR)$(LIBDIR)/pkgconfig
+ifneq ($(DISABLE_SHARED),y)
+	test -d $(DESTDIR)$(SHLIBDIR) || install -m 755 -d $(DESTDIR)$(SHLIBDIR)
+	install -m 755 $(LIBSO) $(DESTDIR)$(SHLIBDIR)
 	$(LN) -sf --relative $(DESTDIR)$(SHLIBDIR)/$(LIBSO) $(DESTDIR)$(LIBDIR)/$(TARGET)
+endif
 
 relabel:
 	/sbin/restorecon $(DESTDIR)$(SHLIBDIR)/$(LIBSO)
policycoreutils/Makefile +5 -0
index 32ad0201..7acd51dd 100644
@@ -1,5 +1,10 @@
 SUBDIRS = setfiles load_policy newrole run_init secon sestatus semodule setsebool scripts po man hll unsetfiles
 
+PKG_CONFIG ?= pkg-config
+
+LIBSELINUX_LDLIBS := $(shell $(PKG_CONFIG) --libs libselinux)
+export LIBSELINUX_LDLIBS
+
 all install relabel clean indent:
 	@for subdir in $(SUBDIRS); do \
 		(cd $$subdir && $(MAKE) $@) || exit 1; \
policycoreutils/load_policy/Makefile +1 -1
index ad80d500..37c0111b 100644
@@ -7,7 +7,7 @@ LOCALEDIR ?= $(DESTDIR)$(PREFIX)/share/locale
 
 CFLAGS ?= -Werror -Wall -W
 override CFLAGS += $(LDFLAGS) -DUSE_NLS -DLOCALEDIR="\"$(LOCALEDIR)\"" -DPACKAGE="\"policycoreutils\""
-override LDLIBS += -lsepol -lselinux
+override LDLIBS += $(LIBSELINUX_LDLIBS) -lsepol
 
 TARGETS=$(patsubst %.c,%,$(sort $(wildcard *.c)))
 
policycoreutils/newrole/Makefile +1 -1
index 4b8145d3..6e95e79f 100644
@@ -25,7 +25,7 @@ VERSION = $(shell cat ../VERSION)
 CFLAGS ?= -Werror -Wall -W
 EXTRA_OBJS =
 override CFLAGS += -DVERSION=\"$(VERSION)\" -DUSE_NLS -DLOCALEDIR="\"$(LOCALEDIR)\"" -DPACKAGE="\"policycoreutils\""
-override LDLIBS += -lselinux
+override LDLIBS += $(LIBSELINUX_LDLIBS)
 ifeq ($(PAMH), y)
 	override CFLAGS += -DUSE_PAM
 	EXTRA_OBJS += hashtab.o
policycoreutils/run_init/Makefile +1 -1
index 619ebc1d..a5002587 100644
@@ -11,7 +11,7 @@ AUDITH ?= $(shell test -f /usr/include/libaudit.h && echo y)
 
 CFLAGS ?= -Werror -Wall -W
 override CFLAGS += -DUSE_NLS -DLOCALEDIR="\"$(LOCALEDIR)\"" -DPACKAGE="\"policycoreutils\""
-override LDLIBS += -lselinux
+override LDLIBS += $(LIBSELINUX_LDLIBS)
 ifeq ($(PAMH), y)
 	override CFLAGS += -DUSE_PAM
 	override LDLIBS += -lpam -lpam_misc
policycoreutils/secon/Makefile +1 -1
index 440503a1..daa3e10e 100644
@@ -8,7 +8,7 @@ WARNS=-Werror -W -Wall -Wundef -Wshadow -Wpointer-arith -Wbad-function-cast -Wca
 VERSION = $(shell cat ../VERSION)
 CFLAGS ?= $(WARNS) -O1
 override CFLAGS += -DVERSION=\"$(VERSION)\"
-override LDLIBS += -lselinux
+override LDLIBS += $(LIBSELINUX_LDLIBS)
 
 all: secon
 
policycoreutils/semodule/Makefile +2 -1
index 9fbf99d6..3855f95e 100644
@@ -5,11 +5,12 @@ SBINDIR ?= $(PREFIX)/sbin
 MANDIR = $(PREFIX)/share/man
 
 CFLAGS ?= -Werror -Wall -W
-override LDLIBS += -lsepol -lselinux -lsemanage
+override LDLIBS += -lsemanage -lsepol $(LIBSELINUX_LDLIBS)
 SEMODULE_OBJS = semodule.o
 
 all: semodule genhomedircon
 
+semodule: LDLIBS += -laudit -lbz2
 semodule: $(SEMODULE_OBJS)
 
 genhomedircon:
policycoreutils/sestatus/Makefile +1 -1
index aebf050c..b0df6d28 100644
@@ -8,7 +8,7 @@ ETCDIR ?= /etc
 
 CFLAGS ?= -Werror -Wall -W
 override CFLAGS += -D_FILE_OFFSET_BITS=64
-override LDLIBS += -lselinux
+override LDLIBS += $(LIBSELINUX_LDLIBS)
 
 all: sestatus
 
policycoreutils/setfiles/Makefile +1 -1
index 84ffb08b..0b27e934 100644
@@ -6,7 +6,7 @@ MANDIR = $(PREFIX)/share/man
 AUDITH ?= $(shell test -f /usr/include/libaudit.h && echo y)
 
 CFLAGS ?= -g -Werror -Wall -W
-override LDLIBS += -lselinux -lsepol -lpthread
+override LDLIBS += $(LIBSELINUX_LDLIBS) -lsepol -lpthread
 
 ifeq ($(AUDITH), y)
 	override CFLAGS += -DUSE_AUDIT
policycoreutils/setsebool/Makefile +2 -1
index fc5b4ff6..12b6315d 100644
@@ -6,13 +6,14 @@ MANDIR = $(PREFIX)/share/man
 BASHCOMPLETIONDIR ?= $(PREFIX)/share/bash-completion/completions
 
 CFLAGS ?= -Werror -Wall -W
-override LDLIBS += -lselinux -lsemanage
+override LDLIBS += -lsemanage $(LIBSELINUX_LDLIBS)
 SETSEBOOL_OBJS = setsebool.o
 
 BASHCOMPLETIONS=setsebool-bash-completion.sh 
 
 all: setsebool
 
+setsebool: LDLIBS += -laudit -lbz2
 setsebool: $(SETSEBOOL_OBJS)
 
 install: all
policycoreutils/unsetfiles/Makefile +1 -1
index 9e5edc04..bdc1b9de 100644
@@ -3,7 +3,7 @@ SBINDIR ?= $(PREFIX)/sbin
 MANDIR ?= $(PREFIX)/share/man
 
 override CFLAGS += -D_GNU_SOURCE
-override LDLIBS += -lselinux
+override LDLIBS += $(LIBSELINUX_LDLIBS)
 
 
 all: unsetfiles

base-commit: 71aec30d068789e856e7cc429b620ae1cfa890f1

Signature · 1 line
2.47.0
#1 lore raw
Quoted 161 lines · Alyssa Ross

Sometimes it's useful to have a static-only toolchain. This can be due to targetting some weird embedded platform, or it can be because it ensures that no dynamic libraries are sneaking into a system that's supposed to be 100% static due to non-cooperative build systems. Most build systems support static-only builds, e.g. autoconf provides a --disable-shared configure option.

selinux's custom make-based build system did not support such an option, so here I've added one. Apart from the obvious changes, I had to make the utilities that use external libraries link against them manually, because that can't be inferred from the static selinux libraries. For downstream users of libselinux using pkg-config, this shouldn't be a problem, because libselinux.pc already includes the Requires.private line that specifies libpcre should be linked against as well.

---
Changes since v3:

• Resolve conflicts.
• Add selabel_compare to PCRE_USERS.
• Use pkg-config for libselinux in policycoreutils, so PCRE is linked.

v2: https://lore.kernel.org/selinux/[email protected]

  libselinux/src/Makefile              | 11 ++++++++---
  libselinux/utils/Makefile            |  8 +++++++-
  libsemanage/src/Makefile             |  9 +++++++--
  libsepol/src/Makefile                | 11 ++++++++---
  policycoreutils/Makefile             |  5 +++++
  policycoreutils/load_policy/Makefile |  2 +-
  policycoreutils/newrole/Makefile     |  2 +-
  policycoreutils/run_init/Makefile    |  2 +-
  policycoreutils/secon/Makefile       |  2 +-
  policycoreutils/semodule/Makefile    |  3 ++-
  policycoreutils/sestatus/Makefile    |  2 +-
  policycoreutils/setfiles/Makefile    |  2 +-
  policycoreutils/setsebool/Makefile   |  3 ++-
  policycoreutils/unsetfiles/Makefile  |  2 +-
  14 files changed, 46 insertions(+), 18 deletions(-)
libselinux/src/Makefile +8 -3
index 213c7d34..261c22d4 100644
@@ -147,7 +147,10 @@ endif
 
  SWIGRUBY = swig -Wall -ruby -o $(SWIGRUBYCOUT) -outdir ./ $(DISABLE_FLAGS)
 
-all: $(LIBA) $(LIBSO) $(LIBPC)
+all: $(LIBA) $(LIBPC)
+ifneq ($(DISABLE_SHARED),y)
+all: $(LIBSO)
+endif
 
  pywrap: all selinuxswig_python_exception.i
  	CFLAGS="$(CPPFLAGS) $(CFLAGS) $(SWIG_CFLAGS)" $(PYTHON) setup.py build_ext
@@ -186,11 +189,13 @@ $(SWIGRUBYCOUT): $(SWIGRUBYIF)
  install: all
  	test -d $(DESTDIR)$(LIBDIR) || install -m 755 -d $(DESTDIR)$(LIBDIR)
  	install -m 644 $(LIBA) $(DESTDIR)$(LIBDIR)
-	test -d $(DESTDIR)$(SHLIBDIR) || install -m 755 -d $(DESTDIR)$(SHLIBDIR)
-	install -m 755 $(LIBSO) $(DESTDIR)$(SHLIBDIR)
  	test -d $(DESTDIR)$(LIBDIR)/pkgconfig || install -m 755 -d $(DESTDIR)$(LIBDIR)/pkgconfig
  	install -m 644 $(LIBPC) $(DESTDIR)$(LIBDIR)/pkgconfig
+ifneq ($(DISABLE_SHARED),y)
+	test -d $(DESTDIR)$(SHLIBDIR) || install -m 755 -d $(DESTDIR)$(SHLIBDIR)
+	install -m 755 $(LIBSO) $(DESTDIR)$(SHLIBDIR)
  	ln -sf --relative $(DESTDIR)$(SHLIBDIR)/$(LIBSO) $(DESTDIR)$(LIBDIR)/$(TARGET)
+endif
 
  install-pywrap: pywrap
  	CFLAGS="$(CPPFLAGS) $(CFLAGS) $(SWIG_CFLAGS)" $(PYTHON) -m pip install --prefix=$(PREFIX) `test -n "$(DESTDIR)" && echo --root $(DESTDIR) --ignore-installed --no-deps` $(PYTHON_SETUP_ARGS) .
libselinux/utils/Makefile +7 -1
index 0d7095b1..6b1dc7c9 100644
@@ -53,7 +53,13 @@ else
  TARGETS=$(patsubst %.c,%,$(sort $(wildcard *.c)))
  endif
 
-sefcontext_compile: LDLIBS += ../src/libselinux.a $(PCRE_LDLIBS) -lsepol
+sefcontext_compile: LDLIBS += ../src/libselinux.a -lsepol
+
+PCRE_USERS = matchpathcon sefcontext_compile selabel_compare \
+	selabel_digest selabel_get_digests_all_partial_matches \
+	selabel_lookup selabel_lookup_best_match \
+	selabel_partial_match
+$(PCRE_USERS): LDLIBS += $(PCRE_LDLIBS)
 
  all: $(TARGETS)
 
libsemanage/src/Makefile +7 -2
index 8dfbd762..7d60b1e9 100644
@@ -67,7 +67,10 @@ SWIG = swig -Wall -python -o $(SWIGCOUT) -outdir ./
 
  SWIGRUBY = swig -Wall -ruby -o $(SWIGRUBYCOUT) -outdir ./
 
-all: $(LIBA) $(LIBSO) $(LIBPC)
+all: $(LIBA) $(LIBPC)
+ifneq ($(DISABLE_SHARED),y)
+all: $(LIBSO)
+endif
 
  pywrap: all $(SWIGSO)
 
@@ -137,11 +140,13 @@ swigify: $(SWIGIF)
  install: all
  	test -d $(DESTDIR)$(LIBDIR) || install -m 755 -d $(DESTDIR)$(LIBDIR)
  	install -m 644 $(LIBA) $(DESTDIR)$(LIBDIR)
-	install -m 755 $(LIBSO) $(DESTDIR)$(LIBDIR)
  	test -d $(DESTDIR)$(LIBDIR)/pkgconfig || install -m 755 -d $(DESTDIR)$(LIBDIR)/pkgconfig
  	install -m 644 $(LIBPC) $(DESTDIR)$(LIBDIR)/pkgconfig
  	test -f $(DESTDIR)$(DEFAULT_SEMANAGE_CONF_LOCATION) || install -m 644 -D semanage.conf $(DESTDIR)$(DEFAULT_SEMANAGE_CONF_LOCATION)
+ifneq ($(DISABLE_SHARED),y)
+	install -m 755 $(LIBSO) $(DESTDIR)$(LIBDIR)
  	cd $(DESTDIR)$(LIBDIR) && ln -sf $(LIBSO) $(TARGET)
+endif
 
  install-pywrap: pywrap
  	test -d $(DESTDIR)$(PYTHONLIBDIR) || install -m 755 -d $(DESTDIR)$(PYTHONLIBDIR)
libsepol/src/Makefile +8 -3
index 71fa3ed7..a1aed072 100644
@@ -45,7 +45,10 @@ LDFLAGS += -undefined dynamic_lookup
  LN=gln
  endif
 
-all: $(LIBA) $(LIBSO) $(LIBPC)
+all: $(LIBA) $(LIBPC)
+ifneq ($(DISABLE_SHARED),y)
+all: $(LIBSO)
+endif
 
 
  $(LIBA):  $(OBJS)
@@ -87,11 +90,13 @@ endif
  install: all
  	test -d $(DESTDIR)$(LIBDIR) || install -m 755 -d $(DESTDIR)$(LIBDIR)
  	install -m 644 $(LIBA) $(DESTDIR)$(LIBDIR)
-	test -d $(DESTDIR)$(SHLIBDIR) || install -m 755 -d $(DESTDIR)$(SHLIBDIR)
-	install -m 755 $(LIBSO) $(DESTDIR)$(SHLIBDIR)
  	test -d $(DESTDIR)$(LIBDIR)/pkgconfig || install -m 755 -d $(DESTDIR)$(LIBDIR)/pkgconfig
  	install -m 644 $(LIBPC) $(DESTDIR)$(LIBDIR)/pkgconfig
+ifneq ($(DISABLE_SHARED),y)
+	test -d $(DESTDIR)$(SHLIBDIR) || install -m 755 -d $(DESTDIR)$(SHLIBDIR)
+	install -m 755 $(LIBSO) $(DESTDIR)$(SHLIBDIR)
  	$(LN) -sf --relative $(DESTDIR)$(SHLIBDIR)/$(LIBSO) $(DESTDIR)$(LIBDIR)/$(TARGET)
+endif
 
  relabel:
  	/sbin/restorecon $(DESTDIR)$(SHLIBDIR)/$(LIBSO)
policycoreutils/Makefile +0 -0
index 32ad0201..7acd51dd 100644

policycoreutils/Makefile line 7

Quoted 7 lines
policycoreutils/Makefile +5 -0
@@ -1,5 +1,10 @@
  SUBDIRS = setfiles load_policy newrole run_init secon sestatus semodule setsebool scripts po man hll unsetfiles
 
+PKG_CONFIG ?= pkg-config
+
+LIBSELINUX_LDLIBS := $(shell $(PKG_CONFIG) --libs libselinux)
+export LIBSELINUX_LDLIBS
+

I think that in the DISABLE_SHARED case, the pkg-config command needs --static as well. I tried your patch, and I get errors that the downstream users of libselinux have undefined references to libpcre2, and they are being build without -lpcre2-8. Based on the pkg-config man page, it looks like Requires.private libraries are only included if the --static flag is passed.

I also see that restorecond is not including -lpcre2-8. It probably needs the same treatment as policycoreutils/*.

Finally, I was unable to get the install-rubywrap and install-pywrap targets to build with DISABLE_SHARED=y. I wasn't able to figure out the ultimate issue there.

-Daniel

#2 lore raw
Quoted 8 lines · Daniel Burgener
Quoted 7 lines · Alyssa Ross
policycoreutils/Makefile +0 -0
index 32ad0201..7acd51dd 100644
@@ -1,5 +1,10 @@
  SUBDIRS = setfiles load_policy newrole run_init secon sestatus semodule setsebool scripts po man hll unsetfiles
 
Quoted 12 lines

policycoreutils/Makefile line 7

Quoted 5 lines
policycoreutils/Makefile +5 -0
+PKG_CONFIG ?= pkg-config
+
+LIBSELINUX_LDLIBS := $(shell $(PKG_CONFIG) --libs libselinux)
+export LIBSELINUX_LDLIBS
+

I think that in the DISABLE_SHARED case, the pkg-config command needs --static as well. I tried your patch, and I get errors that the downstream users of libselinux have undefined references to libpcre2, and they are being build without -lpcre2-8. Based on the pkg-config man page, it looks like Requires.private libraries are only included if the --static flag is passed.

I think it's generally expected that the user set PKG_CONFIG="pkg-config --static" when they want static linking. See e.g. <https://bugs.freedesktop.org/show_bug.cgi?id=19541#c3>.

Quoted 2 lines

I also see that restorecond is not including -lpcre2-8. It probably needs the same treatment as policycoreutils/*.

Does it fail to build for you? It builds DISABLE_SHARED=y for me

Quoted 3 lines

Finally, I was unable to get the install-rubywrap and install-pywrap targets to build with DISABLE_SHARED=y. I wasn't able to figure out the ultimate issue there.

I think Ruby and Python bindings need to be shared libraries, so it doesn't make sense to build them with DISABLE_SHARED=y.

#3 lore raw
Quoted 23 lines · Alyssa Ross
Quoted 8 lines · Daniel Burgener
Quoted 7 lines · Alyssa Ross
policycoreutils/Makefile +0 -0
index 32ad0201..7acd51dd 100644
@@ -1,5 +1,10 @@
   SUBDIRS = setfiles load_policy newrole run_init secon sestatus semodule setsebool scripts po man hll unsetfiles
 
Quoted 12 lines

policycoreutils/Makefile line 7

Quoted 5 lines
policycoreutils/Makefile +5 -0
+PKG_CONFIG ?= pkg-config
+
+LIBSELINUX_LDLIBS := $(shell $(PKG_CONFIG) --libs libselinux)
+export LIBSELINUX_LDLIBS
+

I think that in the DISABLE_SHARED case, the pkg-config command needs --static as well. I tried your patch, and I get errors that the downstream users of libselinux have undefined references to libpcre2, and they are being build without -lpcre2-8. Based on the pkg-config man page, it looks like Requires.private libraries are only included if the --static flag is passed.

Quoted 3 lines

I think it's generally expected that the user set PKG_CONFIG="pkg-config --static" when they want static linking. See e.g. <https://bugs.freedesktop.org/show_bug.cgi?id=19541#c3>.

Thanks for clarifying. Yes, this command builds everything for me:

make DESTDIR=~/obj PKG_CONFIG="pkg-config --static" DISABLE_SHARED=y install

However, the binaries still appear dynamically linked when I investigate them with the "file" command. Am I missing some other step?

Quoted 5 lines
Quoted 3 lines

I also see that restorecond is not including -lpcre2-8. It probably needs the same treatment as policycoreutils/*.

Does it fail to build for you? It builds DISABLE_SHARED=y for me

Now that I added PKG_CONFIG="pkg-config --static", restorecond is building. However, as above, it appears dynamically linked.

Quoted 7 lines
Quoted 4 lines

Finally, I was unable to get the install-rubywrap and install-pywrap targets to build with DISABLE_SHARED=y. I wasn't able to figure out the ultimate issue there.

I think Ruby and Python bindings need to be shared libraries, so it doesn't make sense to build them with DISABLE_SHARED=y.

Fair enough. I think it would be helpful if these caveats could all get documented. I just tried following the README.md instructions and adding "DISABLE_SHARED=y", which as mentioned, didn't work. If "DISABLE_SHARED" requires other options to work, it seems like that should at a minimum be documented.

-Daniel

#4 lore raw
Quoted 27 lines · Daniel Burgener
Quoted 22 lines · Alyssa Ross
Quoted 11 lines · Daniel Burgener
Quoted 10 lines · Alyssa Ross
policycoreutils/Makefile +0 -0
index 32ad0201..7acd51dd 100644
@@ -1,5 +1,10 @@

   SUBDIRS = setfiles load_policy newrole run_init secon sestatus semodule setsebool scripts po man hll unsetfiles

policycoreutils/Makefile +4 -0
+PKG_CONFIG ?= pkg-config
+
+LIBSELINUX_LDLIBS := $(shell $(PKG_CONFIG) --libs libselinux)
+export LIBSELINUX_LDLIBS
Quoted 8 lines
Quoted 1 line

+

I think that in the DISABLE_SHARED case, the pkg-config command needs --static as well.  I tried your patch, and I get errors that the downstream users of libselinux have undefined references to libpcre2, and they are being build without -lpcre2-8.  Based on the pkg-config man page, it looks like Requires.private libraries are only included if the --static flag is passed.

Quoted 3 lines

I think it's generally expected that the user set PKG_CONFIG="pkg-config --static" when they want static linking.  See e.g. <https://bugs.freedesktop.org/show_bug.cgi?id=19541#c3>.

Quoted 5 lines

Thanks for clarifying.  Yes, this command builds everything for me:

make DESTDIR=~/obj PKG_CONFIG="pkg-config --static" DISABLE_SHARED=y install

However, the binaries still appear dynamically linked when I investigate them with the "file" command.  Am I missing some other step?

It occurs to me that I've possibly misunderstood the point of your patch. This is just about not building the shared libraries, independent of whether the binaries are statically linked?

I'm noticing that with the above command, restorecond is still dynamically linking with a libselinux. Since no shared libselinux was built, it's linking with the one that happens to be installed on my system. That is different than the policycoreutils/* like newrole for example, that was dynamically linked with libselinux without this patch, but now is not. That seems like surprising behavior to me. Is it the expected behavior?

-Daniel

Quoted 21 lines
Quoted 6 lines
Quoted 4 lines

I also see that restorecond is not including -lpcre2-8.  It probably needs the same treatment as policycoreutils/*.

Does it fail to build for you?  It builds DISABLE_SHARED=y for me

Now that I added PKG_CONFIG="pkg-config --static", restorecond is building.  However, as above, it appears dynamically linked.

Quoted 7 lines
Quoted 4 lines

Finally, I was unable to get the install-rubywrap and install-pywrap targets to build with DISABLE_SHARED=y.  I wasn't able to figure out the ultimate issue there.

I think Ruby and Python bindings need to be shared libraries, so it doesn't make sense to build them with DISABLE_SHARED=y.

Fair enough. I think it would be helpful if these caveats could all get documented.  I just tried following the README.md instructions and adding "DISABLE_SHARED=y", which as mentioned, didn't work.  If "DISABLE_SHARED" requires other options to work, it seems like that should at a minimum be documented.

-Daniel

#5 lore raw
Quoted 34 lines · Daniel Burgener
Quoted 33 lines · Daniel Burgener
Quoted 23 lines · Alyssa Ross
Quoted 12 lines · Daniel Burgener
Quoted 11 lines · Alyssa Ross
policycoreutils/Makefile +0 -0
index 32ad0201..7acd51dd 100644
@@ -1,5 +1,10 @@

   SUBDIRS = setfiles load_policy newrole run_init secon sestatus semodule setsebool scripts po man hll unsetfiles

policycoreutils/Makefile +4 -0
+PKG_CONFIG ?= pkg-config
+
+LIBSELINUX_LDLIBS := $(shell $(PKG_CONFIG) --libs libselinux)
+export LIBSELINUX_LDLIBS
Quoted 8 lines
Quoted 1 line

+

I think that in the DISABLE_SHARED case, the pkg-config command needs --static as well.  I tried your patch, and I get errors that the downstream users of libselinux have undefined references to libpcre2, and they are being build without -lpcre2-8.  Based on the pkg-config man page, it looks like Requires.private libraries are only included if the --static flag is passed.

Quoted 3 lines

I think it's generally expected that the user set PKG_CONFIG="pkg-config --static" when they want static linking.  See e.g. <https://bugs.freedesktop.org/show_bug.cgi?id=19541#c3>.

Thanks for clarifying.  Yes, this command builds everything for me:

make DESTDIR=~/obj PKG_CONFIG="pkg-config --static" DISABLE_SHARED=y install

Quoted 6 lines
Quoted 2 lines

However, the binaries still appear dynamically linked when I investigate them with the "file" command.  Am I missing some other step?

It occurs to me that I've possibly misunderstood the point of your patch. This is just about not building the shared libraries, independent of whether the binaries are statically linked?

Yes. The purpose of this is to make it possible to build using a compiler that only supports static linking. In Nixpkgs, we have a special mode where a package and all its dependencies can be built statically, and my intention here is to be able to build packages that depend on libselinux in that mode.

Would it maybe make more sense if I split this patch up, so one patch just makes it possible to disable building shared libraries, and another fixes building using only static libraries? Originally this patch was only the former, but then it grew…

Acked-by on v3 1/1
#6 lore raw
In reply to Alyssa Ross
Quoted 17 lines · Alyssa Ross

Sometimes it's useful to have a static-only toolchain. This can be due to targetting some weird embedded platform, or it can be because it ensures that no dynamic libraries are sneaking into a system that's supposed to be 100% static due to non-cooperative build systems. Most build systems support static-only builds, e.g. autoconf provides a --disable-shared configure option.

selinux's custom make-based build system did not support such an option, so here I've added one. Apart from the obvious changes, I had to make the utilities that use external libraries link against them manually, because that can't be inferred from the static selinux libraries. For downstream users of libselinux using pkg-config, this shouldn't be a problem, because libselinux.pc already includes the Requires.private line that specifies libpcre should be linked against as well.

Quoted 1 line
Quoted 289 lines

---
Changes since v3:

• Resolve conflicts.
• Add selabel_compare to PCRE_USERS.
• Use pkg-config for libselinux in policycoreutils, so PCRE is linked.

v2: https://lore.kernel.org/selinux/[email protected]

 libselinux/src/Makefile              | 11 ++++++++---
 libselinux/utils/Makefile            |  8 +++++++-
 libsemanage/src/Makefile             |  9 +++++++--
 libsepol/src/Makefile                | 11 ++++++++---
 policycoreutils/Makefile             |  5 +++++
 policycoreutils/load_policy/Makefile |  2 +-
 policycoreutils/newrole/Makefile     |  2 +-
 policycoreutils/run_init/Makefile    |  2 +-
 policycoreutils/secon/Makefile       |  2 +-
 policycoreutils/semodule/Makefile    |  3 ++-
 policycoreutils/sestatus/Makefile    |  2 +-
 policycoreutils/setfiles/Makefile    |  2 +-
 policycoreutils/setsebool/Makefile   |  3 ++-
 policycoreutils/unsetfiles/Makefile  |  2 +-
 14 files changed, 46 insertions(+), 18 deletions(-)
libselinux/src/Makefile +8 -3
index 213c7d34..261c22d4 100644
@@ -147,7 +147,10 @@ endif
 
 SWIGRUBY = swig -Wall -ruby -o $(SWIGRUBYCOUT) -outdir ./ $(DISABLE_FLAGS)
 
-all: $(LIBA) $(LIBSO) $(LIBPC)
+all: $(LIBA) $(LIBPC)
+ifneq ($(DISABLE_SHARED),y)
+all: $(LIBSO)
+endif
 
 pywrap: all selinuxswig_python_exception.i
        CFLAGS="$(CPPFLAGS) $(CFLAGS) $(SWIG_CFLAGS)" $(PYTHON) setup.py build_ext
@@ -186,11 +189,13 @@ $(SWIGRUBYCOUT): $(SWIGRUBYIF)
 install: all
        test -d $(DESTDIR)$(LIBDIR) || install -m 755 -d $(DESTDIR)$(LIBDIR)
        install -m 644 $(LIBA) $(DESTDIR)$(LIBDIR)
-       test -d $(DESTDIR)$(SHLIBDIR) || install -m 755 -d $(DESTDIR)$(SHLIBDIR)
-       install -m 755 $(LIBSO) $(DESTDIR)$(SHLIBDIR)
        test -d $(DESTDIR)$(LIBDIR)/pkgconfig || install -m 755 -d $(DESTDIR)$(LIBDIR)/pkgconfig
        install -m 644 $(LIBPC) $(DESTDIR)$(LIBDIR)/pkgconfig
+ifneq ($(DISABLE_SHARED),y)
+       test -d $(DESTDIR)$(SHLIBDIR) || install -m 755 -d $(DESTDIR)$(SHLIBDIR)
+       install -m 755 $(LIBSO) $(DESTDIR)$(SHLIBDIR)
        ln -sf --relative $(DESTDIR)$(SHLIBDIR)/$(LIBSO) $(DESTDIR)$(LIBDIR)/$(TARGET)
+endif
 
 install-pywrap: pywrap
        CFLAGS="$(CPPFLAGS) $(CFLAGS) $(SWIG_CFLAGS)" $(PYTHON) -m pip install --prefix=$(PREFIX) `test -n "$(DESTDIR)" && echo --root $(DESTDIR) --ignore-installed --no-deps` $(PYTHON_SETUP_ARGS) .
libselinux/utils/Makefile +7 -1
index 0d7095b1..6b1dc7c9 100644
@@ -53,7 +53,13 @@ else
 TARGETS=$(patsubst %.c,%,$(sort $(wildcard *.c)))
 endif
 
-sefcontext_compile: LDLIBS += ../src/libselinux.a $(PCRE_LDLIBS) -lsepol
+sefcontext_compile: LDLIBS += ../src/libselinux.a -lsepol
+
+PCRE_USERS = matchpathcon sefcontext_compile selabel_compare \
+       selabel_digest selabel_get_digests_all_partial_matches \
+       selabel_lookup selabel_lookup_best_match \
+       selabel_partial_match
+$(PCRE_USERS): LDLIBS += $(PCRE_LDLIBS)
 
 all: $(TARGETS)
 
libsemanage/src/Makefile +7 -2
index 8dfbd762..7d60b1e9 100644
@@ -67,7 +67,10 @@ SWIG = swig -Wall -python -o $(SWIGCOUT) -outdir ./
 
 SWIGRUBY = swig -Wall -ruby -o $(SWIGRUBYCOUT) -outdir ./
 
-all: $(LIBA) $(LIBSO) $(LIBPC)
+all: $(LIBA) $(LIBPC)
+ifneq ($(DISABLE_SHARED),y)
+all: $(LIBSO)
+endif
 
 pywrap: all $(SWIGSO)
 
@@ -137,11 +140,13 @@ swigify: $(SWIGIF)
 install: all
        test -d $(DESTDIR)$(LIBDIR) || install -m 755 -d $(DESTDIR)$(LIBDIR)
        install -m 644 $(LIBA) $(DESTDIR)$(LIBDIR)
-       install -m 755 $(LIBSO) $(DESTDIR)$(LIBDIR)
        test -d $(DESTDIR)$(LIBDIR)/pkgconfig || install -m 755 -d $(DESTDIR)$(LIBDIR)/pkgconfig
        install -m 644 $(LIBPC) $(DESTDIR)$(LIBDIR)/pkgconfig
        test -f $(DESTDIR)$(DEFAULT_SEMANAGE_CONF_LOCATION) || install -m 644 -D semanage.conf $(DESTDIR)$(DEFAULT_SEMANAGE_CONF_LOCATION)
+ifneq ($(DISABLE_SHARED),y)
+       install -m 755 $(LIBSO) $(DESTDIR)$(LIBDIR)
        cd $(DESTDIR)$(LIBDIR) && ln -sf $(LIBSO) $(TARGET)
+endif
 
 install-pywrap: pywrap
        test -d $(DESTDIR)$(PYTHONLIBDIR) || install -m 755 -d $(DESTDIR)$(PYTHONLIBDIR)
libsepol/src/Makefile +8 -3
index 71fa3ed7..a1aed072 100644
@@ -45,7 +45,10 @@ LDFLAGS += -undefined dynamic_lookup
 LN=gln
 endif
 
-all: $(LIBA) $(LIBSO) $(LIBPC)
+all: $(LIBA) $(LIBPC)
+ifneq ($(DISABLE_SHARED),y)
+all: $(LIBSO)
+endif
 
 
 $(LIBA):  $(OBJS)
@@ -87,11 +90,13 @@ endif
 install: all
        test -d $(DESTDIR)$(LIBDIR) || install -m 755 -d $(DESTDIR)$(LIBDIR)
        install -m 644 $(LIBA) $(DESTDIR)$(LIBDIR)
-       test -d $(DESTDIR)$(SHLIBDIR) || install -m 755 -d $(DESTDIR)$(SHLIBDIR)
-       install -m 755 $(LIBSO) $(DESTDIR)$(SHLIBDIR)
        test -d $(DESTDIR)$(LIBDIR)/pkgconfig || install -m 755 -d $(DESTDIR)$(LIBDIR)/pkgconfig
        install -m 644 $(LIBPC) $(DESTDIR)$(LIBDIR)/pkgconfig
+ifneq ($(DISABLE_SHARED),y)
+       test -d $(DESTDIR)$(SHLIBDIR) || install -m 755 -d $(DESTDIR)$(SHLIBDIR)
+       install -m 755 $(LIBSO) $(DESTDIR)$(SHLIBDIR)
        $(LN) -sf --relative $(DESTDIR)$(SHLIBDIR)/$(LIBSO) $(DESTDIR)$(LIBDIR)/$(TARGET)
+endif
 
 relabel:
        /sbin/restorecon $(DESTDIR)$(SHLIBDIR)/$(LIBSO)
policycoreutils/Makefile +5 -0
index 32ad0201..7acd51dd 100644
@@ -1,5 +1,10 @@
 SUBDIRS = setfiles load_policy newrole run_init secon sestatus semodule setsebool scripts po man hll unsetfiles
 
+PKG_CONFIG ?= pkg-config
+
+LIBSELINUX_LDLIBS := $(shell $(PKG_CONFIG) --libs libselinux)
+export LIBSELINUX_LDLIBS
+
 all install relabel clean indent:
        @for subdir in $(SUBDIRS); do \
                (cd $$subdir && $(MAKE) $@) || exit 1; \
policycoreutils/load_policy/Makefile +1 -1
index ad80d500..37c0111b 100644
@@ -7,7 +7,7 @@ LOCALEDIR ?= $(DESTDIR)$(PREFIX)/share/locale
 
 CFLAGS ?= -Werror -Wall -W
 override CFLAGS += $(LDFLAGS) -DUSE_NLS -DLOCALEDIR="\"$(LOCALEDIR)\"" -DPACKAGE="\"policycoreutils\""
-override LDLIBS += -lsepol -lselinux
+override LDLIBS += $(LIBSELINUX_LDLIBS) -lsepol
 
 TARGETS=$(patsubst %.c,%,$(sort $(wildcard *.c)))
 
policycoreutils/newrole/Makefile +1 -1
index 4b8145d3..6e95e79f 100644
@@ -25,7 +25,7 @@ VERSION = $(shell cat ../VERSION)
 CFLAGS ?= -Werror -Wall -W
 EXTRA_OBJS =
 override CFLAGS += -DVERSION=\"$(VERSION)\" -DUSE_NLS -DLOCALEDIR="\"$(LOCALEDIR)\"" -DPACKAGE="\"policycoreutils\""
-override LDLIBS += -lselinux
+override LDLIBS += $(LIBSELINUX_LDLIBS)
 ifeq ($(PAMH), y)
        override CFLAGS += -DUSE_PAM
        EXTRA_OBJS += hashtab.o
policycoreutils/run_init/Makefile +1 -1
index 619ebc1d..a5002587 100644
@@ -11,7 +11,7 @@ AUDITH ?= $(shell test -f /usr/include/libaudit.h && echo y)
 
 CFLAGS ?= -Werror -Wall -W
 override CFLAGS += -DUSE_NLS -DLOCALEDIR="\"$(LOCALEDIR)\"" -DPACKAGE="\"policycoreutils\""
-override LDLIBS += -lselinux
+override LDLIBS += $(LIBSELINUX_LDLIBS)
 ifeq ($(PAMH), y)
        override CFLAGS += -DUSE_PAM
        override LDLIBS += -lpam -lpam_misc
policycoreutils/secon/Makefile +1 -1
index 440503a1..daa3e10e 100644
@@ -8,7 +8,7 @@ WARNS=-Werror -W -Wall -Wundef -Wshadow -Wpointer-arith -Wbad-function-cast -Wca
 VERSION = $(shell cat ../VERSION)
 CFLAGS ?= $(WARNS) -O1
 override CFLAGS += -DVERSION=\"$(VERSION)\"
-override LDLIBS += -lselinux
+override LDLIBS += $(LIBSELINUX_LDLIBS)
 
 all: secon
 
policycoreutils/semodule/Makefile +2 -1
index 9fbf99d6..3855f95e 100644
@@ -5,11 +5,12 @@ SBINDIR ?= $(PREFIX)/sbin
 MANDIR = $(PREFIX)/share/man
 
 CFLAGS ?= -Werror -Wall -W
-override LDLIBS += -lsepol -lselinux -lsemanage
+override LDLIBS += -lsemanage -lsepol $(LIBSELINUX_LDLIBS)
 SEMODULE_OBJS = semodule.o
 
 all: semodule genhomedircon
 
+semodule: LDLIBS += -laudit -lbz2
 semodule: $(SEMODULE_OBJS)
 
 genhomedircon:
policycoreutils/sestatus/Makefile +1 -1
index aebf050c..b0df6d28 100644
@@ -8,7 +8,7 @@ ETCDIR ?= /etc
 
 CFLAGS ?= -Werror -Wall -W
 override CFLAGS += -D_FILE_OFFSET_BITS=64
-override LDLIBS += -lselinux
+override LDLIBS += $(LIBSELINUX_LDLIBS)
 
 all: sestatus
 
policycoreutils/setfiles/Makefile +1 -1
index 84ffb08b..0b27e934 100644
@@ -6,7 +6,7 @@ MANDIR = $(PREFIX)/share/man
 AUDITH ?= $(shell test -f /usr/include/libaudit.h && echo y)
 
 CFLAGS ?= -g -Werror -Wall -W
-override LDLIBS += -lselinux -lsepol -lpthread
+override LDLIBS += $(LIBSELINUX_LDLIBS) -lsepol -lpthread
 
 ifeq ($(AUDITH), y)
        override CFLAGS += -DUSE_AUDIT
policycoreutils/setsebool/Makefile +2 -1
index fc5b4ff6..12b6315d 100644
@@ -6,13 +6,14 @@ MANDIR = $(PREFIX)/share/man
 BASHCOMPLETIONDIR ?= $(PREFIX)/share/bash-completion/completions
 
 CFLAGS ?= -Werror -Wall -W
-override LDLIBS += -lselinux -lsemanage
+override LDLIBS += -lsemanage $(LIBSELINUX_LDLIBS)
 SETSEBOOL_OBJS = setsebool.o
 
 BASHCOMPLETIONS=setsebool-bash-completion.sh
 
 all: setsebool
 
+setsebool: LDLIBS += -laudit -lbz2
 setsebool: $(SETSEBOOL_OBJS)
 
 install: all
policycoreutils/unsetfiles/Makefile +1 -1
index 9e5edc04..bdc1b9de 100644
@@ -3,7 +3,7 @@ SBINDIR ?= $(PREFIX)/sbin
 MANDIR ?= $(PREFIX)/share/man
 
 override CFLAGS += -D_GNU_SOURCE
-override LDLIBS += -lselinux
+override LDLIBS += $(LIBSELINUX_LDLIBS)
 
 
 all: unsetfiles

base-commit: 71aec30d068789e856e7cc429b620ae1cfa890f1 --
2.47.0

#7 lore raw
Quoted 19 lines · James Carter
Quoted 17 lines · Alyssa Ross

Sometimes it's useful to have a static-only toolchain. This can be due to targetting some weird embedded platform, or it can be because it ensures that no dynamic libraries are sneaking into a system that's supposed to be 100% static due to non-cooperative build systems. Most build systems support static-only builds, e.g. autoconf provides a --disable-shared configure option.

selinux's custom make-based build system did not support such an option, so here I've added one. Apart from the obvious changes, I had to make the utilities that use external libraries link against them manually, because that can't be inferred from the static selinux libraries. For downstream users of libselinux using pkg-config, this shouldn't be a problem, because libselinux.pc already includes the Requires.private line that specifies libpcre should be linked against as well.

Quoted 4 lines
Quoted 1 line

Merged.
Thanks,
Jim

Quoted 289 lines
Quoted 289 lines

---
Changes since v3:

• Resolve conflicts.
• Add selabel_compare to PCRE_USERS.
• Use pkg-config for libselinux in policycoreutils, so PCRE is linked.

v2: https://lore.kernel.org/selinux/[email protected]

 libselinux/src/Makefile              | 11 ++++++++---
 libselinux/utils/Makefile            |  8 +++++++-
 libsemanage/src/Makefile             |  9 +++++++--
 libsepol/src/Makefile                | 11 ++++++++---
 policycoreutils/Makefile             |  5 +++++
 policycoreutils/load_policy/Makefile |  2 +-
 policycoreutils/newrole/Makefile     |  2 +-
 policycoreutils/run_init/Makefile    |  2 +-
 policycoreutils/secon/Makefile       |  2 +-
 policycoreutils/semodule/Makefile    |  3 ++-
 policycoreutils/sestatus/Makefile    |  2 +-
 policycoreutils/setfiles/Makefile    |  2 +-
 policycoreutils/setsebool/Makefile   |  3 ++-
 policycoreutils/unsetfiles/Makefile  |  2 +-
 14 files changed, 46 insertions(+), 18 deletions(-)
libselinux/src/Makefile +8 -3
index 213c7d34..261c22d4 100644
@@ -147,7 +147,10 @@ endif
 
 SWIGRUBY = swig -Wall -ruby -o $(SWIGRUBYCOUT) -outdir ./ $(DISABLE_FLAGS)
 
-all: $(LIBA) $(LIBSO) $(LIBPC)
+all: $(LIBA) $(LIBPC)
+ifneq ($(DISABLE_SHARED),y)
+all: $(LIBSO)
+endif
 
 pywrap: all selinuxswig_python_exception.i
        CFLAGS="$(CPPFLAGS) $(CFLAGS) $(SWIG_CFLAGS)" $(PYTHON) setup.py build_ext
@@ -186,11 +189,13 @@ $(SWIGRUBYCOUT): $(SWIGRUBYIF)
 install: all
        test -d $(DESTDIR)$(LIBDIR) || install -m 755 -d $(DESTDIR)$(LIBDIR)
        install -m 644 $(LIBA) $(DESTDIR)$(LIBDIR)
-       test -d $(DESTDIR)$(SHLIBDIR) || install -m 755 -d $(DESTDIR)$(SHLIBDIR)
-       install -m 755 $(LIBSO) $(DESTDIR)$(SHLIBDIR)
        test -d $(DESTDIR)$(LIBDIR)/pkgconfig || install -m 755 -d $(DESTDIR)$(LIBDIR)/pkgconfig
        install -m 644 $(LIBPC) $(DESTDIR)$(LIBDIR)/pkgconfig
+ifneq ($(DISABLE_SHARED),y)
+       test -d $(DESTDIR)$(SHLIBDIR) || install -m 755 -d $(DESTDIR)$(SHLIBDIR)
+       install -m 755 $(LIBSO) $(DESTDIR)$(SHLIBDIR)
        ln -sf --relative $(DESTDIR)$(SHLIBDIR)/$(LIBSO) $(DESTDIR)$(LIBDIR)/$(TARGET)
+endif
 
 install-pywrap: pywrap
        CFLAGS="$(CPPFLAGS) $(CFLAGS) $(SWIG_CFLAGS)" $(PYTHON) -m pip install --prefix=$(PREFIX) `test -n "$(DESTDIR)" && echo --root $(DESTDIR) --ignore-installed --no-deps` $(PYTHON_SETUP_ARGS) .
libselinux/utils/Makefile +7 -1
index 0d7095b1..6b1dc7c9 100644
@@ -53,7 +53,13 @@ else
 TARGETS=$(patsubst %.c,%,$(sort $(wildcard *.c)))
 endif
 
-sefcontext_compile: LDLIBS += ../src/libselinux.a $(PCRE_LDLIBS) -lsepol
+sefcontext_compile: LDLIBS += ../src/libselinux.a -lsepol
+
+PCRE_USERS = matchpathcon sefcontext_compile selabel_compare \
+       selabel_digest selabel_get_digests_all_partial_matches \
+       selabel_lookup selabel_lookup_best_match \
+       selabel_partial_match
+$(PCRE_USERS): LDLIBS += $(PCRE_LDLIBS)
 
 all: $(TARGETS)
 
libsemanage/src/Makefile +7 -2
index 8dfbd762..7d60b1e9 100644
@@ -67,7 +67,10 @@ SWIG = swig -Wall -python -o $(SWIGCOUT) -outdir ./
 
 SWIGRUBY = swig -Wall -ruby -o $(SWIGRUBYCOUT) -outdir ./
 
-all: $(LIBA) $(LIBSO) $(LIBPC)
+all: $(LIBA) $(LIBPC)
+ifneq ($(DISABLE_SHARED),y)
+all: $(LIBSO)
+endif
 
 pywrap: all $(SWIGSO)
 
@@ -137,11 +140,13 @@ swigify: $(SWIGIF)
 install: all
        test -d $(DESTDIR)$(LIBDIR) || install -m 755 -d $(DESTDIR)$(LIBDIR)
        install -m 644 $(LIBA) $(DESTDIR)$(LIBDIR)
-       install -m 755 $(LIBSO) $(DESTDIR)$(LIBDIR)
        test -d $(DESTDIR)$(LIBDIR)/pkgconfig || install -m 755 -d $(DESTDIR)$(LIBDIR)/pkgconfig
        install -m 644 $(LIBPC) $(DESTDIR)$(LIBDIR)/pkgconfig
        test -f $(DESTDIR)$(DEFAULT_SEMANAGE_CONF_LOCATION) || install -m 644 -D semanage.conf $(DESTDIR)$(DEFAULT_SEMANAGE_CONF_LOCATION)
+ifneq ($(DISABLE_SHARED),y)
+       install -m 755 $(LIBSO) $(DESTDIR)$(LIBDIR)
        cd $(DESTDIR)$(LIBDIR) && ln -sf $(LIBSO) $(TARGET)
+endif
 
 install-pywrap: pywrap
        test -d $(DESTDIR)$(PYTHONLIBDIR) || install -m 755 -d $(DESTDIR)$(PYTHONLIBDIR)
libsepol/src/Makefile +8 -3
index 71fa3ed7..a1aed072 100644
@@ -45,7 +45,10 @@ LDFLAGS += -undefined dynamic_lookup
 LN=gln
 endif
 
-all: $(LIBA) $(LIBSO) $(LIBPC)
+all: $(LIBA) $(LIBPC)
+ifneq ($(DISABLE_SHARED),y)
+all: $(LIBSO)
+endif
 
 
 $(LIBA):  $(OBJS)
@@ -87,11 +90,13 @@ endif
 install: all
        test -d $(DESTDIR)$(LIBDIR) || install -m 755 -d $(DESTDIR)$(LIBDIR)
        install -m 644 $(LIBA) $(DESTDIR)$(LIBDIR)
-       test -d $(DESTDIR)$(SHLIBDIR) || install -m 755 -d $(DESTDIR)$(SHLIBDIR)
-       install -m 755 $(LIBSO) $(DESTDIR)$(SHLIBDIR)
        test -d $(DESTDIR)$(LIBDIR)/pkgconfig || install -m 755 -d $(DESTDIR)$(LIBDIR)/pkgconfig
        install -m 644 $(LIBPC) $(DESTDIR)$(LIBDIR)/pkgconfig
+ifneq ($(DISABLE_SHARED),y)
+       test -d $(DESTDIR)$(SHLIBDIR) || install -m 755 -d $(DESTDIR)$(SHLIBDIR)
+       install -m 755 $(LIBSO) $(DESTDIR)$(SHLIBDIR)
        $(LN) -sf --relative $(DESTDIR)$(SHLIBDIR)/$(LIBSO) $(DESTDIR)$(LIBDIR)/$(TARGET)
+endif
 
 relabel:
        /sbin/restorecon $(DESTDIR)$(SHLIBDIR)/$(LIBSO)
policycoreutils/Makefile +5 -0
index 32ad0201..7acd51dd 100644
@@ -1,5 +1,10 @@
 SUBDIRS = setfiles load_policy newrole run_init secon sestatus semodule setsebool scripts po man hll unsetfiles
 
+PKG_CONFIG ?= pkg-config
+
+LIBSELINUX_LDLIBS := $(shell $(PKG_CONFIG) --libs libselinux)
+export LIBSELINUX_LDLIBS
+
 all install relabel clean indent:
        @for subdir in $(SUBDIRS); do \
                (cd $$subdir && $(MAKE) $@) || exit 1; \
policycoreutils/load_policy/Makefile +1 -1
index ad80d500..37c0111b 100644
@@ -7,7 +7,7 @@ LOCALEDIR ?= $(DESTDIR)$(PREFIX)/share/locale
 
 CFLAGS ?= -Werror -Wall -W
 override CFLAGS += $(LDFLAGS) -DUSE_NLS -DLOCALEDIR="\"$(LOCALEDIR)\"" -DPACKAGE="\"policycoreutils\""
-override LDLIBS += -lsepol -lselinux
+override LDLIBS += $(LIBSELINUX_LDLIBS) -lsepol
 
 TARGETS=$(patsubst %.c,%,$(sort $(wildcard *.c)))
 
policycoreutils/newrole/Makefile +1 -1
index 4b8145d3..6e95e79f 100644
@@ -25,7 +25,7 @@ VERSION = $(shell cat ../VERSION)
 CFLAGS ?= -Werror -Wall -W
 EXTRA_OBJS =
 override CFLAGS += -DVERSION=\"$(VERSION)\" -DUSE_NLS -DLOCALEDIR="\"$(LOCALEDIR)\"" -DPACKAGE="\"policycoreutils\""
-override LDLIBS += -lselinux
+override LDLIBS += $(LIBSELINUX_LDLIBS)
 ifeq ($(PAMH), y)
        override CFLAGS += -DUSE_PAM
        EXTRA_OBJS += hashtab.o
policycoreutils/run_init/Makefile +1 -1
index 619ebc1d..a5002587 100644
@@ -11,7 +11,7 @@ AUDITH ?= $(shell test -f /usr/include/libaudit.h && echo y)
 
 CFLAGS ?= -Werror -Wall -W
 override CFLAGS += -DUSE_NLS -DLOCALEDIR="\"$(LOCALEDIR)\"" -DPACKAGE="\"policycoreutils\""
-override LDLIBS += -lselinux
+override LDLIBS += $(LIBSELINUX_LDLIBS)
 ifeq ($(PAMH), y)
        override CFLAGS += -DUSE_PAM
        override LDLIBS += -lpam -lpam_misc
policycoreutils/secon/Makefile +1 -1
index 440503a1..daa3e10e 100644
@@ -8,7 +8,7 @@ WARNS=-Werror -W -Wall -Wundef -Wshadow -Wpointer-arith -Wbad-function-cast -Wca
 VERSION = $(shell cat ../VERSION)
 CFLAGS ?= $(WARNS) -O1
 override CFLAGS += -DVERSION=\"$(VERSION)\"
-override LDLIBS += -lselinux
+override LDLIBS += $(LIBSELINUX_LDLIBS)
 
 all: secon
 
policycoreutils/semodule/Makefile +2 -1
index 9fbf99d6..3855f95e 100644
@@ -5,11 +5,12 @@ SBINDIR ?= $(PREFIX)/sbin
 MANDIR = $(PREFIX)/share/man
 
 CFLAGS ?= -Werror -Wall -W
-override LDLIBS += -lsepol -lselinux -lsemanage
+override LDLIBS += -lsemanage -lsepol $(LIBSELINUX_LDLIBS)
 SEMODULE_OBJS = semodule.o
 
 all: semodule genhomedircon
 
+semodule: LDLIBS += -laudit -lbz2
 semodule: $(SEMODULE_OBJS)
 
 genhomedircon:
policycoreutils/sestatus/Makefile +1 -1
index aebf050c..b0df6d28 100644
@@ -8,7 +8,7 @@ ETCDIR ?= /etc
 
 CFLAGS ?= -Werror -Wall -W
 override CFLAGS += -D_FILE_OFFSET_BITS=64
-override LDLIBS += -lselinux
+override LDLIBS += $(LIBSELINUX_LDLIBS)
 
 all: sestatus
 
policycoreutils/setfiles/Makefile +1 -1
index 84ffb08b..0b27e934 100644
@@ -6,7 +6,7 @@ MANDIR = $(PREFIX)/share/man
 AUDITH ?= $(shell test -f /usr/include/libaudit.h && echo y)
 
 CFLAGS ?= -g -Werror -Wall -W
-override LDLIBS += -lselinux -lsepol -lpthread
+override LDLIBS += $(LIBSELINUX_LDLIBS) -lsepol -lpthread
 
 ifeq ($(AUDITH), y)
        override CFLAGS += -DUSE_AUDIT
policycoreutils/setsebool/Makefile +2 -1
index fc5b4ff6..12b6315d 100644
@@ -6,13 +6,14 @@ MANDIR = $(PREFIX)/share/man
 BASHCOMPLETIONDIR ?= $(PREFIX)/share/bash-completion/completions
 
 CFLAGS ?= -Werror -Wall -W
-override LDLIBS += -lselinux -lsemanage
+override LDLIBS += -lsemanage $(LIBSELINUX_LDLIBS)
 SETSEBOOL_OBJS = setsebool.o
 
 BASHCOMPLETIONS=setsebool-bash-completion.sh
 
 all: setsebool
 
+setsebool: LDLIBS += -laudit -lbz2
 setsebool: $(SETSEBOOL_OBJS)
 
 install: all
policycoreutils/unsetfiles/Makefile +1 -1
index 9e5edc04..bdc1b9de 100644
@@ -3,7 +3,7 @@ SBINDIR ?= $(PREFIX)/sbin
 MANDIR ?= $(PREFIX)/share/man
 
 override CFLAGS += -D_GNU_SOURCE
-override LDLIBS += -lselinux
+override LDLIBS += $(LIBSELINUX_LDLIBS)
 
 
 all: unsetfiles

base-commit: 71aec30d068789e856e7cc429b620ae1cfa890f1 --
2.47.0

#8 lore raw

Re: [PATCH v3] Support static-only builds - unconditional `-laudit -lbz2` in non-static policycoreutils build

In reply to Alyssa Ross
Quoted 90 lines · Alyssa Ross

Sometimes it's useful to have a static-only toolchain. This can be due to targetting some weird embedded platform, or it can be because it ensures that no dynamic libraries are sneaking into a system that's supposed to be 100% static due to non-cooperative build systems. Most build systems support static-only builds, e.g. autoconf provides a --disable-shared configure option.

selinux's custom make-based build system did not support such an option, so here I've added one. Apart from the obvious changes, I had to make the utilities that use external libraries link against them manually, because that can't be inferred from the static selinux libraries. For downstream users of libselinux using pkg-config, this shouldn't be a problem, because libselinux.pc already includes the Requires.private line that specifies libpcre should be linked against as well.

---

policycoreutils/Makefile +5 -0
index 32ad0201..7acd51dd 100644
@@ -1,5 +1,10 @@
 SUBDIRS = setfiles load_policy newrole run_init secon sestatus semodule setsebool scripts po man hll unsetfiles
 
+PKG_CONFIG ?= pkg-config
+
+LIBSELINUX_LDLIBS := $(shell $(PKG_CONFIG) --libs libselinux)
+export LIBSELINUX_LDLIBS
+
 all install relabel clean indent:
 	@for subdir in $(SUBDIRS); do \
 		(cd $$subdir && $(MAKE) $@) || exit 1; \
policycoreutils/load_policy/Makefile +1 -1
index ad80d500..37c0111b 100644
@@ -7,7 +7,7 @@ LOCALEDIR ?= $(DESTDIR)$(PREFIX)/share/locale
 
 CFLAGS ?= -Werror -Wall -W
 override CFLAGS += $(LDFLAGS) -DUSE_NLS -DLOCALEDIR="\"$(LOCALEDIR)\"" -DPACKAGE="\"policycoreutils\""
-override LDLIBS += -lsepol -lselinux
+override LDLIBS += $(LIBSELINUX_LDLIBS) -lsepol
 
 TARGETS=$(patsubst %.c,%,$(sort $(wildcard *.c)))
 
policycoreutils/newrole/Makefile +1 -1
index 4b8145d3..6e95e79f 100644
@@ -25,7 +25,7 @@ VERSION = $(shell cat ../VERSION)
 CFLAGS ?= -Werror -Wall -W
 EXTRA_OBJS =
 override CFLAGS += -DVERSION=\"$(VERSION)\" -DUSE_NLS -DLOCALEDIR="\"$(LOCALEDIR)\"" -DPACKAGE="\"policycoreutils\""
-override LDLIBS += -lselinux
+override LDLIBS += $(LIBSELINUX_LDLIBS)
 ifeq ($(PAMH), y)
 	override CFLAGS += -DUSE_PAM
 	EXTRA_OBJS += hashtab.o
policycoreutils/run_init/Makefile +1 -1
index 619ebc1d..a5002587 100644
@@ -11,7 +11,7 @@ AUDITH ?= $(shell test -f /usr/include/libaudit.h && echo y)
 
 CFLAGS ?= -Werror -Wall -W
 override CFLAGS += -DUSE_NLS -DLOCALEDIR="\"$(LOCALEDIR)\"" -DPACKAGE="\"policycoreutils\""
-override LDLIBS += -lselinux
+override LDLIBS += $(LIBSELINUX_LDLIBS)
 ifeq ($(PAMH), y)
 	override CFLAGS += -DUSE_PAM
 	override LDLIBS += -lpam -lpam_misc
policycoreutils/secon/Makefile +1 -1
index 440503a1..daa3e10e 100644
@@ -8,7 +8,7 @@ WARNS=-Werror -W -Wall -Wundef -Wshadow -Wpointer-arith -Wbad-function-cast -Wca
 VERSION = $(shell cat ../VERSION)
 CFLAGS ?= $(WARNS) -O1
 override CFLAGS += -DVERSION=\"$(VERSION)\"
-override LDLIBS += -lselinux
+override LDLIBS += $(LIBSELINUX_LDLIBS)
 
 all: secon
 
policycoreutils/semodule/Makefile +0 -0
index 9fbf99d6..3855f95e 100644

policycoreutils/semodule/Makefile SBINDIR ?= $(PREFIX)/sbin · line 13

Quoted 10 lines
policycoreutils/semodule/Makefile +2 -1
@@ -5,11 +5,12 @@ SBINDIR ?= $(PREFIX)/sbin
 MANDIR = $(PREFIX)/share/man
 
 CFLAGS ?= -Werror -Wall -W
-override LDLIBS += -lsepol -lselinux -lsemanage
+override LDLIBS += -lsemanage -lsepol $(LIBSELINUX_LDLIBS)
 SEMODULE_OBJS = semodule.o
 
 all: semodule genhomedircon
 
+semodule: LDLIBS += -laudit -lbz2

This change requires libaudit.so and and libbz2.so to be installed during policycoreutils build. This had not been necessary before this change.

While it can be changed in build system, e.g. in Fedora use BuildRequires in policycoreutils.spec, neither semodule nor setseboot does not use those 2 libraries directly.

I have not tested it yet but the following check could fix it:

ifneq ($(DISABLE_SHARED),y)

      semodule: LDLIBS += -laudit -lbz2

endif

Quoted 66 lines
policycoreutils/semodule/Makefile +0 -0
 semodule: $(SEMODULE_OBJS)
 
 genhomedircon:
policycoreutils/sestatus/Makefile +1 -1
index aebf050c..b0df6d28 100644
@@ -8,7 +8,7 @@ ETCDIR ?= /etc
 
 CFLAGS ?= -Werror -Wall -W
 override CFLAGS += -D_FILE_OFFSET_BITS=64
-override LDLIBS += -lselinux
+override LDLIBS += $(LIBSELINUX_LDLIBS)
 
 all: sestatus
 
policycoreutils/setfiles/Makefile +1 -1
index 84ffb08b..0b27e934 100644
@@ -6,7 +6,7 @@ MANDIR = $(PREFIX)/share/man
 AUDITH ?= $(shell test -f /usr/include/libaudit.h && echo y)
 
 CFLAGS ?= -g -Werror -Wall -W
-override LDLIBS += -lselinux -lsepol -lpthread
+override LDLIBS += $(LIBSELINUX_LDLIBS) -lsepol -lpthread
 
 ifeq ($(AUDITH), y)
 	override CFLAGS += -DUSE_AUDIT
policycoreutils/setsebool/Makefile +2 -1
index fc5b4ff6..12b6315d 100644
@@ -6,13 +6,14 @@ MANDIR = $(PREFIX)/share/man
 BASHCOMPLETIONDIR ?= $(PREFIX)/share/bash-completion/completions
 
 CFLAGS ?= -Werror -Wall -W
-override LDLIBS += -lselinux -lsemanage
+override LDLIBS += -lsemanage $(LIBSELINUX_LDLIBS)
 SETSEBOOL_OBJS = setsebool.o
 
 BASHCOMPLETIONS=setsebool-bash-completion.sh 
 
 all: setsebool
 
+setsebool: LDLIBS += -laudit -lbz2
 setsebool: $(SETSEBOOL_OBJS)
 
 install: all
policycoreutils/unsetfiles/Makefile +1 -1
index 9e5edc04..bdc1b9de 100644
@@ -3,7 +3,7 @@ SBINDIR ?= $(PREFIX)/sbin
 MANDIR ?= $(PREFIX)/share/man
 
 override CFLAGS += -D_GNU_SOURCE
-override LDLIBS += -lselinux
+override LDLIBS += $(LIBSELINUX_LDLIBS)
 
 
 all: unsetfiles

base-commit: 71aec30d068789e856e7cc429b620ae1cfa890f1

Signature · 1 line
2.47.0
#9 lore raw

PATCH 1/2 libsemanage: add missing libaudit private library

libsemanage always uses libaudit functions, so we need to make sure that consumers of libsemanage.a know to link against libaudit too.

Fixes 56d9d20a ("Pull auditing into libsemanage.")
---
 libsemanage/src/libsemanage.pc.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libsemanage/src/libsemanage.pc.in +1 -1
index 303f8069..8b7c55a9 100644
@@ -9,5 +9,5 @@ Version: @VERSION@
 URL: https://github.com/selinuxproject/selinux/wiki/Releases
 Requires.private: libselinux libsepol
 Libs: -L${libdir} -lsemanage
-Libs.private: -lbz2
+Libs.private: -laudit -lbz2
 Cflags: -I${includedir}

base-commit: 2304becd8154eeab084a7ef31b29048c0a780e84

Signature · 1 line
2.49.0
#10 lore raw

PATCH 2/2 policycoreutils: use pkg-config for libsemanage

libaudit and libbz2 are only required to be in the linker path for static builds. For dynamic builds, they'll be discovered through ELF metadata. pkg-config knows how to do the right thing in both cases, so just use it rather than listing libsemanage's dependencies manually.

Fixes da6cd3d8 ("Support static-only builds")
---
 policycoreutils/Makefile           | 3 ++-
 policycoreutils/semodule/Makefile  | 3 +--
 policycoreutils/setsebool/Makefile | 3 +--
 3 files changed, 4 insertions(+), 5 deletions(-)
policycoreutils/Makefile +2 -1
index 7acd51dd..0f3d62f2 100644
@@ -3,7 +3,8 @@ SUBDIRS = setfiles load_policy newrole run_init secon sestatus semodule setseboo
 PKG_CONFIG ?= pkg-config
 
 LIBSELINUX_LDLIBS := $(shell $(PKG_CONFIG) --libs libselinux)
-export LIBSELINUX_LDLIBS
+LIBSEMANAGE_LDLIBS := $(shell $(PKG_CONFIG) --libs libsemanage)
+export LIBSELINUX_LDLIBS LIBSEMANAGE_LDLIBS
 
 all install relabel clean indent:
 	@for subdir in $(SUBDIRS); do \
policycoreutils/semodule/Makefile +1 -2
index 7c45831f..018ee2ca 100644
@@ -7,12 +7,11 @@ MANDIR = $(PREFIX)/share/man
 CFLAGS ?= -Werror -Wall -W
 override CFLAGS += -I../../libselinux/include -I../../libsemanage/include
 override LDFLAGS+= -L../../libselinux/src     -L../../libsemanage/src
-override LDLIBS += -lsemanage -lsepol $(LIBSELINUX_LDLIBS)
+override LDLIBS += $(LIBSEMANAGE_LDLIBS) -lsepol $(LIBSELINUX_LDLIBS)
 SEMODULE_OBJS = semodule.o
 
 all: semodule genhomedircon
 
-semodule: LDLIBS += -laudit -lbz2
 semodule: $(SEMODULE_OBJS)
 
 genhomedircon:
policycoreutils/setsebool/Makefile +1 -2
index 1d514846..87494c55 100644
@@ -8,14 +8,13 @@ BASHCOMPLETIONDIR ?= $(PREFIX)/share/bash-completion/completions
 CFLAGS ?= -Werror -Wall -W
 override CFLAGS += -I../../libselinux/include -I../../libsemanage/include
 override LDFLAGS+= -L../../libselinux/src     -L../../libsemanage/src
-override LDLIBS += -lsemanage $(LIBSELINUX_LDLIBS)
+override LDLIBS += $(LIBSEMANAGE_LDLIBS) $(LIBSELINUX_LDLIBS)
 SETSEBOOL_OBJS = setsebool.o
 
 BASHCOMPLETIONS=setsebool-bash-completion.sh 
 
 all: setsebool
 
-setsebool: LDLIBS += -laudit -lbz2
 setsebool: $(SETSEBOOL_OBJS)
 
 install: all
Signature · 1 line
2.49.0
#11 lore raw

Re: [PATCH 2/2] policycoreutils: use pkg-config for libsemanage

Quoted 21 lines · Alyssa Ross

libaudit and libbz2 are only required to be in the linker path for static builds. For dynamic builds, they'll be discovered through ELF metadata. pkg-config knows how to do the right thing in both cases, so just use it rather than listing libsemanage's dependencies manually.

Fixes da6cd3d8 ("Support static-only builds")
---
 policycoreutils/Makefile           | 3 ++-
 policycoreutils/semodule/Makefile  | 3 +--
 policycoreutils/setsebool/Makefile | 3 +--
 3 files changed, 4 insertions(+), 5 deletions(-)
policycoreutils/Makefile +0 -0
index 7acd51dd..0f3d62f2 100644

policycoreutils/Makefile SUBDIRS = setfiles load_policy newrole run_init secon sestatus semodule setseboo · line 8

Quoted 7 lines
policycoreutils/Makefile +2 -1
@@ -3,7 +3,8 @@ SUBDIRS = setfiles load_policy newrole run_init secon sestatus semodule setseboo
 PKG_CONFIG ?= pkg-config
 
 LIBSELINUX_LDLIBS := $(shell $(PKG_CONFIG) --libs libselinux)
-export LIBSELINUX_LDLIBS
+LIBSEMANAGE_LDLIBS := $(shell $(PKG_CONFIG) --libs libsemanage)
+export LIBSELINUX_LDLIBS LIBSEMANAGE_LDLIBS
 

I think that we actually want something like:
ifeq ($(DISABLE_SHARED),y)

    LIBSELINUX_LDLIBS := $(shell PKG_CONFIG_PATH=../libselinux/src
$(PKG_CONFIG) --libs libselinux --static)
    LIBSEMANAGE_LDLIBS := $(shell PKG_CONFIG_PATH=../libsemanage/src
$(PKG_CONFIG) --libs libsemanage --static)
else
    LIBSELINUX_LDLIBS := $(shell PKG_CONFIG_PATH=../libselinux/src
$(PKG_CONFIG) --libs libselinux)
    LIBSEMANAGE_LDLIBS := $(shell PKG_CONFIG_PATH=../libsemanage/src

$(PKG_CONFIG) --libs libsemanage)
endif

As originally written, it is going to find the installed libselinux.pc and libsemanage.pc files which are not going to reflect any changes made to these files in the current build (I noticed this because your patch does make changes).
Also, I believe that "--static" is needed to generate the right libs for a static build.

With my changes above, using DISABLE_SHARED=y results in:
LIBSELINUX_LDLIBS = -L/usr/lib -lselinux -lsepol -lpcre2-8 LIBSEMANAGE_LDLIBS = -L/usr/lib -lsemanage -laudit -lbz2 -lselinux -lpcre2-8 -lsepol

while a normal build results in:
LIBSELINUX_LDLIBS = -L/usr/lib -lselinux
LIBSEMANAGE_LDLIBS = -L/usr/lib -lsemanage

Does this work for everyone?

Thanks,
Jim

Quoted 43 lines
policycoreutils/Makefile +0 -0
 all install relabel clean indent:
        @for subdir in $(SUBDIRS); do \
policycoreutils/semodule/Makefile +1 -2
index 7c45831f..018ee2ca 100644
@@ -7,12 +7,11 @@ MANDIR = $(PREFIX)/share/man
 CFLAGS ?= -Werror -Wall -W
 override CFLAGS += -I../../libselinux/include -I../../libsemanage/include
 override LDFLAGS+= -L../../libselinux/src     -L../../libsemanage/src
-override LDLIBS += -lsemanage -lsepol $(LIBSELINUX_LDLIBS)
+override LDLIBS += $(LIBSEMANAGE_LDLIBS) -lsepol $(LIBSELINUX_LDLIBS)
 SEMODULE_OBJS = semodule.o
 
 all: semodule genhomedircon
 
-semodule: LDLIBS += -laudit -lbz2
 semodule: $(SEMODULE_OBJS)
 
 genhomedircon:
policycoreutils/setsebool/Makefile +1 -3
index 1d514846..87494c55 100644
@@ -8,14 +8,13 @@ BASHCOMPLETIONDIR ?= $(PREFIX)/share/bash-completion/completions
 CFLAGS ?= -Werror -Wall -W
 override CFLAGS += -I../../libselinux/include -I../../libsemanage/include
 override LDFLAGS+= -L../../libselinux/src     -L../../libsemanage/src
-override LDLIBS += -lsemanage $(LIBSELINUX_LDLIBS)
+override LDLIBS += $(LIBSEMANAGE_LDLIBS) $(LIBSELINUX_LDLIBS)
 SETSEBOOL_OBJS = setsebool.o
 
 BASHCOMPLETIONS=setsebool-bash-completion.sh
 
 all: setsebool
 
-setsebool: LDLIBS += -laudit -lbz2
 setsebool: $(SETSEBOOL_OBJS)
 
 install: all
--

2.49.0

#12 lore raw

Re: [PATCH 2/2] policycoreutils: use pkg-config for libsemanage

Quoted 40 lines · James Carter
Quoted 21 lines · Alyssa Ross

libaudit and libbz2 are only required to be in the linker path for static builds. For dynamic builds, they'll be discovered through ELF metadata. pkg-config knows how to do the right thing in both cases, so just use it rather than listing libsemanage's dependencies manually.

Fixes da6cd3d8 ("Support static-only builds")
---
 policycoreutils/Makefile           | 3 ++-
 policycoreutils/semodule/Makefile  | 3 +--
 policycoreutils/setsebool/Makefile | 3 +--
 3 files changed, 4 insertions(+), 5 deletions(-)
policycoreutils/Makefile +0 -0
index 7acd51dd..0f3d62f2 100644

policycoreutils/Makefile SUBDIRS = setfiles load_policy newrole run_init secon sestatus semodule setseboo · line 8

Quoted 7 lines
policycoreutils/Makefile +2 -1
@@ -3,7 +3,8 @@ SUBDIRS = setfiles load_policy newrole run_init secon sestatus semodule setseboo
 PKG_CONFIG ?= pkg-config
 
 LIBSELINUX_LDLIBS := $(shell $(PKG_CONFIG) --libs libselinux)
-export LIBSELINUX_LDLIBS
+LIBSEMANAGE_LDLIBS := $(shell $(PKG_CONFIG) --libs libsemanage)
+export LIBSELINUX_LDLIBS LIBSEMANAGE_LDLIBS
 

I think that we actually want something like:
ifeq ($(DISABLE_SHARED),y)

    LIBSELINUX_LDLIBS := $(shell PKG_CONFIG_PATH=../libselinux/src
$(PKG_CONFIG) --libs libselinux --static)
    LIBSEMANAGE_LDLIBS := $(shell PKG_CONFIG_PATH=../libsemanage/src
$(PKG_CONFIG) --libs libsemanage --static)
else
    LIBSELINUX_LDLIBS := $(shell PKG_CONFIG_PATH=../libselinux/src
$(PKG_CONFIG) --libs libselinux)
    LIBSEMANAGE_LDLIBS := $(shell PKG_CONFIG_PATH=../libsemanage/src
Quoted 7 lines

$(PKG_CONFIG) --libs libsemanage)
endif

As originally written, it is going to find the installed libselinux.pc and libsemanage.pc files which are not going to reflect any changes made to these files in the current build (I noticed this because your patch does make changes).

I see. It hadn't occurred to me that selinux userspace supported being built all at once like this; I'd only seen all the components built individually, which is evidently also what Petr is doing. Your proposed solution wouldn't be compatible with different components being installed to different prefixes, which is how we do it in Nixpkgs, where every package is installed to a unique prefix.

Quoted 2 lines

Also, I believe that "--static" is needed to generate the right libs for a static build.

I /think/ it's generally expected that if you want static builds you set e.g. PKG_CONFIG="pkg-config --static". For example, a quick look at the pkg-config autoconf macros tells me that they don't try to detect whether to pass it or not, and in Nixpkgs we inject --static for static builds. Your proposal would also be a change in the meaning of DISABLE_SHARED, which until now hasn't changed how anything is built, just disabled things.

#13 lore raw

Re: [PATCH 2/2] policycoreutils: use pkg-config for libsemanage

Quoted 51 lines · Alyssa Ross
Quoted 40 lines · James Carter
Quoted 21 lines · Alyssa Ross

libaudit and libbz2 are only required to be in the linker path for static builds. For dynamic builds, they'll be discovered through ELF metadata. pkg-config knows how to do the right thing in both cases, so just use it rather than listing libsemanage's dependencies manually.

Fixes da6cd3d8 ("Support static-only builds")
---
 policycoreutils/Makefile           | 3 ++-
 policycoreutils/semodule/Makefile  | 3 +--
 policycoreutils/setsebool/Makefile | 3 +--
 3 files changed, 4 insertions(+), 5 deletions(-)
policycoreutils/Makefile +0 -0
index 7acd51dd..0f3d62f2 100644

policycoreutils/Makefile SUBDIRS = setfiles load_policy newrole run_init secon sestatus semodule setseboo · line 8

Quoted 7 lines
policycoreutils/Makefile +2 -1
@@ -3,7 +3,8 @@ SUBDIRS = setfiles load_policy newrole run_init secon sestatus semodule setseboo
 PKG_CONFIG ?= pkg-config
 
 LIBSELINUX_LDLIBS := $(shell $(PKG_CONFIG) --libs libselinux)
-export LIBSELINUX_LDLIBS
+LIBSEMANAGE_LDLIBS := $(shell $(PKG_CONFIG) --libs libsemanage)
+export LIBSELINUX_LDLIBS LIBSEMANAGE_LDLIBS
 

I think that we actually want something like:
ifeq ($(DISABLE_SHARED),y)

    LIBSELINUX_LDLIBS := $(shell PKG_CONFIG_PATH=../libselinux/src
$(PKG_CONFIG) --libs libselinux --static)
    LIBSEMANAGE_LDLIBS := $(shell PKG_CONFIG_PATH=../libsemanage/src
$(PKG_CONFIG) --libs libsemanage --static)
else
    LIBSELINUX_LDLIBS := $(shell PKG_CONFIG_PATH=../libselinux/src
$(PKG_CONFIG) --libs libselinux)
    LIBSEMANAGE_LDLIBS := $(shell PKG_CONFIG_PATH=../libsemanage/src
Quoted 7 lines

$(PKG_CONFIG) --libs libsemanage)
endif

As originally written, it is going to find the installed libselinux.pc and libsemanage.pc files which are not going to reflect any changes made to these files in the current build (I noticed this because your patch does make changes).

Quoted 7 lines

I see. It hadn't occurred to me that selinux userspace supported being built all at once like this; I'd only seen all the components built individually, which is evidently also what Petr is doing. Your proposed solution wouldn't be compatible with different components being installed to different prefixes, which is how we do it in Nixpkgs, where every package is installed to a unique prefix.

Obviously we want to support building everything separately as well as everything together.

I think that this should work:
LIBSELINUX_LDLIBS := $(shell PKG_CONFIG_PATH="$(PKG_CONFIG_PATH):../libselinux/src" $(PKG_CONFIG) --libs libselinux)
LIBSEMANAGE_LDLIBS := $(shell PKG_CONFIG_PATH="$(PKG_CONFIG_PATH):../libsemanage/src" $(PKG_CONFIG) --libs libsemanage)

Based on my testing:
1) If PKG_CONFIG_PATH is set, that will be searched first
2) If the pc files are not found, then "../libsemange/src" or "../libselinux/src" will be searched
3) If the pc files are still not found, then pkg-config will search using its defaults

This seems like it should work regardless.

BTW, I also tried using PKG_CONFIG_LIBDIR, but if that is set, then only that directory will be searched.

Quoted 10 lines
Quoted 2 lines

Also, I believe that "--static" is needed to generate the right libs for a static build.

I /think/ it's generally expected that if you want static builds you set e.g. PKG_CONFIG="pkg-config --static". For example, a quick look at the pkg-config autoconf macros tells me that they don't try to detect whether to pass it or not, and in Nixpkgs we inject --static for static builds. Your proposal would also be a change in the meaning of DISABLE_SHARED, which until now hasn't changed how anything is built, just disabled things.

I see. I should just set PKG_CONFIG="pkg-config --static" if I want to build static. That works for me.

Thanks,
Jim

#14 lore raw

Re: [PATCH 2/2] policycoreutils: use pkg-config for libsemanage

Quoted 78 lines · James Carter
Quoted 51 lines · Alyssa Ross
Quoted 40 lines · James Carter
Quoted 21 lines · Alyssa Ross

libaudit and libbz2 are only required to be in the linker path for static builds. For dynamic builds, they'll be discovered through ELF metadata. pkg-config knows how to do the right thing in both cases, so just use it rather than listing libsemanage's dependencies manually.

Fixes da6cd3d8 ("Support static-only builds")
---
 policycoreutils/Makefile           | 3 ++-
 policycoreutils/semodule/Makefile  | 3 +--
 policycoreutils/setsebool/Makefile | 3 +--
 3 files changed, 4 insertions(+), 5 deletions(-)
policycoreutils/Makefile +0 -0
index 7acd51dd..0f3d62f2 100644

policycoreutils/Makefile SUBDIRS = setfiles load_policy newrole run_init secon sestatus semodule setseboo · line 8

Quoted 7 lines
policycoreutils/Makefile +2 -1
@@ -3,7 +3,8 @@ SUBDIRS = setfiles load_policy newrole run_init secon sestatus semodule setseboo
 PKG_CONFIG ?= pkg-config
 
 LIBSELINUX_LDLIBS := $(shell $(PKG_CONFIG) --libs libselinux)
-export LIBSELINUX_LDLIBS
+LIBSEMANAGE_LDLIBS := $(shell $(PKG_CONFIG) --libs libsemanage)
+export LIBSELINUX_LDLIBS LIBSEMANAGE_LDLIBS
 

I think that we actually want something like:
ifeq ($(DISABLE_SHARED),y)

    LIBSELINUX_LDLIBS := $(shell PKG_CONFIG_PATH=../libselinux/src
$(PKG_CONFIG) --libs libselinux --static)
    LIBSEMANAGE_LDLIBS := $(shell PKG_CONFIG_PATH=../libsemanage/src
$(PKG_CONFIG) --libs libsemanage --static)
else
    LIBSELINUX_LDLIBS := $(shell PKG_CONFIG_PATH=../libselinux/src
$(PKG_CONFIG) --libs libselinux)
    LIBSEMANAGE_LDLIBS := $(shell PKG_CONFIG_PATH=../libsemanage/src
Quoted 7 lines

$(PKG_CONFIG) --libs libsemanage)
endif

As originally written, it is going to find the installed libselinux.pc and libsemanage.pc files which are not going to reflect any changes made to these files in the current build (I noticed this because your patch does make changes).

Quoted 7 lines

I see. It hadn't occurred to me that selinux userspace supported being built all at once like this; I'd only seen all the components built individually, which is evidently also what Petr is doing. Your proposed solution wouldn't be compatible with different components being installed to different prefixes, which is how we do it in Nixpkgs, where every package is installed to a unique prefix.

Obviously we want to support building everything separately as well as everything together.

I think that this should work:
LIBSELINUX_LDLIBS := $(shell PKG_CONFIG_PATH="$(PKG_CONFIG_PATH):../libselinux/src" $(PKG_CONFIG) --libs libselinux)
LIBSEMANAGE_LDLIBS := $(shell PKG_CONFIG_PATH="$(PKG_CONFIG_PATH):../libsemanage/src" $(PKG_CONFIG) --libs libsemanage)

Based on my testing:
1) If PKG_CONFIG_PATH is set, that will be searched first
2) If the pc files are not found, then "../libsemange/src" or "../libselinux/src" will be searched
3) If the pc files are still not found, then pkg-config will search using its defaults

Quoted 4 lines

This seems like it should work regardless.

BTW, I also tried using PKG_CONFIG_LIBDIR, but if that is set, then only that directory will be searched.

Looks sensible to me.

Acked-by on v1 2/2
#15 lore raw

Re: [PATCH 2/2] policycoreutils: use pkg-config for libsemanage

In reply to Alyssa Ross
Quoted 10 lines · Alyssa Ross

libaudit and libbz2 are only required to be in the linker path for static builds. For dynamic builds, they'll be discovered through ELF metadata. pkg-config knows how to do the right thing in both cases, so just use it rather than listing libsemanage's dependencies manually.

Fixes da6cd3d8 ("Support static-only builds")
Quoted 61 lines
---
 policycoreutils/Makefile           | 3 ++-
 policycoreutils/semodule/Makefile  | 3 +--
 policycoreutils/setsebool/Makefile | 3 +--
 3 files changed, 4 insertions(+), 5 deletions(-)
policycoreutils/Makefile +2 -1
index 7acd51dd..0f3d62f2 100644
@@ -3,7 +3,8 @@ SUBDIRS = setfiles load_policy newrole run_init secon sestatus semodule setseboo
 PKG_CONFIG ?= pkg-config
 
 LIBSELINUX_LDLIBS := $(shell $(PKG_CONFIG) --libs libselinux)
-export LIBSELINUX_LDLIBS
+LIBSEMANAGE_LDLIBS := $(shell $(PKG_CONFIG) --libs libsemanage)
+export LIBSELINUX_LDLIBS LIBSEMANAGE_LDLIBS
 
 all install relabel clean indent:
        @for subdir in $(SUBDIRS); do \
policycoreutils/semodule/Makefile +1 -2
index 7c45831f..018ee2ca 100644
@@ -7,12 +7,11 @@ MANDIR = $(PREFIX)/share/man
 CFLAGS ?= -Werror -Wall -W
 override CFLAGS += -I../../libselinux/include -I../../libsemanage/include
 override LDFLAGS+= -L../../libselinux/src     -L../../libsemanage/src
-override LDLIBS += -lsemanage -lsepol $(LIBSELINUX_LDLIBS)
+override LDLIBS += $(LIBSEMANAGE_LDLIBS) -lsepol $(LIBSELINUX_LDLIBS)
 SEMODULE_OBJS = semodule.o
 
 all: semodule genhomedircon
 
-semodule: LDLIBS += -laudit -lbz2
 semodule: $(SEMODULE_OBJS)
 
 genhomedircon:
policycoreutils/setsebool/Makefile +1 -3
index 1d514846..87494c55 100644
@@ -8,14 +8,13 @@ BASHCOMPLETIONDIR ?= $(PREFIX)/share/bash-completion/completions
 CFLAGS ?= -Werror -Wall -W
 override CFLAGS += -I../../libselinux/include -I../../libsemanage/include
 override LDFLAGS+= -L../../libselinux/src     -L../../libsemanage/src
-override LDLIBS += -lsemanage $(LIBSELINUX_LDLIBS)
+override LDLIBS += $(LIBSEMANAGE_LDLIBS) $(LIBSELINUX_LDLIBS)
 SETSEBOOL_OBJS = setsebool.o
 
 BASHCOMPLETIONS=setsebool-bash-completion.sh
 
 all: setsebool
 
-setsebool: LDLIBS += -laudit -lbz2
 setsebool: $(SETSEBOOL_OBJS)
 
 install: all
--

2.49.0

Acked-by on v1 1/2
#16 lore raw

Re: [PATCH 1/2] libsemanage: add missing libaudit private library

In reply to Alyssa Ross
Quoted 6 lines · Alyssa Ross

libsemanage always uses libaudit functions, so we need to make sure that consumers of libsemanage.a know to link against libaudit too.

Fixes 56d9d20a ("Pull auditing into libsemanage.")
Quoted 20 lines
---
 libsemanage/src/libsemanage.pc.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libsemanage/src/libsemanage.pc.in +1 -1
index 303f8069..8b7c55a9 100644
@@ -9,5 +9,5 @@ Version: @VERSION@
 URL: https://github.com/selinuxproject/selinux/wiki/Releases
 Requires.private: libselinux libsepol
 Libs: -L${libdir} -lsemanage
-Libs.private: -lbz2
+Libs.private: -laudit -lbz2
 Cflags: -I${includedir}

base-commit: 2304becd8154eeab084a7ef31b29048c0a780e84 --
2.49.0

#17 lore raw

Re: [PATCH 1/2] libsemanage: add missing libaudit private library

Quoted 10 lines · James Carter
Quoted 6 lines · Alyssa Ross

libsemanage always uses libaudit functions, so we need to make sure that consumers of libsemanage.a know to link against libaudit too.

Fixes 56d9d20a ("Pull auditing into libsemanage.")

These two patches have been merged.
Thanks,
Jim

Quoted 21 lines
Quoted 21 lines
---
 libsemanage/src/libsemanage.pc.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libsemanage/src/libsemanage.pc.in +1 -1
index 303f8069..8b7c55a9 100644
@@ -9,5 +9,5 @@ Version: @VERSION@
 URL: https://github.com/selinuxproject/selinux/wiki/Releases
 Requires.private: libselinux libsepol
 Libs: -L${libdir} -lsemanage
-Libs.private: -lbz2
+Libs.private: -laudit -lbz2
 Cflags: -I${includedir}

base-commit: 2304becd8154eeab084a7ef31b29048c0a780e84 --
2.49.0