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