Fix the very long loop reported in https://bugs.wireshark.org/bugzilla/show_bug.cgi...
[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 # $Id$
5 #
6 # Trying to follow "Building Wireshark on SnowLeopard"
7 # given by Michael Tuexen at
8 # http://nplab.fh-muenster.de/groups/wiki/wiki/fb7a4/Building_Wireshark_on_SnowLeopard.html
9 #
10
11 DARWIN_MAJOR_VERSION=`uname -r | sed 's/\([0-9]*\).*/\1/'`
12
13 #
14 # Versions to download and install.
15 #
16 # The following libraries and tools are required.
17 #
18 GETTEXT_VERSION=0.18.2
19 GLIB_VERSION=2.36.0
20 PKG_CONFIG_VERSION=0.28
21 ATK_VERSION=2.8.0
22 PANGO_VERSION=1.30.1
23 PNG_VERSION=1.5.17
24 PIXMAN_VERSION=0.26.0
25 CAIRO_VERSION=1.12.2
26 GDK_PIXBUF_VERSION=2.28.0
27 if [ -z "$GTK3" ]; then
28     GTK_VERSION=2.24.17
29 else
30     GTK_VERSION=3.5.2
31 fi
32
33 #
34 # Some package need xz to unpack their current source.
35 # xz is not yet provided with OS X.
36 #
37 XZ_VERSION=5.0.4
38
39 # In case we want to build with cmake
40 CMAKE_VERSION=2.8.10.2
41
42 #
43 # The following libraries are optional.
44 # Comment them out if you don't want them, but note that some of
45 # the optional libraries are required by other optional libraries.
46 #
47 LIBSMI_VERSION=0.4.8
48 #
49 # libgpg-error is required for libgcrypt.
50 #
51 LIBGPG_ERROR_VERSION=1.10
52 #
53 # libgcrypt is required for GnuTLS.
54 # XXX - the link for "Libgcrypt source code" at
55 # http://www.gnupg.org/download/#libgcrypt is for 1.5.0, and is a bzip2
56 # file, but http://directory.fsf.org/project/libgcrypt/ lists only
57 # 1.4.6.
58 #
59 LIBGCRYPT_VERSION=1.5.0
60 GNUTLS_VERSION=2.12.19
61 # Stay with Lua 5.1 when updating until the code has been changed
62 # to support 5.2
63 LUA_VERSION=5.1.5
64 PORTAUDIO_VERSION=pa_stable_v19_20111121
65 #
66 # XXX - they appear to have an unversioned gzipped tarball for the
67 # current version; should we just download that, with some other
68 # way of specifying whether to download the GeoIP API?
69 #
70 GEOIP_VERSION=1.4.8
71
72 #
73 # GNU autotools; they're provided with releases up to Snow Leopard, but
74 # not in later releases.
75 #
76 if [[ $DARWIN_MAJOR_VERSION -gt 10 ]]; then
77     AUTOCONF_VERSION=2.69
78     AUTOMAKE_VERSION=1.13.3
79     LIBTOOL_VERSION=2.4.2
80 fi
81
82 uninstall() {
83     if [ -d macosx-support-libs ]
84     then
85         cd macosx-support-libs
86
87         #
88         # Uninstall items in the reverse order from the order in which they're
89         # installed.  Only uninstall if we're configured to install them and
90         # if the download/build/install process completed.
91         #
92         # We also do a "make distclean", so that we don't have leftovers from
93         # old configurations.
94         #
95         if [ "$GEOIP_VERSION" -a -f geoip-$GEOIP_VERSION-done ]
96         then
97             echo "Uninstalling GeoIP API:"
98             cd GeoIP-$GEOIP_VERSION
99             $DO_MAKE_UNINSTALL || exit 1
100             make distclean || exit 1
101             cd ..
102             rm geoip-$GEOIP_VERSION-done
103         fi
104
105         if [ "$PORTAUDIO_VERSION" -a -f portaudio-done ] ; then
106             echo "Uninstalling PortAudio:"
107             cd portaudio
108             $DO_MAKE_UNINSTALL || exit 1
109             make distclean || exit 1
110             cd ..
111             rm portaudio-done
112         fi
113
114         if [ "$LUA_VERSION" -a -f lua-$LUA_VERSION-done ] ; then
115             echo "Uninstalling Lua:"
116             #
117             # Lua has no "make uninstall", so just remove stuff manually.
118             # There's no configure script, so there's no need for
119             # "make distclean", either; just do "make clean".
120             #
121             (cd /usr/local/bin; $DO_RM -f lua luac)
122             (cd /usr/local/include; $DO_RM -f lua.h luaconf.h lualib.h lauxlib.h lua.hpp)
123             (cd /usr/local/lib; $DO_RM -f liblua.a)
124             (cd /usr/local/man; $DO_RM -f lua.1 luac.1)
125             cd lua-$LUA_VERSION
126             make clean || exit 1
127             cd ..
128             rm lua-$LUA_VERSION-done
129         fi
130
131         if [ "$GNUTLS_VERSION" -a -f gnutls-$GNUTLS_VERSION-done ] ; then
132             echo "Uninstalling GnuTLS:"
133             cd gnutls-$GNUTLS_VERSION
134             $DO_MAKE_UNINSTALL || exit 1
135             make distclean || exit 1
136             cd ..
137             rm gnutls-$GNUTLS_VERSION-done
138         fi
139
140         if [ "$LIBGCRYPT_VERSION" -a -f libgcrypt-$LIBGCRYPT_VERSION-done ] ; then
141             echo "Uninstalling libgcrypt:"
142             cd libgcrypt-$LIBGCRYPT_VERSION
143             $DO_MAKE_UNINSTALL || exit 1
144             make distclean || exit 1
145             cd ..
146             rm libgcrypt-$LIBGCRYPT_VERSION-done
147         fi
148
149         if [ "$LIBGPG_ERROR_VERSION" -a -f libgpg-error-$LIBGPG_ERROR_VERSION-done ] ; then
150             echo "Uninstalling libgpg-error:"
151             cd libgpg-error-$LIBGPG_ERROR_VERSION
152             $DO_MAKE_UNINSTALL || exit 1
153             make distclean || exit 1
154             cd ..
155             rm libgpg-error-$LIBGPG_ERROR_VERSION-done
156         fi
157
158         if [ "$LIBSMI_VERSION" -a -f libsmi-$LIBSMI_VERSION-done ] ; then
159             echo "Uninstalling libsmi:"
160             cd libsmi-$LIBSMI_VERSION
161             $DO_MAKE_UNINSTALL || exit 1
162             make distclean || exit 1
163             cd ..
164             rm libsmi-$LIBSMI_VERSION-done
165         fi
166
167         if [ -f gtk+-$GTK_VERSION-done ] ; then
168             echo "Uninstalling GTK+:"
169             cd gtk+-$GTK_VERSION
170             $DO_MAKE_UNINSTALL || exit 1
171             make distclean || exit 1
172             cd ..
173             rm gtk+-$GTK_VERSION-done
174         fi
175
176         if [ -f gdk-pixbuf-$GDK_PIXBUF_VERSION-done ] ; then
177             echo "Uninstalling gdk-pixbuf:"
178             cd gdk-pixbuf-$GDK_PIXBUF_VERSION
179             $DO_MAKE_UNINSTALL || exit 1
180             make distclean || exit 1
181             cd ..
182             rm gdk-pixbuf-$GDK_PIXBUF_VERSION-done
183         fi
184
185         if [ -f pango-$PANGO_VERSION-done ] ; then
186             echo "Uninstalling Pango:"
187             cd pango-$PANGO_VERSION
188             $DO_MAKE_UNINSTALL || exit 1
189             make distclean || exit 1
190             cd ..
191             rm pango-$PANGO_VERSION-done
192         fi
193
194         if [ -f atk-$ATK_VERSION-done ] ; then
195             echo "Uninstalling ATK:"
196             cd atk-$ATK_VERSION
197             $DO_MAKE_UNINSTALL || exit 1
198             make distclean || exit 1
199             cd ..
200             rm atk-$ATK_VERSION-done
201         fi
202
203         if [ -f cairo-$CAIRO_VERSION-done ] ; then
204             echo "Uninstalling Cairo:"
205             cd cairo-$CAIRO_VERSION
206             $DO_MAKE_INSTALL || exit 1
207             make distclean || exit 1
208             cd ..
209             rm cairo-$CAIRO_VERSION-done
210         fi
211
212         if [ -f pixman-$PIXMAN_VERSION-done ] ; then
213             echo "Uninstalling pixman:"
214             cd pixman-$PIXMAN_VERSION
215             $DO_MAKE_UNINSTALL || exit 1
216             make distclean || exit 1
217             cd ..
218             rm pixman-$PIXMAN_VERSION-done
219         fi
220
221         if [ -f libpng-$PNG_VERSION-done ] ; then
222             echo "Uninstalling libpng:"
223             cd libpng-$PNG_VERSION
224             $DO_MAKE_UNINSTALL || exit 1
225             make distclean || exit 1
226             cd ..
227             rm libpng-$PNG_VERSION-done
228         fi
229
230         if [ -f pkg-config-$PKG_CONFIG_VERSION-done ] ; then
231             echo "Uninstalling pkg-config:"
232             cd pkg-config-$PKG_CONFIG_VERSION
233             $DO_MAKE_UNINSTALL || exit 1
234             make distclean || exit 1
235             cd ..
236             rm pkg-config-$PKG_CONFIG_VERSION-done
237         fi
238
239         if [ -f glib-$GLIB_VERSION-done ] ; then
240             echo "Uninstalling GLib:"
241             cd glib-$GLIB_VERSION
242             $DO_MAKE_UNINSTALL || exit 1
243             make distclean || exit 1
244             cd ..
245             rm glib-$GLIB_VERSION-done
246         fi
247
248         if [ -f gettext-$GETTEXT_VERSION-done ] ; then
249             echo "Uninstalling GNU gettext:"
250             cd gettext-$GETTEXT_VERSION
251             $DO_MAKE_UNINSTALL || exit 1
252             make distclean || exit 1
253             cd ..
254             rm gettext-$GETTEXT_VERSION-done
255         fi
256
257         if [ -n "$CMAKE" -a -f cmake-$CMAKE_VERSION-done ]; then
258             echo "Uninstalling CMAKE:"
259             cd cmake-$CMAKE_VERSION
260             $DO_MAKE_UNINSTALL || exit 1
261             make distclean || exit 1
262             cd ..
263             rm cmake-$CMAKE_VERSION-done
264         fi
265
266         if [ "$LIBTOOL_VERSION" -a -f libtool-$LIBTOOL_VERSION-done ] ; then
267             echo "Uninstalling GNU libtool:"
268             cd libtool-$LIBTOOL_VERSION
269             mv /usr/local/bin/glibtool /usr/local/bin/libtool
270             mv /usr/local/bin/glibtoolize /usr/local/bin/libtoolize
271             $DO_MAKE_UNINSTALL || exit 1
272             make distclean || exit 1
273             cd ..
274             rm libtool-$LIBTOOL_VERSION-done
275         fi
276
277         if [ "$AUTOMAKE_VERSION" -a -f automake-$AUTOMAKE_VERSION-done ] ; then
278             echo "Uninstalling GNU automake:"
279             cd automake-$AUTOMAKE_VERSION
280             $DO_MAKE_UNINSTALL || exit 1
281             make distclean || exit 1
282             cd ..
283             rm automake-$AUTOMAKE_VERSION-done
284         fi
285
286         if [ "$AUTOCONF_VERSION" -a -f autoconf-$AUTOCONF_VERSION-done ] ; then
287             echo "Uninstalling GNU autoconf:"
288             cd autoconf-$AUTOCONF_VERSION
289             $DO_MAKE_UNINSTALL || exit 1
290             make distclean || exit 1
291             cd ..
292             rm autoconf-$AUTOCONF_VERSION-done
293         fi
294
295         if [ "$XZ_VERSION" -a -f xz-$XZ_VERSION-done ] ; then
296             echo "Uninstalling xz:"
297             cd xz-$XZ_VERSION
298             $DO_MAKE_UNINSTALL || exit 1
299             make distclean || exit 1
300             cd ..
301             rm xz-$XZ_VERSION-done
302         fi
303     fi
304 }
305
306 #
307 # Do we have permission to write in /usr/local?
308 #
309 # If so, assume we have permission to write in its subdirectories.
310 # (If that's not the case, this test needs to check the subdirectories
311 # as well.)
312 #
313 # If not, do "make install", "make uninstall", and the removes for Lua
314 # with sudo.
315 #
316 if [ -w /usr/local ]
317 then
318     DO_MAKE_INSTALL="make install"
319     DO_MAKE_UNINSTALL="make uninstall"
320     DO_RM="rm"
321 else
322     DO_MAKE_INSTALL="sudo make install"
323     DO_MAKE_UNINSTALL="sudo make uninstall"
324     DO_RM="sudo rm"
325 fi
326
327 #
328 # Parse command-line flags:
329 #
330 # -h - print help.
331 # -t <target> - build libraries so that they'll work on the specified
332 # version of OS X and later versions.
333 # -u - do an uninstall.
334 #
335 while getopts ht:u name
336 do
337     case $name in
338     u)
339         do_uninstall=yes
340         ;;
341     t)
342         min_osx_target="$OPTARG"
343         ;;
344     h|?)
345         echo "Usage: macosx-setup.sh [ -t <target> ] [ -u ]" 1>&1
346         exit 0
347         ;;
348     esac
349 done
350
351 if [ "$do_uninstall" = "yes" ]
352 then
353     uninstall
354     exit 0
355 fi
356
357 #
358 # To make this work on Leopard will take a lot of work.
359 #
360 # First of all, Leopard's /usr/X11/lib/libXdamage.la claims, at least
361 # with all software updates applied, that the Xdamage shared library
362 # is libXdamage.1.0.0.dylib, but it is, in fact, libXdamage.1.1.0.dylib.
363 # This causes problems when building GTK+, so the script would have to
364 # fix that file.
365 #
366 # Second of all, the version of fontconfig that comes with Leopard
367 # doesn't support FC_WEIGHT_EXTRABLACK, so we can't use any version
368 # of Pango newer than 1.22.4.
369 #
370 # However, Pango 1.22.4 doesn't work with versions of GLib after
371 # 2.29.6, because Pango 1.22.4 uses G_CONST_RETURN and GLib 2.29.8
372 # and later deprecate it (there doesn't appear to be a GLib 2.29.7).
373 # That means we'd either have to patch Pango not to use it (just
374 # use "const"; G_CONST_RETURN was there to allow code to choose whether
375 # to use "const" or not), or use GLib 2.29.6 or earlier.
376 #
377 # GLib 2.29.6 includes an implementation of g_bit_lock() that, on x86
378 # (32-bit and 64-bit), uses asms in a fashion ("asm volatile goto") that
379 # doesn't work with the Apple version of GCC 4.0.1, which is the compiler
380 # you get with Leopard+updates.  Apparently, that requires GCC 4.5 or
381 # later; recent versions of GLib check for that, but 2.29.6 doesn't.
382 # Therefore, we would have to patch glib/gbitlock.c to do what the
383 # newer versions of GLib do:
384 #
385 #  define a USE_ASM_GOTO macro that indicates whether "asm goto"
386 #  can be used:
387 #    #if (defined (i386) || defined (__amd64__))
388 #      #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
389 #        #define USE_ASM_GOTO 1
390 #      #endif
391 #    #endif
392 #
393 #  replace all occurrences of
394 #
395 #    #if defined (__GNUC__) && (defined (i386) || defined (__amd64__))
396 #
397 #  with
398 #
399 #    #ifdef USE_ASM_GOTO
400 #
401 # Using GLib 2.29.6 or earlier, however, would mean that we can't
402 # use a version of ATK later than 2.3.93, as those versions don't
403 # work with GLib 2.29.6.  The same applies to gdk-pixbuf; versions
404 # of gdk-pixbuf after 2.24.1 won't work with GLib 2.29.6.
405 #
406 # Once you've set this script up to use the older versions of the
407 # libraries, and built and installed them, you find that Wireshark,
408 # when built with them, crashes the X server that comes with Leopard,
409 # at least with all updates from Apple.  Maybe patching Pango rather
410 # than going with an older version of Pango would work.
411 #
412 # The Leopard Wireshark buildbot uses GTK+ 2.12.9, Cairo 1.6.4,
413 # Pango 1.20.2, and GLib 2.16.3, with an unknown version of ATK,
414 # and, I think, without gdk-pixbuf, as it hadn't been made a
415 # separate library from GTK+ as of GTK+ 2.12.9.  Its binaries
416 # don't crash the X server.
417 #
418 # However, if you try various older versions of Cairo, including
419 # 1.6.4 and at least some 1.8.x versions, when you try to build
420 # it, the build fails because it can't find png_set_longjmp_fn().
421 # I vaguely remember dealing with that, ages ago, but don't
422 # remember what I did; fixing *that* is left as an exercise for
423 # the reader.
424 #
425 # Oh, and if you're building with a version of GTK+ that doesn't
426 # have the gdk-pixbuf stuff in a separate library, you probably
427 # don't want to bother downloading or installing the gdk-pixbuf
428 # library, *and* you will need to configure GTK+ with
429 # --without-libtiff and --without-libjpeg (as we currently do
430 # with gdk-pixbuf).
431 #
432 if [[ $DARWIN_MAJOR_VERSION -le 9 ]]; then
433     echo "This script does not support any versions of OS X before Snow Leopard" 1>&2 
434     exit 1
435 fi
436
437 # To set up a GTK3 environment
438 # GTK3=1
439 # To build cmake
440 # CMAKE=1
441 #
442 # To build all libraries as 32-bit libraries uncomment the following three lines.
443 # export CFLAGS="$CFLAGS -arch i386"
444 # export CXXFLAGS="$CXXFLAGS -arch i386"
445 # export LDFLAGS="$LDFLAGS -arch i386"
446 #
447
448 # if no make options are present, set default options
449 if [ -z "$MAKE_BUILD_OPTS" ] ; then
450     # by default use 1.5x number of cores for parallel build
451     MAKE_BUILD_OPTS="-j $(( $(sysctl -n hw.logicalcpu) * 3 / 2))"
452 fi
453
454 #
455 # Was a minimum target release specified?
456 #
457 if [ ! -z "$min_osx_target" ]
458 then
459     #
460     # Look for the SDK for that release, and build libraries against
461     # it rather than against the headers and, more importantly,
462     # libraries that come with the OS, so that we don't end up with
463     # support libraries that only work on the OS version on which
464     # we built them, not earlier versions of the same release, or
465     # earlier releases if the minimum is earlier.
466     #
467     for i in /Developer/SDKs \
468         /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs \
469         /Library/Developer/CommandLineTools/SDKs
470     do
471         if [ -d "$i"/"MacOSX$min_osx_target.sdk" ]
472         then
473             SDKPATH="$i"/"MacOSX$min_osx_target.sdk"
474             break
475         fi
476     done
477
478     if [ -z "$SDKPATH" ]
479     then
480         echo "macosx-setup.sh: Couldn't find the SDK for OS X $min_osx_target" 1>&2
481         exit 1
482     fi
483
484     #
485     # Make sure there are links to /usr/local/include and /usr/local/lib
486     # in the SDK's usr/local.
487     #
488     if [ ! -e $SDKPATH/usr/local/include ]
489     then
490         if [ ! -d $SDKPATH/usr/local ]
491         then
492             sudo mkdir $SDKPATH/usr/local
493         fi
494         sudo ln -s /usr/local/include $SDKPATH/usr/local/include
495     fi
496     if [ ! -e $SDKPATH/usr/local/lib ]
497     then
498         if [ ! -d $SDKPATH/usr/local ]
499         then
500             sudo mkdir $SDKPATH/usr/local
501         fi
502         sudo ln -s /usr/local/lib $SDKPATH/usr/local/lib
503     fi
504
505     #
506     # Set the minimum OS version for which to build to the specified
507     # minimum target OS version, so we don't, for example, end up using
508     # linker features supported by the OS verson on which we're building
509     # but not by the target version.
510     #
511     VERSION_MIN_FLAGS="-mmacosx-version-min=$min_osx_target"
512
513     #
514     # Compile and link against the SDK.
515     #
516     SDKFLAGS="-isysroot $SDKPATH"
517
518     if [[ "$min_osx_target" == "10.5" ]]
519     then
520         #
521         # Cairo is part of Mac OS X 10.6 and later.
522         # The *headers* are supplied by 10.5, but the *libraries*
523         # aren't, so we have to build it if we're building for 10.5.
524         #
525         cairo_not_in_the_os=yes
526     fi
527 else
528     #
529     # We're building for the OS version on which we're running; if it's
530     # Leopard or earlier, we need to build Cairo - see above.
531     # The major version number of Darwin in 10.5 is 9.
532     #
533     if [[ $DARWIN_MAJOR_VERSION = "9" ]]
534     then
535         cairo_not_in_the_os=yes
536     fi
537 fi
538
539 #
540 # You need Xcode installed to get the compilers.
541 #
542 if [ ! -x /usr/bin/xcodebuild ]; then
543     echo "Please install Xcode first (should be available on DVD or from http://developer.apple.com/xcode/index.php)."
544     exit 1
545 fi
546
547 #
548 # You also need the X11 SDK; with at least some versions of OS X and
549 # Xcode, that is, I think, an optional install.  (Or it might be
550 # installed with X11, but I think *that* is an optional install on
551 # at least some versions of OS X.)
552 #
553 if [ ! -d /usr/X11/include ]; then
554     echo "Please install X11 and the X11 SDK first."
555     exit 1
556 fi
557
558 export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/X11/lib/pkgconfig
559
560 #
561 # Do all the downloads and untarring in a subdirectory, so all that
562 # stuff can be removed once we've installed the support libraries.
563 #
564 if [ ! -d macosx-support-libs ]
565 then
566     mkdir macosx-support-libs || exit 1
567 fi
568 cd macosx-support-libs
569
570 # Start with xz: It is the sole download format of glib later than 2.31.2
571 #
572 if [ "$XZ_VERSION" -a ! -f xz-$XZ_VERSION-done ] ; then
573     echo "Downloading, building, and installing xz:"
574     [ -f xz-$XZ_VERSION.tar.bz2 ] || curl -O http://tukaani.org/xz/xz-$XZ_VERSION.tar.bz2 || exit 1
575     bzcat xz-$XZ_VERSION.tar.bz2 | tar xf - || exit 1
576     cd xz-$XZ_VERSION
577     CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=0" ./configure || exit 1
578     make $MAKE_BUILD_OPTS || exit 1
579     $DO_MAKE_INSTALL || exit 1
580     cd ..
581     touch xz-$XZ_VERSION-done
582 fi
583
584 if [ "$AUTOCONF_VERSION" -a ! -f autoconf-$AUTOCONF_VERSION-done ] ; then
585     echo "Downloading, building and installing GNU autoconf..."
586     [ -f autoconf-$AUTOCONF_VERSION.tar.xz ] || curl -O ftp://ftp.gnu.org/gnu/autoconf/autoconf-$AUTOCONF_VERSION.tar.xz || exit 1
587     xzcat autoconf-$AUTOCONF_VERSION.tar.xz | tar xf - || exit 1
588     cd autoconf-$AUTOCONF_VERSION
589     ./configure || exit 1
590     make $MAKE_BUILD_OPTS || exit 1
591     $DO_MAKE_INSTALL || exit 1
592     cd ..
593     touch autoconf-$AUTOCONF_VERSION-done
594 fi
595
596 if [ "$AUTOMAKE_VERSION" -a ! -f automake-$AUTOMAKE_VERSION-done ] ; then
597     echo "Downloading, building and installing GNU automake..."
598     [ -f automake-$AUTOMAKE_VERSION.tar.xz ] || curl -O ftp://ftp.gnu.org/gnu/automake/automake-$AUTOMAKE_VERSION.tar.xz || exit 1
599     xzcat automake-$AUTOMAKE_VERSION.tar.xz | tar xf - || exit 1
600     cd automake-$AUTOMAKE_VERSION
601     ./configure || exit 1
602     make $MAKE_BUILD_OPTS || exit 1
603     $DO_MAKE_INSTALL || exit 1
604     cd ..
605     touch automake-$AUTOMAKE_VERSION-done
606 fi
607
608 if [ "$LIBTOOL_VERSION" -a ! -f libtool-$LIBTOOL_VERSION-done ] ; then
609     echo "Downloading, building and installing GNU libtool..."
610     [ -f libtool-$LIBTOOL_VERSION.tar.xz ] || curl -O ftp://ftp.gnu.org/gnu/libtool/libtool-$LIBTOOL_VERSION.tar.xz || exit 1
611     xzcat libtool-$LIBTOOL_VERSION.tar.xz | tar xf - || exit 1
612     cd libtool-$LIBTOOL_VERSION
613     ./configure || exit 1
614     make $MAKE_BUILD_OPTS || exit 1
615     $DO_MAKE_INSTALL || exit 1
616     mv /usr/local/bin/libtool /usr/local/bin/glibtool
617     mv /usr/local/bin/libtoolize /usr/local/bin/glibtoolize
618     cd ..
619     touch libtool-$LIBTOOL_VERSION-done
620 fi
621
622 if [ -n "$CMAKE" -a ! -f cmake-$CMAKE_VERSION-done ]; then
623   echo "Downloading, building, and installing CMAKE:"
624   cmake_dir=`expr $CMAKE_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
625   [ -f cmake-$CMAKE_VERSION.tar.gz ] || curl -O http://www.cmake.org/files/v$cmake_dir/cmake-$CMAKE_VERSION.tar.gz || exit 1
626   gzcat cmake-$CMAKE_VERSION.tar.gz | tar xf - || exit 1
627   cd cmake-$CMAKE_VERSION
628   ./bootstrap || exit 1
629   make $MAKE_BUILD_OPTS || exit 1
630   $DO_MAKE_INSTALL || exit 1
631   cd ..
632   touch cmake-$CMAKE_VERSION-done
633 fi
634
635 #
636 # Start with GNU gettext; GLib requires it, and OS X doesn't have it
637 # or a BSD-licensed replacement.
638 #
639 # At least on Lion with Xcode 4, _FORTIFY_SOURCE gets defined as 2
640 # by default, which causes, for example, stpncpy to be defined as
641 # a hairy macro that collides with the GNU gettext configure script's
642 # attempts to workaround AIX's lack of a declaration for stpncpy,
643 # with the result being a huge train wreck.  Define _FORTIFY_SOURCE
644 # as 0 in an attempt to keep the trains on separate tracks.
645 #
646 if [ ! -f gettext-$GETTEXT_VERSION-done ] ; then
647     echo "Downloading, building, and installing GNU gettext:"
648     [ -f gettext-$GETTEXT_VERSION.tar.gz ] || curl -O http://ftp.gnu.org/pub/gnu/gettext/gettext-$GETTEXT_VERSION.tar.gz || exit 1
649     gzcat gettext-$GETTEXT_VERSION.tar.gz | tar xf - || exit 1
650     cd gettext-$GETTEXT_VERSION
651     CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=0 $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
652     make $MAKE_BUILD_OPTS || exit 1
653     $DO_MAKE_INSTALL || exit 1
654     cd ..
655     touch gettext-$GETTEXT_VERSION-done
656 fi
657
658 if [ ! -f glib-$GLIB_VERSION-done ] ; then
659     echo "Downloading, building, and installing GLib:"
660     glib_dir=`expr $GLIB_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
661     [ -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
662     xzcat glib-$GLIB_VERSION.tar.xz | tar xf - || exit 1
663     cd glib-$GLIB_VERSION
664     #
665     # OS X ships with libffi, but doesn't provide its pkg-config file;
666     # explicitly specify LIBFFI_CFLAGS and LIBFFI_LIBS, so the configure
667     # script doesn't try to use pkg-config to get the appropriate
668     # C flags and loader flags.
669     #
670     # And, what's worse, at least with the version of Xcode that comes
671     # with Leopard, /usr/include/ffi/fficonfig.h doesn't define MACOSX,
672     # which causes the build of GLib to fail.  If we don't find
673     # "#define.*MACOSX" in /usr/include/ffi/fficonfig.h, explictly
674     # define it.
675     #
676     # While we're at it, suppress -Wformat-nonliteral to avoid a case
677     # where clang's stricter rules on when not to complain about
678     # non-literal format arguments cause it to complain about code
679     # that's safe but it wasn't told that.  See my comment #25 in
680     # GNOME bug 691608:
681     #
682     #   https://bugzilla.gnome.org/show_bug.cgi?id=691608#c25
683     #
684     # First, determine where the system include files are.  (It's not
685     # necessarily /usr/include.)  There's a bit of a greasy hack here;
686     # pre-5.x versions of the developer tools don't support the
687     # --show-sdk-path option, and will produce no output, so includedir
688     # will be set to /usr/include (in those older versions of the
689     # developer tools, there is a /usr/include directory).
690     #
691     includedir=`xcrun --show-sdk-path 2>/dev/null`/usr/include
692     if grep -qs '#define.*MACOSX' $includedir/ffi/fficonfig.h
693     then
694         # It's defined, nothing to do
695         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
696     else
697         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
698     fi
699     make $MAKE_BUILD_OPTS || exit 1
700     # Apply patch: we depend on libffi, but pkg-config doesn't get told.
701     patch -p0 <../../macosx-support-lib-patches/glib-pkgconfig.patch || exit 1
702     $DO_MAKE_INSTALL || exit 1
703     cd ..
704     touch glib-$GLIB_VERSION-done
705 fi
706
707 if [ ! -f pkg-config-$PKG_CONFIG_VERSION-done ] ; then
708     echo "Downloading, building, and installing pkg-config:"
709     [ -f pkg-config-$PKG_CONFIG_VERSION.tar.gz ] || curl -O http://pkgconfig.freedesktop.org/releases/pkg-config-$PKG_CONFIG_VERSION.tar.gz || exit 1
710     gzcat pkg-config-$PKG_CONFIG_VERSION.tar.gz | tar xf - || exit 1
711     cd pkg-config-$PKG_CONFIG_VERSION
712     # Avoid another pkgconfig call, because we don't have pkg-config
713     # yet
714     GLIB_CFLAGS="-I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include" GLIB_LIBS="-L/usr/local/lib -lglib-2.0 -lintl" CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
715     make $MAKE_BUILD_OPTS || exit 1
716     $DO_MAKE_INSTALL || exit 1
717     cd ..
718     touch pkg-config-$PKG_CONFIG_VERSION-done
719 fi
720
721 #
722 # Now we have reached a point where we can build everything but
723 # the GUI (Wireshark).
724 #
725 # GTK+ 3 requires a newer Cairo build than the one that comes with
726 # 10.6, so we build Cairo if we are using GTK+ 3.
727 #
728 # In 10.6 and 10.7, it's an X11 library; if we build with "native" GTK+
729 # rather than X11 GTK+, we might have to build and install Cairo.
730 # In 10.8 and later, there is no X11, but it's included in Xquartz;
731 # again, if we build with "native" GTK+, we'd have to build and install
732 # it.
733 #
734 if [[ -n "$GTK3" || "$cairo_not_in_the_os" = yes ]]; then
735     #
736     # Requirements for Cairo first
737     #
738     # The libpng that comes with the X11 for leopard has a bogus
739     # pkg-config file that lies about where the header files are,
740     # which causes other packages not to be able to find its
741     # headers.
742     #
743     if [ ! -f libpng-$PNG_VERSION-done ] ; then
744         echo "Downloading, building, and installing libpng:"
745         #
746         # The FTP site puts libpng x.y.* into a libpngxy directory.
747         #
748         subdir=`echo $PNG_VERSION | sed 's/\([1-9][0-9]*\)\.\([1-9][0-9]*\).*/libpng\1\2'/`
749         [ -f libpng-$PNG_VERSION.tar.xz ] || curl -O ftp://ftp.simplesystems.org/pub/libpng/png/src/$subdir/libpng-$PNG_VERSION.tar.xz
750         xzcat libpng-$PNG_VERSION.tar.xz | tar xf - || exit 1
751         cd libpng-$PNG_VERSION
752         CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
753         make $MAKE_BUILD_OPTS || exit 1
754         $DO_MAKE_INSTALL || exit 1
755         cd ..
756         touch libpng-$PNG_VERSION-done
757       fi
758
759     #
760     # The libpixman that comes with the X11 for Leopard is too old
761     # to support Cairo's image surface backend feature (which requires
762     # pixman-1 >= 0.22.0).
763     #
764     if [ ! -f pixman-$PIXMAN_VERSION-done ] ; then
765         echo "Downloading, building, and installing pixman:"
766         [ -f pixman-$PIXMAN_VERSION.tar.gz ] || curl -O http://www.cairographics.org/releases/pixman-$PIXMAN_VERSION.tar.gz
767         gzcat pixman-$PIXMAN_VERSION.tar.gz | tar xf - || exit 1
768         cd pixman-$PIXMAN_VERSION
769         CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
770         make $MAKE_BUILD_OPTS || exit 1
771         $DO_MAKE_INSTALL || exit 1
772         cd ..
773         touch pixman-$PIXMAN_VERSION-done
774     fi
775
776     #
777     # And now Cairo itself.
778     #
779     if [ ! -f cairo-$CAIRO_VERSION-done ] ; then
780         echo "Downloading, building, and installing Cairo:"
781         CAIRO_MAJOR_VERSION="`expr $CAIRO_VERSION : '\([0-9][0-9]*\).*'`"
782         CAIRO_MINOR_VERSION="`expr $CAIRO_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
783         CAIRO_DOTDOT_VERSION="`expr $CAIRO_VERSION : '[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
784         if [[ $CAIRO_MAJOR_VERSION -gt 1 ||
785               $CAIRO_MINOR_VERSION -gt 12 ||
786               ($CAIRO_MINOR_VERSION -eq 12 && $CAIRO_DOTDOT_VERSION -ge 2) ]]
787         then
788             #
789             # Starting with Cairo 1.12.2, the tarballs are compressed with
790             # xz rather than gzip.
791             #
792             [ -f cairo-$CAIRO_VERSION.tar.xz ] || curl -O http://cairographics.org/releases/cairo-$CAIRO_VERSION.tar.xz || exit 1
793             xzcat cairo-$CAIRO_VERSION.tar.xz | tar xf - || exit 1
794         else
795             [ -f cairo-$CAIRO_VERSION.tar.gz ] || curl -O http://cairographics.org/releases/cairo-$CAIRO_VERSION.tar.gz || exit 1
796             gzcat cairo-$CAIRO_VERSION.tar.gz | tar xf - || exit 1
797         fi
798         cd cairo-$CAIRO_VERSION
799         # CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --enable-quartz=no || exit 1
800         # Maybe follow http://cairographics.org/end_to_end_build_for_mac_os_x/
801         CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --enable-quartz=yes || exit 1
802         #
803         # We must avoid the version of libpng that comes with X11; the
804         # only way I've found to force that is to forcibly set INCLUDES
805         # when we do the build, so that this comes before CAIRO_CFLAGS,
806         # which has -I/usr/X11/include added to it before anything
807         # connected to libpng is.
808         #
809         INCLUDES="-I/usr/local/include/libpng15" make $MAKE_BUILD_OPTS || exit 1
810         $DO_MAKE_INSTALL || exit 1
811         cd ..
812         touch cairo-$CAIRO_VERSION-done
813     fi
814 fi
815
816 if [ ! -f atk-$ATK_VERSION-done ] ; then
817     echo "Downloading, building, and installing ATK:"
818     atk_dir=`expr $ATK_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
819     [ -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
820     xzcat atk-$ATK_VERSION.tar.xz | tar xf - || exit 1
821     cd atk-$ATK_VERSION
822     CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
823     make $MAKE_BUILD_OPTS || exit 1
824     $DO_MAKE_INSTALL || exit 1
825     cd ..
826     touch atk-$ATK_VERSION-done
827 fi
828
829 if [ ! -f pango-$PANGO_VERSION-done ] ; then
830     echo "Downloading, building, and installing Pango:"
831     pango_dir=`expr $PANGO_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
832     PANGO_MAJOR_VERSION="`expr $PANGO_VERSION : '\([0-9][0-9]*\).*'`"
833     PANGO_MINOR_VERSION="`expr $PANGO_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
834     if [[ $PANGO_MAJOR_VERSION -gt 1 ||
835           $PANGO_MINOR_VERSION -ge 29 ]]
836     then
837         #
838         # Starting with Pango 1.29, the tarballs are compressed with
839         # xz rather than bzip2.
840         #
841         [ -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
842         xzcat pango-$PANGO_VERSION.tar.xz | tar xf - || exit 1
843     else
844         [ -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
845         gzcat pango-$PANGO_VERSION.tar.bz2 | tar xf - || exit 1
846     fi
847     cd pango-$PANGO_VERSION
848     CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
849     make $MAKE_BUILD_OPTS || exit 1
850     $DO_MAKE_INSTALL || exit 1
851     cd ..
852     touch pango-$PANGO_VERSION-done
853 fi
854
855 if [ ! -f gdk-pixbuf-$GDK_PIXBUF_VERSION-done ] ; then
856     echo "Downloading, building, and installing gdk-pixbuf:"
857     gdk_pixbuf_dir=`expr $GDK_PIXBUF_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
858     [ -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
859     xzcat gdk-pixbuf-$GDK_PIXBUF_VERSION.tar.xz | tar xf - || exit 1
860     cd gdk-pixbuf-$GDK_PIXBUF_VERSION
861     CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --without-libtiff --without-libjpeg || exit 1
862     make $MAKE_BUILD_OPTS || exit 1
863     $DO_MAKE_INSTALL || exit 1
864     cd ..
865     touch gdk-pixbuf-$GDK_PIXBUF_VERSION-done
866 fi
867
868 if [ ! -f gtk+-$GTK_VERSION-done ] ; then
869     echo "Downloading, building, and installing GTK+:"
870     gtk_dir=`expr $GTK_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
871     GTK_MAJOR_VERSION="`expr $GTK_VERSION : '\([0-9][0-9]*\).*'`"
872     GTK_MINOR_VERSION="`expr $GTK_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
873     GTK_DOTDOT_VERSION="`expr $GTK_VERSION : '[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
874     if [[ $GTK_MAJOR_VERSION -gt 2 ||
875           $GTK_MINOR_VERSION -gt 24 ||
876          ($GTK_MINOR_VERSION -eq 24 && $GTK_DOTDOT_VERSION -ge 5) ]]
877     then
878         #
879         # Starting with GTK+ 2.24.5, the tarballs are compressed with
880         # xz rather than gzip, in addition to bzip2; use xz, as we've
881         # built and installed it, and as xz compresses better than
882         # bzip2 so the tarballs take less time to download.
883         #
884         [ -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
885         xzcat gtk+-$GTK_VERSION.tar.xz | tar xf - || exit 1
886     else
887         [ -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
888         gzcat gtk+-$GTK_VERSION.tar.bz2 | tar xf - || exit 1
889     fi
890     cd gtk+-$GTK_VERSION
891     if [ $DARWIN_MAJOR_VERSION -ge "12" ]
892     then
893         #
894         # GTK+ 2.24.10, at least, doesn't build on Mountain Lion with the
895         # CUPS printing backend - either the CUPS API changed incompatibly
896         # or the backend was depending on non-API implementation details.
897         #
898         # Configure it out, on Mountain Lion and later, for now.
899         # (12 is the Darwin major version number in Mountain Lion.)
900         #
901         CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --disable-cups || exit 1
902     else
903         CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
904     fi
905     make $MAKE_BUILD_OPTS || exit 1
906     $DO_MAKE_INSTALL || exit 1
907     cd ..
908     touch gtk+-$GTK_VERSION-done
909 fi
910
911 #
912 # Now we have reached a point where we can build everything including
913 # the GUI (Wireshark), but not with any optional features such as
914 # SNMP OID resolution, some forms of decryption, Lua scripting, playback
915 # of audio, or GeoIP mapping of IP addresses.
916 #
917 # We now conditionally download optional libraries to support them;
918 # the default is to download them all.
919 #
920
921 if [ "$LIBSMI_VERSION" -a ! -f libsmi-$LIBSMI_VERSION-done ] ; then
922     echo "Downloading, building, and installing libsmi:"
923     [ -f libsmi-$LIBSMI_VERSION.tar.gz ] || curl -L -O ftp://ftp.ibr.cs.tu-bs.de/pub/local/libsmi/libsmi-$LIBSMI_VERSION.tar.gz || exit 1
924     gzcat libsmi-$LIBSMI_VERSION.tar.gz | tar xf - || exit 1
925     cd libsmi-$LIBSMI_VERSION
926     CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
927     make $MAKE_BUILD_OPTS || exit 1
928     $DO_MAKE_INSTALL || exit 1
929     cd ..
930     touch libsmi-$LIBSMI_VERSION-done
931 fi
932
933 if [ "$LIBGPG_ERROR_VERSION" -a ! -f libgpg-error-$LIBGPG_ERROR_VERSION-done ] ; then
934     echo "Downloading, building, and installing libgpg-error:"
935     [ -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
936     bzcat libgpg-error-$LIBGPG_ERROR_VERSION.tar.bz2 | tar xf - || exit 1
937     cd libgpg-error-$LIBGPG_ERROR_VERSION
938     CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
939     make $MAKE_BUILD_OPTS || exit 1
940     $DO_MAKE_INSTALL || exit 1
941     cd ..
942     touch libgpg-error-$LIBGPG_ERROR_VERSION-done
943 fi
944
945 if [ "$LIBGCRYPT_VERSION" -a ! -f libgcrypt-$LIBGCRYPT_VERSION-done ] ; then
946     #
947     # libgpg-error is required for libgcrypt.
948     #
949     if [ -z $LIBGPG_ERROR_VERSION ]
950     then
951         echo "libgcrypt requires libgpg-error, but you didn't install libgpg-error." 1>&2
952         exit 1
953     fi
954
955     echo "Downloading, building, and installing libgcrypt:"
956     [ -f libgcrypt-$LIBGCRYPT_VERSION.tar.gz ] || curl -L -O ftp://ftp.gnupg.org/gcrypt/libgcrypt/libgcrypt-$LIBGCRYPT_VERSION.tar.gz || exit 1
957     gzcat libgcrypt-$LIBGCRYPT_VERSION.tar.gz | tar xf - || exit 1
958     cd libgcrypt-$LIBGCRYPT_VERSION
959     #
960     # The assembler language code is not compatible with the OS X
961     # x86 assembler (or is it an x86-64 vs. x86-32 issue?).
962     #
963     # libgcrypt expects gnu89, not c99/gnu99, semantics for
964     # "inline".  See, for example:
965     #
966     #    http://lists.freebsd.org/pipermail/freebsd-ports-bugs/2010-October/198809.html
967     #
968     CFLAGS="$CFLAGS -std=gnu89 $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --disable-asm || exit 1
969     make $MAKE_BUILD_OPTS || exit 1
970     $DO_MAKE_INSTALL || exit 1
971     cd ..
972     touch libgcrypt-$LIBGCRYPT_VERSION-done
973 fi
974
975 if [ "$GNUTLS_VERSION" -a ! -f gnutls-$GNUTLS_VERSION-done ] ; then
976     #
977     # GnuTLS requires libgcrypt (or nettle, in newer versions).
978     #
979     if [ -z $LIBGCRYPT_VERSION ]
980     then
981         echo "GnuTLS requires libgcrypt, but you didn't install libgcrypt" 1>&2
982         exit 1
983     fi
984
985     echo "Downloading, building, and installing GnuTLS:"
986     [ -f gnutls-$GNUTLS_VERSION.tar.bz2 ] || curl -L -O http://ftp.gnu.org/gnu/gnutls/gnutls-$GNUTLS_VERSION.tar.bz2 || exit 1
987     bzcat gnutls-$GNUTLS_VERSION.tar.bz2 | tar xf - || exit 1
988     cd gnutls-$GNUTLS_VERSION
989     #
990     # Use libgcrypt, not nettle.
991     # XXX - is there some reason to prefer nettle?  Or does
992     # Wireshark directly use libgcrypt routines?
993     #
994     CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --with-libgcrypt --without-p11-kit || exit 1
995     make $MAKE_BUILD_OPTS || exit 1
996     #
997     # The pkgconfig file for GnuTLS says "requires zlib", but OS X,
998     # while it supplies zlib, doesn't supply a pkgconfig file for
999     # it.
1000     #
1001     # Patch the GnuTLS pkgconfig file not to require zlib.
1002     # (If the capabilities of GnuTLS that Wireshark uses don't
1003     # depend on building GnuTLS with zlib, an alternative would be
1004     # to configure it not to use zlib.)
1005     #
1006     patch -p0 lib/gnutls.pc.in <../../macosx-support-lib-patches/gnutls-pkgconfig.patch || exit 1
1007     $DO_MAKE_INSTALL || exit 1
1008     cd ..
1009     touch gnutls-$GNUTLS_VERSION-done
1010 fi
1011
1012 if [ "$LUA_VERSION" -a ! -f lua-$LUA_VERSION-done ] ; then
1013     echo "Downloading, building, and installing Lua:"
1014     [ -f lua-$LUA_VERSION.tar.gz ] || curl -L -O http://www.lua.org/ftp/lua-$LUA_VERSION.tar.gz || exit 1
1015     gzcat lua-$LUA_VERSION.tar.gz | tar xf - || exit 1
1016     cd lua-$LUA_VERSION
1017     make $MAKE_BUILD_OPTS macosx || exit 1
1018     $DO_MAKE_INSTALL || exit 1
1019     cd ..
1020     touch lua-$LUA_VERSION-done
1021 fi
1022
1023 if [ "$PORTAUDIO_VERSION" -a ! -f portaudio-done ] ; then
1024     echo "Downloading, building, and installing PortAudio:"
1025     [ -f $PORTAUDIO_VERSION.tgz ] || curl -L -O http://www.portaudio.com/archives/$PORTAUDIO_VERSION.tgz || exit 1
1026     gzcat $PORTAUDIO_VERSION.tgz | tar xf - || exit 1
1027     cd portaudio
1028     #
1029     # Un-comment an include that's required on Lion.
1030     #
1031     patch -p0 include/pa_mac_core.h <../../macosx-support-lib-patches/portaudio-pa_mac_core.h.patch
1032     #
1033     # Fix a bug that showed up with clang (but is a bug with any
1034     # compiler).
1035     #
1036     patch -p0 src/hostapi/coreaudio/pa_mac_core.c <../../macosx-support-lib-patches/portaudio-pa_mac_core.c.patch
1037     #
1038     # Disable fat builds - the configure script doesn't work right
1039     # with Xcode 4 if you leave them enabled, and we don't build
1040     # any other libraries fat (GLib, for example, would be very
1041     # hard to build fat), so there's no advantage to having PortAudio
1042     # built fat.
1043     #
1044     # Set the minimum OS X version to 10.4, to suppress some
1045     # deprecation warnings.  (Good luck trying to make any of
1046     # this build on an OS+Xcode with a pre-10.4 SDK; we don't
1047     # worry about the user requesting that.)
1048     #
1049     CFLAGS="$CFLAGS -mmacosx-version-min=10.4 $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --disable-mac-universal || exit 1
1050     make $MAKE_BUILD_OPTS || exit 1
1051     $DO_MAKE_INSTALL || exit 1
1052     cd ..
1053     touch portaudio-done
1054 fi
1055
1056 if [ "$GEOIP_VERSION" -a ! -f geoip-$GEOIP_VERSION-done ]
1057 then
1058     echo "Downloading, building, and installing GeoIP API:"
1059     [ -f GeoIP-$GEOIP_VERSION.tar.gz ] || curl -L -O http://geolite.maxmind.com/download/geoip/api/c/GeoIP-$GEOIP_VERSION.tar.gz || exit 1
1060     gzcat GeoIP-$GEOIP_VERSION.tar.gz | tar xf - || exit 1
1061     cd GeoIP-$GEOIP_VERSION
1062     CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
1063     #
1064     # Grr.  Their man pages "helpfully" have an ISO 8859-1
1065     # copyright symbol in the copyright notice, but OS X's
1066     # default character encoding is UTF-8.  sed on Mountain
1067     # Lion barfs at the "illegal character sequence" represented
1068     # by an ISO 8859-1 copyright symbol, as it's not a valid
1069     # UTF-8 sequence.
1070     #
1071     # iconv the relevant man pages into UTF-8.
1072     #
1073     for i in geoipupdate.1.in geoiplookup6.1.in geoiplookup.1.in
1074     do
1075         iconv -f iso8859-1 -t utf-8 man/"$i" >man/"$i".tmp &&
1076             mv man/"$i".tmp man/"$i"
1077     done
1078     make $MAKE_BUILD_OPTS || exit 1
1079     $DO_MAKE_INSTALL || exit 1
1080     cd ..
1081     touch geoip-$GEOIP_VERSION-done
1082 fi
1083
1084 echo ""
1085
1086 echo "You are now prepared to build Wireshark. To do so do:"
1087 echo "export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/X11/lib/pkgconfig"
1088 echo ""
1089 if [ -n "$CMAKE" ]; then
1090     echo "mkdir build; cd build"
1091     echo "cmake .."
1092     echo
1093     echo "or"
1094     echo
1095 fi
1096 echo "./autogen.sh"
1097 echo "mkdir build; cd build"
1098 echo "../configure"
1099 echo ""
1100 echo "make $MAKE_BUILD_OPTS"
1101 echo "make install"
1102
1103 echo ""
1104
1105 echo "Make sure you are allowed capture access to the network devices"
1106 echo "See: http://wiki.wireshark.org/CaptureSetup/CapturePrivileges"
1107
1108 echo ""
1109
1110 exit 0