8b9733bd5835d0c6815c1249f03e0ca3abeebf4c
[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.14
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 fi
518
519 #
520 # You need Xcode installed to get the compilers.
521 #
522 if [ ! -x /usr/bin/xcodebuild ]; then
523     echo "Please install Xcode first (should be available on DVD or from http://developer.apple.com/xcode/index.php)."
524     exit 1
525 fi
526
527 #
528 # You also need the X11 SDK; with at least some versions of OS X and
529 # Xcode, that is, I think, an optional install.  (Or it might be
530 # installed with X11, but I think *that* is an optional install on
531 # at least some versions of OS X.)
532 #
533 if [ ! -d /usr/X11/include ]; then
534     echo "Please install X11 and the X11 SDK first."
535     exit 1
536 fi
537
538 export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/X11/lib/pkgconfig
539
540 #
541 # Do all the downloads and untarring in a subdirectory, so all that
542 # stuff can be removed once we've installed the support libraries.
543 #
544 if [ ! -d macosx-support-libs ]
545 then
546     mkdir macosx-support-libs || exit 1
547 fi
548 cd macosx-support-libs
549
550 # Start with xz: It is the sole download format of glib later than 2.31.2
551 #
552 if [ "$XZ_VERSION" -a ! -f xz-$XZ_VERSION-done ] ; then
553     echo "Downloading, building, and installing xz:"
554     [ -f xz-$XZ_VERSION.tar.bz2 ] || curl -O http://tukaani.org/xz/xz-$XZ_VERSION.tar.bz2 || exit 1
555     bzcat xz-$XZ_VERSION.tar.bz2 | tar xf - || exit 1
556     cd xz-$XZ_VERSION
557     CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=0" ./configure || exit 1
558     make $MAKE_BUILD_OPTS || exit 1
559     $DO_MAKE_INSTALL || exit 1
560     cd ..
561     touch xz-$XZ_VERSION-done
562 fi
563
564 if [ "$AUTOCONF_VERSION" -a ! -f autoconf-$AUTOCONF_VERSION-done ] ; then
565     echo "Downloading, building and installing GNU autoconf..."
566     [ -f autoconf-$AUTOCONF_VERSION.tar.xz ] || curl -O ftp://ftp.gnu.org/gnu/autoconf/autoconf-$AUTOCONF_VERSION.tar.xz || exit 1
567     xzcat autoconf-$AUTOCONF_VERSION.tar.xz | tar xf - || exit 1
568     cd autoconf-$AUTOCONF_VERSION
569     ./configure || exit 1
570     make $MAKE_BUILD_OPTS || exit 1
571     $DO_MAKE_INSTALL || exit 1
572     cd ..
573     touch autoconf-$AUTOCONF_VERSION-done
574 fi
575
576 if [ "$AUTOMAKE_VERSION" -a ! -f automake-$AUTOMAKE_VERSION-done ] ; then
577     echo "Downloading, building and installing GNU automake..."
578     [ -f automake-$AUTOMAKE_VERSION.tar.xz ] || curl -O ftp://ftp.gnu.org/gnu/automake/automake-$AUTOMAKE_VERSION.tar.xz || exit 1
579     xzcat automake-$AUTOMAKE_VERSION.tar.xz | tar xf - || exit 1
580     cd automake-$AUTOMAKE_VERSION
581     ./configure || exit 1
582     make $MAKE_BUILD_OPTS || exit 1
583     $DO_MAKE_INSTALL || exit 1
584     cd ..
585     touch automake-$AUTOMAKE_VERSION-done
586 fi
587
588 if [ "$LIBTOOL_VERSION" -a ! -f libtool-$LIBTOOL_VERSION-done ] ; then
589     echo "Downloading, building and installing GNU libtool..."
590     [ -f libtool-$LIBTOOL_VERSION.tar.xz ] || curl -O ftp://ftp.gnu.org/gnu/libtool/libtool-$LIBTOOL_VERSION.tar.xz || exit 1
591     xzcat libtool-$LIBTOOL_VERSION.tar.xz | tar xf - || exit 1
592     cd libtool-$LIBTOOL_VERSION
593     ./configure || exit 1
594     make $MAKE_BUILD_OPTS || exit 1
595     $DO_MAKE_INSTALL || exit 1
596     mv /usr/local/bin/libtool /usr/local/bin/glibtool
597     mv /usr/local/bin/libtoolize /usr/local/bin/glibtoolize
598     cd ..
599     touch libtool-$LIBTOOL_VERSION-done
600 fi
601
602 if [ -n "$CMAKE" -a ! -f cmake-$CMAKE_VERSION-done ]; then
603   echo "Downloading, building, and installing CMAKE:"
604   cmake_dir=`expr $CMAKE_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
605   [ -f cmake-$CMAKE_VERSION.tar.gz ] || curl -O http://www.cmake.org/files/v$cmake_dir/cmake-$CMAKE_VERSION.tar.gz || exit 1
606   gzcat cmake-$CMAKE_VERSION.tar.gz | tar xf - || exit 1
607   cd cmake-$CMAKE_VERSION
608   ./bootstrap || exit 1
609   make $MAKE_BUILD_OPTS || exit 1
610   $DO_MAKE_INSTALL || exit 1
611   cd ..
612   touch cmake-$CMAKE_VERSION-done
613 fi
614
615 #
616 # Start with GNU gettext; GLib requires it, and OS X doesn't have it
617 # or a BSD-licensed replacement.
618 #
619 # At least on Lion with Xcode 4, _FORTIFY_SOURCE gets defined as 2
620 # by default, which causes, for example, stpncpy to be defined as
621 # a hairy macro that collides with the GNU gettext configure script's
622 # attempts to workaround AIX's lack of a declaration for stpncpy,
623 # with the result being a huge train wreck.  Define _FORTIFY_SOURCE
624 # as 0 in an attempt to keep the trains on separate tracks.
625 #
626 if [ ! -f gettext-$GETTEXT_VERSION-done ] ; then
627     echo "Downloading, building, and installing GNU gettext:"
628     [ -f gettext-$GETTEXT_VERSION.tar.gz ] || curl -O http://ftp.gnu.org/pub/gnu/gettext/gettext-$GETTEXT_VERSION.tar.gz || exit 1
629     gzcat gettext-$GETTEXT_VERSION.tar.gz | tar xf - || exit 1
630     cd gettext-$GETTEXT_VERSION
631     CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=0 $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
632     make $MAKE_BUILD_OPTS || exit 1
633     $DO_MAKE_INSTALL || exit 1
634     cd ..
635     touch gettext-$GETTEXT_VERSION-done
636 fi
637
638 if [ ! -f glib-$GLIB_VERSION-done ] ; then
639     echo "Downloading, building, and installing GLib:"
640     glib_dir=`expr $GLIB_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
641     [ -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
642     xzcat glib-$GLIB_VERSION.tar.xz | tar xf - || exit 1
643     cd glib-$GLIB_VERSION
644     #
645     # OS X ships with libffi, but doesn't provide its pkg-config file;
646     # explicitly specify LIBFFI_CFLAGS and LIBFFI_LIBS, so the configure
647     # script doesn't try to use pkg-config to get the appropriate
648     # C flags and loader flags.
649     #
650     # And, what's worse, at least with the version of Xcode that comes
651     # with Leopard, /usr/include/ffi/fficonfig.h doesn't define MACOSX,
652     # which causes the build of GLib to fail.  If we don't find
653     # "#define.*MACOSX" in /usr/include/ffi/fficonfig.h, explictly
654     # define it.
655     #
656     # While we're at it, suppress -Wformat-nonliteral to avoid a case
657     # where clang's stricter rules on when not to complain about
658     # non-literal format arguments cause it to complain about code
659     # that's safe but it wasn't told that.  See my comment #25 in
660     # GNOME bug 691608:
661     #
662     #   https://bugzilla.gnome.org/show_bug.cgi?id=691608#c25
663     #
664     # First, determine where the system include files are.  (It's not
665     # necessarily /usr/include.)  There's a bit of a greasy hack here;
666     # pre-5.x versions of the developer tools don't support the
667     # --show-sdk-path option, and will produce no output, so includedir
668     # will be set to /usr/include (in those older versions of the
669     # developer tools, there is a /usr/include directory).
670     #
671     includedir=`xcrun --show-sdk-path 2>/dev/null`/usr/include
672     if grep -qs '#define.*MACOSX' $includedir/ffi/fficonfig.h
673     then
674         # It's defined, nothing to do
675         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
676     else
677         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
678     fi
679     make $MAKE_BUILD_OPTS || exit 1
680     # Apply patch: we depend on libffi, but pkg-config doesn't get told.
681     patch -p0 <../../macosx-support-lib-patches/glib-pkgconfig.patch || exit 1
682     $DO_MAKE_INSTALL || exit 1
683     cd ..
684     touch glib-$GLIB_VERSION-done
685 fi
686
687 if [ ! -f pkg-config-$PKG_CONFIG_VERSION-done ] ; then
688     echo "Downloading, building, and installing pkg-config:"
689     [ -f pkg-config-$PKG_CONFIG_VERSION.tar.gz ] || curl -O http://pkgconfig.freedesktop.org/releases/pkg-config-$PKG_CONFIG_VERSION.tar.gz || exit 1
690     gzcat pkg-config-$PKG_CONFIG_VERSION.tar.gz | tar xf - || exit 1
691     cd pkg-config-$PKG_CONFIG_VERSION
692     # Avoid another pkgconfig call, because we don't have pkg-config
693     # yet
694     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
695     make $MAKE_BUILD_OPTS || exit 1
696     $DO_MAKE_INSTALL || exit 1
697     cd ..
698     touch pkg-config-$PKG_CONFIG_VERSION-done
699 fi
700
701 #
702 # Now we have reached a point where we can build everything but
703 # the GUI (Wireshark).
704 #
705 # Cairo is part of Mac OS X 10.6 and 10.7.
706 # The *headers* are supplied by 10.5, but the *libraries* aren't, so
707 # we have to build it on 10.5.
708 # GTK+ 3 requires a newer Cairo build than the one that comes with
709 # 10.6, so we build Cairo if we are using GTK+ 3.
710 # In 10.6 and 10.7, it's an X11 library; if we build with "native" GTK+
711 # rather than X11 GTK+, we might have to build and install Cairo.
712 # The major version number of Darwin in 10.5 is 9.
713 #
714 if [[ -n "$GTK3" || $DARWIN_MAJOR_VERSION = "9" ]]; then
715     #
716     # Requirements for Cairo first
717     #
718     # The libpng that comes with the X11 for leopard has a bogus
719     # pkg-config file that lies about where the header files are,
720     # which causes other packages not to be able to find its
721     # headers.
722     #
723     if [ ! -f libpng-$PNG_VERSION-done ] ; then
724         echo "Downloading, building, and installing libpng:"
725         [ -f libpng-$PNG_VERSION.tar.xz ] || curl -O ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng-$PNG_VERSION.tar.xz
726         xzcat libpng-$PNG_VERSION.tar.xz | tar xf - || exit 1
727         cd libpng-$PNG_VERSION
728         CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
729         make $MAKE_BUILD_OPTS || exit 1
730         $DO_MAKE_INSTALL || exit 1
731         cd ..
732         touch libpng-$PNG_VERSION-done
733       fi
734
735     #
736     # The libpixman that comes with the X11 for Leopard is too old
737     # to support Cairo's image surface backend feature (which requires
738     # pixman-1 >= 0.22.0).
739     #
740     if [ ! -f pixman-$PIXMAN_VERSION-done ] ; then
741         echo "Downloading, building, and installing pixman:"
742         [ -f pixman-$PIXMAN_VERSION.tar.gz ] || curl -O http://www.cairographics.org/releases/pixman-$PIXMAN_VERSION.tar.gz
743         gzcat pixman-$PIXMAN_VERSION.tar.gz | tar xf - || exit 1
744         cd pixman-$PIXMAN_VERSION
745         CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
746         make $MAKE_BUILD_OPTS || exit 1
747         $DO_MAKE_INSTALL || exit 1
748         cd ..
749         touch pixman-$PIXMAN_VERSION-done
750     fi
751
752     #
753     # And now Cairo itself.
754     #
755     if [ ! -f cairo-$CAIRO_VERSION-done ] ; then
756         echo "Downloading, building, and installing Cairo:"
757         CAIRO_MAJOR_VERSION="`expr $CAIRO_VERSION : '\([0-9][0-9]*\).*'`"
758         CAIRO_MINOR_VERSION="`expr $CAIRO_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
759         CAIRO_DOTDOT_VERSION="`expr $CAIRO_VERSION : '[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
760         if [[ $CAIRO_MAJOR_VERSION -gt 1 ||
761               $CAIRO_MINOR_VERSION -gt 12 ||
762               ($CAIRO_MINOR_VERSION -eq 12 && $CAIRO_DOTDOT_VERSION -ge 2) ]]
763         then
764             #
765             # Starting with Cairo 1.12.2, the tarballs are compressed with
766             # xz rather than gzip.
767             #
768             [ -f cairo-$CAIRO_VERSION.tar.xz ] || curl -O http://cairographics.org/releases/cairo-$CAIRO_VERSION.tar.xz || exit 1
769             xzcat cairo-$CAIRO_VERSION.tar.xz | tar xf - || exit 1
770         else
771             [ -f cairo-$CAIRO_VERSION.tar.gz ] || curl -O http://cairographics.org/releases/cairo-$CAIRO_VERSION.tar.gz || exit 1
772             gzcat cairo-$CAIRO_VERSION.tar.gz | tar xf - || exit 1
773         fi
774         cd cairo-$CAIRO_VERSION
775         # CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --enable-quartz=no || exit 1
776         # Maybe follow http://cairographics.org/end_to_end_build_for_mac_os_x/
777         CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --enable-quartz=yes || exit 1
778         #
779         # We must avoid the version of libpng that comes with X11; the
780         # only way I've found to force that is to forcibly set INCLUDES
781         # when we do the build, so that this comes before CAIRO_CFLAGS,
782         # which has -I/usr/X11/include added to it before anything
783         # connected to libpng is.
784         #
785         INCLUDES="-I/usr/local/include/libpng15" make $MAKE_BUILD_OPTS || exit 1
786         $DO_MAKE_INSTALL || exit 1
787         cd ..
788         touch cairo-$CAIRO_VERSION-done
789     fi
790 fi
791
792 if [ ! -f atk-$ATK_VERSION-done ] ; then
793     echo "Downloading, building, and installing ATK:"
794     atk_dir=`expr $ATK_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
795     [ -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
796     xzcat atk-$ATK_VERSION.tar.xz | tar xf - || exit 1
797     cd atk-$ATK_VERSION
798     CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
799     make $MAKE_BUILD_OPTS || exit 1
800     $DO_MAKE_INSTALL || exit 1
801     cd ..
802     touch atk-$ATK_VERSION-done
803 fi
804
805 if [ ! -f pango-$PANGO_VERSION-done ] ; then
806     echo "Downloading, building, and installing Pango:"
807     pango_dir=`expr $PANGO_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
808     PANGO_MAJOR_VERSION="`expr $PANGO_VERSION : '\([0-9][0-9]*\).*'`"
809     PANGO_MINOR_VERSION="`expr $PANGO_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
810     if [[ $PANGO_MAJOR_VERSION -gt 1 ||
811           $PANGO_MINOR_VERSION -ge 29 ]]
812     then
813         #
814         # Starting with Pango 1.29, the tarballs are compressed with
815         # xz rather than bzip2.
816         #
817         [ -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
818         xzcat pango-$PANGO_VERSION.tar.xz | tar xf - || exit 1
819     else
820         [ -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
821         gzcat pango-$PANGO_VERSION.tar.bz2 | tar xf - || exit 1
822     fi
823     cd pango-$PANGO_VERSION
824     CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
825     make $MAKE_BUILD_OPTS || exit 1
826     $DO_MAKE_INSTALL || exit 1
827     cd ..
828     touch pango-$PANGO_VERSION-done
829 fi
830
831 if [ ! -f gdk-pixbuf-$GDK_PIXBUF_VERSION-done ] ; then
832     echo "Downloading, building, and installing gdk-pixbuf:"
833     gdk_pixbuf_dir=`expr $GDK_PIXBUF_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
834     [ -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
835     xzcat gdk-pixbuf-$GDK_PIXBUF_VERSION.tar.xz | tar xf - || exit 1
836     cd gdk-pixbuf-$GDK_PIXBUF_VERSION
837     CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --without-libtiff --without-libjpeg || exit 1
838     make $MAKE_BUILD_OPTS || exit 1
839     $DO_MAKE_INSTALL || exit 1
840     cd ..
841     touch gdk-pixbuf-$GDK_PIXBUF_VERSION-done
842 fi
843
844 if [ ! -f gtk+-$GTK_VERSION-done ] ; then
845     echo "Downloading, building, and installing GTK+:"
846     gtk_dir=`expr $GTK_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
847     GTK_MAJOR_VERSION="`expr $GTK_VERSION : '\([0-9][0-9]*\).*'`"
848     GTK_MINOR_VERSION="`expr $GTK_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
849     GTK_DOTDOT_VERSION="`expr $GTK_VERSION : '[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
850     if [[ $GTK_MAJOR_VERSION -gt 2 ||
851           $GTK_MINOR_VERSION -gt 24 ||
852          ($GTK_MINOR_VERSION -eq 24 && $GTK_DOTDOT_VERSION -ge 5) ]]
853     then
854         #
855         # Starting with GTK+ 2.24.5, the tarballs are compressed with
856         # xz rather than gzip, in addition to bzip2; use xz, as we've
857         # built and installed it, and as xz compresses better than
858         # bzip2 so the tarballs take less time to download.
859         #
860         [ -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
861         xzcat gtk+-$GTK_VERSION.tar.xz | tar xf - || exit 1
862     else
863         [ -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
864         gzcat gtk+-$GTK_VERSION.tar.bz2 | tar xf - || exit 1
865     fi
866     cd gtk+-$GTK_VERSION
867     if [ $DARWIN_MAJOR_VERSION -ge "12" ]
868     then
869         #
870         # GTK+ 2.24.10, at least, doesn't build on Mountain Lion with the
871         # CUPS printing backend - either the CUPS API changed incompatibly
872         # or the backend was depending on non-API implementation details.
873         #
874         # Configure it out, on Mountain Lion and later, for now.
875         # (12 is the Darwin major version number in Mountain Lion.)
876         #
877         CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --disable-cups || exit 1
878     else
879         CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
880     fi
881     make $MAKE_BUILD_OPTS || exit 1
882     $DO_MAKE_INSTALL || exit 1
883     cd ..
884     touch gtk+-$GTK_VERSION-done
885 fi
886
887 #
888 # Now we have reached a point where we can build everything including
889 # the GUI (Wireshark), but not with any optional features such as
890 # SNMP OID resolution, some forms of decryption, Lua scripting, playback
891 # of audio, or GeoIP mapping of IP addresses.
892 #
893 # We now conditionally download optional libraries to support them;
894 # the default is to download them all.
895 #
896
897 if [ "$LIBSMI_VERSION" -a ! -f libsmi-$LIBSMI_VERSION-done ] ; then
898     echo "Downloading, building, and installing libsmi:"
899     [ -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
900     gzcat libsmi-$LIBSMI_VERSION.tar.gz | tar xf - || exit 1
901     cd libsmi-$LIBSMI_VERSION
902     CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
903     make $MAKE_BUILD_OPTS || exit 1
904     $DO_MAKE_INSTALL || exit 1
905     cd ..
906     touch libsmi-$LIBSMI_VERSION-done
907 fi
908
909 if [ "$LIBGPG_ERROR_VERSION" -a ! -f libgpg-error-$LIBGPG_ERROR_VERSION-done ] ; then
910     echo "Downloading, building, and installing libgpg-error:"
911     [ -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
912     bzcat libgpg-error-$LIBGPG_ERROR_VERSION.tar.bz2 | tar xf - || exit 1
913     cd libgpg-error-$LIBGPG_ERROR_VERSION
914     CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
915     make $MAKE_BUILD_OPTS || exit 1
916     $DO_MAKE_INSTALL || exit 1
917     cd ..
918     touch libgpg-error-$LIBGPG_ERROR_VERSION-done
919 fi
920
921 if [ "$LIBGCRYPT_VERSION" -a ! -f libgcrypt-$LIBGCRYPT_VERSION-done ] ; then
922     #
923     # libgpg-error is required for libgcrypt.
924     #
925     if [ -z $LIBGPG_ERROR_VERSION ]
926     then
927         echo "libgcrypt requires libgpg-error, but you didn't install libgpg-error." 1>&2
928         exit 1
929     fi
930
931     echo "Downloading, building, and installing libgcrypt:"
932     [ -f libgcrypt-$LIBGCRYPT_VERSION.tar.gz ] || curl -L -O ftp://ftp.gnupg.org/gcrypt/libgcrypt/libgcrypt-$LIBGCRYPT_VERSION.tar.gz || exit 1
933     gzcat libgcrypt-$LIBGCRYPT_VERSION.tar.gz | tar xf - || exit 1
934     cd libgcrypt-$LIBGCRYPT_VERSION
935     #
936     # The assembler language code is not compatible with the OS X
937     # x86 assembler (or is it an x86-64 vs. x86-32 issue?).
938     #
939     # libgcrypt expects gnu89, not c99/gnu99, semantics for
940     # "inline".  See, for example:
941     #
942     #    http://lists.freebsd.org/pipermail/freebsd-ports-bugs/2010-October/198809.html
943     #
944     CFLAGS="$CFLAGS -std=gnu89 $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --disable-asm || exit 1
945     make $MAKE_BUILD_OPTS || exit 1
946     $DO_MAKE_INSTALL || exit 1
947     cd ..
948     touch libgcrypt-$LIBGCRYPT_VERSION-done
949 fi
950
951 if [ "$GNUTLS_VERSION" -a ! -f gnutls-$GNUTLS_VERSION-done ] ; then
952     #
953     # GnuTLS requires libgcrypt (or nettle, in newer versions).
954     #
955     if [ -z $LIBGCRYPT_VERSION ]
956     then
957         echo "GnuTLS requires libgcrypt, but you didn't install libgcrypt" 1>&2
958         exit 1
959     fi
960
961     echo "Downloading, building, and installing GnuTLS:"
962     [ -f gnutls-$GNUTLS_VERSION.tar.bz2 ] || curl -L -O http://ftp.gnu.org/gnu/gnutls/gnutls-$GNUTLS_VERSION.tar.bz2 || exit 1
963     bzcat gnutls-$GNUTLS_VERSION.tar.bz2 | tar xf - || exit 1
964     cd gnutls-$GNUTLS_VERSION
965     #
966     # Use libgcrypt, not nettle.
967     # XXX - is there some reason to prefer nettle?  Or does
968     # Wireshark directly use libgcrypt routines?
969     #
970     CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --with-libgcrypt --without-p11-kit || exit 1
971     make $MAKE_BUILD_OPTS || exit 1
972     #
973     # The pkgconfig file for GnuTLS says "requires zlib", but OS X,
974     # while it supplies zlib, doesn't supply a pkgconfig file for
975     # it.
976     #
977     # Patch the GnuTLS pkgconfig file not to require zlib.
978     # (If the capabilities of GnuTLS that Wireshark uses don't
979     # depend on building GnuTLS with zlib, an alternative would be
980     # to configure it not to use zlib.)
981     #
982     patch -p0 lib/gnutls.pc.in <../../macosx-support-lib-patches/gnutls-pkgconfig.patch || exit 1
983     $DO_MAKE_INSTALL || exit 1
984     cd ..
985     touch gnutls-$GNUTLS_VERSION-done
986 fi
987
988 if [ "$LUA_VERSION" -a ! -f lua-$LUA_VERSION-done ] ; then
989     echo "Downloading, building, and installing Lua:"
990     [ -f lua-$LUA_VERSION.tar.gz ] || curl -L -O http://www.lua.org/ftp/lua-$LUA_VERSION.tar.gz || exit 1
991     gzcat lua-$LUA_VERSION.tar.gz | tar xf - || exit 1
992     cd lua-$LUA_VERSION
993     make $MAKE_BUILD_OPTS macosx || exit 1
994     $DO_MAKE_INSTALL || exit 1
995     cd ..
996     touch lua-$LUA_VERSION-done
997 fi
998
999 if [ "$PORTAUDIO_VERSION" -a ! -f portaudio-done ] ; then
1000     echo "Downloading, building, and installing PortAudio:"
1001     [ -f $PORTAUDIO_VERSION.tgz ] || curl -L -O http://www.portaudio.com/archives/$PORTAUDIO_VERSION.tgz || exit 1
1002     gzcat $PORTAUDIO_VERSION.tgz | tar xf - || exit 1
1003     cd portaudio
1004     #
1005     # Un-comment an include that's required on Lion.
1006     #
1007     patch -p0 include/pa_mac_core.h <../../macosx-support-lib-patches/portaudio-pa_mac_core.h.patch
1008     #
1009     # Fix a bug that showed up with clang (but is a bug with any
1010     # compiler).
1011     #
1012     patch -p0 src/hostapi/coreaudio/pa_mac_core.c <../../macosx-support-lib-patches/portaudio-pa_mac_core.c.patch
1013     #
1014     # Disable fat builds - the configure script doesn't work right
1015     # with Xcode 4 if you leave them enabled, and we don't build
1016     # any other libraries fat (GLib, for example, would be very
1017     # hard to build fat), so there's no advantage to having PortAudio
1018     # built fat.
1019     #
1020     # Set the minimum OS X version to 10.4, to suppress some
1021     # deprecation warnings.  (Good luck trying to make any of
1022     # this build on an OS+Xcode with a pre-10.4 SDK; we don't
1023     # worry about the user requesting that.)
1024     #
1025     CFLAGS="$CFLAGS -mmacosx-version-min=10.4 $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --disable-mac-universal || exit 1
1026     make $MAKE_BUILD_OPTS || exit 1
1027     $DO_MAKE_INSTALL || exit 1
1028     cd ..
1029     touch portaudio-done
1030 fi
1031
1032 if [ "$GEOIP_VERSION" -a ! -f geoip-$GEOIP_VERSION-done ]
1033 then
1034     echo "Downloading, building, and installing GeoIP API:"
1035     [ -f GeoIP-$GEOIP_VERSION.tar.gz ] || curl -L -O http://geolite.maxmind.com/download/geoip/api/c/GeoIP-$GEOIP_VERSION.tar.gz || exit 1
1036     gzcat GeoIP-$GEOIP_VERSION.tar.gz | tar xf - || exit 1
1037     cd GeoIP-$GEOIP_VERSION
1038     CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
1039     #
1040     # Grr.  Their man pages "helpfully" have an ISO 8859-1
1041     # copyright symbol in the copyright notice, but OS X's
1042     # default character encoding is UTF-8.  sed on Mountain
1043     # Lion barfs at the "illegal character sequence" represented
1044     # by an ISO 8859-1 copyright symbol, as it's not a valid
1045     # UTF-8 sequence.
1046     #
1047     # iconv the relevant man pages into UTF-8.
1048     #
1049     for i in geoipupdate.1.in geoiplookup6.1.in geoiplookup.1.in
1050     do
1051         iconv -f iso8859-1 -t utf-8 man/"$i" >man/"$i".tmp &&
1052             mv man/"$i".tmp man/"$i"
1053     done
1054     make $MAKE_BUILD_OPTS || exit 1
1055     $DO_MAKE_INSTALL || exit 1
1056     cd ..
1057     touch geoip-$GEOIP_VERSION-done
1058 fi
1059
1060 echo ""
1061
1062 echo "You are now prepared to build Wireshark. To do so do:"
1063 echo "export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/X11/lib/pkgconfig"
1064 echo ""
1065 if [ -n "$CMAKE" ]; then
1066     echo "mkdir build; cd build"
1067     echo "cmake .."
1068     echo
1069     echo "or"
1070     echo
1071 fi
1072 echo "./autogen.sh"
1073 echo "mkdir build; cd build"
1074 echo "../configure"
1075 echo ""
1076 echo "make $MAKE_BUILD_OPTS"
1077 echo "make install"
1078
1079 echo ""
1080
1081 echo "Make sure you are allowed capture access to the network devices"
1082 echo "See: http://wiki.wireshark.org/CaptureSetup/CapturePrivileges"
1083
1084 echo ""
1085
1086 exit 0