1# Macros to check compiler options 2# 3 4# Helper function that adds flags (words) to variable listing them. 5# Makes sure there is no extra spaces in any situation 6# 7# $1 - Name of the target variable 8# $2 - Flags to add 9# 10AC_DEFUN([FC_ADD_WORDS_TO_VAR], 11[ 12old_value="`eval echo '$'$1`" 13if test "x$old_value" = "x" ; then 14 $1="$2" 15elif test "x$2" != "x" ; then 16 $1="$old_value $2" 17fi 18]) 19 20# Check if compiler supports given commandline parameter in language specific 21# variable. If it does, it will be concatenated to variable. If several 22# parameters are given, they are tested, and added to target variable, 23# one at a time. 24# 25# $1 - Language 26# $2 - Language specific variable 27# $3 - Parameters to test 28# $4 - Additional parameters 29# $5 - Variable where to add 30# 31 32AC_DEFUN([FC_COMPILER_FLAGS], 33[ 34AC_LANG_PUSH([$1]) 35 36flags_save="`eval echo '$'$2`" 37accepted_flags="" 38existing_flags="`eval echo '$'$5`" 39 40for flag in $3 41do 42 dnl We need -Werror to test any flags (it can't be tested itself) 43 dnl Without it, illegal flag will not give an error for us to detect 44 $2="-Werror $flags_save $existing_flags $accepted_flags $flag $4" 45 AC_COMPILE_IFELSE([AC_LANG_SOURCE([int a;])], 46 [FC_ADD_WORDS_TO_VAR([accepted_flags], [$flag])]) 47done 48FC_ADD_WORDS_TO_VAR([$5], [$accepted_flags]) 49 50$2="$flags_save" 51 52AC_LANG_POP([$1]) 53]) 54 55# Commandline flag tests for C and C++ 56# 57# 58# $1 - Parameters to test 59# $2 - Additional parameters 60# $3 - Variable where to add 61 62AC_DEFUN([FC_C_FLAGS], 63[ 64FC_COMPILER_FLAGS([C], [CFLAGS], [$1], [$2], [$3]) 65]) 66 67 68AC_DEFUN([FC_CXX_FLAGS], 69[ 70FC_COMPILER_FLAGS([C++], [CXXFLAGS], [$1], [$2], [$3]) 71]) 72 73# Commandline flag tests for linker 74# 75# 76# $1 - Parameters to test 77# $2 - Additional parameters 78# $3 - Variable where to add 79AC_DEFUN([FC_LD_FLAGS], 80[ 81flags_save=$LDFLAGS 82accepted_flags="" 83existing_flags="`eval echo '$'$3`" 84 85for flag in $1 86do 87 LDFLAGS="$flags_save $existing_flags $accepted_flags $flag $2" 88 AC_LINK_IFELSE([AC_LANG_PROGRAM([], [int a;])], 89 [FC_ADD_WORDS_TO_VAR([accepted_flags], [$flag])]) 90done 91FC_ADD_WORDS_TO_VAR([$3], [$accepted_flags]) 92 93LDFLAGS="$flags_save" 94]) 95 96# Does current C++ compiler work. 97# Sets variable cxx_works accordingly. 98AC_DEFUN([FC_WORKING_CXX], 99[ 100AC_MSG_CHECKING([whether C++ compiler works]) 101 102AC_LANG_PUSH([C++]) 103 104AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])], 105[ 106AC_MSG_RESULT([yes]) 107cxx_works=yes], 108[ 109AC_MSG_RESULT([not]) 110cxx_works=no]) 111 112AC_LANG_POP([C++]) 113]) 114