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