remove trans_info parameter from dissect_usb_unknown_descriptor()
[metze/wireshark/wip.git] / macosx-setup.sh
1 #!/bin/sh
2 # Setup development environment on Mac OS X (tested with 10.6.8 and Xcode 3.2.6)
3 #
4 # Copyright 2011 Michael Tuexen, Joerg Mayer, Guy Harris (see AUTHORS file)
5 #
6 # Wireshark - Network traffic analyzer
7 # By Gerald Combs <gerald@wireshark.org>
8 # Copyright 1998 Gerald Combs
9 #
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License
12 # as published by the Free Software Foundation; either version 2
13 # of the License, or (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23
24 #
25 # To install cmake
26 #
27 CMAKE=1
28 #
29 # To build all libraries as 32-bit libraries uncomment the following three lines.
30 #
31 # export CFLAGS="$CFLAGS -arch i386"
32 # export CXXFLAGS="$CXXFLAGS -arch i386"
33 # export LDFLAGS="$LDFLAGS -arch i386"
34 #
35 # and change "macx-clang" to "macx-clang-32" in the line below.
36 #
37 # Note: when building against the 10.6 SDK, clang fails, because there's
38 # a missing libstdc++.dylib in the SDK; this does not bother g++, however.
39 #
40 #TARGET_PLATFORM=macx-g++
41 TARGET_PLATFORM=macx-clang
42
43 #
44 # Versions of packages to download and install.
45 #
46
47 #
48 # Some packages need xz to unpack their current source.
49 # xz is not yet provided with OS X.
50 #
51 XZ_VERSION=5.0.4
52
53 #
54 # In case we want to build with cmake.
55 #
56 CMAKE_VERSION=2.8.12.2
57
58 #
59 # The following libraries and tools are required even to build only TShark.
60 #
61 GETTEXT_VERSION=0.18.2
62 GLIB_VERSION=2.36.0
63 PKG_CONFIG_VERSION=0.28
64
65 #
66 # One or more of the following libraries are required to build Wireshark.
67 #
68 # If you don't want to build with Qt, comment out the QT_VERSION= line.
69 #
70 # If you want to build with GTK+ 2, comment out the GTK_VERSION=3.* line
71 # and un-comment the GTK_VERSION=2.* line.
72 #
73 # If you don't want to build with GTK+ at all, comment out both lines.
74
75 QT_VERSION=5.2.1
76 GTK_VERSION=2.24.17
77 #GTK_VERSION=3.5.2
78 if [ "$GTK_VERSION" ]; then
79     #
80     # We'll be building GTK+, so we need some additional libraries.
81     #
82     GTK_MAJOR_VERSION="`expr $GTK_VERSION : '\([0-9][0-9]*\).*'`"
83     GTK_MINOR_VERSION="`expr $GTK_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
84     GTK_DOTDOT_VERSION="`expr $GTK_VERSION : '[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
85
86     ATK_VERSION=2.8.0
87     PANGO_VERSION=1.30.1
88     PNG_VERSION=1.5.17
89     PIXMAN_VERSION=0.26.0
90     CAIRO_VERSION=1.12.2
91     GDK_PIXBUF_VERSION=2.28.0
92 fi
93
94 # In case we want to build GTK *and* we don't have Apple's X11 SDK installed
95 # we may want to install XQuartz. The version will only be used in the printing
96 # of a URL, the package will not be installed.
97 #
98 XQUARTZ_VERSION=2.7.5
99 #
100 # The following libraries are optional.
101 # Comment them out if you don't want them, but note that some of
102 # the optional libraries are required by other optional libraries.
103 #
104 LIBSMI_VERSION=0.4.8
105 #
106 # libgpg-error is required for libgcrypt.
107 #
108 LIBGPG_ERROR_VERSION=1.10
109 #
110 # libgcrypt is required for GnuTLS.
111 # XXX - the link for "Libgcrypt source code" at
112 # http://www.gnupg.org/download/#libgcrypt is for 1.5.0, and is a bzip2
113 # file, but http://directory.fsf.org/project/libgcrypt/ lists only
114 # 1.4.6.
115 #
116 LIBGCRYPT_VERSION=1.5.0
117 GNUTLS_VERSION=2.12.19
118 # Default to 5.2 now, unless user overrides it later
119 LUA_VERSION=5.2.3
120 PORTAUDIO_VERSION=pa_stable_v19_20111121
121 #
122 # XXX - they appear to have an unversioned gzipped tarball for the
123 # current version; should we just download that, with some other
124 # way of specifying whether to download the GeoIP API?
125 #
126 GEOIP_VERSION=1.4.8
127
128 CARES_VERSION=1.10.0
129
130 DARWIN_MAJOR_VERSION=`uname -r | sed 's/\([0-9]*\).*/\1/'`
131
132 #
133 # GNU autotools; they're provided with releases up to Snow Leopard, but
134 # not in later releases.
135 #
136 if [[ $DARWIN_MAJOR_VERSION -gt 10 ]]; then
137     AUTOCONF_VERSION=2.69
138     AUTOMAKE_VERSION=1.13.3
139     LIBTOOL_VERSION=2.4.2
140 fi
141
142 uninstall() {
143     if [ -d macosx-support-libs ]
144     then
145         cd macosx-support-libs
146
147         #
148         # Uninstall items in the reverse order from the order in which they're
149         # installed.  Only uninstall if the download/build/install process
150         # completed; uninstall the version that appears in the name of
151         # the -done file.
152         #
153         # We also do a "make distclean", so that we don't have leftovers from
154         # old configurations.
155         #
156
157         installed_cares_version=`ls cares-*-done 2>/dev/null | sed 's/cares-\(.*\)-done/\1/'`
158         if [ ! -z "$installed_cares_version" ] ; then
159             echo "Uninstalling C-Ares API:"
160             cd cares-$installed_cares_version
161             $DO_MAKE_UNINSTALL || exit 1
162             make distclean || exit 1
163             cd ..
164             rm cares-$installed_cares_version-done
165         fi
166
167         installed_geoip_version=`ls geoip-*-done 2>/dev/null | sed 's/geoip-\(.*\)-done/\1/'`
168         if [ ! -z "$installed_geoip_version" ] ; then
169             echo "Uninstalling GeoIP API:"
170             cd GeoIP-$installed_geoip_version
171             $DO_MAKE_UNINSTALL || exit 1
172             make distclean || exit 1
173             cd ..
174             rm geoip-$installed_geoip_version-done
175         fi
176
177         if [ "$PORTAUDIO_VERSION" -a -f portaudio-done ] ; then
178             echo "Uninstalling PortAudio:"
179             cd portaudio
180             $DO_MAKE_UNINSTALL || exit 1
181             make distclean || exit 1
182             cd ..
183             rm portaudio-done
184         fi
185
186         installed_lua_version=`ls lua-*-done 2>/dev/null | sed 's/lua-\(.*\)-done/\1/'`
187         if [ ! -z "$installed_lua_version" ] ; then
188             echo "Uninstalling Lua:"
189             #
190             # Lua has no "make uninstall", so just remove stuff manually.
191             # There's no configure script, so there's no need for
192             # "make distclean", either; just do "make clean".
193             #
194             (cd /usr/local/bin; $DO_RM -f lua luac)
195             (cd /usr/local/include; $DO_RM -f lua.h luaconf.h lualib.h lauxlib.h lua.hpp)
196             (cd /usr/local/lib; $DO_RM -f liblua.a)
197             (cd /usr/local/man/man1; $DO_RM -f lua.1 luac.1)
198             cd lua-$installed_lua_version
199             make clean || exit 1
200             cd ..
201             rm lua-$installed_lua_version-done
202         fi
203
204         installed_gnutls_version=`ls gnutls-*-done 2>/dev/null | sed 's/gnutls-\(.*\)-done/\1/'`
205         if [ ! -z "$installed_gnutls_version" ] ; then
206             echo "Uninstalling GnuTLS:"
207             cd gnutls-$installed_gnutls_version
208             $DO_MAKE_UNINSTALL || exit 1
209             make distclean || exit 1
210             cd ..
211             rm gnutls-$installed_gnutls_version-done
212         fi
213
214         installed_libgcrypt_version=`ls libgcrypt-*-done 2>/dev/null | sed 's/libgcrypt-\(.*\)-done/\1/'`
215         if [ ! -z "$installed_libgcrypt_version" ] ; then
216             echo "Uninstalling libgcrypt:"
217             cd libgcrypt-$installed_libgcrypt_version
218             $DO_MAKE_UNINSTALL || exit 1
219             make distclean || exit 1
220             cd ..
221             rm libgcrypt-$installed_libgcrypt_version-done
222         fi
223
224         installed_libgpg_error_version=`ls libgpg-error-*-done 2>/dev/null | sed 's/libgpg-error-\(.*\)-done/\1/'`
225         if [ ! -z "$installed_libgpg_error_version" ] ; then
226             echo "Uninstalling libgpg-error:"
227             cd libgpg-error-$installed_libgpg_error_version
228             $DO_MAKE_UNINSTALL || exit 1
229             make distclean || exit 1
230             cd ..
231             rm libgpg-error-$installed_libgpg_error_version-done
232         fi
233
234         installed_libsmi_version=`ls libsmi-*-done 2>/dev/null | sed 's/libsmi-\(.*\)-done/\1/'`
235         if [ ! -z "$installed_libsmi_version" ] ; then
236             echo "Uninstalling libsmi:"
237             cd libsmi-$installed_libsmi_version
238             $DO_MAKE_UNINSTALL || exit 1
239             make distclean || exit 1
240             cd ..
241             rm libsmi-$installed_libsmi_version-done
242         fi
243
244         installed_gtk_version=`ls gtk+-*-done 2>/dev/null | sed 's/gtk+-\(.*\)-done/\1/'`
245         if [ ! -z "$installed_gtk_version" ] ; then
246             echo "Uninstalling GTK+:"
247             cd gtk+-$installed_gtk_version
248             $DO_MAKE_UNINSTALL || exit 1
249             make distclean || exit 1
250             cd ..
251             rm gtk+-$installed_gtk_version-done
252         fi
253
254         installed_gdk_pixbuf_version=`ls gdk-pixbuf-*-done 2>/dev/null | sed 's/gdk-pixbuf-\(.*\)-done/\1/'`
255         if [ ! -z "$installed_gdk_pixbuf_version" ] ; then
256             echo "Uninstalling gdk-pixbuf:"
257             cd gdk-pixbuf-$installed_gdk_pixbuf_version
258             $DO_MAKE_UNINSTALL || exit 1
259             make distclean || exit 1
260             cd ..
261             rm gdk-pixbuf-$installed_gdk_pixbuf_version-done
262         fi
263
264         installed_pango_version=`ls pango-*-done 2>/dev/null | sed 's/pango-\(.*\)-done/\1/'`
265         if [ ! -z "$installed_pango_version" ] ; then
266             echo "Uninstalling Pango:"
267             cd pango-$installed_pango_version
268             $DO_MAKE_UNINSTALL || exit 1
269             make distclean || exit 1
270             cd ..
271             rm pango-$installed_pango_version-done
272         fi
273
274         installed_atk_version=`ls atk-*-done 2>/dev/null | sed 's/atk-\(.*\)-done/\1/'`
275         if [ ! -z "$installed_atk_version" ] ; then
276             echo "Uninstalling ATK:"
277             cd atk-$installed_atk_version
278             $DO_MAKE_UNINSTALL || exit 1
279             make distclean || exit 1
280             cd ..
281             rm atk-$installed_atk_version-done
282         fi
283
284         installed_cairo_version=`ls cairo-*-done 2>/dev/null | sed 's/cairo-\(.*\)-done/\1/'`
285         if [ ! -z "$installed_cairo_version" ] ; then
286             echo "Uninstalling Cairo:"
287             cd cairo-$installed_cairo_version
288             $DO_MAKE_UNINSTALL || exit 1
289             make distclean || exit 1
290             cd ..
291             rm cairo-$installed_cairo_version-done
292         fi
293
294         installed_pixman_version=`ls pixman-*-done 2>/dev/null | sed 's/pixman-\(.*\)-done/\1/'`
295         if [ ! -z "$installed_pixman_version" ] ; then
296             echo "Uninstalling pixman:"
297             cd pixman-$installed_pixman_version
298             $DO_MAKE_UNINSTALL || exit 1
299             make distclean || exit 1
300             cd ..
301             rm pixman-$installed_pixman_version-done
302         fi
303
304         installed_libpng_version=`ls libpng-*-done 2>/dev/null | sed 's/libpng-\(.*\)-done/\1/'`
305         if [ ! -z "$installed_libpng_version" ] ; then
306             echo "Uninstalling libpng:"
307             cd libpng-$installed_libpng_version
308             $DO_MAKE_UNINSTALL || exit 1
309             make distclean || exit 1
310             cd ..
311             rm libpng-$installed_libpng_version-done
312         fi
313
314         installed_qt_version=`ls qt-*-done 2>/dev/null | sed 's/qt-\(.*\)-done/\1/'`
315         if [ ! -z "$installed_qt_version" ] ; then
316             echo "Uninstalling Qt:"
317             cd qt-everywhere-opensource-src-$installed_qt_version
318             $DO_MAKE_UNINSTALL || exit 1
319             #
320             # XXX - "make distclean" doesn't work.  qmake sure does a
321             # good job of constructing Makefiles that work correctly....
322             #
323             #make distclean || exit 1
324             cd ..
325             rm qt-$installed_qt_version-done
326         fi
327
328         installed_glib_version=`ls glib-*-done 2>/dev/null | sed 's/glib-\(.*\)-done/\1/'`
329         if [ ! -z "$installed_glib_version" ] ; then
330             echo "Uninstalling GLib:"
331             cd glib-$installed_glib_version
332             $DO_MAKE_UNINSTALL || exit 1
333             make distclean || exit 1
334             cd ..
335             rm glib-$installed_glib_version-done
336         fi
337
338         installed_pkg_config_version=`ls pkg-config-*-done 2>/dev/null | sed 's/pkg-config-\(.*\)-done/\1/'`
339         if [ ! -z "$installed_pkg_config_version" ] ; then
340             echo "Uninstalling pkg-config:"
341             cd pkg-config-$installed_pkg_config_version
342             $DO_MAKE_UNINSTALL || exit 1
343             make distclean || exit 1
344             cd ..
345             rm pkg-config-$installed_pkg_config_version-done
346         fi
347
348         installed_gettext_version=`ls gettext-*-done 2>/dev/null | sed 's/gettext-\(.*\)-done/\1/'`
349         if [ ! -z "$installed_gettext_version" ] ; then
350             echo "Uninstalling GNU gettext:"
351             cd gettext-$installed_gettext_version
352             $DO_MAKE_UNINSTALL || exit 1
353             make distclean || exit 1
354             cd ..
355             rm gettext-$installed_gettext_version-done
356         fi
357
358         #
359         # XXX - really remove this?
360         # Or should we remember it as installed only if this script
361         # installed it?
362         #
363         installed_cmake_version=`ls cmake-*-done 2>/dev/null | sed 's/cmake-\(.*\)-done/\1/'`
364         if [ ! -z "$installed_cmake_version" ]; then
365             echo "Uninstalling CMake:"
366             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
367             sudo rm /usr/bin/ccmake
368             sudo rm /usr/bin/cmake
369             sudo rm /usr/bin/cmake-gui
370             sudo rm /usr/bin/cmakexbuild
371             sudo rm /usr/bin/cpack
372             sudo rm /usr/bin/ctest
373             sudo pkgutil --forget com.Kitware.CMake
374             rm cmake-$installed_cmake_version-done
375         fi
376
377         installed_libtool_version=`ls libtool-*-done 2>/dev/null | sed 's/libtool-\(.*\)-done/\1/'`
378         if [ ! -z "$installed_libtool_version" ] ; then
379             echo "Uninstalling GNU libtool:"
380             cd libtool-$installed_libtool_version
381             mv /usr/local/bin/glibtool /usr/local/bin/libtool
382             mv /usr/local/bin/glibtoolize /usr/local/bin/libtoolize
383             $DO_MAKE_UNINSTALL || exit 1
384             make distclean || exit 1
385             cd ..
386             rm libtool-$installed_libtool_version-done
387         fi
388
389         installed_automake_version=`ls automake-*-done 2>/dev/null | sed 's/automake-\(.*\)-done/\1/'`
390         if [ ! -z "$installed_automake_version" ] ; then
391             echo "Uninstalling GNU automake:"
392             cd automake-$installed_automake_version
393             $DO_MAKE_UNINSTALL || exit 1
394             make distclean || exit 1
395             cd ..
396             rm automake-$installed_automake_version-done
397         fi
398
399         installed_autoconf_version=`ls autoconf-*-done 2>/dev/null | sed 's/autoconf-\(.*\)-done/\1/'`
400         if [ ! -z "$installed_autoconf_version" ] ; then
401             echo "Uninstalling GNU autoconf:"
402             cd autoconf-$installed_autoconf_version
403             $DO_MAKE_UNINSTALL || exit 1
404             make distclean || exit 1
405             cd ..
406             rm autoconf-$installed_autoconf_version-done
407         fi
408
409         installed_xz_version=`ls xz-*-done 2>/dev/null | sed 's/xz-\(.*\)-done/\1/'`
410         if [ ! -z "$installed_xz_version" ] ; then
411             echo "Uninstalling xz:"
412             cd xz-$installed_xz_version
413             $DO_MAKE_UNINSTALL || exit 1
414             make distclean || exit 1
415             cd ..
416             rm xz-$installed_xz_version-done
417         fi
418     fi
419 }
420
421 #
422 # Do we have permission to write in /usr/local?
423 #
424 # If so, assume we have permission to write in its subdirectories.
425 # (If that's not the case, this test needs to check the subdirectories
426 # as well.)
427 #
428 # If not, do "make install", "make uninstall", and the removes for Lua
429 # with sudo.
430 #
431 if [ -w /usr/local ]
432 then
433     DO_MAKE_INSTALL="make install"
434     DO_MAKE_UNINSTALL="make uninstall"
435     DO_RM="rm"
436 else
437     DO_MAKE_INSTALL="sudo make install"
438     DO_MAKE_UNINSTALL="sudo make uninstall"
439     DO_RM="sudo rm"
440 fi
441
442 #
443 # If we have SDKs available, the default target OS is the major version
444 # of the one we're running; get that and strip off the third component.
445 #
446 for i in /Developer/SDKs \
447     /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs \
448     /Library/Developer/CommandLineTools/SDKs
449 do
450     if [ -d "$i" ]
451     then
452         min_osx_target=`sw_vers -productVersion | sed 's/\([[0-9]]*\).\([[0-9]]*\).[[0-9]]*/\1.\2/'`
453         break
454     fi
455 done
456
457 #
458 # Parse command-line flags:
459 #
460 # -h - print help.
461 # -t <target> - build libraries so that they'll work on the specified
462 # version of OS X and later versions.
463 # -u - do an uninstall.
464 #
465 while getopts ht:u name
466 do
467     case $name in
468     u)
469         do_uninstall=yes
470         ;;
471     t)
472         min_osx_target="$OPTARG"
473         ;;
474     h|?)
475         echo "Usage: macosx-setup.sh [ -t <target> ] [ -u ]" 1>&1
476         exit 0
477         ;;
478     esac
479 done
480
481 if [ "$do_uninstall" = "yes" ]
482 then
483     uninstall
484     exit 0
485 fi
486
487 #
488 # Configure scripts tend to set CFLAGS and CXXFLAGS to "-g -O2" if
489 # invoked without CFLAGS or CXXFLAGS being set in the environment.
490 #
491 # However, we *are* setting them in the environment, for our own
492 # nefarious purposes, so start them out as "-g -O2".
493 #
494 CFLAGS="-g -O2"
495 CXXFLAGS="-g -O2"
496
497 #
498 # To make this work on Leopard (rather than working *on* Snow Leopard
499 # when building *for* Leopard) will take more work.
500 #
501 # For one thing, Leopard's /usr/X11/lib/libXdamage.la claims, at least
502 # with all software updates applied, that the Xdamage shared library
503 # is libXdamage.1.0.0.dylib, but it is, in fact, libXdamage.1.1.0.dylib.
504 # This causes problems when building GTK+, so the script would have to
505 # fix that file.
506 #
507 if [[ $DARWIN_MAJOR_VERSION -le 9 ]]; then
508     echo "This script does not support any versions of OS X before Snow Leopard" 1>&2 
509     exit 1
510 fi
511
512 # if no make options are present, set default options
513 if [ -z "$MAKE_BUILD_OPTS" ] ; then
514     # by default use 1.5x number of cores for parallel build
515     MAKE_BUILD_OPTS="-j $(( $(sysctl -n hw.logicalcpu) * 3 / 2))"
516 fi
517
518 #
519 # If we have a target release, look for its SDK, and build libraries
520 # against it rather than against the headers and, more importantly,
521 # libraries that come with the OS, so that we don't end up with
522 # support libraries that only work on the OS version on which
523 # we built them, not earlier versions of the same release, or
524 # earlier releases if the minimum is earlier.
525 #
526 if [ ! -z "$min_osx_target" ]
527 then
528     for i in /Developer/SDKs \
529         /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs \
530         /Library/Developer/CommandLineTools/SDKs
531     do
532         if [ -d "$i"/"MacOSX$min_osx_target.sdk" ]
533         then
534             SDKPATH="$i"/"MacOSX$min_osx_target.sdk"
535             break
536         fi
537     done
538
539     if [ -z "$SDKPATH" ]
540     then
541         echo "macosx-setup.sh: Couldn't find the SDK for OS X $min_osx_target" 1>&2
542         exit 1
543     fi
544
545     #
546     # Make sure there are links to /usr/local/include and /usr/local/lib
547     # in the SDK's usr/local.
548     #
549     if [ ! -e $SDKPATH/usr/local/include ]
550     then
551         if [ ! -d $SDKPATH/usr/local ]
552         then
553             sudo mkdir $SDKPATH/usr/local
554         fi
555         sudo ln -s /usr/local/include $SDKPATH/usr/local/include
556     fi
557     if [ ! -e $SDKPATH/usr/local/lib ]
558     then
559         if [ ! -d $SDKPATH/usr/local ]
560         then
561             sudo mkdir $SDKPATH/usr/local
562         fi
563         sudo ln -s /usr/local/lib $SDKPATH/usr/local/lib
564     fi
565
566     #
567     # Set the minimum OS version for which to build to the specified
568     # minimum target OS version, so we don't, for example, end up using
569     # linker features supported by the OS verson on which we're building
570     # but not by the target version.
571     #
572     VERSION_MIN_FLAGS="-mmacosx-version-min=$min_osx_target"
573
574     #
575     # Compile and link against the SDK.
576     #
577     SDKFLAGS="-isysroot $SDKPATH"
578
579     if [[ "$min_osx_target" == "10.5" ]]
580     then
581         #
582         # Cairo is part of Mac OS X 10.6 and later.
583         # The *headers* are supplied by 10.5, but the *libraries*
584         # aren't, so we have to build it if we're building for 10.5.
585         #
586         cairo_not_in_the_os=yes
587
588         #
589         # Build with older versions of the support libraries, as
590         # were used on the Wireshark Leopard buildbot at one
591         # point.  (Most of these versions come from the About page
592         # from Wireshark 1.8.6, the last build done on that buildbot;
593         # the ATK version isn't reported, so this is a guess.)
594         #
595         # If you want to try building with newer versions of
596         # the libraries, note that:
597         #
598         # The version of fontconfig that comes with Leopard doesn't
599         # support FC_WEIGHT_EXTRABLACK, so we can't use any version
600         # of Pango newer than 1.22.4.
601         #
602         # However, Pango 1.22.4 doesn't work with versions of GLib
603         # after 2.29.6, because Pango 1.22.4 uses G_CONST_RETURN and
604         # GLib 2.29.8 and later deprecate it (there doesn't appear to
605         # be a GLib 2.29.7).  That means we'd either have to patch
606         # Pango not to use it (just use "const"; G_CONST_RETURN was
607         # there to allow code to choose whether to use "const" or not),
608         # or use GLib 2.29.6 or earlier.
609         #
610         # GLib 2.29.6 includes an implementation of g_bit_lock() that,
611         # on x86 (32-bit and 64-bit), uses asms in a fashion
612         # ("asm volatile goto") that requires GCC 4.5 or later, which
613         # is later than the compilers that come with Leopard and Snow
614         # Leopard.  Recent versions of GLib check for that, but 2.29.6
615         # doesn't, so, if you want to build GLib 2.29.6 on Leopard or
616         # Snow Leopard, you would have to patch glib/gbitlock.c to do
617         # what the newer versions of GLib do:
618         #
619         #  define a USE_ASM_GOTO macro that indicates whether "asm goto"
620         #  can be used:
621         #    #if (defined (i386) || defined (__amd64__))
622         #      #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
623         #        #define USE_ASM_GOTO 1
624         #      #endif
625         #    #endif
626         #
627         #  replace all occurrences of
628         #
629         #    #if defined (__GNUC__) && (defined (i386) || defined (__amd64__))
630         #
631         #  with
632         #
633         #    #ifdef USE_ASM_GOTO
634         #
635         # Using GLib 2.29.6 or earlier, however, means that we can't
636         # use a version of ATK later than 2.3.93, as those versions
637         # don't work with GLib 2.29.6.  The same applies to gdk-pixbuf;
638         # versions of gdk-pixbuf after 2.24.1 won't work with GLib
639         # 2.29.6.
640         #
641         # Then you have to make sure that what you've build doesn't
642         # cause the X server that comes with Leopard to crash; at
643         # least one attempt at building for Leopard did.
644         #
645         # At least if building on Leopard, you might also find
646         # that, with various older versions of Cairo, including
647         # 1.6.4 and at least some 1.8.x versions, when you try to
648         # build it, the build fails because it can't find
649         # png_set_longjmp_fn().  I vaguely remember dealing with that,
650         # ages ago, but don't remember what I did.
651         #
652         GLIB_VERSION=2.16.3
653         CAIRO_VERSION=1.6.4
654         ATK_VERSION=1.24.0
655         PANGO_VERSION=1.20.2
656         GTK_VERSION=2.12.9
657
658         #
659         # That version of GTK+ includes gdk-pixbuf.
660         # XXX - base this on the version of GTK+ requested.
661         #
662         GDK_PIXBUF_VERSION=
663
664         #
665         # Libgcrypt 1.5.0 fails to compile due to some problem with an
666         # asm in rijndael.c, at least with i686-apple-darwin10-gcc-4.2.1
667         # (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3) when building
668         # 32-bit.
669         #
670         # We try libgcrypt 1.4.3 instead, as that's what shows up in
671         # the version from the Leopard buildbot.
672         LIBGCRYPT_VERSION=1.4.3
673
674         #
675         # Build 32-bit while we're at it; Leopard has a bug that
676         # causes some BPF functions not to work with 64-bit userland
677         # code, so capturing won't work.
678         #
679         CFLAGS="$CFLAGS -arch i386"
680         CXXFLAGS="$CXXFLAGS -arch i386"
681         export LDFLAGS="$LDFLAGS -arch i386"
682     fi
683 fi
684
685 export CFLAGS
686 export CXXFLAGS
687
688 #
689 # You need Xcode or the command-line tools installed to get the compilers.
690 #
691 if [ ! -x /usr/bin/xcodebuild ]; then
692     echo "Please install Xcode first (should be available on DVD or from http://developer.apple.com/xcode/index.php)."
693     exit 1
694 fi
695
696 if [ "$QT_VERSION" ]; then
697     #
698     # We need Xcode, not just the command-line tools, installed to build
699     # Qt.
700     #
701     if ! /usr/bin/xcrun -find xcrun >/dev/null 2>&1; then
702         echo "Please install Xcode first (should be available on DVD or from http://developer.apple.com/xcode/index.php)."
703         echo "The command-line build tools are not sufficient to build Qt."
704         exit 1
705     fi
706 fi
707 if [ "$GTK_VERSION" ]; then
708     #
709     # If we're building with GTK+, you also need the X11 SDK; with at least
710     # some versions of OS X and Xcode, that is, I think, an optional install.
711     # (Or it might be installed with X11, but I think *that* is an optional
712     # install on at least some versions of OS X.)
713     #
714     if [ ! -d /usr/X11/include ]; then
715         echo "Please install X11 and the X11 SDK first."
716         echo "  You can either use http://xquartz.macosforge.org/, e.g."
717         echo "  http://xquartz-dl.macosforge.org/SL/XQuartz-$XQUARTZ_VERSION.dmg"
718         echo "  or the native Apple packages if you are on Lion or below."
719         exit 1
720     fi
721 fi
722
723 export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/X11/lib/pkgconfig
724
725 #
726 # Do all the downloads and untarring in a subdirectory, so all that
727 # stuff can be removed once we've installed the support libraries.
728 #
729 if [ ! -d macosx-support-libs ]
730 then
731     mkdir macosx-support-libs || exit 1
732 fi
733 cd macosx-support-libs
734
735 # Start with xz: It is the sole download format of glib later than 2.31.2
736 #
737 if [ "$XZ_VERSION" -a ! -f xz-$XZ_VERSION-done ] ; then
738     echo "Downloading, building, and installing xz:"
739     [ -f xz-$XZ_VERSION.tar.bz2 ] || curl -O http://tukaani.org/xz/xz-$XZ_VERSION.tar.bz2 || exit 1
740     bzcat xz-$XZ_VERSION.tar.bz2 | tar xf - || exit 1
741     cd xz-$XZ_VERSION
742     CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=0" ./configure || exit 1
743     make $MAKE_BUILD_OPTS || exit 1
744     $DO_MAKE_INSTALL || exit 1
745     cd ..
746     touch xz-$XZ_VERSION-done
747 fi
748
749 if [ "$AUTOCONF_VERSION" -a ! -f autoconf-$AUTOCONF_VERSION-done ] ; then
750     echo "Downloading, building and installing GNU autoconf..."
751     [ -f autoconf-$AUTOCONF_VERSION.tar.xz ] || curl -O ftp://ftp.gnu.org/gnu/autoconf/autoconf-$AUTOCONF_VERSION.tar.xz || exit 1
752     xzcat autoconf-$AUTOCONF_VERSION.tar.xz | tar xf - || exit 1
753     cd autoconf-$AUTOCONF_VERSION
754     ./configure || exit 1
755     make $MAKE_BUILD_OPTS || exit 1
756     $DO_MAKE_INSTALL || exit 1
757     cd ..
758     touch autoconf-$AUTOCONF_VERSION-done
759 fi
760
761 if [ "$AUTOMAKE_VERSION" -a ! -f automake-$AUTOMAKE_VERSION-done ] ; then
762     echo "Downloading, building and installing GNU automake..."
763     [ -f automake-$AUTOMAKE_VERSION.tar.xz ] || curl -O ftp://ftp.gnu.org/gnu/automake/automake-$AUTOMAKE_VERSION.tar.xz || exit 1
764     xzcat automake-$AUTOMAKE_VERSION.tar.xz | tar xf - || exit 1
765     cd automake-$AUTOMAKE_VERSION
766     ./configure || exit 1
767     make $MAKE_BUILD_OPTS || exit 1
768     $DO_MAKE_INSTALL || exit 1
769     cd ..
770     touch automake-$AUTOMAKE_VERSION-done
771 fi
772
773 if [ "$LIBTOOL_VERSION" -a ! -f libtool-$LIBTOOL_VERSION-done ] ; then
774     echo "Downloading, building and installing GNU libtool..."
775     [ -f libtool-$LIBTOOL_VERSION.tar.xz ] || curl -O ftp://ftp.gnu.org/gnu/libtool/libtool-$LIBTOOL_VERSION.tar.xz || exit 1
776     xzcat libtool-$LIBTOOL_VERSION.tar.xz | tar xf - || exit 1
777     cd libtool-$LIBTOOL_VERSION
778     ./configure || exit 1
779     make $MAKE_BUILD_OPTS || exit 1
780     $DO_MAKE_INSTALL || exit 1
781     mv /usr/local/bin/libtool /usr/local/bin/glibtool
782     mv /usr/local/bin/libtoolize /usr/local/bin/glibtoolize
783     cd ..
784     touch libtool-$LIBTOOL_VERSION-done
785 fi
786
787 if [ -n "$CMAKE" -a ! -f cmake-$CMAKE_VERSION-done ]; then
788   echo "Downloading and installing CMake:"
789   cmake_dir=`expr $CMAKE_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
790   #
791   # NOTE: the "64" in "Darwin64" doesn't mean "64-bit-only"; the
792   # package in question supports both 32-bit and 64-bit x86.
793   #
794   [ -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
795   sudo hdiutil attach http://www.cmake.org/files/v2.8/cmake-$CMAKE_VERSION-Darwin64-universal.dmg || exit 1
796   sudo installer -target / -pkg /Volumes/cmake-$CMAKE_VERSION-Darwin64-universal/cmake-$CMAKE_VERSION-Darwin64-universal.pkg || exit 1
797   sudo hdiutil detach /Volumes/cmake-$CMAKE_VERSION-Darwin64-universal
798   touch cmake-$CMAKE_VERSION-done
799 fi
800
801 #
802 # Start with GNU gettext; GLib requires it, and OS X doesn't have it
803 # or a BSD-licensed replacement.
804 #
805 # At least on Lion with Xcode 4, _FORTIFY_SOURCE gets defined as 2
806 # by default, which causes, for example, stpncpy to be defined as
807 # a hairy macro that collides with the GNU gettext configure script's
808 # attempts to workaround AIX's lack of a declaration for stpncpy,
809 # with the result being a huge train wreck.  Define _FORTIFY_SOURCE
810 # as 0 in an attempt to keep the trains on separate tracks.
811 #
812 if [ ! -f gettext-$GETTEXT_VERSION-done ] ; then
813     echo "Downloading, building, and installing GNU gettext:"
814     [ -f gettext-$GETTEXT_VERSION.tar.gz ] || curl -O http://ftp.gnu.org/pub/gnu/gettext/gettext-$GETTEXT_VERSION.tar.gz || exit 1
815     gzcat gettext-$GETTEXT_VERSION.tar.gz | tar xf - || exit 1
816     cd gettext-$GETTEXT_VERSION
817     CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=0 $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
818     make $MAKE_BUILD_OPTS || exit 1
819     $DO_MAKE_INSTALL || exit 1
820     cd ..
821     touch gettext-$GETTEXT_VERSION-done
822 fi
823
824 #
825 # GLib depends on pkg-config.
826 # By default, pkg-config depends on GLib; we break the dependency cycle
827 # by configuring pkg-config to use its own internal version of GLib.
828 #
829 if [ ! -f pkg-config-$PKG_CONFIG_VERSION-done ] ; then
830     echo "Downloading, building, and installing pkg-config:"
831     [ -f pkg-config-$PKG_CONFIG_VERSION.tar.gz ] || curl -O http://pkgconfig.freedesktop.org/releases/pkg-config-$PKG_CONFIG_VERSION.tar.gz || exit 1
832     gzcat pkg-config-$PKG_CONFIG_VERSION.tar.gz | tar xf - || exit 1
833     cd pkg-config-$PKG_CONFIG_VERSION
834     ./configure --with-internal-glib || exit 1
835     make $MAKE_BUILD_OPTS || exit 1
836     $DO_MAKE_INSTALL || exit 1
837     cd ..
838     touch pkg-config-$PKG_CONFIG_VERSION-done
839 fi
840
841 if [ ! -f glib-$GLIB_VERSION-done ] ; then
842     echo "Downloading, building, and installing GLib:"
843     glib_dir=`expr $GLIB_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
844     GLIB_MAJOR_VERSION="`expr $GLIB_VERSION : '\([0-9][0-9]*\).*'`"
845     GLIB_MINOR_VERSION="`expr $GLIB_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
846     GLIB_DOTDOT_VERSION="`expr $GLIB_VERSION : '[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
847     if [[ $GLIB_MAJOR_VERSION -gt 2 ||
848           $GLIB_MINOR_VERSION -gt 28 ||
849           ($GLIB_MINOR_VERSION -eq 28 && $GLIB_DOTDOT_VERSION -ge 8) ]]
850     then
851         #
852         # Starting with GLib 2.28.8, xz-compressed tarballs are available.
853         #
854         [ -f glib-$GLIB_VERSION.tar.xz ] || curl -L -O http://ftp.gnome.org/pub/gnome/sources/glib/$glib_dir/glib-$GLIB_VERSION.tar.xz || exit 1
855         xzcat glib-$GLIB_VERSION.tar.xz | tar xf - || exit 1
856     else
857         [ -f glib-$GLIB_VERSION.tar.bz2 ] || curl -L -O http://ftp.gnome.org/pub/gnome/sources/glib/$glib_dir/glib-$GLIB_VERSION.tar.bz2 || exit 1
858         bzcat glib-$GLIB_VERSION.tar.bz2 | tar xf - || exit 1
859     fi
860     cd glib-$GLIB_VERSION
861     #
862     # OS X ships with libffi, but doesn't provide its pkg-config file;
863     # explicitly specify LIBFFI_CFLAGS and LIBFFI_LIBS, so the configure
864     # script doesn't try to use pkg-config to get the appropriate
865     # C flags and loader flags.
866     #
867     # And, what's worse, at least with the version of Xcode that comes
868     # with Leopard, /usr/include/ffi/fficonfig.h doesn't define MACOSX,
869     # which causes the build of GLib to fail.  If we don't find
870     # "#define.*MACOSX" in /usr/include/ffi/fficonfig.h, explicitly
871     # define it.
872     #
873     # While we're at it, suppress -Wformat-nonliteral to avoid a case
874     # where clang's stricter rules on when not to complain about
875     # non-literal format arguments cause it to complain about code
876     # that's safe but it wasn't told that.  See my comment #25 in
877     # GNOME bug 691608:
878     #
879     #    https://bugzilla.gnome.org/show_bug.cgi?id=691608#c25
880     #
881     # First, determine where the system include files are.  (It's not
882     # necessarily /usr/include.)  There's a bit of a greasy hack here;
883     # pre-5.x versions of the developer tools don't support the
884     # --show-sdk-path option, and will produce no output, so includedir
885     # will be set to /usr/include (in those older versions of the
886     # developer tools, there is a /usr/include directory).
887     #
888     includedir=`xcrun --show-sdk-path 2>/dev/null`/usr/include
889     if grep -qs '#define.*MACOSX' $includedir/ffi/fficonfig.h
890     then
891         # It's defined, nothing to do
892         LIBFFI_CFLAGS="-I $includedir/ffi" LIBFFI_LIBS="-lffi" CFLAGS="$CFLAGS -Wno-format-nonliteral $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
893     else
894         LIBFFI_CFLAGS="-I $includedir/ffi" LIBFFI_LIBS="-lffi" CFLAGS="$CFLAGS -DMACOSX -Wno-format-nonliteral $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
895     fi
896
897     #
898     # Apply the fix to GNOME bug 529806:
899     #
900     #    https://bugzilla.gnome.org/show_bug.cgi?id=529806
901     #
902     # if we have a version of GLib prior to 2.30.
903     #
904     if [[ $GLIB_MAJOR_VERSION -eq 2 && $GLIB_MINOR_VERSION -le 30 ]]
905     then
906         patch -p0 <../../macosx-support-lib-patches/glib-gconvert.c.patch || exit 1
907     fi
908     make $MAKE_BUILD_OPTS || exit 1
909     $DO_MAKE_INSTALL || exit 1
910     cd ..
911     touch glib-$GLIB_VERSION-done
912 fi
913
914 #
915 # Now we have reached a point where we can build everything but
916 # the GUI (Wireshark).
917 #
918 if [ "$QT_VERSION" -a ! -f qt-$QT_VERSION-done ]; then
919     echo "Downloading, building, and installing Qt:"
920     QT_MAJOR_VERSION="`expr $QT_VERSION : '\([0-9][0-9]*\).*'`"
921     QT_MINOR_VERSION="`expr $QT_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
922     QT_DOTDOT_VERSION="`expr $QT_VERSION : '[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
923     QT_MAJOR_MINOR_VERSION=$QT_MAJOR_VERSION.$QT_MINOR_VERSION
924     #
925     # What you get for this URL might just be a 302 Found reply, so use
926     # -L so we get redirected.
927     #
928     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
929     #
930     # Qt 5.1.x sets QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.6
931     # in qtbase/mkspecs/$TARGET_PLATFORM/qmake.conf
932     # We may need to adjust this manually in the future.
933     #
934     # The -no-c++11 flag is needed to work around
935     # https://bugreports.qt-project.org/browse/QTBUG-30487
936     #
937     tar xf qt-everywhere-opensource-src-$QT_VERSION.tar.gz
938     cd qt-everywhere-opensource-src-$QT_VERSION
939     #
940     # We don't build Qt in its Full Shining Glory, as we don't need all
941     # of its components, and it takes *forever* to build in that form.
942     #
943     # Qt 5.2.0 beta1 fails to build on OS X without -no-xcb due to bug
944     # QTBUG-34382.
945     #
946     # Qt 5.x fails to build on OS X with -no-opengl due to bug
947     # QTBUG-31151.
948     #
949     ./configure -v -sdk macosx$min_osx_target -platform $TARGET_PLATFORM \
950         -opensource -confirm-license -no-c++11 -no-dbus \
951         -no-sql-sqlite -no-xcb -nomake examples \
952         -skip qtdoc -skip qtquickcontrols -skip qtwebkit \
953         -skip qtwebkit-examples -skip qtxmlpatterns
954     make || exit 1
955     $DO_MAKE_INSTALL || exit 1
956     cd ..
957     touch qt-$QT_VERSION-done
958 fi
959
960 if [ "$GTK_VERSION" ]; then
961     #
962     # GTK+ 3 requires a newer Cairo build than the one that comes with
963     # 10.6, so we build Cairo if we are using GTK+ 3.
964     #
965     # In 10.6 and 10.7, it's an X11 library; if we build with "native" GTK+
966     # rather than X11 GTK+, we might have to build and install Cairo.
967     # In 10.8 and later, there is no X11, but it's included in Xquartz;
968     # again, if we build with "native" GTK+, we'd have to build and install
969     # it.
970     #
971     if [[ "$GTK_MAJOR_VERSION" -eq 3 || "$cairo_not_in_the_os" = yes ]]; then
972         #
973         # Requirements for Cairo first
974         #
975         # The libpng that comes with the X11 for Leopard has a bogus
976         # pkg-config file that lies about where the header files are,
977         # which causes other packages not to be able to find its
978         # headers.
979         #
980         # The libpng in later versions is not what the version of
981         # libpixman we build below wants - it wants libpng15.
982         #
983         if [ ! -f libpng-$PNG_VERSION-done ] ; then
984             echo "Downloading, building, and installing libpng:"
985             #
986             # The FTP site puts libpng x.y.* into a libpngxy directory.
987             #
988             subdir=`echo $PNG_VERSION | sed 's/\([1-9][0-9]*\)\.\([1-9][0-9]*\).*/libpng\1\2'/`
989             [ -f libpng-$PNG_VERSION.tar.xz ] || curl -O ftp://ftp.simplesystems.org/pub/libpng/png/src/$subdir/libpng-$PNG_VERSION.tar.xz
990             xzcat libpng-$PNG_VERSION.tar.xz | tar xf - || exit 1
991             cd libpng-$PNG_VERSION
992             CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
993             make $MAKE_BUILD_OPTS || exit 1
994             $DO_MAKE_INSTALL || exit 1
995             cd ..
996             touch libpng-$PNG_VERSION-done
997         fi
998
999         #
1000         # The libpixman versions that come with the X11s for Leopard,
1001         # Snow Leopard, and Lion is too old to support Cairo's image
1002         # surface backend feature (which requires pixman-1 >= 0.22.0).
1003         #
1004         # XXX - what about the one that comes with the latest version
1005         # of Xquartz?
1006         #
1007         if [ ! -f pixman-$PIXMAN_VERSION-done ] ; then
1008             echo "Downloading, building, and installing pixman:"
1009             [ -f pixman-$PIXMAN_VERSION.tar.gz ] || curl -O http://www.cairographics.org/releases/pixman-$PIXMAN_VERSION.tar.gz
1010             gzcat pixman-$PIXMAN_VERSION.tar.gz | tar xf - || exit 1
1011             cd pixman-$PIXMAN_VERSION
1012             CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
1013             make V=1 $MAKE_BUILD_OPTS || exit 1
1014             $DO_MAKE_INSTALL || exit 1
1015             cd ..
1016             touch pixman-$PIXMAN_VERSION-done
1017         fi
1018
1019         #
1020         # And now Cairo itself.
1021         # XXX - with the libxcb that comes with 10.6,
1022         #
1023         # xcb_discard_reply() is missing, and the build fails.
1024         #
1025         if [ ! -f cairo-$CAIRO_VERSION-done ] ; then
1026             echo "Downloading, building, and installing Cairo:"
1027             CAIRO_MAJOR_VERSION="`expr $CAIRO_VERSION : '\([0-9][0-9]*\).*'`"
1028             CAIRO_MINOR_VERSION="`expr $CAIRO_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
1029             CAIRO_DOTDOT_VERSION="`expr $CAIRO_VERSION : '[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
1030             if [[ $CAIRO_MAJOR_VERSION -gt 1 ||
1031                   $CAIRO_MINOR_VERSION -gt 12 ||
1032                   ($CAIRO_MINOR_VERSION -eq 12 && $CAIRO_DOTDOT_VERSION -ge 2) ]]
1033             then
1034                 #
1035                 # Starting with Cairo 1.12.2, the tarballs are compressed with
1036                 # xz rather than gzip.
1037                 #
1038                 [ -f cairo-$CAIRO_VERSION.tar.xz ] || curl -O http://cairographics.org/releases/cairo-$CAIRO_VERSION.tar.xz || exit 1
1039                 xzcat cairo-$CAIRO_VERSION.tar.xz | tar xf - || exit 1
1040             else
1041                 [ -f cairo-$CAIRO_VERSION.tar.gz ] || curl -O http://cairographics.org/releases/cairo-$CAIRO_VERSION.tar.gz || exit 1
1042                 gzcat cairo-$CAIRO_VERSION.tar.gz | tar xf - || exit 1
1043             fi
1044             cd cairo-$CAIRO_VERSION
1045             # CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --enable-quartz=no || exit 1
1046             # Maybe follow http://cairographics.org/end_to_end_build_for_mac_os_x/
1047             CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --enable-quartz=yes || exit 1
1048             #
1049             # We must avoid the version of libpng that comes with X11; the
1050             # only way I've found to force that is to forcibly set INCLUDES
1051             # when we do the build, so that this comes before CAIRO_CFLAGS,
1052             # which has -I/usr/X11/include added to it before anything
1053             # connected to libpng is.
1054             #
1055             INCLUDES="-I/usr/local/include/libpng15" make $MAKE_BUILD_OPTS || exit 1
1056             $DO_MAKE_INSTALL || exit 1
1057             cd ..
1058             touch cairo-$CAIRO_VERSION-done
1059         fi
1060     fi
1061
1062     if [ ! -f atk-$ATK_VERSION-done ] ; then
1063         echo "Downloading, building, and installing ATK:"
1064         atk_dir=`expr $ATK_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
1065         ATK_MAJOR_VERSION="`expr $ATK_VERSION : '\([0-9][0-9]*\).*'`"
1066         ATK_MINOR_VERSION="`expr $ATK_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
1067         ATK_DOTDOT_VERSION="`expr $ATK_VERSION : '[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
1068         if [[ $ATK_MAJOR_VERSION -gt 2 ||
1069               ($ATK_MAJOR_VERSION -eq 2 && $ATK_MINOR_VERSION -gt 0) ||
1070               ($ATK_MANOR_VERSION -eq 2 && $ATK_MINOR_VERSION -eq 0 && $ATK_DOTDOT_VERSION -ge 1) ]]
1071         then
1072             #
1073             # Starting with ATK 2.0.1, xz-compressed tarballs are available.
1074             #
1075             [ -f atk-$ATK_VERSION.tar.xz ] || curl -O http://ftp.gnome.org/pub/gnome/sources/atk/$atk_dir/atk-$ATK_VERSION.tar.xz || exit 1
1076             xzcat atk-$ATK_VERSION.tar.xz | tar xf - || exit 1
1077         else
1078             [ -f atk-$ATK_VERSION.tar.bz2 ] || curl -O http://ftp.gnome.org/pub/gnome/sources/atk/$atk_dir/atk-$ATK_VERSION.tar.bz2 || exit 1
1079             bzcat atk-$ATK_VERSION.tar.bz2 | tar xf - || exit 1
1080         fi
1081         cd atk-$ATK_VERSION
1082         CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
1083         make $MAKE_BUILD_OPTS || exit 1
1084         $DO_MAKE_INSTALL || exit 1
1085         cd ..
1086         touch atk-$ATK_VERSION-done
1087     fi
1088
1089     if [ ! -f pango-$PANGO_VERSION-done ] ; then
1090         echo "Downloading, building, and installing Pango:"
1091         pango_dir=`expr $PANGO_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
1092         PANGO_MAJOR_VERSION="`expr $PANGO_VERSION : '\([0-9][0-9]*\).*'`"
1093         PANGO_MINOR_VERSION="`expr $PANGO_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
1094         if [[ $PANGO_MAJOR_VERSION -gt 1 ||
1095               $PANGO_MINOR_VERSION -ge 29 ]]
1096         then
1097             #
1098             # Starting with Pango 1.29, the tarballs are compressed with
1099             # xz rather than bzip2.
1100             #
1101             [ -f pango-$PANGO_VERSION.tar.xz ] || curl -L -O http://ftp.gnome.org/pub/gnome/sources/pango/$pango_dir/pango-$PANGO_VERSION.tar.xz || exit 1
1102             xzcat pango-$PANGO_VERSION.tar.xz | tar xf - || exit 1
1103         else
1104             [ -f pango-$PANGO_VERSION.tar.bz2 ] || curl -L -O http://ftp.gnome.org/pub/gnome/sources/pango/$pango_dir/pango-$PANGO_VERSION.tar.bz2 || exit 1
1105             bzcat pango-$PANGO_VERSION.tar.bz2 | tar xf - || exit 1
1106         fi
1107         cd pango-$PANGO_VERSION
1108         CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
1109         make $MAKE_BUILD_OPTS || exit 1
1110         $DO_MAKE_INSTALL || exit 1
1111         cd ..
1112         touch pango-$PANGO_VERSION-done
1113     fi
1114
1115     if [ "$GDK_PIXBUF_VERSION" -a ! -f gdk-pixbuf-$GDK_PIXBUF_VERSION-done ] ; then
1116         echo "Downloading, building, and installing gdk-pixbuf:"
1117         gdk_pixbuf_dir=`expr $GDK_PIXBUF_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
1118         [ -f gdk-pixbuf-$GDK_PIXBUF_VERSION.tar.xz ] || curl -L -O http://ftp.gnome.org/pub/gnome/sources/gdk-pixbuf/$gdk_pixbuf_dir/gdk-pixbuf-$GDK_PIXBUF_VERSION.tar.xz || exit 1
1119         xzcat gdk-pixbuf-$GDK_PIXBUF_VERSION.tar.xz | tar xf - || exit 1
1120         cd gdk-pixbuf-$GDK_PIXBUF_VERSION
1121         #
1122         # If we're building for 10.6, use libpng12; if you have 10.7.5, including
1123         # X11, and Xcode 4.3.3, the system has libpng15, complete with pkg-config
1124         # files, as part of X11, but 10.6's X11 has only libpng12, and the 10.6
1125         # SDK in Xcode 4.3.3 also has only libpng12, and has no pkg-config files
1126         # of its own, so we have to explicitly set LIBPNG to override the
1127         # configure script, and also force the CFLAGS to look for the header
1128         # files for libpng12 (note that -isysroot doesn't affect the arguments
1129         # to -I, so we need to include the SDK path explicitly).
1130         #
1131         if [[ "$min_osx_target" = 10.6 ]]
1132         then
1133             LIBPNG="-L/usr/X11/lib -lpng12" CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS -I$SDKPATH/usr/X11/include/libpng12" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --without-libtiff --without-libjpeg || exit 1
1134         else
1135             CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --without-libtiff --without-libjpeg || exit 1
1136         fi
1137         make $MAKE_BUILD_OPTS || exit 1
1138         $DO_MAKE_INSTALL || exit 1
1139         cd ..
1140         touch gdk-pixbuf-$GDK_PIXBUF_VERSION-done
1141     fi
1142
1143     if [ ! -f gtk+-$GTK_VERSION-done ] ; then
1144         echo "Downloading, building, and installing GTK+:"
1145         gtk_dir=`expr $GTK_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
1146         if [[ $GTK_MAJOR_VERSION -gt 2 ||
1147               $GTK_MINOR_VERSION -gt 24 ||
1148              ($GTK_MINOR_VERSION -eq 24 && $GTK_DOTDOT_VERSION -ge 5) ]]
1149         then
1150             #
1151             # Starting with GTK+ 2.24.5, the tarballs are compressed with
1152             # xz rather than gzip, in addition to bzip2; use xz, as we've
1153             # built and installed it, and as xz compresses better than
1154             # bzip2 so the tarballs take less time to download.
1155             #
1156             [ -f gtk+-$GTK_VERSION.tar.xz ] || curl -L -O http://ftp.gnome.org/pub/gnome/sources/gtk+/$gtk_dir/gtk+-$GTK_VERSION.tar.xz || exit 1
1157             xzcat gtk+-$GTK_VERSION.tar.xz | tar xf - || exit 1
1158         else
1159             [ -f gtk+-$GTK_VERSION.tar.bz2 ] || curl -L -O http://ftp.gnome.org/pub/gnome/sources/gtk+/$gtk_dir/gtk+-$GTK_VERSION.tar.bz2 || exit 1
1160             bzcat gtk+-$GTK_VERSION.tar.bz2 | tar xf - || exit 1
1161         fi
1162         cd gtk+-$GTK_VERSION
1163         if [ $DARWIN_MAJOR_VERSION -ge "12" ]
1164         then
1165             #
1166             # GTK+ 2.24.10, at least, doesn't build on Mountain Lion with the
1167             # CUPS printing backend - either the CUPS API changed incompatibly
1168             # or the backend was depending on non-API implementation details.
1169             #
1170             # Configure it out, on Mountain Lion and later, for now.
1171             # (12 is the Darwin major version number in Mountain Lion.)
1172             #
1173             # Also, configure out libtiff and libjpeg; configure scripts
1174             # just ignore unknown --enable/--disable and --with/--without
1175             # options (at least they've always do so up to now).
1176             #
1177             CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --disable-cups --without-libtiff --without-libjpeg || exit 1
1178         else
1179             CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --without-libtiff --without-libjpeg || exit 1
1180         fi
1181         make $MAKE_BUILD_OPTS || exit 1
1182         $DO_MAKE_INSTALL || exit 1
1183         cd ..
1184         touch gtk+-$GTK_VERSION-done
1185     fi
1186 fi
1187
1188 #
1189 # Now we have reached a point where we can build everything including
1190 # the GUI (Wireshark), but not with any optional features such as
1191 # SNMP OID resolution, some forms of decryption, Lua scripting, playback
1192 # of audio, or GeoIP mapping of IP addresses.
1193 #
1194 # We now conditionally download optional libraries to support them;
1195 # the default is to download them all.
1196 #
1197
1198 if [ "$LIBSMI_VERSION" -a ! -f libsmi-$LIBSMI_VERSION-done ] ; then
1199     echo "Downloading, building, and installing libsmi:"
1200     [ -f libsmi-$LIBSMI_VERSION.tar.gz ] || curl -L -O https://www.ibr.cs.tu-bs.de/projects/libsmi/download/libsmi-$LIBSMI_VERSION.tar.gz || exit 1
1201     gzcat libsmi-$LIBSMI_VERSION.tar.gz | tar xf - || exit 1
1202     cd libsmi-$LIBSMI_VERSION
1203     CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
1204     make $MAKE_BUILD_OPTS || exit 1
1205     $DO_MAKE_INSTALL || exit 1
1206     cd ..
1207     touch libsmi-$LIBSMI_VERSION-done
1208 fi
1209
1210 if [ "$LIBGPG_ERROR_VERSION" -a ! -f libgpg-error-$LIBGPG_ERROR_VERSION-done ] ; then
1211     echo "Downloading, building, and installing libgpg-error:"
1212     [ -f libgpg-error-$LIBGPG_ERROR_VERSION.tar.bz2 ] || curl -L -O ftp://ftp.gnupg.org/gcrypt/libgpg-error/libgpg-error-$LIBGPG_ERROR_VERSION.tar.bz2 || exit 1
1213     bzcat libgpg-error-$LIBGPG_ERROR_VERSION.tar.bz2 | tar xf - || exit 1
1214     cd libgpg-error-$LIBGPG_ERROR_VERSION
1215     CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
1216     make $MAKE_BUILD_OPTS || exit 1
1217     $DO_MAKE_INSTALL || exit 1
1218     cd ..
1219     touch libgpg-error-$LIBGPG_ERROR_VERSION-done
1220 fi
1221
1222 if [ "$LIBGCRYPT_VERSION" -a ! -f libgcrypt-$LIBGCRYPT_VERSION-done ] ; then
1223     #
1224     # libgpg-error is required for libgcrypt.
1225     #
1226     if [ -z $LIBGPG_ERROR_VERSION ]
1227     then
1228         echo "libgcrypt requires libgpg-error, but you didn't install libgpg-error." 1>&2
1229         exit 1
1230     fi
1231
1232     echo "Downloading, building, and installing libgcrypt:"
1233     [ -f libgcrypt-$LIBGCRYPT_VERSION.tar.gz ] || curl -L -O ftp://ftp.gnupg.org/gcrypt/libgcrypt/libgcrypt-$LIBGCRYPT_VERSION.tar.gz || exit 1
1234     gzcat libgcrypt-$LIBGCRYPT_VERSION.tar.gz | tar xf - || exit 1
1235     cd libgcrypt-$LIBGCRYPT_VERSION
1236     #
1237     # The assembler language code is not compatible with the OS X
1238     # x86 assembler (or is it an x86-64 vs. x86-32 issue?).
1239     #
1240     # libgcrypt expects gnu89, not c99/gnu99, semantics for
1241     # "inline".  See, for example:
1242     #
1243     #    http://lists.freebsd.org/pipermail/freebsd-ports-bugs/2010-October/198809.html
1244     #
1245     CFLAGS="$CFLAGS -std=gnu89 $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --disable-asm || exit 1
1246     make $MAKE_BUILD_OPTS || exit 1
1247     $DO_MAKE_INSTALL || exit 1
1248     cd ..
1249     touch libgcrypt-$LIBGCRYPT_VERSION-done
1250 fi
1251
1252 if [ "$GNUTLS_VERSION" -a ! -f gnutls-$GNUTLS_VERSION-done ] ; then
1253     #
1254     # GnuTLS requires libgcrypt (or nettle, in newer versions).
1255     #
1256     if [ -z $LIBGCRYPT_VERSION ]
1257     then
1258         echo "GnuTLS requires libgcrypt, but you didn't install libgcrypt" 1>&2
1259         exit 1
1260     fi
1261
1262     echo "Downloading, building, and installing GnuTLS:"
1263     [ -f gnutls-$GNUTLS_VERSION.tar.bz2 ] || curl -L -O http://ftp.gnu.org/gnu/gnutls/gnutls-$GNUTLS_VERSION.tar.bz2 || exit 1
1264     bzcat gnutls-$GNUTLS_VERSION.tar.bz2 | tar xf - || exit 1
1265     cd gnutls-$GNUTLS_VERSION
1266     #
1267     # Use libgcrypt, not nettle.
1268     # XXX - is there some reason to prefer nettle?  Or does
1269     # Wireshark directly use libgcrypt routines?
1270     #
1271     CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --with-libgcrypt --without-p11-kit || exit 1
1272     make $MAKE_BUILD_OPTS || exit 1
1273     #
1274     # The pkgconfig file for GnuTLS says "requires zlib", but OS X,
1275     # while it supplies zlib, doesn't supply a pkgconfig file for
1276     # it.
1277     #
1278     # Patch the GnuTLS pkgconfig file not to require zlib.
1279     # (If the capabilities of GnuTLS that Wireshark uses don't
1280     # depend on building GnuTLS with zlib, an alternative would be
1281     # to configure it not to use zlib.)
1282     #
1283     patch -p0 lib/gnutls.pc.in <../../macosx-support-lib-patches/gnutls-pkgconfig.patch || exit 1
1284     $DO_MAKE_INSTALL || exit 1
1285     cd ..
1286     touch gnutls-$GNUTLS_VERSION-done
1287 fi
1288
1289 if [ "$LUA_VERSION" -a ! -f lua-$LUA_VERSION-done ] ; then
1290     echo "Downloading, building, and installing Lua:"
1291     [ -f lua-$LUA_VERSION.tar.gz ] || curl -L -O http://www.lua.org/ftp/lua-$LUA_VERSION.tar.gz || exit 1
1292     gzcat lua-$LUA_VERSION.tar.gz | tar xf - || exit 1
1293     cd lua-$LUA_VERSION
1294     make $MAKE_BUILD_OPTS macosx || exit 1
1295     $DO_MAKE_INSTALL || exit 1
1296     cd ..
1297     touch lua-$LUA_VERSION-done
1298 fi
1299
1300 if [ "$PORTAUDIO_VERSION" -a ! -f portaudio-done ] ; then
1301     echo "Downloading, building, and installing PortAudio:"
1302     [ -f $PORTAUDIO_VERSION.tgz ] || curl -L -O http://www.portaudio.com/archives/$PORTAUDIO_VERSION.tgz || exit 1
1303     gzcat $PORTAUDIO_VERSION.tgz | tar xf - || exit 1
1304     cd portaudio
1305     #
1306     # Un-comment an include that's required on Lion.
1307     #
1308     patch -p0 include/pa_mac_core.h <../../macosx-support-lib-patches/portaudio-pa_mac_core.h.patch
1309     #
1310     # Fix a bug that showed up with clang (but is a bug with any
1311     # compiler).
1312     #
1313     patch -p0 src/hostapi/coreaudio/pa_mac_core.c <../../macosx-support-lib-patches/portaudio-pa_mac_core.c.patch
1314     #
1315     # Disable fat builds - the configure script doesn't work right
1316     # with Xcode 4 if you leave them enabled, and we don't build
1317     # any other libraries fat (GLib, for example, would be very
1318     # hard to build fat), so there's no advantage to having PortAudio
1319     # built fat.
1320     #
1321     # Set the minimum OS X version to 10.4, to suppress some
1322     # deprecation warnings.  (Good luck trying to make any of
1323     # this build on an OS+Xcode with a pre-10.4 SDK; we don't
1324     # worry about the user requesting that.)
1325     #
1326     CFLAGS="$CFLAGS -mmacosx-version-min=10.4 $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --disable-mac-universal || exit 1
1327     make $MAKE_BUILD_OPTS || exit 1
1328     $DO_MAKE_INSTALL || exit 1
1329     cd ..
1330     touch portaudio-done
1331 fi
1332
1333 if [ "$GEOIP_VERSION" -a ! -f geoip-$GEOIP_VERSION-done ]
1334 then
1335     echo "Downloading, building, and installing GeoIP API:"
1336     [ -f GeoIP-$GEOIP_VERSION.tar.gz ] || curl -L -O http://geolite.maxmind.com/download/geoip/api/c/GeoIP-$GEOIP_VERSION.tar.gz || exit 1
1337     gzcat GeoIP-$GEOIP_VERSION.tar.gz | tar xf - || exit 1
1338     cd GeoIP-$GEOIP_VERSION
1339     CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
1340     #
1341     # Grr.  Their man pages "helpfully" have an ISO 8859-1
1342     # copyright symbol in the copyright notice, but OS X's
1343     # default character encoding is UTF-8.  sed on Mountain
1344     # Lion barfs at the "illegal character sequence" represented
1345     # by an ISO 8859-1 copyright symbol, as it's not a valid
1346     # UTF-8 sequence.
1347     #
1348     # iconv the relevant man pages into UTF-8.
1349     #
1350     for i in geoipupdate.1.in geoiplookup6.1.in geoiplookup.1.in
1351     do
1352         iconv -f iso8859-1 -t utf-8 man/"$i" >man/"$i".tmp &&
1353             mv man/"$i".tmp man/"$i"
1354     done
1355     make $MAKE_BUILD_OPTS || exit 1
1356     $DO_MAKE_INSTALL || exit 1
1357     cd ..
1358     touch geoip-$GEOIP_VERSION-done
1359 fi
1360
1361 if [ "$CARES_VERSION" -a ! -f geoip-$CARES_VERSION-done ]
1362 then
1363     echo "Downloading, building, and installing C-Ares API:"
1364     [ -f c-ares-$CARES_VERSION.tar.gz ] || curl -L -O http://c-ares.haxx.se/download/c-ares-$CARES_VERSION.tar.gz || exit 1
1365     gzcat c-ares-$CARES_VERSION.tar.gz | tar xf - || exit 1
1366     cd c-ares-$CARES_VERSION
1367     CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
1368     make $MAKE_BUILD_OPTS || exit 1
1369     $DO_MAKE_INSTALL || exit 1
1370     cd ..
1371     touch geoip-$CARES_VERSION-done
1372 fi
1373
1374 echo ""
1375
1376 echo "You are now prepared to build Wireshark. To do so do:"
1377 echo "export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/X11/lib/pkgconfig"
1378 echo ""
1379 if [ -n "$CMAKE" ]; then
1380     echo "mkdir build; cd build"
1381     echo "cmake .."
1382     echo
1383     echo "or"
1384     echo
1385 fi
1386 echo "./autogen.sh"
1387 echo "mkdir build; cd build"
1388 echo "../configure"
1389 echo ""
1390 echo "make $MAKE_BUILD_OPTS"
1391 echo "make install"
1392
1393 echo ""
1394
1395 echo "Make sure you are allowed capture access to the network devices"
1396 echo "See: http://wiki.wireshark.org/CaptureSetup/CapturePrivileges"
1397
1398 echo ""
1399
1400 exit 0