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