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