Skip to contentSkip to conversation

Policycoreutils: Make pkg-config work for more types of builds

PATCH In review James Carter 1 participant 3 messages Jul 1, 2025 – Jul 2, 2025 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Policycoreutils: Make pkg-config work for more types of builds

To support static builds, pkg-config is used to add the libraries needed for libselinux and libsemanage during the build. Unforunately, pkg-config will always use the installed pc files for libselinux and libsemanage.

Instead set PKG_CONFIG_PATH when invoking pkg-config so that it searches in order:
1) The directory specified by PKG_CONFIG_PATH, if already set.
2) The local src directories of libselinux and libsemaange.
3) The default directories specified by the system.

---
 policycoreutils/Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
policycoreutils/Makefile +2 -2
index 0f3d62f2..7c9706e3 100644
@@ -2,8 +2,8 @@ SUBDIRS = setfiles load_policy newrole run_init secon sestatus semodule setseboo
 
 PKG_CONFIG ?= pkg-config
 
-LIBSELINUX_LDLIBS := $(shell $(PKG_CONFIG) --libs libselinux)
-LIBSEMANAGE_LDLIBS := $(shell $(PKG_CONFIG) --libs libsemanage)
+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)
 export LIBSELINUX_LDLIBS LIBSEMANAGE_LDLIBS
 
 all install relabel clean indent:
Signature · 1 line
2.50.0
#1 lore raw
Quoted 6 lines · James Carter

To support static builds, pkg-config is used to add the libraries needed for libselinux and libsemanage during the build. Unforunately, pkg-config will always use the installed pc files for libselinux and libsemanage.

Quoted 7 lines

Instead set PKG_CONFIG_PATH when invoking pkg-config so that it searches in order:
1) The directory specified by PKG_CONFIG_PATH, if already set.
2) The local src directories of libselinux and libsemaange.
3) The default directories specified by the system.

BTW, this applies on top of Alyssa's two patches.
Jim

Quoted 22 lines
---
 policycoreutils/Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
policycoreutils/Makefile +2 -3
index 0f3d62f2..7c9706e3 100644
@@ -2,8 +2,8 @@ SUBDIRS = setfiles load_policy newrole run_init secon sestatus semodule setseboo
 
 PKG_CONFIG ?= pkg-config
 
-LIBSELINUX_LDLIBS := $(shell $(PKG_CONFIG) --libs libselinux)
-LIBSEMANAGE_LDLIBS := $(shell $(PKG_CONFIG) --libs libsemanage)
+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)
 export LIBSELINUX_LDLIBS LIBSEMANAGE_LDLIBS
 
 all install relabel clean indent:
--

2.50.0

#2 lore raw
In reply to James Carter
Quoted 6 lines · James Carter

To support static builds, pkg-config is used to add the libraries needed for libselinux and libsemanage during the build. Unforunately, pkg-config will always use the installed pc files for libselinux and libsemanage.

Quoted 7 lines

Instead set PKG_CONFIG_PATH when invoking pkg-config so that it searches in order:
1) The directory specified by PKG_CONFIG_PATH, if already set.
2) The local src directories of libselinux and libsemaange.
3) The default directories specified by the system.

It seems like there are no objections, so I have merged this. Jim

Quoted 22 lines
---
 policycoreutils/Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
policycoreutils/Makefile +2 -3
index 0f3d62f2..7c9706e3 100644
@@ -2,8 +2,8 @@ SUBDIRS = setfiles load_policy newrole run_init secon sestatus semodule setseboo
 
 PKG_CONFIG ?= pkg-config
 
-LIBSELINUX_LDLIBS := $(shell $(PKG_CONFIG) --libs libselinux)
-LIBSEMANAGE_LDLIBS := $(shell $(PKG_CONFIG) --libs libsemanage)
+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)
 export LIBSELINUX_LDLIBS LIBSEMANAGE_LDLIBS
 
 all install relabel clean indent:
--

2.50.0