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