Use wmem_memdup() instead of wmem_alloc() followed by memcpy().
[metze/wireshark/wip.git] / macosx-setup.sh
index cb625c78d3594e8233ef0bc06347923cf39383a5..90f0d7c42672a437f5081692365d3c542eae7a85 100755 (executable)
 #
 CMAKE=1
 #
+# To install autotools
+#
+AUTOTOOLS=1
+#
 # To build all libraries as 32-bit libraries uncomment the following three lines.
 #
 # export CFLAGS="$CFLAGS -arch i386"
@@ -53,7 +57,7 @@ XZ_VERSION=5.0.4
 #
 # In case we want to build with cmake.
 #
-CMAKE_VERSION=2.8.12.2
+CMAKE_VERSION=${CMAKE_VERSION-2.8.12.2}
 
 #
 # The following libraries and tools are required even to build only TShark.
@@ -65,16 +69,20 @@ PKG_CONFIG_VERSION=0.28
 #
 # One or more of the following libraries are required to build Wireshark.
 #
-# If you don't want to build with Qt, comment out the QT_VERSION= line.
+# To override the versions of Qt and GTK call the script with some of the
+# variables set to the new values. Setting a variable to empty will disable
+# building the toolkit and will un-install any version previously installed
+# by the script, e.g. "GTK_VERSION=3.5.2 QT_VERSION= ./macos-setup.sh"
+# will build and install with GTK+ 3.5.2 and will not install Qt (and,
+# if the script installed Qt earlier, will un-install that version of Qt).
 #
-# If you want to build with GTK+ 2, comment out the GTK_VERSION=3.* line
-# and un-comment the GTK_VERSION=2.* line.
+# Note that Qt 5, prior to 5.5.0, mishandles context menus in ways that,
+# for example, cause them not to work reliably in the packet detail or
+# packet data pane; see, for example, Qt bugs QTBUG-31937, QTBUG-41017,
+# and QTBUG-43464, all of which seem to be the same bug.
 #
-# If you don't want to build with GTK+ at all, comment out both lines.
-# 
-QT_VERSION=5.2.1
-GTK_VERSION=2.24.17
-#GTK_VERSION=3.5.2
+QT_VERSION=${QT_VERSION-5.5.0}
+GTK_VERSION=${GTK_VERSION-2.24.17}
 if [ "$GTK_VERSION" ]; then
     #
     # We'll be building GTK+, so we need some additional libraries.
@@ -85,11 +93,18 @@ if [ "$GTK_VERSION" ]; then
 
     ATK_VERSION=2.8.0
     PANGO_VERSION=1.30.1
-    PNG_VERSION=1.5.17
+    PNG_VERSION=1.6.17
     PIXMAN_VERSION=0.26.0
     CAIRO_VERSION=1.12.2
     GDK_PIXBUF_VERSION=2.28.0
 fi
+if [ "$QT_VERSION" ]; then
+    QT_MAJOR_VERSION="`expr $QT_VERSION : '\([0-9][0-9]*\).*'`"
+    QT_MINOR_VERSION="`expr $QT_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
+    QT_DOTDOT_VERSION="`expr $QT_VERSION : '[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
+    QT_MAJOR_MINOR_VERSION=$QT_MAJOR_VERSION.$QT_MINOR_VERSION
+    QT_MAJOR_MINOR_DOTDOT_VERSION=$QT_MAJOR_VERSION.$QT_MINOR_VERSION.$QT_DOTDOT_VERSION
+fi
 
 # In case we want to build GTK *and* we don't have Apple's X11 SDK installed
 # we may want to install XQuartz. The version will only be used in the printing
@@ -108,14 +123,14 @@ LIBSMI_VERSION=0.4.8
 LIBGPG_ERROR_VERSION=1.10
 #
 # libgcrypt is required for GnuTLS.
