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