Instead of having GCC and CLANG variables, just have
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Wed, 20 Apr 2011 08:37:45 +0000 (08:37 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Wed, 20 Apr 2011 08:37:45 +0000 (08:37 +0000)
ac_supports_gcc_flags and ac_supports_W_linker_passthrough flags, the
first of which, for now, we set for GCC and clang, and the latter of
which we set for GCC, clang, and xlc (probably true for some other
compilers as well).

Rename AC_WIRESHARK_GCC_LDFLAGS_CHECK to AC_WIRESHARK_LDFLAGS_CHECK, as
it's not checking for anything GCC-specific.  (Leave
AC_WIRESHARK_GCC_CFLAGS_CHECK unrenamed for now, as the flags we test
with it are originally GCC flags that clang also supports for GCC
compatibility.)

Fix some string-equality tests to use = rather than ==; the former is
what the test/[ command uses.

Don't turn on "-no-cpp-precomp" for clang - it whines if you do.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@36731 f5534014-38df-0310-8fa8-9805f1628bb7

acinclude.m4
configure.in

index 67eb67d9379ed00dbcb2bc6d4e061bdb5548dd6a..f296be9e470790760f8b5389c3a4c6f93d54f5e4 100644 (file)
@@ -1681,20 +1681,19 @@ AC_DEFUN([AC_WIRESHARK_GEOIP_CHECK],
        fi
 ])
 
-#AC_WIRESHARK_GCC_LDFLAGS_CHECK
+#AC_WIRESHARK_LDFLAGS_CHECK
 #
 # $1 : ldflag(s) to test
 #
-# The macro first determines if the compiler is GCC. Then compile with the
-# defined ldflags. The defined flags are added to LDFLAGS only if the
-# compilation succeeds.
+# The macro first determines if the compiler supports "-Wl,{option}" to
+# pass options through to the linker. Then it attempts to compile with
+# the defined ldflags. The defined flags are added to LDFLAGS only if
+# the compilation succeeds.
 #
