Download the Qt dmg and just do a binary installation.
[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 install cmake
26 #
27 CMAKE=1
28 #
29 # To build all libraries as 32-bit libraries uncomment the following three lines.
30 #
31 # export CFLAGS="$CFLAGS -arch i386"
32 # export CXXFLAGS="$CXXFLAGS -arch i386"
33 # export LDFLAGS="$LDFLAGS -arch i386"
34 #
35 # and change "macx-clang" to "macx-clang-32" in the line below.
36 #
37 # Note: when building against the 10.6 SDK, clang fails, because there's
38 # a missing libstdc++.dylib in the SDK; this does not bother g++, however.
39 #
40 #TARGET_PLATFORM=macx-g++
41 TARGET_PLATFORM=macx-clang
42
43 #
44 # Versions of packages to download and install.
45 #
46
47 #
48 # Some packages need xz to unpack their current source.
49 # xz is not yet provided with OS X.
50 #
51 XZ_VERSION=5.0.4
52
53 #
54 # In case we want to build with cmake.
55 #
56 CMAKE_VERSION=2.8.12.2
57
58 #
59 # The following libraries and tools are required even to build only TShark.
60 #
61 GETTEXT_VERSION=0.18.2
62 GLIB_VERSION=2.36.0
63 PKG_CONFIG_VERSION=0.28
64
65 #
66 # One or more of the following libraries are required to build Wireshark.
67 #
68 # If you don't want to build with Qt, comment out the QT_VERSION= line.
69 #
70 # If you want to build with GTK+ 2, comment out the GTK_VERSION=3.* line
71 # and un-comment the GTK_VERSION=2.* line.
72 #
73 # If you don't want to build with GTK+ at all, comment out both lines.
74 #
75 QT_VERSION=5.3.2
76 GTK_VERSION=2.24.17
77 #GTK_VERSION=3.5.2
78 if [ "$GTK_VERSION" ]; then
79     #
80     # We'll be building GTK+, so we need some additional libraries.
81     #
82     GTK_MAJOR_VERSION="`expr $GTK_VERSION : '\([0-9][0-9]*\).*'`"
83     GTK_MINOR_VERSION="`expr $GTK_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
84     GTK_DOTDOT_VERSION="`expr $GTK_VERSION : '[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
85
86     ATK_VERSION=2.8.0
87     PANGO_VERSION=1.30.1
88     PNG_VERSION=1.5.17
89     PIXMAN_VERSION=0.26.0
90     CAIRO_VERSION=1.12.2
91     GDK_PIXBUF_VERSION=2.28.0
92 fi
93 if [ "$QT_VERSION" ]; then
94     QT_MAJOR_VERSION="`expr $QT_VERSION : '\([0-9][0-9]*\).*'`"
95     QT_MINOR_VERSION="`expr $QT_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
96     QT_DOTDOT_VERSION="`expr $QT_VERSION : '[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
97     QT_MAJOR_MINOR_VERSION=$QT_MAJOR_VERSION.$QT_MINOR_VERSION
98 fi
99
100 # In case we want to build GTK *and* we don't have Apple's X11 SDK installed
101 # we may want to install XQuartz. The version will only be used in the printing
102 # of a URL, the package will not be installed.
103 #
104 XQUARTZ_VERSION=2.7.5
105 #
106 # The following libraries are optional.
107 # Comment them out if you don't want them, but note that some of
108 # the optional libraries are required by other optional libraries.
109 #
110 LIBSMI_VERSION=0.4.8
111 #
112 # libgpg-error is required for libgcrypt.
113 #
114 LIBGPG_ERROR_VERSION=1.10
115 #
116 # libgcrypt is required for GnuTLS.
117 #
118 LIBGCRYPT_VERSION=1.5.0
119 GNUTLS_VERSION=2.12.19
120 # Use 5.2.3, not 5.3, for now; lua_bitop.c hasn't been ported to 5.3
121 # yet, and we need to check for compatibility issues (we'd want Lua
122 # scripts to work with 5.1, 5.2, and 5.3, as long as they only use Lua
123 # features present in all three versions)
124 LUA_VERSION=5.2.3
125 PORTAUDIO_VERSION=pa_stable_v19_20111121
126 #
127 # XXX - they appear to have an unversioned gzipped tarball for the
128 # current version; should we just download that, with some other
129 # way of specifying whether to download the GeoIP API?
130 #
131 GEOIP_VERSION=1.4.8
132
133 CARES_VERSION=1.10.0
134
135 DARWIN_MAJOR_VERSION=`uname -r | sed 's/\([0-9]*\).*/\1/'`
136
137 #
138 # GNU autotools; they're provided with releases up to Snow Leopard, but
139 # not in later releases.
140 #
141 if [[ $DARWIN_MAJOR_VERSION -gt 10 ]]; then
142     AUTOCONF_VERSION=2.69
143     AUTOMAKE_VERSION=1.13.3
144     LIBTOOL_VERSION=2.4.2
145 fi
146
147 install_xz() {
148     if [ "$XZ_VERSION" -a ! -f xz-$XZ_VERSION-done ] ; then
149         echo "Downloading, building, and installing xz:"
150         [ -f xz-$XZ_VERSION.tar.bz2 ] || curl -O http://tukaani.org/xz/xz-$XZ_VERSION.tar.bz2 || exit 1
151         bzcat xz-$XZ_VERSION.tar.bz2 | tar xf - || exit 1
152         cd xz-$XZ_VERSION
153         CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=0" ./configure || exit 1
154         make $MAKE_BUILD_OPTS || exit 1
155         $DO_MAKE_INSTALL || exit 1
156         cd ..
157         touch xz-$XZ_VERSION-done
158     fi
159 }
160
161 uninstall_xz() {
162     if [ ! -z "$installed_xz_version" ] ; then
163         echo "Uninstalling xz:"
164         cd xz-$installed_xz_version
165         $DO_MAKE_UNINSTALL || exit 1
166         make distclean || exit 1
167         cd ..
168         rm xz-$installed_xz_version-done
169
170         if [ "$#" -eq 1 -a "$1" = "-r" ] ; then
171             #
172             # Get rid of the previously downloaded and unpacked version.
173             #
174             rm -rf xz-$installed_xz_version
175             rm -rf xz-$installed_xz_version.tar.bz2
176         fi
177
178         installed_xz_version=""
179     fi
180 }
181
182 install_autoconf() {
183     if [ "$AUTOCONF_VERSION" -a ! -f autoconf-$AUTOCONF_VERSION-done ] ; then
184         echo "Downloading, building and installing GNU autoconf..."
185         [ -f autoconf-$AUTOCONF_VERSION.tar.xz ] || curl -O ftp://ftp.gnu.org/gnu/autoconf/autoconf-$AUTOCONF_VERSION.tar.xz || exit 1
186         xzcat autoconf-$AUTOCONF_VERSION.tar.xz | tar xf - || exit 1
187         cd autoconf-$AUTOCONF_VERSION
188         ./configure || exit 1
189         make $MAKE_BUILD_OPTS || exit 1
190         $DO_MAKE_INSTALL || exit 1
191         cd ..
192         touch autoconf-$AUTOCONF_VERSION-done
193     fi
194 }
195
196 uninstall_autoconf() {
197     if [ ! -z "$installed_autoconf_version" ] ; then
198         #
199         # automake and libtool depend on this, so uninstall them.
200         #
201         uninstall_libtool
202         uninstall_automake
203
204         echo "Uninstalling GNU autoconf:"
205         cd autoconf-$installed_autoconf_version
206         $DO_MAKE_UNINSTALL || exit 1
207         make distclean || exit 1
208         cd ..
209         rm autoconf-$installed_autoconf_version-done
210
211         if [ "$#" -eq 1 -a "$1" = "-r" ] ; then
212             #
213             # Get rid of the previously downloaded and unpacked version.
214             #
215             rm -rf autoconf-$installed_autoconf_version
216             rm -rf autoconf-$installed_autoconf_version.tar.xz
217         fi
218
219         installed_autoconf_version=""
220     fi
221 }
222
223 install_automake() {
224     if [ "$AUTOMAKE_VERSION" -a ! -f automake-$AUTOMAKE_VERSION-done ] ; then
225         echo "Downloading, building and installing GNU automake..."
226         [ -f automake-$AUTOMAKE_VERSION.tar.xz ] || curl -O ftp://ftp.gnu.org/gnu/automake/automake-$AUTOMAKE_VERSION.tar.xz || exit 1
227         xzcat automake-$AUTOMAKE_VERSION.tar.xz | tar xf - || exit 1
228         cd automake-$AUTOMAKE_VERSION
229         ./configure || exit 1
230         make $MAKE_BUILD_OPTS || exit 1
231         $DO_MAKE_INSTALL || exit 1
232         cd ..
233         touch automake-$AUTOMAKE_VERSION-done
234     fi
235 }
236
237 uninstall_automake() {
238     if [ ! -z "$installed_automake_version" ] ; then
239         #
240         # libtool depends on this(?), so uninstall it.
241         #
242         uninstall_libtool "$@"
243
244         echo "Uninstalling GNU automake:"
245         cd automake-$installed_automake_version
246         $DO_MAKE_UNINSTALL || exit 1
247         make distclean || exit 1
248         cd ..
249         rm automake-$installed_automake_version-done
250
251         if [ "$#" -eq 1 -a "$1" = "-r" ] ; then
252             #
253             # Get rid of the previously downloaded and unpacked version.
254             #
255             rm -rf automake-$installed_automake_version
256             rm -rf automake-$installed_automake_version.tar.xz
257         fi
258
259         installed_automake_version=""
260     fi
261 }
262
263 install_libtool() {
264     if [ "$LIBTOOL_VERSION" -a ! -f libtool-$LIBTOOL_VERSION-done ] ; then
265         echo "Downloading, building and installing GNU libtool..."
266         [ -f libtool-$LIBTOOL_VERSION.tar.xz ] || curl -O ftp://ftp.gnu.org/gnu/libtool/libtool-$LIBTOOL_VERSION.tar.xz || exit 1
267         xzcat libtool-$LIBTOOL_VERSION.tar.xz | tar xf - || exit 1
268         cd libtool-$LIBTOOL_VERSION
269         ./configure || exit 1
270         make $MAKE_BUILD_OPTS || exit 1
271         $DO_MAKE_INSTALL || exit 1
272         $DO_MV /usr/local/bin/libtool /usr/local/bin/glibtool
273         $DO_MV /usr/local/bin/libtoolize /usr/local/bin/glibtoolize
274         cd ..
275        touch libtool-$LIBTOOL_VERSION-done
276     fi
277 }
278
279 uninstall_libtool() {
280     if [ ! -z "$installed_libtool_version" ] ; then
281         echo "Uninstalling GNU libtool:"
282         cd libtool-$installed_libtool_version
283         $DO_MV /usr/local/bin/glibtool /usr/local/bin/libtool
284         $DO_MV /usr/local/bin/glibtoolize /usr/local/bin/libtoolize
285         $DO_MAKE_UNINSTALL || exit 1
286         make distclean || exit 1
287         cd ..
288         rm libtool-$installed_libtool_version-done
289
290         if [ "$#" -eq 1 -a "$1" = "-r" ] ; then
291             #
292             # Get rid of the previously downloaded and unpacked version.
293             #
294             rm -rf libtool-$installed_libtool_version
295             rm -rf libtool-$installed_libtool_version.tar.xz
296         fi
297
298         installed_libtool_version=""
299     fi
300 }
301
302 install_cmake() {
303     if [ -n "$CMAKE" -a ! -f cmake-$CMAKE_VERSION-done ]; then
304         echo "Downloading and installing CMake:"
305         cmake_dir=`expr $CMAKE_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
306         #
307         # NOTE: the "64" in "Darwin64" doesn't mean "64-bit-only"; the
308         # package in question supports both 32-bit and 64-bit x86.
309         #
310         [ -f cmake-$CMAKE_VERSION-Darwin64-universal.dmg ] || curl -O http://www.cmake.org/files/v$cmake_dir/cmake-$CMAKE_VERSION-Darwin64-universal.dmg || exit 1
311         sudo hdiutil attach cmake-$CMAKE_VERSION-Darwin64-universal.dmg || exit 1
312         sudo installer -target / -pkg /Volumes/cmake-$CMAKE_VERSION-Darwin64-universal/cmake-$CMAKE_VERSION-Darwin64-universal.pkg || exit 1
313         sudo hdiutil detach /Volumes/cmake-$CMAKE_VERSION-Darwin64-universal
314         touch cmake-$CMAKE_VERSION-done
315     fi
316 }
317
318 uninstall_cmake() {
319     if [ ! -z "$installed_cmake_version" ]; then
320         echo "Uninstalling CMake:"
321         sudo rm -rf "/Applications/CMake "`echo "$installed_cmake_version" | sed 's/\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*/\1.\2-\3/'`.app
322         sudo rm /usr/bin/ccmake
323         sudo rm /usr/bin/cmake
324         sudo rm /usr/bin/cmake-gui
325         sudo rm /usr/bin/cmakexbuild
326         sudo rm /usr/bin/cpack
327         sudo rm /usr/bin/ctest
328         sudo pkgutil --forget com.Kitware.CMake
329         rm cmake-$installed_cmake_version-done
330
331         if [ "$#" -eq 1 -a "$1" = "-r" ] ; then
332             #
333             # Get rid of the previously downloaded and unpacked version.
334             #
335             rm -f cmake-$installed_cmake_version-Darwin64-universal.dmg
336         fi
337
338         installed_cmake_version=""
339     fi
340 }
341
342 install_gettext() {
343     if [ ! -f gettext-$GETTEXT_VERSION-done ] ; then
344         echo "Downloading, building, and installing GNU gettext:"
345         [ -f gettext-$GETTEXT_VERSION.tar.gz ] || curl -O http://ftp.gnu.org/pub/gnu/gettext/gettext-$GETTEXT_VERSION.tar.gz || exit 1
346         gzcat gettext-$GETTEXT_VERSION.tar.gz | tar xf - || exit 1
347         cd gettext-$GETTEXT_VERSION
348         CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=0 $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
349         make $MAKE_BUILD_OPTS || exit 1
350         $DO_MAKE_INSTALL || exit 1
351         cd ..
352        touch gettext-$GETTEXT_VERSION-done
353     fi
354 }
355
356 uninstall_gettext() {
357     if [ ! -z "$installed_gettext_version" ] ; then
358         #
359         # GLib depends on this, so uninstall it.
360         #
361         uninstall_glib "$@"
362
363         echo "Uninstalling GNU gettext:"
364         cd gettext-$installed_gettext_version
365         $DO_MAKE_UNINSTALL || exit 1
366         make distclean || exit 1
367         cd ..
368         rm gettext-$installed_gettext_version-done
369
370         if [ "$#" -eq 1 -a "$1" = "-r" ] ; then
371             #
372             # Get rid of the previously downloaded and unpacked version.
373             #
374             rm -rf gettext-$installed_gettext_version
375             rm -rf gettext-$installed_gettext_version.tar.gz
376         fi
377
378         installed_gettext_version=""
379     fi
380 }
381
382 install_pkg_config() {
383     if [ ! -f pkg-config-$PKG_CONFIG_VERSION-done ] ; then
384         echo "Downloading, building, and installing pkg-config:"
385         [ -f pkg-config-$PKG_CONFIG_VERSION.tar.gz ] || curl -O http://pkgconfig.freedesktop.org/releases/pkg-config-$PKG_CONFIG_VERSION.tar.gz || exit 1
386         gzcat pkg-config-$PKG_CONFIG_VERSION.tar.gz | tar xf - || exit 1
387         cd pkg-config-$PKG_CONFIG_VERSION
388         ./configure --with-internal-glib || exit 1
389         make $MAKE_BUILD_OPTS || exit 1
390         $DO_MAKE_INSTALL || exit 1
391         cd ..
392         touch pkg-config-$PKG_CONFIG_VERSION-done
393     fi
394 }
395
396 uninstall_pkg_config() {
397     if [ ! -z "$installed_pkg_config_version" ] ; then
398         echo "Uninstalling pkg-config:"
399         cd pkg-config-$installed_pkg_config_version
400         $DO_MAKE_UNINSTALL || exit 1
401         make distclean || exit 1
402         cd ..
403         rm pkg-config-$installed_pkg_config_version-done
404
405         if [ "$#" -eq 1 -a "$1" = "-r" ] ; then
406             #
407             # Get rid of the previously downloaded and unpacked version.
408             #
409             rm -rf pkg-config-$installed_pkg_config_version
410             rm -rf pkg-config-$installed_pkg_config_version.tar.gz
411         fi
412
413         installed_pkg_config_version=""
414     fi
415 }
416
417 install_glib() {
418     if [ ! -f glib-$GLIB_VERSION-done ] ; then
419         echo "Downloading, building, and installing GLib:"
420         glib_dir=`expr $GLIB_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
421         GLIB_MAJOR_VERSION="`expr $GLIB_VERSION : '\([0-9][0-9]*\).*'`"
422         GLIB_MINOR_VERSION="`expr $GLIB_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
423         GLIB_DOTDOT_VERSION="`expr $GLIB_VERSION : '[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
424         if [[ $GLIB_MAJOR_VERSION -gt 2 ||
425               $GLIB_MINOR_VERSION -gt 28 ||
426               ($GLIB_MINOR_VERSION -eq 28 && $GLIB_DOTDOT_VERSION -ge 8) ]]
427         then
428             #
429             # Starting with GLib 2.28.8, xz-compressed tarballs are available.
430             #
431             [ -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
432             xzcat glib-$GLIB_VERSION.tar.xz | tar xf - || exit 1
433         else
434             [ -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
435             bzcat glib-$GLIB_VERSION.tar.bz2 | tar xf - || exit 1
436         fi
437         cd glib-$GLIB_VERSION
438         #
439         # OS X ships with libffi, but doesn't provide its pkg-config file;
440         # explicitly specify LIBFFI_CFLAGS and LIBFFI_LIBS, so the configure
441         # script doesn't try to use pkg-config to get the appropriate
442         # C flags and loader flags.
443         #
444         # And, what's worse, at least with the version of Xcode that comes
445         # with Leopard, /usr/include/ffi/fficonfig.h doesn't define MACOSX,
446         # which causes the build of GLib to fail.  If we don't find
447         # "#define.*MACOSX" in /usr/include/ffi/fficonfig.h, explicitly
448         # define it.
449         #
450         # While we're at it, suppress -Wformat-nonliteral to avoid a case
451         # where clang's stricter rules on when not to complain about
452         # non-literal format arguments cause it to complain about code
453         # that's safe but it wasn't told that.  See my comment #25 in
454         # GNOME bug 691608:
455         #
456         #    https://bugzilla.gnome.org/show_bug.cgi?id=691608#c25
457         #
458         # First, determine where the system include files are.  (It's not
459         # necessarily /usr/include.)  There's a bit of a greasy hack here;
460         # pre-5.x versions of the developer tools don't support the
461         # --show-sdk-path option, and will produce no output, so includedir
462         # will be set to /usr/include (in those older versions of the
463         # developer tools, there is a /usr/include directory).
464         #
465         includedir=`xcrun --show-sdk-path 2>/dev/null`/usr/include
466         if grep -qs '#define.*MACOSX' $includedir/ffi/fficonfig.h
467         then
468             # It's defined, nothing to do
469             LIBFFI_CFLAGS="-I $includedir/ffi" LIBFFI_LIBS="-lffi" CFLAGS="$CFLAGS -Wno-format-nonliteral $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS -Wno-format-nonliteral $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
470         else
471             LIBFFI_CFLAGS="-I $includedir/ffi" LIBFFI_LIBS="-lffi" CFLAGS="$CFLAGS -DMACOSX -Wno-format-nonliteral $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS -DMACOSX -Wno-format-nonliteral $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
472         fi
473
474         #
475         # Apply the fix to GNOME bug 529806:
476         #
477         #    https://bugzilla.gnome.org/show_bug.cgi?id=529806
478         #
479         # if we have a version of GLib prior to 2.30.
480         #
481         if [[ $GLIB_MAJOR_VERSION -eq 2 && $GLIB_MINOR_VERSION -le 30 ]]
482         then
483             patch -p0 <../../macosx-support-lib-patches/glib-gconvert.c.patch || exit 1
484         fi
485         make $MAKE_BUILD_OPTS || exit 1
486         $DO_MAKE_INSTALL || exit 1
487         cd ..
488         touch glib-$GLIB_VERSION-done
489     fi
490 }
491
492 uninstall_glib() {
493     if [ ! -z "$installed_glib_version" ] ; then
494         #
495         # ATK, Pango, and GTK depend on this, so uninstall them.
496         #
497         uninstall_gtk
498         uninstall_pango
499         uninstall_atk
500
501         echo "Uninstalling GLib:"
502         cd glib-$installed_glib_version
503         $DO_MAKE_UNINSTALL || exit 1
504         make distclean || exit 1
505         cd ..
506         rm glib-$installed_glib_version-done
507
508         if [ "$#" -eq 1 -a "$1" = "-r" ] ; then
509             #
510             # Get rid of the previously downloaded and unpacked version.
511             #
512             rm -rf glib-$installed_glib_version
513             rm -rf glib-$installed_glib_version.tar.xz glib-$installed_glib_version.tar.bz2
514         fi
515
516         installed_glib_version=""
517     fi
518 }
519
520 install_qt() {
521     if [ "$QT_VERSION" -a ! -f qt-$QT_VERSION-done ]; then
522         echo "Downloading, building, and installing Qt:"
523         #
524         # What you get for this URL might just be a 302 Found reply, so use
525         # -L so we get redirected.
526         #
527         [ -f qt-opensource-mac-x64-clang-$QT_VERSION.dmg ] || curl -L -O http://download.qt.io/archive/qt/$QT_MAJOR_MINOR_VERSION/$QT_VERSION/qt-opensource-mac-x64-clang-$QT_VERSION.dmg || exit 1
528         sudo hdiutil attach qt-opensource-mac-x64-clang-$QT_VERSION.dmg || exit 1
529
530         #
531         # Run the executable directly, so that we wait for it to finish.
532         #
533         /Volumes/qt-opensource-mac-x64-clang-$QT_VERSION/qt-opensource-mac-x64-clang-$QT_VERSION.app/Contents/MacOS/qt-opensource-mac-x64-clang-$QT_VERSION
534         sudo hdiutil detach /Volumes/qt-opensource-mac-x64-clang-$QT_VERSION
535
536         #
537         # The 5.3.x versions, at least, have bogus .pc files.
538         # Fix them.
539         #
540         for i in $HOME/Qt$QT_VERSION/$QT_MAJOR_MINOR_VERSION/clang_64/lib/pkgconfig/*.pc
541         do
542             ed - $i <<EOF
543 H
544 g/Cflags: /s;;Cflags: -F\${libdir} ;
545 g/Cflags: /s;-I\${includedir}/Qt\([a-zA-Z0-9_]*\);-I\${libdir}/Qt\1.framework/Versions/5/Headers;
546 w
547 q
548 EOF
549         done
550         touch qt-$QT_VERSION-done
551     fi
552 }
553
554 uninstall_qt() {
555     if [ ! -z "$installed_qt_version" ] ; then
556         echo "Uninstalling Qt:"
557         rm -rf $HOME/Qt$installed_qt_version
558         rm qt-$installed_qt_version-done
559
560         if [ "$#" -eq 1 -a "$1" = "-r" ] ; then
561             #
562             # Get rid of the previously downloaded version.
563             #
564             rm -rf qt-opensource-mac-x64-clang-$installed_qt_version.dmg
565         fi
566
567         installed_qt_version=""
568     fi
569 }
570
571 install_libpng() {
572     if [ ! -f libpng-$PNG_VERSION-done ] ; then
573         echo "Downloading, building, and installing libpng:"
574         #
575         # The FTP site puts libpng x.y.* into a libpngxy directory.
576         #
577         subdir=`echo $PNG_VERSION | sed 's/\([1-9][0-9]*\)\.\([1-9][0-9]*\).*/libpng\1\2'/`
578         [ -f libpng-$PNG_VERSION.tar.xz ] || curl -O ftp://ftp.simplesystems.org/pub/libpng/png/src/$subdir/libpng-$PNG_VERSION.tar.xz
579         xzcat libpng-$PNG_VERSION.tar.xz | tar xf - || exit 1
580         cd libpng-$PNG_VERSION
581         CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
582         make $MAKE_BUILD_OPTS || exit 1
583         $DO_MAKE_INSTALL || exit 1
584         cd ..
585         touch libpng-$PNG_VERSION-done
586     fi
587 }
588
589 uninstall_libpng() {
590     if [ ! -z "$installed_libpng_version" ] ; then
591         #
592         # Cairo depends on this, so uninstall it.
593         #
594         uninstall_cairo "$@"
595
596         echo "Uninstalling libpng:"
597         cd libpng-$installed_libpng_version
598         $DO_MAKE_UNINSTALL || exit 1
599         make distclean || exit 1
600         cd ..
601         rm libpng-$installed_libpng_version-done
602
603         if [ "$#" -eq 1 -a "$1" = "-r" ] ; then
604             #
605             # Get rid of the previously downloaded and unpacked version.
606             #
607             rm -rf libpng-$installed_libpng_version
608             rm -rf libpng-$installed_libpng_version.tar.xz
609         fi
610
611         installed_libpng_version=""
612     fi
613 }
614
615 install_pixman() {
616     if [ ! -f pixman-$PIXMAN_VERSION-done ] ; then
617         echo "Downloading, building, and installing pixman:"
618         [ -f pixman-$PIXMAN_VERSION.tar.gz ] || curl -O http://www.cairographics.org/releases/pixman-$PIXMAN_VERSION.tar.gz
619         gzcat pixman-$PIXMAN_VERSION.tar.gz | tar xf - || exit 1
620         cd pixman-$PIXMAN_VERSION
621         CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
622         make $MAKE_BUILD_OPTS || exit 1
623         $DO_MAKE_INSTALL || exit 1
624         cd ..
625         touch pixman-$PIXMAN_VERSION-done
626     fi
627 }
628
629 uninstall_pixman() {
630     if [ ! -z "$installed_pixman_version" ] ; then
631         #
632         # Cairo depends on this, so uninstall it.
633         #
634         uninstall_cairo "$@"
635
636         echo "Uninstalling pixman:"
637         cd pixman-$installed_pixman_version
638         $DO_MAKE_UNINSTALL || exit 1
639         make distclean || exit 1
640         cd ..
641         rm pixman-$installed_pixman_version-done
642
643         if [ "$#" -eq 1 -a "$1" = "-r" ] ; then
644             #
645             # Get rid of the previously downloaded and unpacked version.
646             #
647             rm -rf pixman-$installed_pixman_version
648             rm -rf pixman-$installed_pixman_version.tar.gz
649         fi
650
651         installed_pixman_version=""
652     fi
653 }
654
655 install_cairo() {
656     if [ ! -f cairo-$CAIRO_VERSION-done ] ; then
657         echo "Downloading, building, and installing Cairo:"
658         CAIRO_MAJOR_VERSION="`expr $CAIRO_VERSION : '\([0-9][0-9]*\).*'`"
659         CAIRO_MINOR_VERSION="`expr $CAIRO_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
660         CAIRO_DOTDOT_VERSION="`expr $CAIRO_VERSION : '[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
661         if [[ $CAIRO_MAJOR_VERSION -gt 1 ||
662               $CAIRO_MINOR_VERSION -gt 12 ||
663               ($CAIRO_MINOR_VERSION -eq 12 && $CAIRO_DOTDOT_VERSION -ge 2) ]]
664         then
665             #
666             # Starting with Cairo 1.12.2, the tarballs are compressed with
667             # xz rather than gzip.
668             #
669             [ -f cairo-$CAIRO_VERSION.tar.xz ] || curl -O http://cairographics.org/releases/cairo-$CAIRO_VERSION.tar.xz || exit 1
670             xzcat cairo-$CAIRO_VERSION.tar.xz | tar xf - || exit 1
671         else
672             [ -f cairo-$CAIRO_VERSION.tar.gz ] || curl -O http://cairographics.org/releases/cairo-$CAIRO_VERSION.tar.gz || exit 1
673             gzcat cairo-$CAIRO_VERSION.tar.gz | tar xf - || exit 1
674         fi
675         cd cairo-$CAIRO_VERSION
676         # CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --enable-quartz=no || exit 1
677         # Maybe follow http://cairographics.org/end_to_end_build_for_mac_os_x/
678         CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --enable-quartz=yes || exit 1
679         #
680         # We must avoid the version of libpng that comes with X11; the
681         # only way I've found to force that is to forcibly set INCLUDES
682         # when we do the build, so that this comes before CAIRO_CFLAGS,
683         # which has -I/usr/X11/include added to it before anything
684         # connected to libpng is.
685         #
686         INCLUDES="-I/usr/local/include/libpng15" make $MAKE_BUILD_OPTS || exit 1
687         $DO_MAKE_INSTALL || exit 1
688         cd ..
689         touch cairo-$CAIRO_VERSION-done
690     fi
691 }
692
693 uninstall_cairo() {
694     if [ ! -z "$installed_cairo_version" ] ; then
695         #
696         # GTK+ depends on this, so uninstall it.
697         #
698         uninstall_gtk "$@"
699
700         echo "Uninstalling Cairo:"
701         cd cairo-$installed_cairo_version
702         $DO_MAKE_UNINSTALL || exit 1
703         make distclean || exit 1
704         cd ..
705         rm cairo-$installed_cairo_version-done
706
707         if [ "$#" -eq 1 -a "$1" = "-r" ] ; then
708             #
709             # Get rid of the previously downloaded and unpacked version.
710             #
711             rm -rf cairo-$installed_cairo_version
712             rm -rf cairo-$installed_cairo_version.tar.xz cairo-$installed_cairo_version.tar.gz
713         fi
714
715         installed_cairo_version=""
716     fi
717 }
718
719 install_atk() {
720     if [ ! -f atk-$ATK_VERSION-done ] ; then
721         echo "Downloading, building, and installing ATK:"
722         atk_dir=`expr $ATK_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
723         ATK_MAJOR_VERSION="`expr $ATK_VERSION : '\([0-9][0-9]*\).*'`"
724         ATK_MINOR_VERSION="`expr $ATK_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
725         ATK_DOTDOT_VERSION="`expr $ATK_VERSION : '[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
726         if [[ $ATK_MAJOR_VERSION -gt 2 ||
727               ($ATK_MAJOR_VERSION -eq 2 && $ATK_MINOR_VERSION -gt 0) ||
728               ($ATK_MANOR_VERSION -eq 2 && $ATK_MINOR_VERSION -eq 0 && $ATK_DOTDOT_VERSION -ge 1) ]]
729         then
730             #
731             # Starting with ATK 2.0.1, xz-compressed tarballs are available.
732             #
733             [ -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
734             xzcat atk-$ATK_VERSION.tar.xz | tar xf - || exit 1
735         else
736             [ -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
737             bzcat atk-$ATK_VERSION.tar.bz2 | tar xf - || exit 1
738         fi
739         cd atk-$ATK_VERSION
740         CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
741         make $MAKE_BUILD_OPTS || exit 1
742         $DO_MAKE_INSTALL || exit 1
743         cd ..
744         touch atk-$ATK_VERSION-done
745     fi
746 }
747
748 uninstall_atk() {
749     if [ ! -z "$installed_atk_version" ] ; then
750         #
751         # GTK+ depends on this, so uninstall it.
752         #
753         uninstall_gtk "$@"
754
755         echo "Uninstalling ATK:"
756         cd atk-$installed_atk_version
757         $DO_MAKE_UNINSTALL || exit 1
758         make distclean || exit 1
759         cd ..
760         rm atk-$installed_atk_version-done
761
762         if [ "$#" -eq 1 -a "$1" = "-r" ] ; then
763             #
764             # Get rid of the previously downloaded and unpacked version.
765             #
766             rm -rf atk-$installed_atk_version
767             rm -rf atk-$installed_atk_version.tar.xz atk-$installed_atk_version.tar.bz2
768         fi
769
770         installed_atk_version=""
771     fi
772 }
773
774 install_pango() {
775     if [ ! -f pango-$PANGO_VERSION-done ] ; then
776         echo "Downloading, building, and installing Pango:"
777         pango_dir=`expr $PANGO_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
778         PANGO_MAJOR_VERSION="`expr $PANGO_VERSION : '\([0-9][0-9]*\).*'`"
779         PANGO_MINOR_VERSION="`expr $PANGO_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
780         if [[ $PANGO_MAJOR_VERSION -gt 1 ||
781               $PANGO_MINOR_VERSION -ge 29 ]]
782         then
783             #
784             # Starting with Pango 1.29, the tarballs are compressed with
785             # xz rather than bzip2.
786             #
787             [ -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
788             xzcat pango-$PANGO_VERSION.tar.xz | tar xf - || exit 1
789         else
790             [ -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
791             bzcat pango-$PANGO_VERSION.tar.bz2 | tar xf - || exit 1
792         fi
793         cd pango-$PANGO_VERSION
794         CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
795         make $MAKE_BUILD_OPTS || exit 1
796         $DO_MAKE_INSTALL || exit 1
797         cd ..
798         touch pango-$PANGO_VERSION-done
799     fi
800 }
801
802 uninstall_pango() {
803     if [ ! -z "$installed_pango_version" ] ; then
804         #
805         # GTK+ depends on this, so uninstall it.
806         #
807         uninstall_gtk "$@"
808
809         echo "Uninstalling Pango:"
810         cd pango-$installed_pango_version
811         $DO_MAKE_UNINSTALL || exit 1
812         make distclean || exit 1
813         cd ..
814         rm pango-$installed_pango_version-done
815
816         if [ "$#" -eq 1 -a "$1" = "-r" ] ; then
817             #
818             # Get rid of the previously downloaded and unpacked version.
819             #
820             rm -rf pango-$installed_pango_version
821             rm -rf pango-$installed_pango_version.tar.xz pango-$installed_pango_version.tar.bz2
822         fi
823
824         installed_pango_version=""
825     fi
826 }
827
828 install_gdk_pixbuf() {
829     if [ "$GDK_PIXBUF_VERSION" -a ! -f gdk-pixbuf-$GDK_PIXBUF_VERSION-done ] ; then
830         echo "Downloading, building, and installing gdk-pixbuf:"
831         gdk_pixbuf_dir=`expr $GDK_PIXBUF_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
832         [ -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
833         xzcat gdk-pixbuf-$GDK_PIXBUF_VERSION.tar.xz | tar xf - || exit 1
834         cd gdk-pixbuf-$GDK_PIXBUF_VERSION
835         #
836         # If we're building using the 10.6 SDK, force the use of libpng12.
837         #
838         # The OS's X11, and corresponding SDK, didn't introduce libpng15,
839         # or pkg-config files, until 10.7, so, for 10.6 have to explicitly
840         # set LIBPNG to override the configure script, and also force the
841         # CFLAGS to look for the header files for libpng12 (note that
842         # -isysroot doesn't affect the arguments to -I, so we need to
843         # include the SDK path explicitly).
844         #
845         if [[ "$sdk_target" = 10.6 ]]
846         then
847             LIBPNG="-L/usr/X11/lib -lpng12" CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS -I$SDKPATH/usr/X11/include/libpng12" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS -I$SDKPATH/usr/X11/include/libpng12" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --without-libtiff --without-libjpeg || exit 1
848         else
849             CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --without-libtiff --without-libjpeg || exit 1
850         fi
851         make $MAKE_BUILD_OPTS || exit 1
852         $DO_MAKE_INSTALL || exit 1
853         cd ..
854         touch gdk-pixbuf-$GDK_PIXBUF_VERSION-done
855     fi
856 }
857
858 uninstall_gdk_pixbuf() {
859     if [ ! -z "$installed_gdk_pixbuf_version" ] ; then
860         #
861         # GTK+ depends on this, so uninstall it.
862         #
863         uninstall_gtk "$@"
864
865         echo "Uninstalling gdk-pixbuf:"
866         cd gdk-pixbuf-$installed_gdk_pixbuf_version
867         $DO_MAKE_UNINSTALL || exit 1
868         make distclean || exit 1
869         cd ..
870         rm gdk-pixbuf-$installed_gdk_pixbuf_version-done
871
872         if [ "$#" -eq 1 -a "$1" = "-r" ] ; then
873             #
874             # Get rid of the previously downloaded and unpacked version.
875             #
876             rm -rf gdk-pixbuf-$installed_gdk_pixbuf_version
877             rm -rf gdk-pixbuf-$installed_gdk_pixbuf_version.tar.xz
878         fi
879
880         installed_gdk_pixbuf_version=""
881     fi
882 }
883
884 install_gtk() {
885     if [ ! -f gtk+-$GTK_VERSION-done ] ; then
886         echo "Downloading, building, and installing GTK+:"
887         gtk_dir=`expr $GTK_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
888         if [[ $GTK_MAJOR_VERSION -gt 2 ||
889               $GTK_MINOR_VERSION -gt 24 ||
890              ($GTK_MINOR_VERSION -eq 24 && $GTK_DOTDOT_VERSION -ge 5) ]]
891         then
892             #
893             # Starting with GTK+ 2.24.5, the tarballs are compressed with
894             # xz rather than gzip, in addition to bzip2; use xz, as we've
895             # built and installed it, and as xz compresses better than
896             # bzip2 so the tarballs take less time to download.
897             #
898             [ -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
899             xzcat gtk+-$GTK_VERSION.tar.xz | tar xf - || exit 1
900         else
901             [ -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
902             bzcat gtk+-$GTK_VERSION.tar.bz2 | tar xf - || exit 1
903         fi
904         cd gtk+-$GTK_VERSION
905         if [ $DARWIN_MAJOR_VERSION -ge "12" ]
906         then
907             #
908             # GTK+ 2.24.10, at least, doesn't build on Mountain Lion with the
909             # CUPS printing backend - either the CUPS API changed incompatibly
910             # or the backend was depending on non-API implementation details.
911             #
912             # Configure it out, on Mountain Lion and later, for now.
913             # (12 is the Darwin major version number in Mountain Lion.)
914             #
915             # Also, configure out libtiff and libjpeg; configure scripts
916             # just ignore unknown --enable/--disable and --with/--without
917             # options (at least they've always do so up to now).
918             #
919             CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --disable-cups --without-libtiff --without-libjpeg || exit 1
920         else
921             CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --without-libtiff --without-libjpeg || exit 1
922         fi
923         make $MAKE_BUILD_OPTS || exit 1
924         $DO_MAKE_INSTALL || exit 1
925         cd ..
926         touch gtk+-$GTK_VERSION-done
927     fi
928 }
929
930 uninstall_gtk() {
931     if [ ! -z "$installed_gtk_version" ] ; then
932         echo "Uninstalling GTK+:"
933         cd gtk+-$installed_gtk_version
934         $DO_MAKE_UNINSTALL || exit 1
935         make distclean || exit 1
936         cd ..
937         rm gtk+-$installed_gtk_version-done
938
939         if [ "$#" -eq 1 -a "$1" = "-r" ] ; then
940             #
941             # Get rid of the previously downloaded and unpacked version.
942             #
943             rm -rf gtk+-$installed_gtk_version
944             rm -rf gtk+-$installed_gtk_version.tar.xz gtk+-$installed_gtk_version.tar.bz2
945         fi
946
947         installed_gtk_version=""
948     fi
949 }
950
951 install_libsmi() {
952     if [ "$LIBSMI_VERSION" -a ! -f libsmi-$LIBSMI_VERSION-done ] ; then
953         echo "Downloading, building, and installing libsmi:"
954         [ -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
955         gzcat libsmi-$LIBSMI_VERSION.tar.gz | tar xf - || exit 1
956         cd libsmi-$LIBSMI_VERSION
957         CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
958         make $MAKE_BUILD_OPTS || exit 1
959         $DO_MAKE_INSTALL || exit 1
960         cd ..
961         touch libsmi-$LIBSMI_VERSION-done
962     fi
963 }
964
965 uninstall_libsmi() {
966     if [ ! -z "$installed_libsmi_version" ] ; then
967         echo "Uninstalling libsmi:"
968         cd libsmi-$installed_libsmi_version
969         $DO_MAKE_UNINSTALL || exit 1
970         make distclean || exit 1
971         cd ..
972         rm libsmi-$installed_libsmi_version-done
973
974         if [ "$#" -eq 1 -a "$1" = "-r" ] ; then
975             #
976             # Get rid of the previously downloaded and unpacked version.
977             #
978             rm -rf libsmi-$installed_libsmi_version
979             rm -rf libsmi-$installed_libsmi_version.tar.gz
980         fi
981
982         installed_libsmi_version=""
983     fi
984 }
985
986 install_libgpg_error() {
987     if [ "$LIBGPG_ERROR_VERSION" -a ! -f libgpg-error-$LIBGPG_ERROR_VERSION-done ] ; then
988         echo "Downloading, building, and installing libgpg-error:"
989         [ -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
990         bzcat libgpg-error-$LIBGPG_ERROR_VERSION.tar.bz2 | tar xf - || exit 1
991         cd libgpg-error-$LIBGPG_ERROR_VERSION
992         CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
993         make $MAKE_BUILD_OPTS || exit 1
994         $DO_MAKE_INSTALL || exit 1
995         cd ..
996         touch libgpg-error-$LIBGPG_ERROR_VERSION-done
997     fi
998 }
999
1000 uninstall_libgpg_error() {
1001     if [ ! -z "$installed_libgpg_error_version" ] ; then
1002         #
1003         # libgcrypt depends on this, so uninstall it.
1004         #
1005         uninstall_libgcrypt "$@"
1006
1007         echo "Uninstalling libgpg-error:"
1008         cd libgpg-error-$installed_libgpg_error_version
1009         $DO_MAKE_UNINSTALL || exit 1
1010         make distclean || exit 1
1011         cd ..
1012         rm libgpg-error-$installed_libgpg_error_version-done
1013
1014         if [ "$#" -eq 1 -a "$1" = "-r" ] ; then
1015             #
1016             # Get rid of the previously downloaded and unpacked version.
1017             #
1018             rm -rf libgpg-error-$installed_libgpg_error_version
1019             rm -rf libgpg-error-$installed_libgpg_error_version.tar.bz2
1020         fi
1021
1022         installed_libgpg_error_version=""
1023     fi
1024 }
1025
1026 install_libgcrypt() {
1027     if [ "$LIBGCRYPT_VERSION" -a ! -f libgcrypt-$LIBGCRYPT_VERSION-done ] ; then
1028         #
1029         # libgpg-error is required for libgcrypt.
1030         #
1031         if [ -z $LIBGPG_ERROR_VERSION ]
1032         then
1033             echo "libgcrypt requires libgpg-error, but you didn't install libgpg-error." 1>&2
1034             exit 1
1035         fi
1036
1037         echo "Downloading, building, and installing libgcrypt:"
1038         [ -f libgcrypt-$LIBGCRYPT_VERSION.tar.gz ] || curl -L -O ftp://ftp.gnupg.org/gcrypt/libgcrypt/libgcrypt-$LIBGCRYPT_VERSION.tar.gz || exit 1
1039         gzcat libgcrypt-$LIBGCRYPT_VERSION.tar.gz | tar xf - || exit 1
1040         cd libgcrypt-$LIBGCRYPT_VERSION
1041         #
1042         # The assembler language code is not compatible with the OS X
1043         # x86 assembler (or is it an x86-64 vs. x86-32 issue?).
1044         #
1045         # libgcrypt expects gnu89, not c99/gnu99, semantics for
1046         # "inline".  See, for example:
1047         #
1048         #    http://lists.freebsd.org/pipermail/freebsd-ports-bugs/2010-October/198809.html
1049         #
1050         CFLAGS="$CFLAGS -std=gnu89 $VERSION_MIN_FLAGS $SDKFLAGS" CFLAGS="$CFLAGS -std=gnu89 $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --disable-asm || exit 1
1051         make $MAKE_BUILD_OPTS || exit 1
1052         $DO_MAKE_INSTALL || exit 1
1053         cd ..
1054         touch libgcrypt-$LIBGCRYPT_VERSION-done
1055     fi
1056 }
1057
1058 uninstall_libgcrypt() {
1059     if [ ! -z "$installed_libgcrypt_version" ] ; then
1060         #
1061         # GnuTLS depends on this, so uninstall it.
1062         #
1063         uninstall_gnutls "$@"
1064
1065         echo "Uninstalling libgcrypt:"
1066         cd libgcrypt-$installed_libgcrypt_version
1067         $DO_MAKE_UNINSTALL || exit 1
1068         make distclean || exit 1
1069         cd ..
1070         rm libgcrypt-$installed_libgcrypt_version-done
1071
1072         if [ "$#" -eq 1 -a "$1" = "-r" ] ; then
1073             #
1074             # Get rid of the previously downloaded and unpacked version.
1075             #
1076             rm -rf libgcrypt-$installed_libgcrypt_version
1077             rm -rf libgcrypt-$installed_libgcrypt_version.tar.gz
1078         fi
1079
1080         installed_libgcrypt_version=""
1081     fi
1082 }
1083
1084 install_gnutls() {
1085     if [ "$GNUTLS_VERSION" -a ! -f gnutls-$GNUTLS_VERSION-done ] ; then
1086         #
1087         # GnuTLS requires libgcrypt (or nettle, in newer versions).
1088         #
1089         if [ -z $LIBGCRYPT_VERSION ]
1090         then
1091             echo "GnuTLS requires libgcrypt, but you didn't install libgcrypt" 1>&2
1092             exit 1
1093         fi
1094
1095         echo "Downloading, building, and installing GnuTLS:"
1096         [ -f gnutls-$GNUTLS_VERSION.tar.bz2 ] || curl -L -O http://ftp.gnu.org/gnu/gnutls/gnutls-$GNUTLS_VERSION.tar.bz2 || exit 1
1097         bzcat gnutls-$GNUTLS_VERSION.tar.bz2 | tar xf - || exit 1
1098         cd gnutls-$GNUTLS_VERSION
1099         #
1100         # Use libgcrypt, not nettle.
1101         # XXX - is there some reason to prefer nettle?  Or does
1102         # Wireshark directly use libgcrypt routines?
1103         #
1104         CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --with-libgcrypt --without-p11-kit || exit 1
1105         make $MAKE_BUILD_OPTS || exit 1
1106         #
1107         # The pkgconfig file for GnuTLS says "requires zlib", but OS X,
1108         # while it supplies zlib, doesn't supply a pkgconfig file for
1109         # it.
1110         #
1111         # Patch the GnuTLS pkgconfig file not to require zlib.
1112         # (If the capabilities of GnuTLS that Wireshark uses don't
1113         # depend on building GnuTLS with zlib, an alternative would be
1114         # to configure it not to use zlib.)
1115         #
1116         patch -p0 lib/gnutls.pc.in <../../macosx-support-lib-patches/gnutls-pkgconfig.patch || exit 1
1117         $DO_MAKE_INSTALL || exit 1
1118         cd ..
1119         touch gnutls-$GNUTLS_VERSION-done
1120     fi
1121 }
1122
1123 uninstall_gnutls() {
1124     if [ ! -z "$installed_gnutls_version" ] ; then
1125         echo "Uninstalling GnuTLS:"
1126         cd gnutls-$installed_gnutls_version
1127         $DO_MAKE_UNINSTALL || exit 1
1128         make distclean || exit 1
1129         cd ..
1130         rm gnutls-$installed_gnutls_version-done
1131
1132         if [ "$#" -eq 1 -a "$1" = "-r" ] ; then
1133             #
1134             # Get rid of the previously downloaded and unpacked version.
1135             #
1136             rm -rf gnutls-$installed_gnutls_version
1137             rm -rf gnutls-$installed_gnutls_version.tar.bz2
1138         fi
1139
1140         installed_gnutls_version=""
1141     fi
1142 }
1143
1144 install_lua() {
1145     if [ "$LUA_VERSION" -a ! -f lua-$LUA_VERSION-done ] ; then
1146         echo "Downloading, building, and installing Lua:"
1147         [ -f lua-$LUA_VERSION.tar.gz ] || curl -L -O http://www.lua.org/ftp/lua-$LUA_VERSION.tar.gz || exit 1
1148         gzcat lua-$LUA_VERSION.tar.gz | tar xf - || exit 1
1149         cd lua-$LUA_VERSION
1150         make $MAKE_BUILD_OPTS macosx || exit 1
1151         $DO_MAKE_INSTALL || exit 1
1152         cd ..
1153         touch lua-$LUA_VERSION-done
1154     fi
1155 }
1156
1157 uninstall_lua() {
1158     if [ ! -z "$installed_lua_version" ] ; then
1159         echo "Uninstalling Lua:"
1160         #
1161         # Lua has no "make uninstall", so just remove stuff manually.
1162         # There's no configure script, so there's no need for
1163         # "make distclean", either; just do "make clean".
1164         #
1165         (cd /usr/local/bin; $DO_RM -f lua luac)
1166         (cd /usr/local/include; $DO_RM -f lua.h luaconf.h lualib.h lauxlib.h lua.hpp)
1167         (cd /usr/local/lib; $DO_RM -f liblua.a)
1168         (cd /usr/local/man/man1; $DO_RM -f lua.1 luac.1)
1169         cd lua-$installed_lua_version
1170         make clean || exit 1
1171         cd ..
1172         rm lua-$installed_lua_version-done
1173
1174         if [ "$#" -eq 1 -a "$1" = "-r" ] ; then
1175             #
1176             # Get rid of the previously downloaded and unpacked version.
1177             #
1178             rm -rf lua-$installed_lua_version
1179             rm -rf lua-$installed_lua_version.tar.gz
1180         fi
1181
1182         installed_lua_version=""
1183     fi
1184 }
1185
1186 install_portaudio() {
1187     #
1188     # Check for both the old versionless portaudio-done and the new
1189     # versioned -done file.
1190     #
1191     if [ "$PORTAUDIO_VERSION" -a ! -f portaudio-$PORTAUDIO_VERSION-done ] ; then
1192         echo "Downloading, building, and installing PortAudio:"
1193         [ -f $PORTAUDIO_VERSION.tgz ] || curl -L -O http://www.portaudio.com/archives/$PORTAUDIO_VERSION.tgz || exit 1
1194         gzcat $PORTAUDIO_VERSION.tgz | tar xf - || exit 1
1195         cd portaudio
1196         #
1197         # Un-comment an include that's required on Lion.
1198         #
1199         patch -p0 include/pa_mac_core.h <../../macosx-support-lib-patches/portaudio-pa_mac_core.h.patch
1200         #
1201         # Fix a bug that showed up with clang (but is a bug with any
1202         # compiler).
1203         #
1204         patch -p0 src/hostapi/coreaudio/pa_mac_core.c <../../macosx-support-lib-patches/portaudio-pa_mac_core.c.patch
1205         #
1206         # Disable fat builds - the configure script doesn't work right
1207         # with Xcode 4 if you leave them enabled, and we don't build
1208         # any other libraries fat (GLib, for example, would be very
1209         # hard to build fat), so there's no advantage to having PortAudio
1210         # built fat.
1211         #
1212         # Set the minimum OS X version to 10.4, to suppress some
1213         # deprecation warnings.  (Good luck trying to make any of
1214         # this build on an OS+Xcode with a pre-10.4 SDK; we don't
1215         # worry about the user requesting that.)
1216         #
1217         CFLAGS="$CFLAGS -mmacosx-version-min=10.4 $SDKFLAGS" CXXFLAGS="$CXXFLAGS -mmacosx-version-min=10.4 $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --disable-mac-universal || exit 1
1218         make $MAKE_BUILD_OPTS || exit 1
1219         $DO_MAKE_INSTALL || exit 1
1220         cd ..
1221         touch portaudio-$PORTAUDIO_VERSION-done
1222     fi
1223 }
1224
1225 uninstall_portaudio() {
1226     if [ ! -z "$installed_portaudio_version" ] ; then
1227         echo "Uninstalling PortAudio:"
1228         cd portaudio
1229         $DO_MAKE_UNINSTALL || exit 1
1230         make distclean || exit 1
1231         cd ..
1232         rm portaudio-$installed_portaudio_version-done
1233
1234         if [ "$#" -eq 1 -a "$1" = "-r" ] ; then
1235             #
1236             # Get rid of the previously downloaded and unpacked version.
1237             #
1238             rm -rf portaudio
1239             rm -rf $installed_portaudio_version.tgz
1240         fi
1241
1242         installed_portaudio_version=""
1243     fi
1244 }
1245
1246 install_geoip() {
1247     if [ "$GEOIP_VERSION" -a ! -f geoip-$GEOIP_VERSION-done ] ; then
1248         echo "Downloading, building, and installing GeoIP API:"
1249         [ -f GeoIP-$GEOIP_VERSION.tar.gz ] || curl -L -O http://geolite.maxmind.com/download/geoip/api/c/GeoIP-$GEOIP_VERSION.tar.gz || exit 1
1250         gzcat GeoIP-$GEOIP_VERSION.tar.gz | tar xf - || exit 1
1251         cd GeoIP-$GEOIP_VERSION
1252         CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
1253         #
1254         # Grr.  Their man pages "helpfully" have an ISO 8859-1
1255         # copyright symbol in the copyright notice, but OS X's
1256         # default character encoding is UTF-8.  sed on Mountain
1257         # Lion barfs at the "illegal character sequence" represented
1258         # by an ISO 8859-1 copyright symbol, as it's not a valid
1259         # UTF-8 sequence.
1260         #
1261         # iconv the relevant man pages into UTF-8.
1262         #
1263         for i in geoipupdate.1.in geoiplookup6.1.in geoiplookup.1.in
1264         do
1265             iconv -f iso8859-1 -t utf-8 man/"$i" >man/"$i".tmp &&
1266                 mv man/"$i".tmp man/"$i"
1267         done
1268         make $MAKE_BUILD_OPTS || exit 1
1269         $DO_MAKE_INSTALL || exit 1
1270         cd ..
1271         touch geoip-$GEOIP_VERSION-done
1272     fi
1273 }
1274
1275 uninstall_geoip() {
1276     if [ ! -z "$installed_geoip_version" ] ; then
1277         echo "Uninstalling GeoIP API:"
1278         cd GeoIP-$installed_geoip_version
1279         $DO_MAKE_UNINSTALL || exit 1
1280         make distclean || exit 1
1281         cd ..
1282         rm geoip-$installed_geoip_version-done
1283
1284         if [ "$#" -eq 1 -a "$1" = "-r" ] ; then
1285             #
1286             # Get rid of the previously downloaded and unpacked version.
1287             #
1288             rm -rf GeoIP-$installed_geoip_version
1289             rm -rf GeoIP-$installed_geoip_version.tar.gz
1290         fi
1291
1292         installed_geoip_version=""
1293     fi
1294 }
1295
1296 install_c_ares() {
1297     if [ "$CARES_VERSION" -a ! -f c-ares-$CARES_VERSION-done ] ; then
1298         echo "Downloading, building, and installing C-Ares API:"
1299         [ -f c-ares-$CARES_VERSION.tar.gz ] || curl -L -O http://c-ares.haxx.se/download/c-ares-$CARES_VERSION.tar.gz || exit 1
1300         gzcat c-ares-$CARES_VERSION.tar.gz | tar xf - || exit 1
1301         cd c-ares-$CARES_VERSION
1302         CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS"  LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
1303         make $MAKE_BUILD_OPTS || exit 1
1304         $DO_MAKE_INSTALL || exit 1
1305         cd ..
1306         touch c-ares-$CARES_VERSION-done
1307     fi
1308 }
1309
1310 uninstall_c_ares() {
1311     if [ ! -z "$installed_cares_version" ] ; then
1312         echo "Uninstalling C-Ares API:"
1313         cd c-ares-$installed_cares_version
1314         $DO_MAKE_UNINSTALL || exit 1
1315         make distclean || exit 1
1316         cd ..
1317         rm c-ares-$installed_cares_version-done
1318
1319         if [ "$#" -eq 1 -a "$1" = "-r" ] ; then
1320             #
1321             # Get rid of the previously downloaded and unpacked version.
1322             #
1323             rm -rf c-ares-$installed_cares_version
1324             rm -rf c-ares-$installed_cares_version.tar.gz
1325         fi
1326
1327         installed_cares_version=""
1328     fi
1329 }
1330
1331 install_all() {
1332     #
1333     # Check whether the versions we have installed are the versions
1334     # requested; if not, uninstall the installed versions.
1335     #
1336     if [ ! -z "$installed_cares_version" -a \
1337               "$installed_cares_version" != "$CARES_VERSION" ] ; then
1338         echo "Installed C-Ares version is $installed_cares_version"
1339         if [ -z "$CARES_VERSION" ] ; then
1340             echo "C-Ares is not requested"
1341         else
1342             echo "Requested C-Ares version is $CARES_VERSION"
1343         fi
1344         uninstall_c_ares -r
1345     fi
1346
1347     if [ ! -z "$installed_geoip_version" -a \
1348               "$installed_geoip_version" != "$GEOIP_VERSION" ] ; then
1349         echo "Installed GeoIP API version is $installed_geoip_version"
1350         if [ -z "$GEOIP_VERSION" ] ; then
1351             echo "GeoIP is not requested"
1352         else
1353             echo "Requested GeoIP version is $GEOIP_VERSION"
1354         fi
1355         uninstall_geoip -r
1356     fi
1357
1358     if [ ! -z "$installed_portaudio_version" -a \
1359               "$installed_portaudio_version" != "$PORTAUDIO_VERSION" ] ; then
1360         echo "Installed PortAudio version is $installed_portaudio_version"
1361         if [ -z "$PORTAUDIO_VERSION" ] ; then
1362             echo "PortAudio is not requested"
1363         else
1364             echo "Requested PortAudio version is $PORTAUDIO_VERSION"
1365         fi
1366         uninstall_portaudio -r
1367     fi
1368
1369     if [ ! -z "$installed_lua_version" -a \
1370               "$installed_lua_version" != "$LUA_VERSION" ] ; then
1371         echo "Installed Lua version is $installed_lua_version"
1372         if [ -z "$LUA_VERSION" ] ; then
1373             echo "Lua is not requested"
1374         else
1375             echo "Requested Lua version is $LUA_VERSION"
1376         fi
1377         uninstall_lua -r
1378     fi
1379
1380     if [ ! -z "$installed_gnutls_version" -a \
1381               "$installed_gnutls_version" != "$GNUTLS_VERSION" ] ; then
1382         echo "Installed GnuTLS version is $installed_gnutls_version"
1383         if [ -z "$GNUTLS_VERSION" ] ; then
1384             echo "GnuTLS is not requested"
1385         else
1386             echo "Requested GnuTLS version is $GNUTLS_VERSION"
1387         fi
1388         uninstall_gnutls -r
1389     fi
1390
1391     if [ ! -z "$installed_libgcrypt_version" -a \
1392               "$installed_libgcrypt_version" != "$LIBGCRYPT_VERSION" ] ; then
1393         echo "Installed libgcrypt version is $installed_libgcrypt_version"
1394         if [ -z "$LIBGCRYPT_VERSION" ] ; then
1395             echo "libgcrypt is not requested"
1396         else
1397             echo "Requested libgcrypt version is $LIBGCRYPT_VERSION"
1398         fi
1399         uninstall_libgcrypt -r
1400     fi
1401
1402     if [ ! -z "$installed_libgpg_error_version" -a \
1403               "$installed_libgpg_error_version" != "$LIBGPG_ERROR_VERSION" ] ; then
1404         echo "Installed libgpg-error version is $installed_libgpg_error_version"
1405         if [ -z "$LIBGPG_ERROR_VERSION" ] ; then
1406             echo "libgpg-error is not requested"
1407         else
1408             echo "Requested libgpg-error version is $LIBGPG_ERROR_VERSION"
1409         fi
1410         uninstall_libgpg_error -r
1411     fi
1412
1413     if [ ! -z "$installed_libsmi_version" -a \
1414               "$installed_libsmi_version" != "$LIBSMI_VERSION" ] ; then
1415         echo "Installed libsmi version is $installed_libsmi_version"
1416         if [ -z "$LIBSMI_VERSION" ] ; then
1417             echo "libsmi is not requested"
1418         else
1419             echo "Requested libsmi version is $LIBSMI_VERSION"
1420         fi
1421         uninstall_libsmi -r
1422     fi
1423
1424     if [ ! -z "$installed_gtk_version" -a \
1425               "$installed_gtk_version" != "$GTK_VERSION" ] ; then
1426         echo "Installed GTK+ version is $installed_gtk_version"
1427         if [ -z "$GTK_VERSION" ] ; then
1428             echo "GTK+ is not requested"
1429         else
1430             echo "Requested GTK+ version is $GTK_VERSION"
1431         fi
1432         uninstall_gtk -r
1433     fi
1434
1435     if [ ! -z "$installed_gdk_pixbuf_version" -a \
1436               "$installed_gdk_pixbuf_version" != "$GDK_PIXBUF_VERSION" ] ; then
1437         echo "Installed gdk-pixbuf version is $installed_gdk_pixbuf_version"
1438         if [ -z "$GDK_PIXBUF_VERSION" ] ; then
1439             echo "gdk-pixbuf is not requested"
1440         else
1441             echo "Requested gdk-pixbuf version is $GDK_PIXBUF_VERSION"
1442         fi
1443         uninstall_gdk_pixbuf -r
1444     fi
1445
1446     if [ ! -z "$installed_pango_version" -a \
1447               "$installed_pango_version" != "$PANGO_VERSION" ] ; then
1448         echo "Installed Pango version is $installed_pango_version"
1449         if [ -z "$PANGO_VERSION" ] ; then
1450             echo "Pango is not requested"
1451         else
1452             echo "Requested Pango version is $PANGO_VERSION"
1453         fi
1454         uninstall_pango -r
1455     fi
1456
1457     if [ ! -z "$installed_atk_version" -a \
1458               "$installed_atk_version" != "$ATK_VERSION" ] ; then
1459         echo "Installed ATK version is $installed_atk_version"
1460         if [ -z "$ATK_VERSION" ] ; then
1461             echo "ATK is not requested"
1462         else
1463             echo "Requested ATK version is $ATK_VERSION"
1464         fi
1465         uninstall_atk -r
1466     fi
1467
1468     if [ ! -z "$installed_cairo_version" -a \
1469               "$installed_cairo_version" != "$CAIRO_VERSION" ] ; then
1470         echo "Installed Cairo version is $installed_cairo_version"
1471         if [ -z "$CAIRO_VERSION" ] ; then
1472             echo "Cairo is not requested"
1473         else
1474             echo "Requested Cairo version is $CAIRO_VERSION"
1475         fi
1476         uninstall_cairo -r
1477     fi
1478
1479     if [ ! -z "$installed_pixman_version" -a \
1480               "$installed_pixman_version" != "$PIXMAN_VERSION" ] ; then
1481         echo "Installed pixman version is $installed_pixman_version"
1482         if [ -z "$PIXMAN_VERSION" ] ; then
1483             echo "pixman is not requested"
1484         else
1485             echo "Requested pixman version is $PIXMAN_VERSION"
1486         fi
1487         uninstall_pixman -r
1488     fi
1489
1490     if [ ! -z "$installed_libpng_version" -a \
1491               "$installed_libpng_version" != "$PNG_VERSION" ] ; then
1492         echo "Installed libpng version is $installed_libpng_version"
1493         if [ -z "$PNG_VERSION" ] ; then
1494             echo "libpng is not requested"
1495         else
1496             echo "Requested libpng version is $PNG_VERSION"
1497         fi
1498         uninstall_libpng -r
1499     fi
1500
1501     if [ ! -z "$installed_qt_version" -a \
1502               "$installed_qt_version" != "$QT_VERSION" ] ; then
1503         echo "Installed Qt version is $installed_qt_version"
1504         if [ -z "$QT_VERSION" ] ; then
1505             echo "Qt is not requested"
1506         else
1507             echo "Requested Qt version is $QT_VERSION"
1508         fi
1509         uninstall_qt -r
1510     fi
1511
1512     if [ ! -z "$installed_glib_version" -a \
1513               "$installed_glib_version" != "$GLIB_VERSION" ] ; then
1514         echo "Installed GLib version is $installed_glib_version"
1515         if [ -z "$GLIB_VERSION" ] ; then
1516             echo "GLib is not requested"
1517         else
1518             echo "Requested GLib version is $GLIB_VERSION"
1519         fi
1520         uninstall_glib -r
1521     fi
1522
1523     if [ ! -z "$installed_pkg_config_version" -a \
1524               "$installed_pkg_config_version" != "$PKG_CONFIG_VERSION" ] ; then
1525         echo "Installed pkg-config version is $installed_pkg_config_version"
1526         if [ -z "$PKG_CONFIG_VERSION" ] ; then
1527             echo "pkg-config is not requested"
1528         else
1529             echo "Requested pkg-config version is $PKG_CONFIG_VERSION"
1530         fi
1531         uninstall_pkg_config -r
1532     fi
1533
1534     if [ ! -z "$installed_gettext_version" -a \
1535               "$installed_gettext_version" != "$GETTEXT_VERSION" ] ; then
1536         echo "Installed GNU gettext version is $installed_gettext_version"
1537         if [ -z "$GETTEXT_VERSION" ] ; then
1538             echo "GNU gettext is not requested"
1539         else
1540             echo "Requested GNU gettext version is $GETTEXT_VERSION"
1541         fi
1542         uninstall_gettext -r
1543     fi
1544
1545     if [ ! -z "$installed_cmake_version" -a \
1546               "$installed_cmake_version" != "$CMAKE_VERSION" ] ; then
1547         echo "Installed CMake version is $installed_cmake_version"
1548         if [ -z "$CMAKE_VERSION" ] ; then
1549             echo "CMake is not requested"
1550         else
1551             echo "Requested CMake version is $CMAKE_VERSION"
1552         fi
1553         #
1554         # XXX - really remove this?
1555         # Or should we remember it as installed only if this script
1556         # installed it?
1557         #
1558         uninstall_cmake -r
1559     fi
1560
1561     if [ ! -z "$installed_libtool_version" -a \
1562               "$installed_libtool_version" != "$LIBTOOL_VERSION" ] ; then
1563         echo "Installed GNU libtool version is $installed_libtool_version"
1564         if [ -z "$LIBTOOL_VERSION" ] ; then
1565             echo "GNU libtool is not requested"
1566         else
1567             echo "Requested GNU libtool version is $LIBTOOL_VERSION"
1568         fi
1569         uninstall_libtool -r
1570     fi
1571
1572     if [ ! -z "$installed_automake_version" -a \
1573               "$installed_automake_version" != "$AUTOMAKE_VERSION" ] ; then
1574         echo "Installed GNU automake version is $installed_automake_version"
1575         if [ -z "$AUTOMAKE_VERSION" ] ; then
1576             echo "GNU automake is not requested"
1577         else
1578             echo "Requested GNU automake version is $AUTOMAKE_VERSION"
1579         fi
1580         uninstall_automake -r
1581     fi
1582
1583     if [ ! -z "$installed_autoconf_version" -a \
1584               "$installed_autoconf_version" != "$AUTOCONF_VERSION" ] ; then
1585         echo "Installed GNU autoconf version is $installed_autoconf_version"
1586         if [ -z "$AUTOCONF_VERSION" ] ; then
1587             echo "GNU autoconf is not requested"
1588         else
1589             echo "Requested GNU autoconf version is $AUTOCONF_VERSION"
1590         fi
1591         uninstall_autoconf -r
1592     fi
1593
1594     if [ ! -z "$installed_xz_version" -a \
1595               "$installed_xz_version" != "$XZ_VERSION" ] ; then
1596         echo "Installed xz version is $installed_xz_version"
1597         if [ -z "$XZ_VERSION" ] ; then
1598             echo "xz is not requested"
1599         else
1600             echo "Requested xz version is $XZ_VERSION"
1601         fi
1602         uninstall_xz -r
1603     fi
1604
1605     #
1606     # Start with xz: It is the sole download format of glib later than 2.31.2
1607     #
1608     install_xz
1609
1610     install_autoconf
1611
1612     install_automake
1613
1614     install_libtool
1615
1616     install_cmake
1617
1618     #
1619     # Start with GNU gettext; GLib requires it, and OS X doesn't have it
1620     # or a BSD-licensed replacement.
1621     #
1622     # At least on Lion with Xcode 4, _FORTIFY_SOURCE gets defined as 2
1623     # by default, which causes, for example, stpncpy to be defined as
1624     # a hairy macro that collides with the GNU gettext configure script's
1625     # attempts to workaround AIX's lack of a declaration for stpncpy,
1626     # with the result being a huge train wreck.  Define _FORTIFY_SOURCE
1627     # as 0 in an attempt to keep the trains on separate tracks.
1628     #
1629     install_gettext
1630
1631     #
1632     # GLib depends on pkg-config.
1633     # By default, pkg-config depends on GLib; we break the dependency cycle
1634     # by configuring pkg-config to use its own internal version of GLib.
1635     #
1636     install_pkg_config
1637
1638     install_glib
1639
1640     #
1641     # Now we have reached a point where we can build everything but
1642     # the GUI (Wireshark).
1643     #
1644     install_qt
1645
1646     if [ "$GTK_VERSION" ]; then
1647         #
1648         # GTK+ 3 requires a newer Cairo build than the one that comes with
1649         # 10.6, so we build Cairo if we are using GTK+ 3.
1650         #
1651         # In 10.6 and 10.7, it's an X11 library; if we build with "native" GTK+
1652         # rather than X11 GTK+, we might have to build and install Cairo.
1653         # In 10.8 and later, there is no X11, but it's included in Xquartz;
1654         # again, if we build with "native" GTK+, we'd have to build and install
1655         # it.
1656         #
1657         if [[ "$GTK_MAJOR_VERSION" -eq 3 || "$cairo_not_in_the_os" = yes ]]; then
1658             #
1659             # Requirements for Cairo first
1660             #
1661             # The libpng that comes with the X11 for Leopard has a bogus
1662             # pkg-config file that lies about where the header files are,
1663             # which causes other packages not to be able to find its
1664             # headers.
1665             #
1666             # The libpng in later versions is not what the version of
1667             # libpixman we build below wants - it wants libpng15.
1668             #
1669             install_libpng
1670
1671             #
1672             # The libpixman versions that come with the X11s for Leopard,
1673             # Snow Leopard, and Lion is too old to support Cairo's image
1674             # surface backend feature (which requires pixman-1 >= 0.22.0).
1675             #
1676             # XXX - what about the one that comes with the latest version
1677             # of Xquartz?
1678             #
1679             install_pixman
1680
1681             #
1682             # And now Cairo itself.
1683             # XXX - with the libxcb that comes with 10.6,
1684             # xcb_discard_reply() is missing, and the build fails.
1685             #
1686             install_cairo
1687         fi
1688
1689         install_atk
1690
1691         install_pango
1692
1693         install_gdk_pixbuf
1694
1695         install_gtk
1696     fi
1697
1698     #
1699     # Now we have reached a point where we can build everything including
1700     # the GUI (Wireshark), but not with any optional features such as
1701     # SNMP OID resolution, some forms of decryption, Lua scripting, playback
1702     # of audio, or GeoIP mapping of IP addresses.
1703     #
1704     # We now conditionally download optional libraries to support them;
1705     # the default is to download them all.
1706     #
1707
1708     install_libsmi
1709
1710     install_libgpg_error
1711
1712     install_libgcrypt
1713
1714     install_gnutls
1715
1716     install_lua
1717
1718     install_portaudio
1719
1720     install_geoip
1721
1722     install_c_ares
1723 }
1724
1725 uninstall_all() {
1726     if [ -d macosx-support-libs ]
1727     then
1728         cd macosx-support-libs
1729
1730         #
1731         # Uninstall items in the reverse order from the order in which they're
1732         # installed.  Only uninstall if the download/build/install process
1733         # completed; uninstall the version that appears in the name of
1734         # the -done file.
1735         #
1736         # We also do a "make distclean", so that we don't have leftovers from
1737         # old configurations.
1738         #
1739         uninstall_c_ares
1740
1741         uninstall_geoip
1742
1743         uninstall_portaudio
1744
1745         uninstall_lua
1746
1747         uninstall_gnutls
1748
1749         uninstall_libgcrypt
1750
1751         uninstall_libgpg_error
1752
1753         uninstall_libsmi
1754
1755         uninstall_gtk
1756
1757         uninstall_gdk_pixbuf
1758
1759         uninstall_pango
1760
1761         uninstall_atk
1762
1763         uninstall_cairo
1764
1765         uninstall_pixman
1766
1767         uninstall_libpng
1768
1769         uninstall_qt
1770
1771         uninstall_glib
1772
1773         uninstall_pkg_config
1774
1775         uninstall_gettext
1776
1777         #
1778         # XXX - really remove this?
1779         # Or should we remember it as installed only if this script
1780         # installed it?
1781         #
1782         uninstall_cmake
1783
1784         uninstall_libtool
1785
1786         uninstall_automake
1787
1788         uninstall_autoconf
1789
1790         uninstall_xz
1791     fi
1792 }
1793
1794 #
1795 # Do we have permission to write in /usr/local?
1796 #
1797 # If so, assume we have permission to write in its subdirectories.
1798 # (If that's not the case, this test needs to check the subdirectories
1799 # as well.)
1800 #
1801 # If not, do "make install", "make uninstall", the removes for Lua,
1802 # and the renames of [g]libtool* with sudo.
1803 #
1804 if [ -w /usr/local ]
1805 then
1806     DO_MAKE_INSTALL="make install"
1807     DO_MAKE_UNINSTALL="make uninstall"
1808     DO_RM="rm"
1809     DO_MV="mv"
1810 else
1811     DO_MAKE_INSTALL="sudo make install"
1812     DO_MAKE_UNINSTALL="sudo make uninstall"
1813     DO_RM="sudo rm"
1814     DO_MV="sudo mv"
1815 fi
1816
1817 #
1818 # If we have SDKs available, the default target OS is the major version
1819 # of the one we're running; get that and strip off the third component
1820 # if present.
1821 #
1822 for i in /Developer/SDKs \
1823     /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs \
1824     /Library/Developer/CommandLineTools/SDKs
1825 do
1826     if [ -d "$i" ]
1827     then
1828         min_osx_target=`sw_vers -productVersion | sed 's/\([0-9]*\)\.\([0-9]*\)\.[0-9]*/\1.\2/'`
1829
1830         #
1831         # That's also the OS whose SDK we'd be using.
1832         #
1833         sdk_target=$min_osx_target
1834         break
1835     fi
1836 done
1837
1838 #
1839 # Parse command-line flags:
1840 #
1841 # -h - print help.
1842 # -t <target> - build libraries so that they'll work on the specified
1843 # version of OS X and later versions.
1844 # -u - do an uninstall.
1845 #
1846 while getopts ht:u name
1847 do
1848     case $name in
1849     u)
1850         do_uninstall=yes
1851         ;;
1852     t)
1853         min_osx_target="$OPTARG"
1854         ;;
1855     h|?)
1856         echo "Usage: macosx-setup.sh [ -t <target> ] [ -u ]" 1>&1
1857         exit 0
1858         ;;
1859     esac
1860 done
1861
1862 #
1863 # Get the version numbers of installed packages, if any.
1864 #
1865 if [ -d macosx-support-libs ]
1866 then
1867     cd macosx-support-libs
1868
1869     installed_xz_version=`ls xz-*-done 2>/dev/null | sed 's/xz-\(.*\)-done/\1/'`
1870     installed_autoconf_version=`ls autoconf-*-done 2>/dev/null | sed 's/autoconf-\(.*\)-done/\1/'`
1871     installed_automake_version=`ls automake-*-done 2>/dev/null | sed 's/automake-\(.*\)-done/\1/'`
1872     installed_libtool_version=`ls libtool-*-done 2>/dev/null | sed 's/libtool-\(.*\)-done/\1/'`
1873     installed_cmake_version=`ls cmake-*-done 2>/dev/null | sed 's/cmake-\(.*\)-done/\1/'`
1874     installed_gettext_version=`ls gettext-*-done 2>/dev/null | sed 's/gettext-\(.*\)-done/\1/'`
1875     installed_pkg_config_version=`ls pkg-config-*-done 2>/dev/null | sed 's/pkg-config-\(.*\)-done/\1/'`
1876     installed_glib_version=`ls glib-*-done 2>/dev/null | sed 's/glib-\(.*\)-done/\1/'`
1877     installed_qt_version=`ls qt-*-done 2>/dev/null | sed 's/qt-\(.*\)-done/\1/'`
1878     installed_libpng_version=`ls libpng-*-done 2>/dev/null | sed 's/libpng-\(.*\)-done/\1/'`
1879     installed_pixman_version=`ls pixman-*-done 2>/dev/null | sed 's/pixman-\(.*\)-done/\1/'`
1880     installed_cairo_version=`ls cairo-*-done 2>/dev/null | sed 's/cairo-\(.*\)-done/\1/'`
1881     installed_atk_version=`ls atk-*-done 2>/dev/null | sed 's/atk-\(.*\)-done/\1/'`
1882     installed_pango_version=`ls pango-*-done 2>/dev/null | sed 's/pango-\(.*\)-done/\1/'`
1883     installed_gdk_pixbuf_version=`ls gdk-pixbuf-*-done 2>/dev/null | sed 's/gdk-pixbuf-\(.*\)-done/\1/'`
1884     installed_gtk_version=`ls gtk+-*-done 2>/dev/null | sed 's/gtk+-\(.*\)-done/\1/'`
1885     installed_libsmi_version=`ls libsmi-*-done 2>/dev/null | sed 's/libsmi-\(.*\)-done/\1/'`
1886     installed_libgpg_error_version=`ls libgpg-error-*-done 2>/dev/null | sed 's/libgpg-error-\(.*\)-done/\1/'`
1887     installed_libgcrypt_version=`ls libgcrypt-*-done 2>/dev/null | sed 's/libgcrypt-\(.*\)-done/\1/'`
1888     installed_gnutls_version=`ls gnutls-*-done 2>/dev/null | sed 's/gnutls-\(.*\)-done/\1/'`
1889     installed_lua_version=`ls lua-*-done 2>/dev/null | sed 's/lua-\(.*\)-done/\1/'`
1890     installed_portaudio_version=`ls portaudio-*-done 2>/dev/null | sed 's/portaudio-\(.*\)-done/\1/'`
1891     installed_geoip_version=`ls geoip-*-done 2>/dev/null | sed 's/geoip-\(.*\)-done/\1/'`
1892     installed_cares_version=`ls c-ares-*-done 2>/dev/null | sed 's/c-ares-\(.*\)-done/\1/'`
1893
1894     #
1895     # If we don't have a versioned -done file for portaudio, but do have
1896     # an unversioned -done file for it, assume the installed version is the
1897     # requested version, and rename the -done file to include that version.
1898     #
1899     if [ -z "$installed_portaudio_version" -a -f portaudio-done ] ; then
1900         mv portaudio-done portaudio-$PORTAUDIO_VERSION-done
1901         installed_portaudio_version=`ls portaudio-*-done 2>/dev/null | sed 's/portaudio-\(.*\)-done/\1/'`
1902     fi
1903
1904     cd ..
1905 fi
1906
1907 if [ "$do_uninstall" = "yes" ]
1908 then
1909     uninstall_all
1910     exit 0
1911 fi
1912
1913 #
1914 # Configure scripts tend to set CFLAGS and CXXFLAGS to "-g -O2" if
1915 # invoked without CFLAGS or CXXFLAGS being set in the environment.
1916 #
1917 # However, we *are* setting them in the environment, for our own
1918 # nefarious purposes, so start them out as "-g -O2".
1919 #
1920 CFLAGS="-g -O2"
1921 CXXFLAGS="-g -O2"
1922
1923 #
1924 # To make this work on Leopard (rather than working *on* Snow Leopard
1925 # when building *for* Leopard) will take more work.
1926 #
1927 # For one thing, Leopard's /usr/X11/lib/libXdamage.la claims, at least
1928 # with all software updates applied, that the Xdamage shared library
1929 # is libXdamage.1.0.0.dylib, but it is, in fact, libXdamage.1.1.0.dylib.
1930 # This causes problems when building GTK+, so the script would have to
1931 # fix that file.
1932 #
1933 if [[ $DARWIN_MAJOR_VERSION -le 9 ]]; then
1934     echo "This script does not support any versions of OS X before Snow Leopard" 1>&2
1935     exit 1
1936 fi
1937
1938 # if no make options are present, set default options
1939 if [ -z "$MAKE_BUILD_OPTS" ] ; then
1940     # by default use 1.5x number of cores for parallel build
1941     MAKE_BUILD_OPTS="-j $(( $(sysctl -n hw.logicalcpu) * 3 / 2))"
1942 fi
1943
1944 #
1945 # If we have a target release, look for the oldest SDK that's for an
1946 # OS equal to or later than that one, and build libraries against it
1947 # rather than against the headers and, more importantly, libraries
1948 # that come with the OS, so that we don't end up with support libraries
1949 # that only work on the OS version on which we built them, not earlier
1950 # versions of the same release, or earlier releases if the minimum is
1951 # earlier.
1952 #
1953 if [ ! -z "$min_osx_target" ]
1954 then
1955     #
1956     # Get the real version - strip off the "10.".
1957     # We'll worry about that if, as, and when there's ever
1958     # an OS XI.
1959     #
1960     deploy_real_version=`echo "$min_osx_target" | sed -n 's/10\.\(.*\)/\1/p'`
1961
1962     #
1963     # Search each directory that might contain SDKs.
1964     #
1965     sdkpath=""
1966     for sdksdir in /Developer/SDKs \
1967         /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs \
1968         /Library/Developer/CommandLineTools/SDKs
1969     do
1970         #
1971         # Get a list of all the SDKs.
1972         #
1973         if ! test -d "$sdksdir"
1974         then
1975             #
1976             # There is no directory with that name.
1977             # Move on to the next one in the list, if any.
1978             #
1979             continue
1980         fi
1981
1982         #
1983         # Get a list of all the SDKs in that directory, if any.
1984         #
1985         sdklist=`(cd "$sdksdir"; ls -d MacOSX10.[0-9]*.sdk 2>/dev/null)`
1986
1987         for sdk in $sdklist
1988         do
1989             #
1990             # Get the real version for this SDK.
1991             #
1992             sdk_real_version=`echo "$sdk" | sed -n 's/MacOSX10\.\(.*\)\.sdk/\1/p'`
1993
1994             #
1995             # Is it for the deployment target or some later release?
1996             #
1997             if test "$sdk_real_version" -ge "$deploy_real_version"
1998             then
1999                 #
2000                 # Yes, use it.
2001                 #
2002                 sdkpath="$sdksdir/$sdk"
2003                 qt_sdk_arg="-sdk $sdk"
2004                 break 2
2005             fi
2006         done
2007     done
2008
2009     if [ -z "$sdkpath" ]
2010     then
2011         echo "macosx-setup.sh: Couldn't find an SDK for OS X $min_osx_target or later" 1>&2
2012         exit 1
2013     fi
2014
2015     SDKPATH="$sdkpath"
2016     sdk_target=10.$sdk_real_version
2017     echo "Using the 10.$sdk_real_version SDK"
2018
2019     #
2020     # Make sure there are links to /usr/local/include and /usr/local/lib
2021     # in the SDK's usr/local.
2022     #
2023     if [ ! -e $SDKPATH/usr/local/include ]
2024     then
2025         if [ ! -d $SDKPATH/usr/local ]
2026         then
2027             sudo mkdir $SDKPATH/usr/local
2028         fi
2029         sudo ln -s /usr/local/include $SDKPATH/usr/local/include
2030     fi
2031     if [ ! -e $SDKPATH/usr/local/lib ]
2032     then
2033         if [ ! -d $SDKPATH/usr/local ]
2034         then
2035             sudo mkdir $SDKPATH/usr/local
2036         fi
2037         sudo ln -s /usr/local/lib $SDKPATH/usr/local/lib
2038     fi
2039
2040     #
2041     # Set the minimum OS version for which to build to the specified
2042     # minimum target OS version, so we don't, for example, end up using
2043     # linker features supported by the OS verson on which we're building
2044     # but not by the target version.
2045     #
2046     VERSION_MIN_FLAGS="-mmacosx-version-min=$min_osx_target"
2047
2048     #
2049     # Compile and link against the SDK.
2050     #
2051     SDKFLAGS="-isysroot $SDKPATH"
2052
2053     if [[ "$min_osx_target" == "10.5" ]]
2054     then
2055         #
2056         # Cairo is part of Mac OS X 10.6 and later.
2057         # The *headers* are supplied by 10.5, but the *libraries*
2058         # aren't, so we have to build it if we're building for 10.5.
2059         #
2060         cairo_not_in_the_os=yes
2061
2062         #
2063         # Build with older versions of the support libraries, as
2064         # were used on the Wireshark Leopard buildbot at one
2065         # point.  (Most of these versions come from the About page
2066         # from Wireshark 1.8.6, the last build done on that buildbot;
2067         # the ATK version isn't reported, so this is a guess.)
2068         #
2069         # If you want to try building with newer versions of
2070         # the libraries, note that:
2071         #
2072         # The version of fontconfig that comes with Leopard doesn't
2073         # support FC_WEIGHT_EXTRABLACK, so we can't use any version
2074         # of Pango newer than 1.22.4.
2075         #
2076         # However, Pango 1.22.4 doesn't work with versions of GLib
2077         # after 2.29.6, because Pango 1.22.4 uses G_CONST_RETURN and
2078         # GLib 2.29.8 and later deprecate it (there doesn't appear to
2079         # be a GLib 2.29.7).  That means we'd either have to patch
2080         # Pango not to use it (just use "const"; G_CONST_RETURN was
2081         # there to allow code to choose whether to use "const" or not),
2082         # or use GLib 2.29.6 or earlier.
2083         #
2084         # GLib 2.29.6 includes an implementation of g_bit_lock() that,
2085         # on x86 (32-bit and 64-bit), uses asms in a fashion
2086         # ("asm volatile goto") that requires GCC 4.5 or later, which
2087         # is later than the compilers that come with Leopard and Snow
2088         # Leopard.  Recent versions of GLib check for that, but 2.29.6
2089         # doesn't, so, if you want to build GLib 2.29.6 on Leopard or
2090         # Snow Leopard, you would have to patch glib/gbitlock.c to do
2091         # what the newer versions of GLib do:
2092         #
2093         #  define a USE_ASM_GOTO macro that indicates whether "asm goto"
2094         #  can be used:
2095         #    #if (defined (i386) || defined (__amd64__))
2096         #      #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
2097         #        #define USE_ASM_GOTO 1
2098         #      #endif
2099         #    #endif
2100         #
2101         #  replace all occurrences of
2102         #
2103         #    #if defined (__GNUC__) && (defined (i386) || defined (__amd64__))
2104         #
2105         #  with
2106         #
2107         #    #ifdef USE_ASM_GOTO
2108         #
2109         # Using GLib 2.29.6 or earlier, however, means that we can't
2110         # use a version of ATK later than 2.3.93, as those versions
2111         # don't work with GLib 2.29.6.  The same applies to gdk-pixbuf;
2112         # versions of gdk-pixbuf after 2.24.1 won't work with GLib
2113         # 2.29.6.
2114         #
2115         # Then you have to make sure that what you've build doesn't
2116         # cause the X server that comes with Leopard to crash; at
2117         # least one attempt at building for Leopard did.
2118         #
2119         # At least if building on Leopard, you might also find
2120         # that, with various older versions of Cairo, including
2121         # 1.6.4 and at least some 1.8.x versions, when you try to
2122         # build it, the build fails because it can't find
2123         # png_set_longjmp_fn().  I vaguely remember dealing with that,
2124         # ages ago, but don't remember what I did.
2125         #
2126         GLIB_VERSION=2.16.3
2127         CAIRO_VERSION=1.6.4
2128         ATK_VERSION=1.24.0
2129         PANGO_VERSION=1.20.2
2130         GTK_VERSION=2.12.9
2131
2132         #
2133         # That version of GTK+ includes gdk-pixbuf.
2134         # XXX - base this on the version of GTK+ requested.
2135         #
2136         GDK_PIXBUF_VERSION=
2137
2138         #
2139         # Libgcrypt 1.5.0 fails to compile due to some problem with an
2140         # asm in rijndael.c, at least with i686-apple-darwin10-gcc-4.2.1
2141         # (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3) when building
2142         # 32-bit.
2143         #
2144         # We try libgcrypt 1.4.3 instead, as that's what shows up in
2145         # the version from the Leopard buildbot.
2146         LIBGCRYPT_VERSION=1.4.3
2147
2148         #
2149         # Build 32-bit while we're at it; Leopard has a bug that
2150         # causes some BPF functions not to work with 64-bit userland
2151         # code, so capturing won't work.
2152         #
2153         CFLAGS="$CFLAGS -arch i386"
2154         CXXFLAGS="$CXXFLAGS -arch i386"
2155         export LDFLAGS="$LDFLAGS -arch i386"
2156     fi
2157 fi
2158
2159 export CFLAGS
2160 export CXXFLAGS
2161
2162 #
2163 # You need Xcode or the command-line tools installed to get the compilers.
2164 #
2165 if [ ! -x /usr/bin/xcodebuild ]; then
2166     echo "Please install Xcode first (should be available on DVD or from http://developer.apple.com/xcode/index.php)."
2167     exit 1
2168 fi
2169
2170 if [ "$QT_VERSION" ]; then
2171     #
2172     # We need Xcode, not just the command-line tools, installed to build
2173     # Qt.
2174     #
2175     if ! /usr/bin/xcrun -find xcrun >/dev/null 2>&1; then
2176         echo "Please install Xcode first (should be available on DVD or from http://developer.apple.com/xcode/index.php)."
2177         echo "The command-line build tools are not sufficient to build Qt."
2178         exit 1
2179     fi
2180 fi
2181 if [ "$GTK_VERSION" ]; then
2182     #
2183     # If we're building with GTK+, you also need the X11 SDK; with at least
2184     # some versions of OS X and Xcode, that is, I think, an optional install.
2185     # (Or it might be installed with X11, but I think *that* is an optional
2186     # install on at least some versions of OS X.)
2187     #
2188     if [ ! -d /usr/X11/include ]; then
2189         echo "Please install X11 and the X11 SDK first."
2190         echo "  You can either use http://xquartz.macosforge.org/, e.g."
2191         echo "  http://xquartz-dl.macosforge.org/SL/XQuartz-$XQUARTZ_VERSION.dmg"
2192         echo "  or the native Apple packages if you are on Lion or below."
2193         exit 1
2194     fi
2195 fi
2196
2197 export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/X11/lib/pkgconfig
2198
2199 #
2200 # Do all the downloads and untarring in a subdirectory, so all that
2201 # stuff can be removed once we've installed the support libraries.
2202 #
2203 if [ ! -d macosx-support-libs ]
2204 then
2205     mkdir macosx-support-libs || exit 1
2206 fi
2207 cd macosx-support-libs
2208
2209 install_all
2210
2211 echo ""
2212
2213 #
2214 # Indicate what path to use for pkg-config.
2215 #
2216 pkg_config_path=/usr/local/lib/pkgconfig
2217 if [ "$QT_VERSION" ]; then
2218     pkg_config_path="$pkg_config_path":"$HOME/Qt$QT_VERSION/$QT_MAJOR_MINOR_VERSION/clang_64/lib/pkgconfig"
2219 fi
2220 pkg_config_path="$pkg_config_path":/usr/X11/lib/pkgconfig
2221
2222 echo "You are now prepared to build Wireshark. To do so do:"
2223 echo "export PKG_CONFIG_PATH=$pkg_config_path"
2224 echo ""
2225 if [ -n "$CMAKE" ]; then
2226     echo "mkdir build; cd build"
2227     echo "cmake .."
2228     echo
2229     echo "or"
2230     echo
2231 fi
2232 echo "./autogen.sh"
2233 echo "mkdir build; cd build"
2234 echo "../configure"
2235 echo ""
2236 echo "make $MAKE_BUILD_OPTS"
2237 echo "make install"
2238
2239 echo ""
2240
2241 echo "Make sure you are allowed capture access to the network devices"
2242 echo "See: https://wiki.wireshark.org/CaptureSetup/CapturePrivileges"
2243
2244 echo ""
2245
2246 exit 0