Add a few of our headers to code generated by pycrc (their faq says we can do
[metze/wireshark/wip.git] / acinclude.m4
index 45cbc1dfbbd896480ec2693ecd1845c26feab18f..c73a5e12fc9c050d5f67e493a3510e8d484c77d7 100644 (file)
@@ -104,6 +104,28 @@ AC_DEFUN([AC_WIRESHARK_TIMEZONE_ABBREV],
 ])
 
 
+#
+# AC_WIRESHARK_STRUCT_ST_FLAGS
+#
+dnl AC_STRUCT_ST_BLKSIZE extracted from the file in question,
+dnl "acspecific.m4" in GNU Autoconf 2.12, and turned into
+dnl AC_WIRESHARK_STRUCT_ST_FLAGS, which checks if "struct stat"
+dnl has the 4.4BSD "st_flags" member, and defines HAVE_ST_FLAGS; that's
+dnl what's in this file.
+dnl Done by Guy Harris <guy@alum.mit.edu> on 2012-06-02.
+
+dnl ### Checks for structure members
+
+AC_DEFUN([AC_WIRESHARK_STRUCT_ST_FLAGS],
+[AC_CACHE_CHECK([for st_flags in struct stat], ac_cv_wireshark_struct_st_flags,
+[AC_TRY_COMPILE([#include <sys/stat.h>], [struct stat s; s.st_flags;],
+ac_cv_wireshark_struct_st_flags=yes, ac_cv_wireshark_struct_st_flags=no)])
+if test $ac_cv_wireshark_struct_st_flags = yes; then
+  AC_DEFINE(HAVE_ST_FLAGS, 1, [Define if st_flags field exists in struct stat])
+fi
+])
+
+
 #
 # AC_WIRESHARK_STRUCT_SA_LEN
 #
@@ -742,7 +764,7 @@ AC_DEFUN([AC_WIRESHARK_ZLIB_CHECK],
 # AC_WIRESHARK_LIBLUA_CHECK
 #
 AC_DEFUN([AC_WIRESHARK_LIBLUA_CHECK],[
-
+       lua_ver=5.2
        if test "x$lua_dir" != "x"
        then
                #
@@ -763,11 +785,27 @@ AC_DEFUN([AC_WIRESHARK_LIBLUA_CHECK],[
                LIBS="$LIBS -L$lua_dir/lib -llua -lm"
                wireshark_save_LDFLAGS="$LDFLAGS"
                LDFLAGS="$LDFLAGS -L$lua_dir/lib"
+
+               #
+               # Determine Lua version by reading the LUA_VERSION_NUM definition
+               # from lua.h under the given Lua directory. The value is 501 for
+               # Lua 5.1, 502 for Lua 5.2, etc.
+               #
+               AC_MSG_CHECKING(Lua version)
+               [[ -d "$lua_dir/include" ]] && grep -rq 'LUA_VERSION_NUM.*501' "$lua_dir/include" && lua_ver=5.1
+               AC_MSG_RESULT(Lua ${lua_ver})
        else
                #
                # The user specified no directory in which liblua resides,
-               # so just add "-llua -lliblua" to the used libs.
+               # we try to find out the lua version by looking at pathnames
+               # and we just add "-llua -lliblua" to the used libs.
                #
+               AC_MSG_CHECKING(Lua version)
+               for i in 5.0 5.1 5.2
+               do
+                       [[ -d "/usr/include/lua$i" ]] && lua_ver=$i 
+               done
+               AC_MSG_RESULT(Lua ${lua_ver})
                wireshark_save_CPPFLAGS="$CPPFLAGS"
                wireshark_save_LDFLAGS="$LDFLAGS"
                wireshark_save_LIBS="$LIBS"
@@ -780,24 +818,24 @@ AC_DEFUN([AC_WIRESHARK_LIBLUA_CHECK],[
        #
        AC_CHECK_HEADERS(lua.h lualib.h lauxlib.h,,
        [
-               AC_CHECK_HEADERS(lua5.1/lua.h lua5.1/lualib.h lua5.1/lauxlib.h,
+               AC_CHECK_HEADERS(lua${lua_ver}/lua.h lua${lua_ver}/lualib.h lua${lua_ver}/lauxlib.h,
                [
                        if test "x$lua_dir" != "x"
                        then
-                               LUA_INCLUDES="-I$lua_dir/include/lua5.1"
+                               LUA_INCLUDES="-I$lua_dir/include/lua${lua_ver}"
                        else
                                #
                                # The user didn't specify a directory in which liblua resides;
-                               # we must look for the headers in a "lua5.1" subdirectory of
+                               # we must look for the headers in a "lua${lua_ver}" subdirectory of
                                # "/usr/include", "/usr/local/include", or "$prefix/include"
-                               # as some systems apparently put the headers in a "lua5.1"
+                               # as some systems apparently put the headers in a "lua${lua_ver}"
                                # subdirectory.
                                AC_MSG_CHECKING(for extraneous lua header directories)
                                found_lua_dir=""
-                               lua_dir_list="/usr/include/lua5.1 $prefix/include/lua5.1"
+                               lua_dir_list="/usr/include/lua${lua_ver} $prefix/include/lua${lua_ver}"
                                if test "x$ac_cv_enable_usr_local" = "xyes"
                                then
-                                       lua_dir_list="$lua_dir_list /usr/local/include/lua5.1"
+                                       lua_dir_list="$lua_dir_list /usr/local/include/lua${lua_ver}"
                                fi
                                for lua_dir_ent in $lua_dir_list
                                do
@@ -826,8 +864,8 @@ AC_DEFUN([AC_WIRESHARK_LIBLUA_CHECK],[
                                        LUA_LIBS=""
                                        if test "x$want_lua" = "xyes"
                                        then
-                                               # we found lua5.1/lua.h, but we don't know which include dir contains it
-                                               AC_MSG_ERROR(Header file lua.h was found as lua5.1/lua.h but we can't locate the include directory. Please set the DIR for the --with-lua configure parameter.)
+                                               # we found lua${lua_ver}/lua.h, but we don't know which include dir contains it
+                                               AC_MSG_ERROR(Header file lua.h was found as lua${lua_ver}/lua.h but we can't locate the include directory. Please set the DIR for the --with-lua configure parameter.)
                                        else
                                                #
                                                # We couldn't find the header file; don't use the
@@ -835,7 +873,7 @@ AC_DEFUN([AC_WIRESHARK_LIBLUA_CHECK],[
                                                #
                                                want_lua=no
                                        fi
-                               fi
+                               fi
                        fi
                ],
                [
@@ -890,10 +928,10 @@ AC_DEFUN([AC_WIRESHARK_LIBLUA_CHECK],[
                # against libm.
                LIBS="$LIBS $LUA_LIBS -lm"
 
-               AC_CHECK_LIB(lua, luaL_register,
+               AC_CHECK_LIB(lua, luaL_openlibs,
                [
                        #
-                       #  Lua 5.1 found
+                       #  Lua found
                        #
                        if test "x$lua_dir" != "x"
                        then
@@ -907,7 +945,7 @@ AC_DEFUN([AC_WIRESHARK_LIBLUA_CHECK],[
                                LUA_LIBS="-llua -lm"
                                LUA_INCLUDES=""
                        fi
-                       AC_DEFINE(HAVE_LUA_5_1, 1, [Define to use Lua 5.1])
+                       AC_DEFINE(HAVE_LUA, 1, [Define to use Lua ${lua_ver}])
                        want_lua=yes
 
                ],[
@@ -915,15 +953,15 @@ AC_DEFUN([AC_WIRESHARK_LIBLUA_CHECK],[
                        # We could not find the libs, maybe we have version number in the lib name
                        #
 
-                       LIBS="$wireshark_save_LIBS -llua5.1 -lm"
+                       LIBS="$wireshark_save_LIBS -llua${lua_ver} -lm"
 
-                       AC_CHECK_LIB(lua5.1, luaL_register,
+                       AC_CHECK_LIB(lua${lua_ver}, luaL_openlibs,
                        [
                            #
-                           #  Lua 5.1 found
+                           #  Lua found
                            #
-                           LUA_LIBS=" -llua5.1 -lm"
-                           AC_DEFINE(HAVE_LUA_5_1, 1, [Define to use Lua 5.1])
+                           LUA_LIBS=" -llua${lua_ver} -lm"
+                           AC_DEFINE(HAVE_LUA, 1, [Define to use Lua ${lua_ver}])
                            want_lua=yes
                        ],[
                                #
@@ -1547,6 +1585,13 @@ fi
 #
 # $1 : cflags to test
 # $2 : if supplied, C for C-only flags, CXX for C++-only flags
+# $3 : if supplied, a program to try to compile with the flag
+#      and, if the compile fails when -Werror is turned on,
+#      we don't add the flag - used for warning flags that
+#      issue incorrect or non-useful warnings with some
+#      compiler versions
+# $4 : must be supplied if $3 is supplied - a message describing
+#      for what the test program is testing
 #
 # The macro first determines if the compiler supports GCC-style flags.
 # Then it attempts to compile with the defined cflags.  The defined
@@ -1599,16 +1644,60 @@ if test "x$ac_supports_gcc_flags" = "xyes" ; then
                     [
                       AC_MSG_RESULT(yes)
                       #
-                      # Remove -Werror=unknown-warning-option, if we
-                      # added it, by setting CFLAGS to the saved value
-                      # plus just the new option.
-                      #
-                      CFLAGS="$CFLAGS_saved $GCC_OPTION"
-                      if test "$2" != C ; then
+                     # OK, do we have a test program?  If so, check
+                     # whether it fails with this option and -Werror,
+                     # and, if so, don't include it.
+                     #
+                     # We test arg 4 here because arg 3 is a program which
+                     # could contain quotes (breaking the comparison).
+                     #
+                     if test "x$4" != "x" ; then
+                        CFLAGS="$CFLAGS -Werror"
+                        AC_MSG_CHECKING(whether $GCC_OPTION $4)
+                        AC_COMPILE_IFELSE([
+                          AC_LANG_SOURCE($3)],
+                          [
+                            AC_MSG_RESULT(no)
+                            #
+                            # Remove -Werror=unknown-warning-option, if we
+                            # added it, and -Werror by setting CFLAGS to
+                            # the saved value plus just the new option.
+                            #
+                            CFLAGS="$CFLAGS_saved $GCC_OPTION"
+                            #
+                            # Add it to the flags we use when building
+                            # build tools.
+                            #
+                            CFLAGS_FOR_BUILD="$CFLAGS_FOR_BUILD $GCC_OPTION"
+                            if test "$2" != C ; then
+                              #
+                              # Add it to the C++ flags as well.
+                              #
+                              CXXFLAGS="$CXXFLAGS $GCC_OPTION"
+                            fi
+                          ],
+                          [
+                            AC_MSG_RESULT(yes)
+                            CFLAGS="$CFLAGS_saved"
+                          ])
+                      else
+                        #
+                        # Remove -Werror=unknown-warning-option, if we
+                        # added it, and -Werror by setting CFLAGS to
+                        # the saved value plus just the new option.
                         #
-                        # Add it to the C++ flags as well.
+                        CFLAGS="$CFLAGS_saved $GCC_OPTION"
                         #
-                        CXXFLAGS="$CXXFLAGS $GCC_OPTION"
+                        # Add it to the flags we use when building
+                        # build tools.
+                        #
+                        CFLAGS_FOR_BUILD="$CFLAGS_FOR_BUILD $GCC_OPTION"
+                        if test "$2" != C ; then
+                          #
+                          # Add it to the C++ flags as well.
+                          #
+                          CXXFLAGS="$CXXFLAGS $GCC_OPTION"
+                        fi
                       fi
                     ],
                     [
@@ -1631,6 +1720,40 @@ if test "x$ac_supports_gcc_flags" = "xyes" ; then
                     ]])],
                     [
                       AC_MSG_RESULT(yes)
+                      #
+                     # OK, do we have a test program?  If so, check
+                     # whether it fails with this option and -Werror,
+                     # and, if so, don't include it.
+                     #
+                     # We test arg 4 here because arg 3 is a program which
+                     # could contain quotes (breaking the comparison).
+                     #
+                     if test "x$4" != "x" ; then
+                        CXXFLAGS="$CXXFLAGS -Werror"
+                        AC_MSG_CHECKING(whether $GCC_OPTION $4)
+                        AC_COMPILE_IFELSE([
+                          AC_LANG_SOURCE($3)],
+                          [
+                            AC_MSG_RESULT(no)
+                            #
+                            # Remove -Werror=unknown-warning-option, if we
+                            # added it, and -Werror by setting CXXFLAGS to
+                            # the saved value plus just the new option.
+                            #
+                            CXXFLAGS="$CXXFLAGS_saved $GCC_OPTION"
+                          ],
+                          [
+                            AC_MSG_RESULT(yes)
+                            CXXFLAGS="$CXXFLAGS_saved"
+                          ])
+                      else
+                        #
+                        # Remove -Werror=unknown-warning-option, if we
+                        # added it, and -Werror by setting CXXFLAGS to
+                        # the saved value plus just the new option.
+                        #
+                        CXXFLAGS="$CXXFLAGS_saved $GCC_OPTION"
+                      fi
                     ],
                     [
                       AC_MSG_RESULT(no)
@@ -1643,20 +1766,72 @@ else
 fi
 ])
 
+# AC_WIRESHARK_GCC_FORTIFY_SOURCE_CHECK
+#
+# Checks if '-D_FORTIFY_SOURCE=...' is OK to use in CPPFLAGS.
+#  Use '-D_FORTIFY_SOURCE=...' in CPPFLAGS only if the GCC 'optimization level' is > 0.
+#  The use of '-D_FORTIFY_SOURCE=...' will cause a warning with at least some versions
+#    of glibc if the  GCC "optimization level" is 0 (default or -O or -O0)
+#    when using GCC to compile a source file which references the macro definition.
+#
+# See: http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html
+# See: http://sourceware.org/bugzilla/show_bug.cgi?id=13979
+#
+#   We'll use '-D_FORTIFY_SOURCE=2' only if there's no warning; Among other things this means
+#    that the  use of '-D_FORTIFY_SOURCE=2' with '-Werror' and '-O0' won't cause
+#    the compiler to stop on error.
+#   Assumption: CFLAGS already contains whatever optimization option including none) is
+#    to be used.
+#
+
+AC_DEFUN([AC_WIRESHARK_GCC_FORTIFY_SOURCE_CHECK],
+[
+if test "x$GCC" = "xyes" -o "x$CC" = "xclang" ; then
+  AC_MSG_CHECKING([whether -D_FORTIFY_SOURCE=... can be used (without generating a warning)])
+  CFLAGS_saved="$CFLAGS"
+  CPPFLAGS_saved="$CPPFLAGS"
+  CFLAGS="$CFLAGS -Werror"
+  CPPFLAGS="$CPPFLAGS -D_FORTIFY_SOURCE=2"
+  AC_COMPILE_IFELSE([
+    AC_LANG_SOURCE([[
+                  #include <stdio.h>
+                      int foo;
+                  ]])],
+                  [
+                    AC_MSG_RESULT(yes)
+                    #
+                    # (CPPFLAGS contains _D_FORTIFY_SOURCE=2)
+                    #
+                  ],
+                  [
+                    AC_MSG_RESULT(no)
+                    # Remove -D_FORTIFY_SOURCE=2
+                    CPPFLAGS="$CPPFLAGS_saved"
+                  ])
+  CFLAGS="$CFLAGS_saved"
+fi
+])
+
 #
 # AC_WIRESHARK_OSX_INTEGRATION_CHECK
 #
 # Checks for the presence of OS X integration functions in the GTK+ framework
 # or as a separate library.
 #
-# http://sourceforge.net/apps/trac/gtk-osx/wiki/Integrate
+# GTK+ for MAC OS X now lives on www.gtk.org at:
+#
+#   http://www.gtk.org/download/macos.php
+#
+# Details on building with GTK-OSX are available at:
+#
+#   http://live.gnome.org/GTK%2B/OSX/Building
+#
+# The GTK-OSX library has been renamed to gtkmacintegration.
+# It was previously named igemacintegration.
 #
 # http://live.gnome.org/GTK%2B/OSX/Integration
 #    for the old Carbon-based integration functions
 #
-# http://gtk-osx.sourceforge.net/ige-mac-integration/
-#    for the new Cocoa-based integration functions
-#
 AC_DEFUN([AC_WIRESHARK_OSX_INTEGRATION_CHECK],
 [
        ac_save_CFLAGS="$CFLAGS"
@@ -1665,17 +1840,17 @@ AC_DEFUN([AC_WIRESHARK_OSX_INTEGRATION_CHECK],
        LIBS="$GTK_LIBS $LIBS"
 
        #
-       # Check for the new integration functions in a -ligemacintegration
+       # Check for the new integration functions in a -lgtkmacintegration
        # library.
        #
-       AC_CHECK_LIB(igemacintegration, gtk_osxapplication_set_menu_bar,
+       AC_CHECK_LIB(gtkmacintegration, gtkosx_application_set_menu_bar,
        [
                AC_DEFINE(HAVE_GTKOSXAPPLICATION, 1,
-                       [Define to 1 if -ligemacintegration includes the GtkOSXApplication Integration functions.])
+                       [Define to 1 if -lgtkmacintegration includes the GtkOSXApplication Integration functions.])
                have_ige_mac=yes
                # We don't want gtk stuff in LIBS (which is reset below) so
                # manually set GTK_LIBS (which is more appropriate)
-               GTK_LIBS="$GTK_LIBS -ligemacintegration"
+               GTK_LIBS="$GTK_LIBS -lgtkmacintegration"
        ])
 
        if test x$have_ige_mac = x
@@ -1684,7 +1859,7 @@ AC_DEFUN([AC_WIRESHARK_OSX_INTEGRATION_CHECK],
                # Not found - check for the old integration functions in
                # the Gtk framework.
                #
-               AC_CHECK_LIB(Gtk, ige_mac_menu_set_menu_bar,
+               AC_CHECK_LIB(Gtk, gtk_mac_menu_set_menu_bar,
                [
                        AC_DEFINE(HAVE_IGE_MAC_INTEGRATION, 1,
                                [Define to 1 if the the Gtk+ framework or a separate library includes the Imendio IGE Mac OS X Integration functions.])
@@ -1699,16 +1874,16 @@ AC_DEFUN([AC_WIRESHARK_OSX_INTEGRATION_CHECK],
        then
                #
                # Not found - check for the old integration functions in
-               # a -ligemacintegration library.
+               # a -lgtkmacintegration library.
                #
-               AC_CHECK_LIB(igemacintegration, ige_mac_menu_set_menu_bar,
+               AC_CHECK_LIB(gtkmacintegration, gtk_mac_menu_set_menu_bar,
                [
                        AC_DEFINE(HAVE_IGE_MAC_INTEGRATION, 1,
                                [Define to 1 if the the Gtk+ framework or a separate library includes the Imendio IGE Mac OS X Integration functions.])
                        have_ige_mac=yes
                        # We don't want gtk stuff in LIBS (which is reset below) so
                        # manually set GTK_LIBS (which is more appropriate)
-                       GTK_LIBS="$GTK_LIBS -ligemacintegration"
+                       GTK_LIBS="$GTK_LIBS -lgtkmacintegration"
                ])
        fi
        CFLAGS="$ac_save_CFLAGS"