Skip to content

Commit 21ced2d

Browse files
committed
build: Decontaminate enviromental pollution to allow compiliation by clang
The statements in configure.ac "pollute" the environmental variables. This causes problem when --enable-warnings is set and clang is the compiler. It only works by accident on gcc because gcc aborts on illegal flags anyway, but clang does not which causes -Werror to get added to the check. One of the warning conflicts with that, causing it to be uncompiliable under clang. This patch removes the environmental polluation by storing the flags in automake variables. The flags are then added by automake. Also, there already a function in autoconf-archive to determine valid flags, so use that instead of the hand-rolled one. Signed-off-by: Christopher Byrne <salah.coronya@gmail.com>
1 parent b7841fc commit 21ced2d

File tree

11 files changed

+203
-31
lines changed

11 files changed

+203
-31
lines changed

common/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
noinst_LIBRARIES = libtio.a libprot.a libdict.a libexpr.a
2121

2222
AM_CPPFLAGS=-I$(top_srcdir)
23-
AM_CFLAGS = $(PIC_CFLAGS)
23+
AM_CFLAGS = $(PIC_CFLAGS) $(DEBUG_CFLAGS) $(EXTRA_CFLAGS)
2424

2525
libtio_a_SOURCES = tio.c tio.h
2626

compat/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
noinst_LIBRARIES = libcompat.a
2121

2222
AM_CPPFLAGS=-I$(top_srcdir)
23-
AM_CFLAGS = $(PIC_CFLAGS)
23+
AM_CFLAGS = $(PIC_CFLAGS) $(DEBUG_CFLAGS) $(EXTRA_CFLAGS)
2424

2525
EXTRA_DIST = getopt_long.c getopt_long.h \
2626
ether.c ether.h \

configure.ac

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -101,39 +101,25 @@ then
101101
fi
102102

103103
# check for debugging options
104+
DEBUG_CFLAGS=""
104105
AC_ARG_ENABLE(debug,
105106
AS_HELP_STRING([--enable-debug],
106107
[enable extensive debugging and logging]),
107-
[if test "x$enableval" != "xno" ; then CFLAGS="-g -DDEBUG $CFLAGS" ; fi])
108+
[AS_IF([test "x$enableval" != "xno"],
109+
[AX_APPEND_COMPILE_FLAGS([-g -DDEBUG],[DEBUG_CFLAGS])]
110+
)])
111+
AC_SUBST([DEBUG_CFLAGS])
108112

109113
# check for extra compiler warnings
110-
DESIRED_CFLAGS=""
114+
EXTRA_CFLAGS=""
111115
AC_ARG_ENABLE(warnings,
112116
AS_HELP_STRING([--enable-warnings],
113117
[enable extra compiler warnings (gcc)]),
114-
[if test "x$enableval" != "no"
115-
then
116-
CFLAGS="$CFLAGS -pedantic -Wall -Wshadow -Wpointer-arith -Wcast-align -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Waggregate-return -Wmissing-declarations -Wunused -Wformat=2 -Wswitch-default -Wswitch-enum -Wfloat-equal -Wbad-function-cast -Wredundant-decls"
117-
DESIRED_CFLAGS="$DESIRED_CFLAGS -Wextra -Wdeclaration-after-statement -Werror-implicit-function-declaration -Werror=implicit"
118-
fi])
119-
test_gcc_flag() {
120-
AC_LANG_CONFTEST([AC_LANG_PROGRAM()])
121-
$CC -c conftest.c $CFLAGS $@ > /dev/null 2> /dev/null
122-
ret=$?
123-
rm -f conftest.o
124-
return $ret
125-
}
126-
for flag in $DESIRED_CFLAGS
127-
do
128-
AC_MSG_CHECKING([whether $CC accepts $flag])
129-
if test_gcc_flag $flag
130-
then
131-
CFLAGS="$CFLAGS $flag"
132-
AC_MSG_RESULT([yes])
133-
else
134-
AC_MSG_RESULT([no])
135-
fi
136-
done
118+
[AS_IF([test "x$enableval" != "xno"],[
119+
AX_APPEND_COMPILE_FLAGS([-pedantic -Wall -Wshadow -Wpointer-arith -Wcast-align -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Waggregate-return -Wmissing-declarations -Wunused -Wformat=2 -Wswitch-default -Wswitch-enum -Wfloat-equal -Wbad-function-cast -Wredundant-decls],[EXTRA_CFLAGS],[-Werror])
120+
AX_APPEND_COMPILE_FLAGS([-Wextra -Wdeclaration-after-statement -Werror-implicit-function-declaration -Werror=implicit],[EXTRA_CFLAGS],[-Werror])
121+
])])
122+
AC_SUBST([EXTRA_CFLAGS])
137123

138124
# check for Position Independent Code compiler option
139125
PIC_CFLAGS=""