-# XXX - the link for "Libgcrypt source code" at
-# http://www.gnupg.org/download/#libgcrypt is for 1.5.0, and is a bzip2
-# file, but http://directory.fsf.org/project/libgcrypt/ lists only
-# 1.4.6.
 #
 LIBGCRYPT_VERSION=1.5.0
 GNUTLS_VERSION=2.12.19
-LUA_VERSION=5.3.0
+# Use 5.2.3, not 5.3, for now; lua_bitop.c hasn't been ported to 5.3
+# yet, and we need to check for compatibility issues (we'd want Lua
+# scripts to work with 5.1, 5.2, and 5.3, as long as they only use Lua
+# features present in all three versions)
+LUA_VERSION=5.2.3
 PORTAUDIO_VERSION=pa_stable_v19_20111121
 #
 # XXX - they appear to have an unversioned gzipped tarball for the
@@ -132,7 +147,7 @@ DARWIN_MAJOR_VERSION=`uname -r | sed 's/\([0-9]*\).*/\1/'`
 # GNU autotools; they're provided with releases up to Snow Leopard, but
 # not in later releases.
 #
-if [[ $DARWIN_MAJOR_VERSION -gt 10 ]]; then
+if [ -n "$AUTOTOOLS" -a $DARWIN_MAJOR_VERSION -gt 10 ]; then
     AUTOCONF_VERSION=2.69
     AUTOMAKE_VERSION=1.13.3
     LIBTOOL_VERSION=2.4.2
@@ -233,7 +248,7 @@ uninstall_automake() {
         #
         # libtool depends on this(?), so uninstall it.
         #
-        uninstall_automake "$@"
+        uninstall_libtool "$@"
 
         echo "Uninstalling GNU automake:"
         cd automake-$installed_automake_version
@@ -296,15 +311,72 @@ uninstall_libtool() {
 install_cmake() {
     if [ -n "$CMAKE" -a ! -f cmake-$CMAKE_VERSION-done ]; then
         echo "Downloading and installing CMake:"
-        cmake_dir=`expr $CMAKE_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
+        CMAKE_MAJOR_VERSION="`expr $CMAKE_VERSION : '\([0-9][0-9]*\).*'`"
+        CMAKE_MINOR_VERSION="`expr $CMAKE_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
+        CMAKE_DOTDOT_VERSION="`expr $CMAKE_VERSION : '[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
+        CMAKE_MAJOR_MINOR_VERSION=$CMAKE_MAJOR_VERSION.$CMAKE_MINOR_VERSION
+
         #
         # NOTE: the "64" in "Darwin64" doesn't mean "64-bit-only"; the
         # package in question supports both 32-bit and 64-bit x86.
         #
-        [ -f cmake-$CMAKE_VERSION-Darwin64-universal.dmg ] || curl -O http://www.cmake.org/files/v$cmake_dir/cmake-$CMAKE_VERSION-Darwin64-universal.dmg || exit 1
-        sudo hdiutil attach http://www.cmake.org/files/v2.8/cmake-$CMAKE_VERSION-Darwin64-universal.dmg || exit 1
-        sudo installer -target / -pkg /Volumes/cmake-$CMAKE_VERSION-Darwin64-universal/cmake-$CMAKE_VERSION-Darwin64-universal.pkg || exit 1
-        sudo hdiutil detach /Volumes/cmake-$CMAKE_VERSION-Darwin64-universal
+        case "$CMAKE_MAJOR_VERSION" in
+
+        0|1)
+            echo "CMake $CMAKE_VERSION" is too old 1>&2
+            ;;
+
+        2)
+            #
+            # Download the DMG, run the installer.
+            #
+            [ -f cmake-$CMAKE_VERSION-Darwin64-universal.dmg ] || curl -O https://cmake.org/files/v$CMAKE_MAJOR_MINOR_VERSION/cmake-$CMAKE_VERSION-Darwin64-universal.dmg || exit 1
+            sudo hdiutil attach cmake-$CMAKE_VERSION-Darwin64-universal.dmg || exit 1
+            sudo installer -target / -pkg /Volumes/cmake-$CMAKE_VERSION-Darwin64-universal/cmake-$CMAKE_VERSION-Darwin64-universal.pkg || exit 1
+            sudo hdiutil detach /Volumes/cmake-$CMAKE_VERSION-Darwin64-universal
+            ;;
+
+        3)
+            #
+            # Download the DMG and do a drag install, where "drag" means
+            # "mv".
+            #
+            # 3.0.* and 3.1.0 have a Darwin64-universal DMG.
+            # 3.1.1 and later have a Darwin-x86_64 DMG.
+            # Probably not many people are still developing on 32-bit
+            # Macs, so we don't worry about them.
+            #
+            if [ "$CMAKE_MINOR_VERSION" = 0 -o \
+                 "$CMAKE_VERSION" = 3.1.0 ]; then
+                type="Darwin64-universal"
+            else
+                type="Darwin-x86_64"
+            fi
+            [ -f cmake-$CMAKE_VERSION-$type.dmg ] || curl -O https://cmake.org/files/v$CMAKE_MAJOR_MINOR_VERSION/cmake-$CMAKE_VERSION-$type.dmg || exit 1
+            sudo hdiutil attach cmake-$CMAKE_VERSION-$type.dmg || exit 1
+            sudo ditto /Volumes/cmake-$CMAKE_VERSION-$type/CMake.app /Applications/CMake.app || exit 1
+
+            #
+            # Plant the appropriate symbolic links in /usr/local/bin.
+            # It's a drag-install, so there's no installer to make them,
+            # and the CMake code to put them in place is lame, as
+            #
+            #    1) it defaults to /usr/bin, not /usr/local/bin;
+            #    2) it doesn't request the necessary root privileges;
+            #    3) it can't be run from the command line;
+            #
+            # so we do it ourselves.
+            #
+            for i in ccmake cmake cmake-gui cmakexbuild cpack ctest
+            do
+                sudo ln -s /Applications/CMake.app/Contents/bin/$i /usr/local/bin/$i
+            done
+            sudo hdiutil detach /Volumes/cmake-$CMAKE_VERSION-$type
+            ;;
+
+        *)
+            ;;
+        esac
         touch cmake-$CMAKE_VERSION-done
     fi
 }
