Skip to contentSkip to conversation

configure: Add option for building with musl

PATCH In review Joshua Lant 2 participants 2 messages Jul 12, 2024 – Jul 13, 2024 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 configure: Add option for building with musl

Adding this configure option fixes compilation errors which occur when building with musl-libc. These are known issues with musl that cause structure redefinition errors in headers between linux/if_ether.h and netinet/ether.h.

---
 INSTALL      |  7 +++++++
 configure.ac | 10 +++++++++-
 2 files changed, 16 insertions(+), 1 deletion(-)
INSTALL +7 -0
index d62b428c..8095b0bb 100644
@@ -63,6 +63,13 @@ Configuring and compiling
 	optionally specify a search path to include anyway. This is
 	probably only useful for development.
 
+--enable-musl-build
+
+	When compiling against musl-libc, you may encounter issues with
+	redefinitions of structures in headers between musl and the kernel.
+	This is a known issue with musl-libc, and setting this option
+	should fix your build.
+
 If you want to enable debugging, use
 
 	./configure CFLAGS="-ggdb3 -O0"
configure.ac +9 -1
index 2293702b..7f54ccd1 100644
@@ -77,6 +77,9 @@ AC_ARG_WITH([xt-lock-name], AS_HELP_STRING([--with-xt-lock-name=PATH],
 AC_ARG_ENABLE([profiling],
 	AS_HELP_STRING([--enable-profiling], [build for use of gcov/gprof]),
 	[enable_profiling="$enableval"], [enable_profiling="no"])
+AC_ARG_ENABLE([musl-build],
+    AS_HELP_STRING([--enable-musl-build], [Set this option if you encounter compilation errors when building with musl-libc]),
+    [enable_musl_build="$enableval"], [enable_musl_build="no"])
 
 AC_MSG_CHECKING([whether $LD knows -Wl,--no-undefined])
 saved_LDFLAGS="$LDFLAGS";
@@ -206,6 +209,10 @@ if test "x$enable_profiling" = "xyes"; then
 	regular_LDFLAGS+=" -lgcov --coverage"
 fi
 
+if test "x$enable_musl_build" = "xyes"; then
+	regular_CFLAGS+=" -D__UAPI_DEF_ETHHDR=0"
+fi
+
 define([EXPAND_VARIABLE],
 [$2=[$]$1
 if test $prefix = 'NONE'; then
@@ -277,7 +284,8 @@ Build parameters:
   Installation prefix (--prefix):	${prefix}
   Xtables extension directory:		${e_xtlibdir}
   Pkg-config directory:			${e_pkgconfigdir}
-  Xtables lock file:			${xt_lock_name}"
+  Xtables lock file:			${xt_lock_name}
+  Build against musl-libc:		${enable_musl_build}"
 
 if [[ -n "$ksourcedir" ]]; then
 	echo "  Kernel source directory:		${ksourcedir}"
Signature · 1 line
2.25.1
#1 lore raw

Hi Joshua,

Quoted 19 lines · Joshua Lant

Adding this configure option fixes compilation errors which occur when building with musl-libc. These are known issues with musl that cause structure redefinition errors in headers between linux/if_ether.h and netinet/ether.h.

---
 INSTALL      |  7 +++++++
 configure.ac | 10 +++++++++-
 2 files changed, 16 insertions(+), 1 deletion(-)
INSTALL +0 -0
index d62b428c..8095b0bb 100644
@@ -63,6 +63,13 @@ Configuring and compiling
 	optionally specify a search path to include anyway. This is
 	probably only useful for development.
 

INSTALL Configuring and compiling · line 75

Quoted 10 lines
INSTALL +7 -0
+--enable-musl-build
+
+	When compiling against musl-libc, you may encounter issues with
+	redefinitions of structures in headers between musl and the kernel.
+	This is a known issue with musl-libc, and setting this option
+	should fix your build.
+
 If you want to enable debugging, use
 
 	./configure CFLAGS="-ggdb3 -O0"

Niggle: Since at lease gdb 11.2, info gdb section '4.1 Compiling for Debugging' says this:

Quoted 3 lines
|   Older versions of the GNU C compiler permitted a variant option '-gg'
|for debugging information.  GDB no longer supports this format; if your
|GNU C compiler has this option, do not use it.

I suggest -g3 -gdwarf-4. This enables gdb commands like info macro. There is also a -Og option. Personally, I'm not sure that I like it.

Quoted 36 lines
configure.ac +9 -2
index 2293702b..7f54ccd1 100644
@@ -77,6 +77,9 @@ AC_ARG_WITH([xt-lock-name], AS_HELP_STRING([--with-xt-lock-name=PATH],
 AC_ARG_ENABLE([profiling],
 	AS_HELP_STRING([--enable-profiling], [build for use of gcov/gprof]),
 	[enable_profiling="$enableval"], [enable_profiling="no"])
+AC_ARG_ENABLE([musl-build],
+    AS_HELP_STRING([--enable-musl-build], [Set this option if you encounter compilation errors when building with musl-libc]),
+    [enable_musl_build="$enableval"], [enable_musl_build="no"])
 
 AC_MSG_CHECKING([whether $LD knows -Wl,--no-undefined])
 saved_LDFLAGS="$LDFLAGS";
@@ -206,6 +209,10 @@ if test "x$enable_profiling" = "xyes"; then
 	regular_LDFLAGS+=" -lgcov --coverage"
 fi
 
+if test "x$enable_musl_build" = "xyes"; then
+	regular_CFLAGS+=" -D__UAPI_DEF_ETHHDR=0"
+fi
+
 define([EXPAND_VARIABLE],
 [$2=[$]$1
 if test $prefix = 'NONE'; then
@@ -277,7 +284,8 @@ Build parameters:
   Installation prefix (--prefix):	${prefix}
   Xtables extension directory:		${e_xtlibdir}
   Pkg-config directory:			${e_pkgconfigdir}
-  Xtables lock file:			${xt_lock_name}"
+  Xtables lock file:			${xt_lock_name}
+  Build against musl-libc:		${enable_musl_build}"
 
 if [[ -n "$ksourcedir" ]]; then
 	echo "  Kernel source directory:		${ksourcedir}"
--
Quoted 3 lines

2.25.1

Cheers ... Duncan.