m4/ax_append_compile_flags.m4

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# ============================================================================
2+
# https://www.gnu.org/software/autoconf-archive/ax_append_compile_flags.html
3+
# ============================================================================
4+
#
5+
# SYNOPSIS
6+
#
7+
# AX_APPEND_COMPILE_FLAGS([FLAG1 FLAG2 ...], [FLAGS-VARIABLE], [EXTRA-FLAGS], [INPUT])
8+
#
9+
# DESCRIPTION
10+
#
11+
# For every FLAG1, FLAG2 it is checked whether the compiler works with the
12+
# flag. If it does, the flag is added FLAGS-VARIABLE
13+
#
14+
# If FLAGS-VARIABLE is not specified, the current language's flags (e.g.
15+
# CFLAGS) is used. During the check the flag is always added to the
16+
# current language's flags.
17+
#
18+
# If EXTRA-FLAGS is defined, it is added to the current language's default
19+
# flags (e.g. CFLAGS) when the check is done. The check is thus made with
20+
# the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to
21+
# force the compiler to issue an error when a bad flag is given.
22+
#
23+
# INPUT gives an alternative input source to AC_COMPILE_IFELSE.
24+
#
25+
# NOTE: This macro depends on the AX_APPEND_FLAG and
26+
# AX_CHECK_COMPILE_FLAG. Please keep this macro in sync with
27+
# AX_APPEND_LINK_FLAGS.
28+
#
29+
# LICENSE
30+
#
31+
# Copyright (c) 2011 Maarten Bosmans <mkbosmans@gmail.com>
32+
#
33+
# Copying and distribution of this file, with or without modification, are
34+
# permitted in any medium without royalty provided the copyright notice
35+
# and this notice are preserved. This file is offered as-is, without any
36+
# warranty.
37+
38+
#serial 7
39+
40+
AC_DEFUN([AX_APPEND_COMPILE_FLAGS],
41+
[AX_REQUIRE_DEFINED([AX_CHECK_COMPILE_FLAG])
42+
AX_REQUIRE_DEFINED([AX_APPEND_FLAG])
43+
for flag in $1; do
44+
AX_CHECK_COMPILE_FLAG([$flag], [AX_APPEND_FLAG([$flag], [$2])], [], [$3], [$4])
45+
done
46+
])dnl AX_APPEND_COMPILE_FLAGS

m4/ax_append_flag.m4

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# ===========================================================================
2+
# https://www.gnu.org/software/autoconf-archive/ax_append_flag.html
3+
# ===========================================================================
4+
#
5+
# SYNOPSIS
6+
#
7+
# AX_APPEND_FLAG(FLAG, [FLAGS-VARIABLE])
8+
#
9+
# DESCRIPTION
10+
#
11+
# FLAG is appended to the FLAGS-VARIABLE shell variable, with a space
12+
# added in between.
13+
#
14+
# If FLAGS-VARIABLE is not specified, the current language's flags (e.g.
15+
# CFLAGS) is used. FLAGS-VARIABLE is not changed if it already contains
16+
# FLAG. If FLAGS-VARIABLE is unset in the shell, it is set to exactly
17+
# FLAG.
18+
#
19+
# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION.
20+
#
21+
# LICENSE
22+
#
23+
# Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
24+
# Copyright (c) 2011 Maarten Bosmans <mkbosmans@gmail.com>
25+
#
26+
# Copying and distribution of this file, with or without modification, are
27+
# permitted in any medium without royalty provided the copyright notice
28+
# and this notice are preserved. This file is offered as-is, without any
29+
# warranty.
30+
31+
#serial 8
32+
33+
AC_DEFUN([AX_APPEND_FLAG],
34+
[dnl
35+
AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_SET_IF
36+
AS_VAR_PUSHDEF([FLAGS], [m4_default($2,_AC_LANG_PREFIX[FLAGS])])
37+
AS_VAR_SET_IF(FLAGS,[
38+
AS_CASE([" AS_VAR_GET(FLAGS) "],
39+
[*" $1 "*], [AC_RUN_LOG([: FLAGS already contains $1])],
40+
[
41+
AS_VAR_APPEND(FLAGS,[" $1"])
42+
AC_RUN_LOG([: FLAGS="$FLAGS"])
43+
])
44+
],
45+
[
46+
AS_VAR_SET(FLAGS,[$1])
47+
AC_RUN_LOG([: FLAGS="$FLAGS"])
48+
])
49+
AS_VAR_POPDEF([FLAGS])dnl
50+
])dnl AX_APPEND_FLAG

