The build can be force enabled with --with-selinux and vice versa.

* build-aux/gen-lists-of-programs.sh: Move chcon and runcon
to the list of optional programs.
* configure.ac: Only enable chcon and runcon if selinux.h is available.
* NEWS: Mention the Build-related change.
Fixes https://github.com/coreutils/coreutils/issues/121
---
 NEWS                               |  6 ++++++
 build-aux/gen-lists-of-programs.sh |  4 ++--
 configure.ac                       | 10 ++++++++++
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/NEWS b/NEWS
index 402585be3..fa40ef36a 100644
--- a/NEWS
+++ b/NEWS
@@ -67,6 +67,12 @@ GNU coreutils NEWS                                    -*- 
outline -*-
 
   wc -l now operates 10% faster on hosts that support AVX512 instructions.
 
+** Build-related
+
+  chcon and runcon are not built by default if selinux headers are not present,
+  or if the --without-selinux configure option is specified.
+  This can be overridden wtih the --with-selinux configure option.
+
 
 * Noteworthy changes in release 9.8 (2025-09-22) [stable]
 
diff --git a/build-aux/gen-lists-of-programs.sh 
b/build-aux/gen-lists-of-programs.sh
index 4b6af8a4f..454eba0aa 100755
--- a/build-aux/gen-lists-of-programs.sh
+++ b/build-aux/gen-lists-of-programs.sh
@@ -24,12 +24,14 @@ disabled_by_default_progs='
 # Programs that can be built only when certain requisite system
 # features are detected at configure time.
 build_if_possible_progs='
+    chcon
     chroot
     df
     hostid
     libstdbuf.so
     nice
     pinky
+    runcon
     stdbuf
     stty
     timeout
@@ -47,7 +49,6 @@ normal_progs='
     basenc
     basename
     cat
-    chcon
     chgrp
     chmod
     chown
@@ -102,7 +103,6 @@ normal_progs='
     realpath
     rm
     rmdir
-    runcon
     seq
     sha1sum
     sha224sum
diff --git a/configure.ac b/configure.ac
index 1e51aba0e..fd0b11a69 100644
--- a/configure.ac
+++ b/configure.ac
@@ -529,6 +529,16 @@ CFLAGS=$ac_save_CFLAGS
 LDFLAGS=$ac_save_LDFLAGS
 ac_c_werror_flag=$cu_save_c_werror_flag
 
+# Don't build chcon and runcon if only have gnulib stubs
+# Honor --without-selinux to force disable
+# and --with-selinux to force enable.
+if test "$with_selinux" != no &&
+   { test "$with_selinux" = yes ||
+     test "$ac_cv_header_selinux_selinux_h" = yes; }; then
+  gl_ADD_PROG([optional_bin_progs], [chcon])
+  gl_ADD_PROG([optional_bin_progs], [runcon])
+fi
+
 # Test compiler support for half precision floating point types (for od)
 AC_MSG_CHECKING([IEEE 16 bit floating point])
 AC_CACHE_VAL([utils_cv_ieee_16_bit_supported],[
-- 
2.51.0


Reply via email to