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