m4/ax_check_compile_flag.m4

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# ===========================================================================
2+
# https://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html
3+
# ===========================================================================
4+
#
5+
# SYNOPSIS
6+
#
7+
# AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT])
8+
#
9+
# DESCRIPTION
10+
#
11+
# Check whether the given FLAG works with the current language's compiler
12+
# or gives an error. (Warnings, however, are ignored)
13+
#
14+
# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on
15+
# success/failure.
16+
#
17+
# If EXTRA-FLAGS is defined, it is added to the current language's default
18+
# flags (e.g. CFLAGS) when the check is done. The check is thus made with
19+
# the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to
20+
# force the compiler to issue an error when a bad flag is given.
21+
#
22+
# INPUT gives an alternative input source to AC_COMPILE_IFELSE.
23+
#
24+
# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this
25+
# macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG.
26+
#
27+
# LICENSE
28+
#
29+
# Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
30+
# Copyright (c) 2011 Maarten Bosmans <mkbosmans@gmail.com>
31+
#
32+
# Copying and distribution of this file, with or without modification, are
33+
# permitted in any medium without royalty provided the copyright notice
34+
# and this notice are preserved. This file is offered as-is, without any
35+
# warranty.
36+
37+
#serial 6
38+
39+
AC_DEFUN([AX_CHECK_COMPILE_FLAG],
40+
[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF
41+
AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl
42+
AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [
43+
ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS
44+
_AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1"
45+
AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])],
46+
[AS_VAR_SET(CACHEVAR,[yes])],
47+
[AS_VAR_SET(CACHEVAR,[no])])
48+
_AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags])
49+
AS_VAR_IF(CACHEVAR,yes,
50+
[m4_default([$2], :)],
51+
[m4_default([$3], :)])
52+
AS_VAR_POPDEF([CACHEVAR])dnl
53+
])dnl AX_CHECK_COMPILE_FLAGS

m4/ax_require_defined.m4

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# ===========================================================================
2+
# https://www.gnu.org/software/autoconf-archive/ax_require_defined.html
3+
# ===========================================================================
4+
#
5+
# SYNOPSIS
6+
#
7+
# AX_REQUIRE_DEFINED(MACRO)
8+
#
9+
# DESCRIPTION
10+
#
11+
# AX_REQUIRE_DEFINED is a simple helper for making sure other macros have
12+
# been defined and thus are available for use. This avoids random issues
13+
# where a macro isn't expanded. Instead the configure script emits a
14+
# non-fatal:
15+
#
16+
# ./configure: line 1673: AX_CFLAGS_WARN_ALL: command not found
17+
#
18+
# It's like AC_REQUIRE except it doesn't expand the required macro.
19+
#
20+
# Here's an example:
21+
#
22+
# AX_REQUIRE_DEFINED([AX_CHECK_LINK_FLAG])
23+
#
24+
# LICENSE
25+
#
26+
# Copyright (c) 2014 Mike Frysinger <vapier@gentoo.org>
27+
#
28+
# Copying and distribution of this file, with or without modification, are
29+
# permitted in any medium without royalty provided the copyright notice
30+
# and this notice are preserved. This file is offered as-is, without any
31+
# warranty.
32+
33+
#serial 2
34+
35+
AC_DEFUN([AX_REQUIRE_DEFINED], [dnl
36+
m4_ifndef([$1], [m4_fatal([macro ]$1[ is not defined; is a m4 file missing?])])
37+
])dnl AX_REQUIRE_DEFINED

nslcd/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
sbin_PROGRAMS = nslcd
2222

2323
AM_CPPFLAGS=-I$(top_srcdir)
24-
AM_CFLAGS = $(PTHREAD_CFLAGS)
24+
AM_CFLAGS = $(PTHREAD_CFLAGS) $(DEBUG_CFLAGS) $(EXTRA_CFLAGS)
2525

2626
nslcd_SOURCES = nslcd.c ../nslcd.h ../common/nslcd-prot.h \
2727
../compat/attrs.h \

nss/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
noinst_PROGRAMS = nss_ldap.so
2424

2525
AM_CPPFLAGS=-I$(top_srcdir)
26-
AM_CFLAGS = $(PIC_CFLAGS)
26+
AM_CFLAGS = $(PIC_CFLAGS) $(DEBUG_CFLAGS) $(EXTRA_CFLAGS)
2727

2828
nss_ldap_so_SOURCES = common.c common.h prototypes.h solnss.h \
2929
../nslcd.h ../common/nslcd-prot.h \

pam/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
noinst_PROGRAMS = pam_ldap.so
2222

2323
AM_CPPFLAGS=-I$(top_srcdir)
24-
AM_CFLAGS = $(PIC_CFLAGS)
24+
AM_CFLAGS = $(PIC_CFLAGS) $(DEBUG_CFLAGS) $(EXTRA_CFLAGS)
2525

2626
pam_ldap_so_SOURCES = ../nslcd.h ../common/nslcd-prot.h \
2727
../compat/attrs.h pam.c common.h

0 commit comments

Comments
 (0)