Sfoglia il codice sorgente

build: Unify and fix AC_ARG_ENABLE usage

The current code was executing code in the action arguments, instead
of just setting boolean flags and processing them afterwards. This
poses several problems, it implies jugling code around in case the the
default changes, it might also duplicate code, and it might leave the
ACTION-IF-NOT-GIVEN argument empty which could turn into an empty
“then fi” shell block which is a syntax error on POSIX shell. Leaving
the ACTION-IF-GIVEN argument empty is fine as it's always used by
autoconf to set $enableval to the specific enable variable, and setting
that variable from $enableval is redundant and might be wrong depending
on the order they are set, which could empty it.

Reported-by: Michael Schmidt <michael.schmidt.dangel@gmail.com>
Guillem Jover 15 anni fa
parent
commit
fcd428d0b0
3 ha cambiato i file con 22 aggiunte e 15 eliminazioni
  1. 7 4
      m4/dpkg-compiler.m4
  2. 7 6
      m4/dpkg-funcs.m4
  3. 8 5
      m4/dpkg-linker.m4

+ 7 - 4
m4/dpkg-compiler.m4

@@ -8,7 +8,7 @@ AC_DEFUN([DPKG_COMPILER_WARNINGS],
 [AC_ARG_ENABLE(compiler-warnings,
 	AS_HELP_STRING([--disable-compiler-warnings],
 	               [Disable additional compiler warnings]),
-	[enable_compiler_warnings=$enableval],
+	[],
 	[enable_compiler_warnings=yes])
 
 WFLAGS="-Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers \
@@ -35,9 +35,12 @@ AC_DEFUN([DPKG_COMPILER_OPTIMISATIONS],
 [AC_ARG_ENABLE(compiler-optimisations,
 	AS_HELP_STRING([--disable-compiler-optimisations],
 		       [Disable compiler optimisations]),
-[if test "x$enable_compiler_optimisations" = "xno"; then
-	[CFLAGS=$(echo "$CFLAGS" | sed -e "s/ -O[[1-9]]*\b/ -O0/g")]
-fi])dnl
+	[],
+	[enable_compiler_optimisations=yes])
+
+  AS_IF([test "x$enable_compiler_optimisations" = "xno"], [
+    CFLAGS=$(echo "$CFLAGS" | sed -e "s/ -O[[1-9]]*\b/ -O0/g")
+  ])
 ])
 
 # DPKG_TRY_C99([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])

+ 7 - 6
m4/dpkg-funcs.m4

@@ -76,12 +76,13 @@ AC_DEFUN([DPKG_MMAP],
   AC_ARG_ENABLE([mmap],
     AS_HELP_STRING([--enable-mmap],
                    [enable usage of unrealiable mmap if available]),
-    [
-      AC_CHECK_FUNCS([mmap])
-      AC_DEFINE(USE_MMAP, 1, [Use unreliable mmap support])
-    ],
-    []
-  )
+    [],
+    [enable_mmap=no])
+
+  AS_IF([test "x$enable_mmap" = "xyes"], [
+    AC_CHECK_FUNCS([mmap])
+    AC_DEFINE(USE_MMAP, 1, [Use unreliable mmap support])
+  ])
 ])
 
 # DPKG_FUNC_ASYNC_SYNC

+ 8 - 5
m4/dpkg-linker.m4

@@ -7,9 +7,12 @@ AC_DEFUN([DPKG_LINKER_OPTIMISATIONS],
 [AC_ARG_ENABLE(linker-optimisations,
 	AS_HELP_STRING([--disable-linker-optimisations],
 		       [Disable linker optimisations]),
-[if test "x$enable_linker_optimisations" = "xno"; then
-	[LDFLAGS=$(echo "$LDFLAGS" | sed -e "s/ -Wl,-O[[0-9]]*\b//g")]
-else
-	[LDFLAGS="$LDFLAGS -Wl,-O1"]
-fi], [LDFLAGS="$LDFLAGS -Wl,-O1"])dnl
+    [],
+    [enable_linker_optimisations=yes])
+
+  AS_IF([test "x$enable_linker_optimisations" = "xno"], [
+    LDFLAGS=$(echo "$LDFLAGS" | sed -e "s/ -Wl,-O[[0-9]]*\b//g")
+  ], [
+    LDFLAGS="$LDFLAGS -Wl,-O1"
+  ])
 ])