@@ -312,21 +384,40 @@ install_cmake() {
 uninstall_cmake() {
     if [ ! -z "$installed_cmake_version" ]; then
         echo "Uninstalling CMake:"
-        sudo rm -rf "/Applications/CMake "`echo "$installed_cmake_version" | sed 's/\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*/\1.\2-\3/'`.app
-        sudo rm /usr/bin/ccmake
-        sudo rm /usr/bin/cmake
-        sudo rm /usr/bin/cmake-gui
-        sudo rm /usr/bin/cmakexbuild
-        sudo rm /usr/bin/cpack
-        sudo rm /usr/bin/ctest
-        sudo pkgutil --forget com.Kitware.CMake
-        rm cmake-$installed_cmake_version-done
+        installed_cmake_major_version="`expr $installed_cmake_version : '\([0-9][0-9]*\).*'`"
+        case "$installed_cmake_major_version" in
+
+        0|1)
+            echo "CMake $installed_cmake_version" is too old 1>&2
+            ;;
+
+        2)
+            sudo rm -rf "/Applications/CMake "`echo "$installed_cmake_version" | sed 's/\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*/\1.\2-\3/'`.app
+            for i in ccmake cmake cmake-gui cmakexbuild cpack ctest
+            do
+                sudo rm -f /usr/bin/$i /usr/local/bin/$i
+            done
+            sudo pkgutil --forget com.Kitware.CMake
+            rm cmake-$installed_cmake_version-done
+            ;;
+
+        3)
+            sudo rm -rf /Applications/CMake.app
+            for i in ccmake cmake cmake-gui cmakexbuild cpack ctest
+            do
+                sudo rm -f /usr/local/bin/$i
+            done
+            rm cmake-$installed_cmake_version-done
+            ;;
+        esac
 
         if [ "$#" -eq 1 -a "$1" = "-r" ] ; then
             #
