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