config/cxxflags.m4
changeset 1350 fb794edbf04b
child 1369 f1cf6b807414
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/config/cxxflags.m4	Thu Apr 14 12:04:29 2005 +0000
     1.3 @@ -0,0 +1,130 @@
     1.4 +dnl LX_C_IFDEF(MACRO-NAME, ACTION-IF-DEF, ACTION-IF-NOT-DEF)
     1.5 +dnl
     1.6 +dnl Check for the definition of macro MACRO-NAME using the current
     1.7 +dnl language's compiler.
     1.8 +dnl
     1.9 +dnl Orignally written by Ludovic Courtès <ludo@chbouib.org>
    1.10 +AC_DEFUN([LX_C_IFDEF],
    1.11 +  [AC_COMPILE_IFELSE([#ifndef $1
    1.12 +                      # error "Macro $1 is undefined!"
    1.13 +                      /* For some compilers (eg. SGI's CC), #error is not
    1.14 +                         enough...  */
    1.15 +                      please, do fail
    1.16 +                      #endif],
    1.17 +                     [$2], [$3])])
    1.18 +
    1.19 +
    1.20 +dnl LX_CXX_COMPILER_VENDOR(VENDOR-NAME, [NICKNAME])
    1.21 +dnl
    1.22 +dnl Set VENDOR-NAME to the lower-case name of the compiler vendor or
    1.23 +dnl `unknown' if the compiler's vendor is unknown. `compaq' means the
    1.24 +dnl CXX compiler as available on Tru64/OSF1/Digital Unix on Alpha
    1.25 +dnl machines. If NICKNAME is provided, set it to the compiler's usual
    1.26 +dnl name (eg. `g++', `cxx', `aCC', etc.).
    1.27 +dnl
    1.28 +dnl Based on work of Ludovic Courtès <ludo@chbouib.org>
    1.29 +AC_DEFUN([LX_CXX_COMPILER_VENDOR],
    1.30 +  [AC_REQUIRE([AC_PROG_CXX])
    1.31 +   AC_REQUIRE([AC_PROG_CXXCPP])
    1.32 +   AC_CACHE_CHECK([the C++ compiler vendor],
    1.33 +    [lx_cv_cxx_compiler_vendor],
    1.34 +
    1.35 +    [AC_LANG_PUSH([C++])
    1.36 +
    1.37 +     dnl Intel's icpc
    1.38 +     LX_C_IFDEF([__INTEL_COMPILER],
    1.39 +       [lx_cv_cxx_compiler_vendor=intel],
    1.40 +       [dnl GNU C++
    1.41 +        LX_C_IFDEF([__GNUG__],
    1.42 +         [lx_cv_cxx_compiler_vendor=gnu],
    1.43 +         [LX_C_IFDEF([__DECCXX],
    1.44 +           [lx_cv_cxx_compiler_vendor=compaq],
    1.45 +           [dnl HP's aCC
    1.46 +            LX_C_IFDEF([__HP_aCC],
    1.47 +             [lx_cv_cxx_compiler_vendor=hp],
    1.48 +             [dnl SGI CC
    1.49 +              LX_C_IFDEF([__sgi],
    1.50 +               [lx_cv_cxx_compiler_vendor=sgi],
    1.51 +               [dnl Note:  We are using the C compiler because VC++ doesn't
    1.52 +                dnl recognize `.cc'(which is used by `configure') as a C++ file
    1.53 +                dnl extension and requires `/TP' to be passed.
    1.54 +                AC_LANG_PUSH([C])
    1.55 +                LX_C_IFDEF([_MSC_VER],
    1.56 +                  [lx_cv_cxx_compiler_vendor=microsoft],
    1.57 +                  [lx_cv_cxx_compiler_vendor=unknown])
    1.58 +                AC_LANG_POP()])])])])])
    1.59 +
    1.60 +     AC_LANG_POP()])
    1.61 +   $1="$lx_cv_cxx_compiler_vendor"
    1.62 +
    1.63 +   dnl The compiler nickname
    1.64 +   ifelse([$2], , [],
    1.65 +     [case "$lx_cv_cxx_compiler_vendor" in
    1.66 +        intel)     $2=icpc;;
    1.67 +        gnu)       $2=g++;;
    1.68 +        compaq)    $2=cxx;;
    1.69 +        hp)        $2=aCC;;
    1.70 +        sgi)       $2=CC;;
    1.71 +        microsoft) $2=cl;;
    1.72 +        *)         $2=unknown;;
    1.73 +      esac])])
    1.74 +
    1.75 +
    1.76 +dnl Set some debugging and error reporting related compiler flags.
    1.77 +dnl uses lx_user_cxxflags
    1.78 +AC_DEFUN([LX_SET_CXXFLAGS],
    1.79 +  [AC_ARG_ENABLE([debug],
    1.80 +AS_HELP_STRING([--enable-debug@<:@=yes|no|full@:>@], [Build with debugging support])
    1.81 +AS_HELP_STRING([--disable-debug], [Build without debugging support @<:@default@:>@]),
    1.82 +     [], [enable_debug=no])
    1.83 +   LX_CXX_COMPILER_VENDOR([lx_cxx_compiler_vendor])
    1.84 +   AC_MSG_CHECKING([whether to build with debugging support])
    1.85 +   if test x"$enable_debug" != x"no"; then
    1.86 +     AC_DEFINE([DEBUG], [1], [Define for debugging support])
    1.87 +
    1.88 +     lx_gnu_cxxflags="-ansi -pedantic -Wall -Wextra"
    1.89 +     lx_intel_cxxflags="-g"
    1.90 +     lx_unknown_cxxflags="-g"
    1.91 +
    1.92 +     if test x"$enable_debug" = x"yes"; then
    1.93 +       lx_gnu_cxxflags="-g $lx_gnu_cxxflags"
    1.94 +       AC_MSG_RESULT([yes])
    1.95 +     else
    1.96 +       lx_gnu_cxxflags="-g3 --no-inline $lx_gnu_cxxflags"
    1.97 +       AC_MSG_RESULT([full])
    1.98 +     fi
    1.99 +
   1.100 +     if test x"$lx_cxx_compiler_vendor" = x"gnu"; then
   1.101 +       CXXFLAGS="$lx_user_cxxflags $lx_gnu_cxxflags"
   1.102 +     elif test x"$lx_cxx_compiler_vendor" = x"intel"; then
   1.103 +       CXXFLAGS="$lx_user_cxxflags $lx_intel_cxxflags"
   1.104 +     else
   1.105 +       CXXFLAGS="$lx_user_cxxflags $lx_unknown_cxxflags"
   1.106 +     fi
   1.107 +   else
   1.108 +     AC_MSG_RESULT([no])
   1.109 +   fi
   1.110 +
   1.111 +   AC_ARG_ENABLE([extra-warnings],
   1.112 +AS_HELP_STRING([--enable-extra-warnings], [Enable extra warning messages])
   1.113 +AS_HELP_STRING([--disable-extra-warnings], [Disable extra warning messages @<:@default@:>@]),
   1.114 +     [],[enable_extra_warnings=no])
   1.115 +   AC_MSG_CHECKING(whether to enable extra warning flags)
   1.116 +   if test x"$enable_extra_warnings" != x"no"; then
   1.117 +     if test x"$lx_cxx_compiler_vendor" = x"gnu"; then
   1.118 +       CXXFLAGS="$CXXFLAGS -ansi -pedantic -Wall -Wextra"
   1.119 +       CXXFLAGS="$CXXFLAGS -Wfloat-equal -Wundef -Wendif-labels -Wshadow"
   1.120 +       CXXFLAGS="$CXXFLAGS -Wpointer-arith -Wcast-qual -Wcast-align"
   1.121 +       CXXFLAGS="$CXXFLAGS -Wwrite-strings -Wconversion -Waggregate-return"
   1.122 +       CXXFLAGS="$CXXFLAGS -Wmissing-noreturn -Wmissing-format-attribute"
   1.123 +       CXXFLAGS="$CXXFLAGS -Wpacked -Wpadded -Wredundant-decls"
   1.124 +       CXXFLAGS="$CXXFLAGS -Wunreachable-code -Winline -Winvalid-pch"
   1.125 +       CXXFLAGS="$CXXFLAGS -Wlong-long -Wdisabled-optimization"
   1.126 +       CXXFLAGS="$CXXFLAGS -Wstack-protector"
   1.127 +     elif test x"$lx_cxx_compiler_vendor" = x"intel"; then
   1.128 +       CXXFLAGS="$CXXFLAGS -w2"
   1.129 +     fi
   1.130 +     AC_MSG_RESULT([yes])
   1.131 +   else
   1.132 +     AC_MSG_RESULT([no])
   1.133 +   fi])