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