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