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