Skip to content

Commit 2f6ebe5

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 2f6ebe5

File tree

7 files changed

+17
-31
lines changed

7 files changed

+17
-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=""

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

tests/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ clean-local:
5858
-rm -rf *.pyc *.pyo __pycache__ flake8-venv
5959

6060
AM_CPPFLAGS = -I$(top_srcdir)
61-
AM_CFLAGS = $(PTHREAD_CFLAGS) -g
61+
AM_CFLAGS = $(PTHREAD_CFLAGS) -g $(DEBUG_CFLAGS) $(EXTRA_CFLAGS)
6262

6363
test_dict_SOURCES = test_dict.c ../common/dict.h
6464
test_dict_LDADD = ../common/libdict.a

0 commit comments

Comments
 (0)