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