-            # Get rid of the previously downloaded and unpacked version.
+            # Get rid of the previously downloaded and unpacked version,
+            # whatever it might happen to be called.
             #
             rm -f cmake-$installed_cmake_version-Darwin64-universal.dmg
+            rm -f cmake-$installed_cmake_version-Darwin-x86_64.dmg
         fi
 
         installed_cmake_version=""
@@ -514,43 +605,53 @@ uninstall_glib() {
 install_qt() {
     if [ "$QT_VERSION" -a ! -f qt-$QT_VERSION-done ]; then
         echo "Downloading, building, and installing Qt:"
-        QT_MAJOR_VERSION="`expr $QT_VERSION : '\([0-9][0-9]*\).*'`"
-        QT_MINOR_VERSION="`expr $QT_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
-        QT_DOTDOT_VERSION="`expr $QT_VERSION : '[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
-        QT_MAJOR_MINOR_VERSION=$QT_MAJOR_VERSION.$QT_MINOR_VERSION
         #
         # What you get for this URL might just be a 302 Found reply, so use
         # -L so we get redirected.
         #
-        curl -L -O http://download.qt-project.org/official_releases/qt/$QT_MAJOR_MINOR_VERSION/$QT_VERSION/single/qt-everywhere-opensource-src-$QT_VERSION.tar.gz
-        #
-        # Qt 5.1.x sets QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.6
-        # in qtbase/mkspecs/$TARGET_PLATFORM/qmake.conf
-        # We may need to adjust this manually in the future.
-        #
-        # The -no-c++11 flag is needed to work around
-        # https://bugreports.qt-project.org/browse/QTBUG-30487
-        #
-        tar xf qt-everywhere-opensource-src-$QT_VERSION.tar.gz
-        cd qt-everywhere-opensource-src-$QT_VERSION
-        #
-        # We don't build Qt in its Full Shining Glory, as we don't need all
-        # of its components, and it takes *forever* to build in that form.
+        if [ "$QT_MAJOR_VERSION" -ge 5 ]
+        then
+            QT_VOLUME=qt-opensource-mac-x64-clang-$QT_VERSION
+        else
+            QT_VOLUME=qt-opensource-mac-$QT_VERSION
+        fi
+        [ -f $QT_VOLUME.dmg ] || curl -L -O http://download.qt.io/archive/qt/$QT_MAJOR_MINOR_VERSION/$QT_MAJOR_MINOR_DOTDOT_VERSION/$QT_VOLUME.dmg || exit 1
+        sudo hdiutil attach $QT_VOLUME.dmg || exit 1
+
+        if [ "$QT_MAJOR_VERSION" -ge 5 ]
+        then
+            #
+            # Run the installer executable directly, so that we wait for
+            # it to finish.  Then unmount the volume.
+            #
+            /Volumes/$QT_VOLUME/$QT_VOLUME.app/Contents/MacOS/$QT_VOLUME
+            sudo hdiutil detach /Volumes/$QT_VOLUME
+        else
+            #
+            # Open the installer package; use -W, so that we wait for
+            # the installer to finish.  Then unmount the volume.
+            #
+            open -W "/Volumes/Qt $QT_MAJOR_MINOR_DOTDOT_VERSION/Qt.mpkg"
+            sudo hdiutil detach "/Volumes/Qt $QT_MAJOR_MINOR_DOTDOT_VERSION"
+        fi
+
         #
-        # Qt 5.2.0 beta1 fails to build on OS X without -no-xcb due to bug
-        # QTBUG-34382.
+        # Versions 5.3.x through 5.5.0, at least, have bogus .pc files.
+        # See bugs QTBUG-35256 and QTBUG-47162.
         #
-        # Qt 5.x fails to build on OS X with -no-opengl due to bug
-        # QTBUG-31151.
+        # Fix the files.
         #
-        ./configure -v $qt_sdk_arg -platform $TARGET_PLATFORM \
-            -opensource -confirm-license -no-c++11 -no-dbus \
-            -no-sql-sqlite -no-xcb -nomake examples \
-            -skip qtdoc -skip qtquickcontrols -skip qtwebkit \
-            -skip qtwebkit-examples -skip qtxmlpatterns
-        make || exit 1
-        $DO_MAKE_INSTALL || exit 1
-        cd ..
+        for i in $HOME/Qt$QT_VERSION/$QT_MAJOR_MINOR_VERSION/clang_64/lib/pkgconfig/*.pc
+        do
+            ed - $i <<EOF
+H
+g/Cflags: /s;;Cflags: -F\${libdir} ;
+g/Cflags: /s;-I\${includedir}/Qt\([a-zA-Z0-9_]*\);-I\${libdir}/Qt\1.framework/Versions/5/Headers;
+g/Libs: /s;';;g
+w
+q
+EOF
+        done
         touch qt-$QT_VERSION-done
     fi
 }
@@ -558,22 +659,14 @@ install_qt() {
 uninstall_qt() {
     if [ ! -z "$installed_qt_version" ] ; then
         echo "Uninstalling Qt:"
-        cd qt-everywhere-opensource-src-$installed_qt_version
-        $DO_MAKE_UNINSTALL || exit 1
-        #
-        # XXX - "make distclean" doesn't work.  qmake sure does a
-        # good job of constructing Makefiles that work correctly....
-        #
-        #make distclean || exit 1
-        cd ..
+        rm -rf $HOME/Qt$installed_qt_version
         rm qt-$installed_qt_version-done
 
         if [ "$#" -eq 1 -a "$1" = "-r" ] ; then
             #
-            # Get rid of the previously downloaded and unpacked version.
+            # Get rid of the previously downloaded version.
             #
-            rm -rf qt-everywhere-opensource-src-$installed_qt_version
-            rm -rf qt-everywhere-opensource-src-$installed_qt_version.tar.gz
+            rm -rf qt-opensource-mac-x64-clang-$installed_qt_version.dmg
         fi
 
         installed_qt_version=""
@@ -1159,7 +1252,7 @@ install_lua() {
         [ -f lua-$LUA_VERSION.tar.gz ] || curl -L -O http://www.lua.org/ftp/lua-$LUA_VERSION.tar.gz || exit 1
         gzcat lua-$LUA_VERSION.tar.gz | tar xf - || exit 1
         cd lua-$LUA_VERSION
-        make $MAKE_BUILD_OPTS macosx || exit 1
+        make MYCFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" MYLDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" $MAKE_BUILD_OPTS macosx || exit 1
         $DO_MAKE_INSTALL || exit 1
         cd ..
         touch lua-$LUA_VERSION-done
@@ -1226,7 +1319,10 @@ install_portaudio() {
         # this build on an OS+Xcode with a pre-10.4 SDK; we don't
         # worry about the user requesting that.)
         #
-        CFLAGS="$CFLAGS -mmacosx-version-min=10.4 $SDKFLAGS" CXXFLAGS="$CXXFLAGS -mmacosx-version-min=10.4 $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --disable-mac-universal || exit 1
+        # Explicitly disable deprecation, so the damn thing will build
+        # on El Capitan with Xcode 7.
+        #
+        CFLAGS="$CFLAGS -Wno-deprecated-declarations -mmacosx-version-min=10.4 $SDKFLAGS" CXXFLAGS="$CXXFLAGS -mmacosx-version-min=10.4 $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --disable-mac-universal || exit 1
         make $MAKE_BUILD_OPTS || exit 1
         $DO_MAKE_INSTALL || exit 1
         cd ..
@@ -1943,7 +2039,7 @@ CXXFLAGS="-g -O2"
 # fix that file.
 #
 if [[ $DARWIN_MAJOR_VERSION -le 9 ]]; then
-    echo "This script does not support any versions of OS X before Snow Leopard" 1>&2 
+    echo "This script does not support any versions of OS X before Snow Leopard" 1>&2
     exit 1
 fi
 
@@ -2136,10 +2232,22 @@ then
         # ages ago, but don't remember what I did.
         #
         GLIB_VERSION=2.16.3
-        CAIRO_VERSION=1.6.4
-        ATK_VERSION=1.24.0
-        PANGO_VERSION=1.20.2
-        GTK_VERSION=2.12.9
+        if [ "$CAIRO_VERSION" ]
+        then
+            CAIRO_VERSION=1.6.4
+        fi
+        if [ "$ATK_VERSION" ]
+        then
+            ATK_VERSION=1.24.0
+        fi
+        if [ "$PANGO_VERSION" ]
+        then
+            PANGO_VERSION=1.20.2
+        fi
+        if [ "$GTK_VERSION" ]
+        then
+            GTK_VERSION=2.12.9
+        fi
 
         #
         # That version of GTK+ includes gdk-pixbuf.
@@ -2222,28 +2330,46 @@ install_all
 
 echo ""
 
-echo "You are now prepared to build Wireshark. To do so do:"
-echo "export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/X11/lib/pkgconfig"
-echo ""
-if [ -n "$CMAKE" ]; then
+#
+# Indicate what paths to use for pkg-config and cmake.
+#
+pkg_config_path=/usr/local/lib/pkgconfig
+if [ "$QT_VERSION" ]; then
+    qt_base_path=$HOME/Qt$QT_VERSION/$QT_MAJOR_MINOR_VERSION/clang_64
+    pkg_config_path="$pkg_config_path":"$qt_base_path/clang_64/lib/pkgconfig"
+    CMAKE_PREFIX_PATH="$CMAKE_PREFIX_PATH":"$qt_base_path/lib/cmake"
+fi
+pkg_config_path="$pkg_config_path":/usr/X11/lib/pkgconfig
+
+echo "You are now prepared to build Wireshark."
+echo
+if [[ $CMAKE ]]; then
+    echo "To build with CMAKE:"
+    echo
+    echo "export PKG_CONFIG_PATH=$pkg_config_path"
+    echo "export CMAKE_PREFIX_PATH=$CMAKE_PREFIX_PATH"
+    echo "export PATH=$PATH:$qt_base_path/bin"
+    echo
     echo "mkdir build; cd build"
     echo "cmake .."
+    echo "make $MAKE_BUILD_OPTS app_bundle"
+    echo "make install/strip"
+    echo
+fi
+if [[ $AUTOTOOLS ]]; then
+    echo "To build with AUTOTOOLS:"
+    echo
+    echo "export PKG_CONFIG_PATH=$pkg_config_path"
     echo
-    echo "or"
+    echo "./autogen.sh"
+    echo "mkdir build; cd build"
+    echo "../configure"
+    echo "make $MAKE_BUILD_OPTS"
+    echo "make install"
     echo
 fi
-echo "./autogen.sh"
-echo "mkdir build; cd build"
-echo "../configure"
-echo ""
-echo "make $MAKE_BUILD_OPTS"
-echo "make install"
-
-echo ""
-
 echo "Make sure you are allowed capture access to the network devices"
-echo "See: http://wiki.wireshark.org/CaptureSetup/CapturePrivileges"
-
-echo ""
+echo "See: https://wiki.wireshark.org/CaptureSetup/CapturePrivileges"
+echo
 
 exit 0