diff mbox series

configure: Add option for building with musl

Message ID 20240712123859.1108496-1-joshualant@gmail.com
State Changes Requested
Headers show
Series configure: Add option for building with musl | expand

Commit Message

Joshua Lant July 12, 2024, 12:38 p.m. UTC
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.

Signed-off-by: Joshua Lant joshualant@gmail.com
---
 INSTALL      |  7 +++++++
 configure.ac | 10 +++++++++-
 2 files changed, 16 insertions(+), 1 deletion(-)

Comments

Duncan Roe July 13, 2024, 1:16 a.m. UTC | #1
Hi Joshua,

On Fri, Jul 12, 2024 at 12:38:59PM +0000, Joshua Lant wrote:
> 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.
>
> Signed-off-by: Joshua Lant joshualant@gmail.com
> ---
>  INSTALL      |  7 +++++++
>  configure.ac | 10 +++++++++-
>  2 files changed, 16 insertions(+), 1 deletion(-)
>
> diff --git a/INSTALL b/INSTALL
> index d62b428c..8095b0bb 100644
> --- a/INSTALL
> +++ b/INSTALL
> @@ -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"

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

> |   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.

> diff --git a/configure.ac b/configure.ac
> index 2293702b..7f54ccd1 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -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}"
> --
> 2.25.1
>
>
Cheers ... Duncan.
diff mbox series

Patch

diff --git a/INSTALL b/INSTALL
index d62b428c..8095b0bb 100644
--- a/INSTALL
+++ b/INSTALL
@@ -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"
diff --git a/configure.ac b/configure.ac
index 2293702b..7f54ccd1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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}"