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