-# XXX - clang as well?
-#
-AC_DEFUN([AC_WIRESHARK_GCC_LDFLAGS_CHECK],
+AC_DEFUN([AC_WIRESHARK_LDFLAGS_CHECK],
 [GCC_OPTION="$1"
 AC_MSG_CHECKING(whether we can add $GCC_OPTION to LDFLAGS)
-if test "x$GCC" != "x"; then
+if test "x$ac_supports_W_linker_passthrough" = "xyes"; then
   LDFLAGS_saved="$CFLAGS"
   LDFLAGS="$LDFLAGS $GCC_OPTION"
   AC_LINK_IFELSE([
@@ -1718,14 +1717,17 @@ fi
 #
 # $1 : cflags to test
 #
-# The macro first determines if the compiler is GCC or clang. Then compile with
-# the defined cflags. The defined flags are added to CFLAGS only if the
-# compilation succeeds.
+# The macro first determines if the compiler supports GCC-style flags.
+# Then it attempts to compile with the defined cflags.  The defined
+# flags are added to CFLAGS only if the compilation succeeds.
+#
+# We do this because not all such options are necessarily supported by
+# the version of the particular compiler we're using.
 #
 AC_DEFUN([AC_WIRESHARK_GCC_CFLAGS_CHECK],
 [GCC_OPTION="$1"
 AC_MSG_CHECKING(whether we can add $GCC_OPTION to CFLAGS)
-if test "x$GCC" != "x" -o "x$CLANG" != "x" ; then
+if test "x$ac_supports_gcc_flags" = "xyes" ; then
   CFLAGS_saved="$CFLAGS"
   CFLAGS="$CFLAGS $GCC_OPTION"
   AC_COMPILE_IFELSE([
@@ -1779,7 +1781,7 @@ AC_DEFUN([AC_WIRESHARK_OSX_INTEGRATION_CHECK],
                GTK_LIBS="$GTK_LIBS -ligemacintegration"
        ])
 
-       if test x$have_ige_mac == x
+       if test x$have_ige_mac = x
        then
                #
                # Not found - check for the old integration functions in
@@ -1796,7 +1798,7 @@ AC_DEFUN([AC_WIRESHARK_OSX_INTEGRATION_CHECK],
                ])
        fi
 
-       if test x$have_ige_mac == x
+       if test x$have_ige_mac = x
        then
                #
                # Not found - check for the old integration functions in
index 2c25d1884935ea043de7262a087559cf114773e2..af25cb94a1280e91c3d074e1d0fe45b0090a23b3 100644 (file)
@@ -128,15 +128,37 @@ AC_SUBST(XSLTPROC)
 AC_SUBST(XMLLINT)
 
 #
-# Set CLANG if the compiler is clang, to handle compiler options
-# supported both by GCC and clang.  (This does *not* include
-# -no-cpp-precomp; clang says "clang: warning: argument unused during
-# compilation: '-no-cpp-precomp'" if you use it.)
+# Set "ac_supports_gcc_flags" if the compiler is known to support GCC-style
+# flags such as -pedantic, -W warning flags and -f feature flags.  Currently,
+# we assume GCC and clang do; other compilers should be added here.
 #
-if test "x$GCC" != "xyes" ; then
-       if test "x$CC" = "xclang" ; then
-               CLANG=yes
-       fi
+# This is done to avoid getting tripped up by compilers that support
+# those flags but give them a different meaning.
+#
+if test "x$GCC" = "xyes" -o "x$CC" = "xclang" ; then
+       ac_supports_gcc_flags=yes
+fi
+
+#
+# Set "ac_supports_W_linker_passthrough" if the compiler is known to
+# support "-Wl,{options}" to pass options through to the linker.
+# Currently, we assume GCC, xlc, and clang do; other compilers should
+# be added here.
+#
+if test "x$GCC" = "xyes" -o "x$CC" = "xxlc" -o "x$CC" = "xclang" ; then
+       ac_supports_W_linker_passthrough=yes
+fi
+
+#
+# Set "ac_supports_attribute_unused" if the compiler is known to
+# support "__attribute__(unused)".
+# Currently, we assume GCC and clang do; other compilers should
+# be added here.
+#
+# XXX - do this with a compiler test?
+#
+if test "x$GCC" = "xyes" -o "x$CC" = "xclang" ; then
+       ac_supports_W_linker_passthrough=yes
 fi
 
 if test "x$CC_FOR_BUILD" = x
@@ -345,12 +367,12 @@ AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wformat-security)
 # Use the faster pre gcc 4.5 floating point precision
 AC_WIRESHARK_GCC_CFLAGS_CHECK(-fexcess-precision=fast)
 
-AC_WIRESHARK_GCC_LDFLAGS_CHECK([-Wl,--as-needed])
-###AC_WIRESHARK_GCC_LDFLAGS_CHECK([-Wl,-M])
-###AC_WIRESHARK_GCC_LDFLAGS_CHECK([-Wl,--cref])
-# AC_WIRESHARK_GCC_LDFLAGS_CHECK([-flto])
-# AC_WIRESHARK_GCC_LDFLAGS_CHECK([-fwhopr])
-# AC_WIRESHARK_GCC_LDFLAGS_CHECK([-fwhole-program])
+AC_WIRESHARK_LDFLAGS_CHECK([-Wl,--as-needed])
+###AC_WIRESHARK_LDFLAGS_CHECK([-Wl,-M])
+###AC_WIRESHARK_LDFLAGS_CHECK([-Wl,--cref])
+# AC_WIRESHARK_LDFLAGS_CHECK([-flto])
+# AC_WIRESHARK_LDFLAGS_CHECK([-fwhopr])
+# AC_WIRESHARK_LDFLAGS_CHECK([-fwhole-program])
 
 #
 # If we're running GCC or clang, add '-D_U_="__attribute__((unused))"' to
@@ -361,14 +383,15 @@ AC_WIRESHARK_GCC_LDFLAGS_CHECK([-Wl,--as-needed])
 #
 # XXX - other compilers?
 #
-if test "x$GCC" = "xyes" -o "x$CLANG" = "xyes" ; then
+if test "x$GCC" = "xyes" -o "x$CC" = "xclang" ; then
   CFLAGS="-D_U_=\"__attribute__((unused))\" $CFLAGS"
 else
   CFLAGS="-D_U_=\"\" $CFLAGS"
 fi
 
 #
-# If we're running GCC or clang, enable a barrier "stop on warning".
+# If the compiler supports GCC-style flags, enable a barrier "stop on
+# warning".
 # This barrier is set for a very large part of the code. However, it is
 # typically not set for "generated" code  (flex, ans2wrs, idl2wrs, ...)
 #
@@ -378,7 +401,7 @@ AC_ARG_ENABLE(warnings-as-errors,
   AC_HELP_STRING( [--enable-warnings-as-errors],
                  [Treat warnings as errors (only for GCC or clang). @<:@default=yes@:>@]),
 [
-  if test \( "x$GCC" = "xyes" -o "x$CLANG" = "xyes" \) -a "x$enableval" == "xyes" -a "x$wireshark_extra_gcc_flags" != "xyes"; then
+  if test "x$ac_supports_gcc_flags" = "xyes" -a "x$enableval" = "xyes" -a "x$wireshark_extra_gcc_flags" != "xyes"; then
     with_warnings_as_errors="yes"
     AC_MSG_RESULT(yes)
   else
@@ -386,7 +409,7 @@ AC_ARG_ENABLE(warnings-as-errors,
     AC_MSG_RESULT(no)
   fi
 ],
-  if test \( "x$GCC" = "xyes" -o "x$CLANG" = "xyes" \) -a "x$wireshark_extra_gcc_flags" = "x" -a "x$warnings_as_errors_default" = "xyes"; then
+  if test "x$ac_supports_gcc_flags" = "xyes" -a "x$wireshark_extra_gcc_flags" = "x" -a "x$warnings_as_errors_default" = "xyes"; then
     with_warnings_as_errors="yes"
     AC_MSG_RESULT(yes)
   else
@@ -444,8 +467,19 @@ else
                # apparently-legal code won't compile with its precompiled
                # headers.
                #
-               CFLAGS="-no-cpp-precomp $CFLAGS"
-               AC_MSG_RESULT(Apple GCC - added -no-cpp-precomp)
+               # On the other hand, if it's called "clang", it's not a
+               # GCC derivative, and it whines if you pass it
+               # -no-cpp-precomp.
+               #
+               if test "x$CC" != "xclang" ; then
+                       CFLAGS="-no-cpp-precomp $CFLAGS"
+                       AC_MSG_RESULT(Apple GCC - added -no-cpp-precomp)
+               else
+                       #
+                       # Clang, clang, clang went the trolley....
+                       #
+                       AC_MSG_RESULT(none needed)
+               fi
                ;;
        *)
                AC_MSG_RESULT(none needed)