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