Skip to contentSkip to conversation

configure: Determine if musl is used for build

PATCH In review Joshua Lant 2 participants 5 messages Aug 28, 2024 – Aug 29, 2024 netfilter

lore
Share & tools
lore
#0 lore raw

cover configure: Determine if musl is used for build

As per discussions regarding prior patch adding an option for building with musl, this patch automatically detects when building with musl in the configure.ac:

https://marc.info/?l=netfilter-devel&m=172426460502909&w=2
https://marc.info/?l=netfilter-devel&m=172086278122266&w=2

Joshua Lant (1):
configure: Determine if musl is used for build

 configure.ac | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/1 configure: Determine if musl is used for build

Error compiling with musl-libc:
The commit hash 810f8568f44f5863c2350a39f4f5c8d60f762958 introduces the netinet/ether.h header into xtables.h, which causes an error due to the redefinition of the ethhdr struct, defined in linux/if_ether.h and netinet/ether.h. This is fixed by the inclusion of -D__UAPI_DEF_ETHHDR=0 in CFLAGS for musl. Automatically check for this macro, since it is defined in musl but not in glibc.

---
 configure.ac | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
configure.ac +23 -1
index 2293702b..14106a7e 100644
@@ -206,6 +206,27 @@ if test "x$enable_profiling" = "xyes"; then
 	regular_LDFLAGS+=" -lgcov --coverage"
 fi
 
+AC_MSG_CHECKING([whether the build is using musl-libc])
+enable_musl_build=""
+
+AC_COMPILE_IFELSE(
+	[AC_LANG_PROGRAM([[#include <netinet/if_ether.h>]],
+	[[
+	#if defined(__UAPI_DEF_ETHHDR) && __UAPI_DEF_ETHHDR == 0
+		return 0;
+	#else
+		#error error trying musl...
+	#endif
+	]]
+	)],
+	[enable_musl_build="yes"],[enable_musl_build="no"]
+)
+AC_MSG_RESULT([${enable_musl_build}])
+
+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 +298,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.34.1
reviewer
#2 lore raw

Hi Joshua,

Quoted 7 lines · Joshua Lant

Error compiling with musl-libc:
The commit hash 810f8568f44f5863c2350a39f4f5c8d60f762958 introduces the netinet/ether.h header into xtables.h, which causes an error due to the redefinition of the ethhdr struct, defined in linux/if_ether.h and netinet/ether.h. This is fixed by the inclusion of -D__UAPI_DEF_ETHHDR=0 in CFLAGS for musl. Automatically check for this macro, since it is defined in musl but not in glibc.

Thanks for the patch! I tested and it may be simplified a bit:

[...]

configure.ac if test "x$enable_profiling" = "xyes"; then · line 219

Quoted 5 lines
configure.ac +5 -0
+	#if defined(__UAPI_DEF_ETHHDR) && __UAPI_DEF_ETHHDR == 0
+		return 0;
+	#else
+		#error error trying musl...
+	#endif

[...]

Since the non-failure case is the default, this is sufficient:

|       #if ! defined(__UAPI_DEF_ETHHDR) || __UAPI_DEF_ETHHDR != 0
|               #error error trying musl...
|       #endif

Fine with you? If so, I'll push the modified patch out.

Thanks, Phil

#3 lore raw

Hi Phil,

Quoted 12 lines

Thanks for the patch! I tested and it may be simplified a bit:

[...]

configure.ac if test "x$enable_profiling" = "xyes"; then · line 219

Quoted 5 lines
configure.ac +5 -0
+	#if defined(__UAPI_DEF_ETHHDR) && __UAPI_DEF_ETHHDR == 0
+		return 0;
+	#else
+		#error error trying musl...
+	#endif

[...]

Since the non-failure case is the default, this is sufficient:

Quoted 7 lines
|       #if ! defined(__UAPI_DEF_ETHHDR) || __UAPI_DEF_ETHHDR != 0
|               #error error trying musl...
|       #endif

Fine with you? If so, I'll push the modified patch out.

Thanks, Phil

Looks good to me :)

Cheers,

Josh

reviewer
#4 lore raw
Quoted 16 lines · Joshua Lant
Quoted 16 lines

Thanks for the patch! I tested and it may be simplified a bit:

[...]

configure.ac if test "x$enable_profiling" = "xyes"; then · line 219

Quoted 5 lines
configure.ac +5 -0
+	#if defined(__UAPI_DEF_ETHHDR) && __UAPI_DEF_ETHHDR == 0
+		return 0;
+	#else
+		#error error trying musl...
+	#endif

[...]

Since the non-failure case is the default, this is sufficient:

|       #if ! defined(__UAPI_DEF_ETHHDR) || __UAPI_DEF_ETHHDR != 0
|               #error error trying musl...
|       #endif
Quoted 5 lines
Quoted 3 lines

Fine with you? If so, I'll push the modified patch out.

Thanks, Phil

Looks good to me :)

Thanks for your review, modified patch applied.

Thanks, Phil