From 2d2ec7db98e42dcc5579708977dc5c0b27e0283a Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Sun, 18 Jul 2010 02:51:25 +0200 Subject: [PATCH] Improve GCC warning and error triggers and also improve check of GCC version. Configure snippets shamelessly stolen from http://www.libusb.org/browser/configure.ac --- Makefile.in | 1 + config.h.in | 3 ++ configure | 104 +++++++++++++++++++++++++++++++++++++------ configure.ac | 27 +++++++++++ examples/Makefile.in | 2 +- include/Makefile.in | 1 + man/Makefile.in | 1 + src/Makefile.in | 1 + 8 files changed, 125 insertions(+), 15 deletions(-) diff --git a/Makefile.in b/Makefile.in index 9852cff..08cef5c 100644 --- a/Makefile.in +++ b/Makefile.in @@ -113,6 +113,7 @@ distuninstallcheck_listfiles = find . -type f -print distcleancheck_listfiles = find . -type f -print ACLOCAL = @ACLOCAL@ AMTAR = @AMTAR@ +AM_CFLAGS = @AM_CFLAGS@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ AR = @AR@ AUTOCONF = @AUTOCONF@ diff --git a/config.h.in b/config.h.in index eaf43df..90fabc5 100644 --- a/config.h.in +++ b/config.h.in @@ -1,5 +1,8 @@ /* config.h.in. Generated from configure.ac by autoheader. */ +/* Default visibility */ +#undef API_EXPORTED + /* Define to 1 if the `closedir' function returns void instead of `int'. */ #undef CLOSEDIR_VOID diff --git a/configure b/configure index 1b85f05..58898aa 100755 --- a/configure +++ b/configure @@ -746,6 +746,7 @@ ac_includes_default="\ ac_subst_vars='am__EXEEXT_FALSE am__EXEEXT_TRUE LTLIBOBJS +AM_CFLAGS CONFIG_DEFAULT_COMPLETE_FALSE CONFIG_DEFAULT_COMPLETE_TRUE LIBOBJS @@ -4554,13 +4555,13 @@ if test "${lt_cv_nm_interface+set}" = set; then : else lt_cv_nm_interface="BSD nm" echo "int some_variable = 0;" > conftest.$ac_ext - (eval echo "\"\$as_me:4557: $ac_compile\"" >&5) + (eval echo "\"\$as_me:4558: $ac_compile\"" >&5) (eval "$ac_compile" 2>conftest.err) cat conftest.err >&5 - (eval echo "\"\$as_me:4560: $NM \\\"conftest.$ac_objext\\\"\"" >&5) + (eval echo "\"\$as_me:4561: $NM \\\"conftest.$ac_objext\\\"\"" >&5) (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out) cat conftest.err >&5 - (eval echo "\"\$as_me:4563: output\"" >&5) + (eval echo "\"\$as_me:4564: output\"" >&5) cat conftest.out >&5 if $GREP 'External.*some_variable' conftest.out > /dev/null; then lt_cv_nm_interface="MS dumpbin" @@ -5766,7 +5767,7 @@ ia64-*-hpux*) ;; *-*-irix6*) # Find out which ABI we are using. - echo '#line 5769 "configure"' > conftest.$ac_ext + echo '#line 5770 "configure"' > conftest.$ac_ext if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 (eval $ac_compile) 2>&5 ac_status=$? @@ -7296,11 +7297,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:7299: $lt_compile\"" >&5) + (eval echo "\"\$as_me:7300: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:7303: \$? = $ac_status" >&5 + echo "$as_me:7304: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -7635,11 +7636,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:7638: $lt_compile\"" >&5) + (eval echo "\"\$as_me:7639: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:7642: \$? = $ac_status" >&5 + echo "$as_me:7643: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -7740,11 +7741,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:7743: $lt_compile\"" >&5) + (eval echo "\"\$as_me:7744: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:7747: \$? = $ac_status" >&5 + echo "$as_me:7748: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -7795,11 +7796,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:7798: $lt_compile\"" >&5) + (eval echo "\"\$as_me:7799: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:7802: \$? = $ac_status" >&5 + echo "$as_me:7803: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -10179,7 +10180,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 10182 "configure" +#line 10183 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -10275,7 +10276,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 10278 "configure" +#line 10279 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -11104,6 +11105,81 @@ $as_echo "#define CONFIG_ANNOYING_NOISE /**/" >>confdefs.h fi +# Restore gnu89 inline semantics on gcc 4.3 and newer +saved_cflags="$CFLAGS" +CFLAGS="$CFLAGS -fgnu89-inline" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + inline_cflags="-fgnu89-inline" +else + inline_cflags="" +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +CFLAGS="$saved_cflags" + +# check for -fvisibility=hidden compiler support (GCC >= 3.4) +saved_cflags="$CFLAGS" +CFLAGS="$CFLAGS -fvisibility=hidden" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + VISIBILITY_CFLAGS="-fvisibility=hidden" + +$as_echo "#define API_EXPORTED __attribute__((visibility(\"default\")))" >>confdefs.h + +else + VISIBILITY_CFLAGS="" + +$as_echo "#define API_EXPORTED /**/" >>confdefs.h + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +CFLAGS="$saved_cflags" + +# check for -Wno-pointer-sign compiler support (GCC >= 4) +saved_cflags="$CFLAGS" +CFLAGS="$CFLAGS -Wno-pointer-sign" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + nopointersign_cflags="-Wno-pointer-sign" +else + nopointersign_cflags="" +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +CFLAGS="$saved_cflags" + +AM_CFLAGS="-std=gnu99 $inline_cflags -W -Wall -Wundef -Wunused -Wstrict-prototypes -Werror-implicit-function-declaration $nopointersign_cflags -Wshadow" + + ac_config_files="$ac_config_files Makefile src/Makefile include/Makefile man/Makefile examples/Makefile" cat >confcache <<\_ACEOF diff --git a/configure.ac b/configure.ac index 1b6eea4..33322a2 100644 --- a/configure.ac +++ b/configure.ac @@ -59,5 +59,32 @@ AC_ARG_ENABLE(terminal-bell, [ --enable-terminal-bell Enable terminal bell on completion.], AC_DEFINE([CONFIG_ANNOYING_NOISE],, [Define to enable terminal bell on completion.])) +# Restore gnu89 inline semantics on gcc 4.3 and newer +saved_cflags="$CFLAGS" +CFLAGS="$CFLAGS -fgnu89-inline" +AC_COMPILE_IFELSE(AC_LANG_PROGRAM([]), inline_cflags="-fgnu89-inline", inline_cflags="") +CFLAGS="$saved_cflags" + +# check for -fvisibility=hidden compiler support (GCC >= 3.4) +saved_cflags="$CFLAGS" +CFLAGS="$CFLAGS -fvisibility=hidden" +AC_COMPILE_IFELSE(AC_LANG_PROGRAM([]), + [VISIBILITY_CFLAGS="-fvisibility=hidden" + AC_DEFINE([API_EXPORTED], [__attribute__((visibility("default")))], [Default visibility]) ], + [ VISIBILITY_CFLAGS="" + AC_DEFINE([API_EXPORTED], [], [Default visibility]) ], + ]) +CFLAGS="$saved_cflags" + +# check for -Wno-pointer-sign compiler support (GCC >= 4) +saved_cflags="$CFLAGS" +CFLAGS="$CFLAGS -Wno-pointer-sign" +AC_COMPILE_IFELSE(AC_LANG_PROGRAM([]), + nopointersign_cflags="-Wno-pointer-sign", nopointersign_cflags="") +CFLAGS="$saved_cflags" + +AM_CFLAGS="-std=gnu99 $inline_cflags -W -Wall -Wundef -Wunused -Wstrict-prototypes -Werror-implicit-function-declaration $nopointersign_cflags -Wshadow" +AC_SUBST(AM_CFLAGS) + AC_OUTPUT(Makefile src/Makefile include/Makefile man/Makefile examples/Makefile) diff --git a/examples/Makefile.in b/examples/Makefile.in index 99b2093..baf09b7 100644 --- a/examples/Makefile.in +++ b/examples/Makefile.in @@ -93,6 +93,7 @@ CTAGS = ctags DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ AMTAR = @AMTAR@ +AM_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/include AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ AR = @AR@ AUTOCONF = @AUTOCONF@ @@ -205,7 +206,6 @@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ AUTOMAKE_OPTIONS = foreign LDADD = $(top_builddir)/src/libeditline.la -AM_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/include all: all-am .SUFFIXES: diff --git a/include/Makefile.in b/include/Makefile.in index 0af1be5..ce74ba4 100644 --- a/include/Makefile.in +++ b/include/Makefile.in @@ -84,6 +84,7 @@ CTAGS = ctags DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ AMTAR = @AMTAR@ +AM_CFLAGS = @AM_CFLAGS@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ AR = @AR@ AUTOCONF = @AUTOCONF@ diff --git a/man/Makefile.in b/man/Makefile.in index 41bc813..157507b 100644 --- a/man/Makefile.in +++ b/man/Makefile.in @@ -83,6 +83,7 @@ MANS = $(dist_man_MANS) DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ AMTAR = @AMTAR@ +AM_CFLAGS = @AM_CFLAGS@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ AR = @AR@ AUTOCONF = @AUTOCONF@ diff --git a/src/Makefile.in b/src/Makefile.in index 286f4e0..bcbaedb 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -114,6 +114,7 @@ CTAGS = ctags DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ AMTAR = @AMTAR@ +AM_CFLAGS = @AM_CFLAGS@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ AR = @AR@ AUTOCONF = @AUTOCONF@