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