diff options
Diffstat (limited to 'gphoto-m4/gp-pedantic-compiler-flags.m4')
-rw-r--r-- | gphoto-m4/gp-pedantic-compiler-flags.m4 | 108 |
1 files changed, 97 insertions, 11 deletions
diff --git a/gphoto-m4/gp-pedantic-compiler-flags.m4 b/gphoto-m4/gp-pedantic-compiler-flags.m4 index b84aa0b51..1b690428c 100644 --- a/gphoto-m4/gp-pedantic-compiler-flags.m4 +++ b/gphoto-m4/gp-pedantic-compiler-flags.m4 @@ -7,14 +7,30 @@ dnl #################################################################### dnl GP_CONDITIONAL_COMPILE_FLAGS(FLAG_VAR, FLAGS) dnl #################################################################### AC_DEFUN([GP_CONDITIONAL_COMPILE_FLAGS], [dnl +dnl # BEGIN $0($@) -AS_VAR_IF([$1], [], [dnl - $1="$2" -], [dnl - $1="[$]{$1} $2" -]) -AC_MSG_CHECKING([whether $1="[$]$1" compiles]) -AC_COMPILE_IFELSE([m4_case([$1], [CFLAGS], [dnl +dnl +m4_pushdef([the_lang], + [m4_case([$1], + [CFLAGS], [C], + [CXXFLAGS], [C++], + [m4_fatal([unhandled compiler flags variable: ][$1])])])dnl +dnl +AC_LANG_PUSH(the_lang)dnl +dnl +dnl If $2 is a warning option, normalize it, as -Wno-foo will compile +dnl successfully, regardless of whether the compiler even knows the +dnl -Wfoo warning. FIXME: Split $2 and operate on each part? +m4_pushdef([normalized_option], + [m4_bpatsubst([$2], + [^-W\(no-\)?\(error=\)?\([-_0-9a-zA-Z=]+\)$], + [-W\3])])dnl +dnl +saved_$1="${$1}" +$1="${saved_$1} normalized_option -Werror" +AC_MSG_CHECKING([whether $1 can append $2]) +AC_COMPILE_IFELSE([dnl +m4_case(the_lang, [C], [dnl AC_LANG_SOURCE([[ #include <stdio.h> int main(int argc, char *argv[]) @@ -27,7 +43,7 @@ int main(int argc, char *argv[]) return 0; } ]])dnl -], [CXXFLAGS], [dnl +], [C++], [dnl AC_LANG_SOURCE([[ #include <iostream> int main(int argc, char *argv[]) @@ -40,14 +56,18 @@ int main(int argc, char *argv[]) return 0; } ]])dnl -], [m4_fatal([wrong compiler flag])])], [dnl - : "Added flag $2 to $1 and it works" +], [m4_fatal([unhandled language ]the_lang)])dnl +], [dnl AC_MSG_RESULT([yes]) + $1="${saved_$1} $2" ], [dnl - : "Added flag $2 to $1 and it does not work" AC_MSG_RESULT([no]) gp_have_pedantic_compiler=no + $1="$saved_$1" ]) +m4_popdef([normalized_option])dnl +AC_LANG_POP(the_lang)dnl +m4_popdef([the_lang])dnl # END $0($@) ])dnl dnl @@ -117,6 +137,72 @@ dnl dnl dnl #################################################################### dnl +dnl GP_WITH_EMPTY_CONFDEFS_H +dnl +dnl Usage: +dnl GP_WITH_EMPTY_CONFDEFS_H([ +dnl GP_CONDITIONAL_COMPILE_FLAGS([CFLAGS], [-Wno-foo]) +dnl GP_CONDITIONAL_COMPILE_FLAGS([CFLAGS], [-Wno-bar]) +dnl ])dnl +dnl +dnl Since autoconf 2.63b, the macros defined by AC_DEFINE so far +dnl (mostly PACKAGE, VERSION, etc.) are in confdefs.h by now and are +dnl included using AC_LANG_SOURCE or AC_LANG_PROGRAM. +dnl +dnl We cannot use a confdefs.h with macro definitions for the pedantic +dnl compilation tests as that pedantic compilation might complain +dnl about macros being defined but not used. +dnl +dnl We also cannot just put AC_LANG_DEFINES_PROVIDED inside the +dnl program, as that will make sure the program starts with the +dnl current content of confdefs.h. +dnl +dnl In order to be able to test compile programs without any macro +dnl definitions from confdefs.ht, we save the original confdefs.h file +dnl and use an empty confdefs.h for our checks, then restore the +dnl original confdefs.h after our checks are done. +dnl +dnl Of course, we must not append to confdefs.h by e.g. calling +dnl AC_DEFINE or AC_DEFINE_UNQUOTED until the original confdefs.h has +dnl been restored, as those definitions would then be lost. +dnl +dnl #################################################################### +AC_DEFUN([GP_WITH_EMPTY_CONFDEFS_H], [dnl +m4_pushdef([AC_DEFINE], + [m4_fatal([Must not use AC_DEFINE inside $0])])dnl +m4_pushdef([AC_DEFINE_UNQUOTED], + [m4_fatal([Must not use AC_DEFINE_UNQUOTED inside $0])])dnl +cat confdefs.h +AC_MSG_NOTICE([saving original confdefs.h and creating empty confdefs.h]) +rm -f confdefs.h.saved +mv confdefs.h confdefs.h.saved +cat <<EOF >confdefs.h +/* confdefs.h forced empty for the pedantic compile tests */ +EOF +dnl +AC_MSG_CHECKING([CFLAGS value before]) +AC_MSG_RESULT([$CFLAGS]) +AC_MSG_CHECKING([CXXFLAGS value before]) +AC_MSG_RESULT([$CXXFLAGS]) +dnl +$1 +dnl +AC_MSG_CHECKING([CFLAGS value after]) +AC_MSG_RESULT([$CFLAGS]) +AC_MSG_CHECKING([CXXFLAGS value after]) +AC_MSG_RESULT([$CXXFLAGS]) +dnl +AC_MSG_NOTICE([restoring original confdefs.h]) +rm -f confdefs.h +mv confdefs.h.saved confdefs.h +cat confdefs.h +m4_popdef([AC_DEFINE_UNQUOTED])dnl +m4_popdef([AC_DEFINE])dnl +])dnl +dnl +dnl +dnl #################################################################### +dnl dnl Local Variables: dnl mode: autoconf dnl End: |