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