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