Pull the install and uninstall sequences into functions.
[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.2.1
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
94 # In case we want to build GTK *and* we don't have Apple's X11 SDK installed
95 # we may want to install XQuartz. The version will only be used in the printing
96 # of a URL, the package will not be installed.
97 #
98 XQUARTZ_VERSION=2.7.5
99 #
100 # The following libraries are optional.
101 # Comment them out if you don't want them, but note that some of
102 # the optional libraries are required by other optional libraries.
103 #
104 LIBSMI_VERSION=0.4.8
105 #
106 # libgpg-error is required for libgcrypt.
107 #
108 LIBGPG_ERROR_VERSION=1.10
109 #
110 # libgcrypt is required for GnuTLS.
111 # XXX - the link for "Libgcrypt source code" at
112 # http://www.gnupg.org/download/#libgcrypt is for 1.5.0, and is a bzip2
113 # file, but http://directory.fsf.org/project/libgcrypt/ lists only
114 # 1.4.6.
115 #
116 LIBGCRYPT_VERSION=1.5.0
117 GNUTLS_VERSION=2.12.19
118 # Default to 5.2 now, unless user overrides it later
119 LUA_VERSION=5.2.3
120 PORTAUDIO_VERSION=pa_stable_v19_20111121
121 #
122 # XXX - they appear to have an unversioned gzipped tarball for the
123 # current version; should we just download that, with some other
124 # way of specifying whether to download the GeoIP API?
125 #
126 GEOIP_VERSION=1.4.8
127
128 CARES_VERSION=1.10.0
129
130 DARWIN_MAJOR_VERSION=`uname -r | sed 's/\([0-9]*\).*/\1/'`
131
132 #
133 # GNU autotools; they're provided with releases up to Snow Leopard, but
134 # not in later releases.
135 #
136 if [[ $DARWIN_MAJOR_VERSION -gt 10 ]]; then
137     AUTOCONF_VERSION=2.69
138     AUTOMAKE_VERSION=1.13.3
139     LIBTOOL_VERSION=2.4.2
140 fi
141
142 install_xz() {
143     echo "Downloading, building, and installing xz:"
144     [ -f xz-$XZ_VERSION.tar.bz2 ] || curl -O http://tukaani.org/xz/xz-$XZ_VERSION.tar.bz2 || exit 1
145     bzcat xz-$XZ_VERSION.tar.bz2 | tar xf - || exit 1
146     cd xz-$XZ_VERSION
147     CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=0" ./configure || exit 1
148     make $MAKE_BUILD_OPTS || exit 1
149     $DO_MAKE_INSTALL || exit 1
150     cd ..
151     touch xz-$XZ_VERSION-done
152 }
153
154 uninstall_xz() {
155     echo "Uninstalling xz:"
156     cd xz-$installed_xz_version
157     $DO_MAKE_UNINSTALL || exit 1
158     make distclean || exit 1
159     cd ..
160     rm xz-$installed_xz_version-done
161 }
162
163 install_autoconf() {
164     echo "Downloading, building and installing GNU autoconf..."
165     [ -f autoconf-$AUTOCONF_VERSION.tar.xz ] || curl -O ftp://ftp.gnu.org/gnu/autoconf/autoconf-$AUTOCONF_VERSION.tar.xz || exit 1
166     xzcat autoconf-$AUTOCONF_VERSION.tar.xz | tar xf - || exit 1
167     cd autoconf-$AUTOCONF_VERSION
168     ./configure || exit 1
169     make $MAKE_BUILD_OPTS || exit 1
170     $DO_MAKE_INSTALL || exit 1
171     cd ..
172     touch autoconf-$AUTOCONF_VERSION-done
173 }
174
175 uninstall_autoconf() {
176     echo "Uninstalling GNU autoconf:"
177     cd autoconf-$installed_autoconf_version
178     $DO_MAKE_UNINSTALL || exit 1
179     make distclean || exit 1
180     cd ..
181     rm autoconf-$installed_autoconf_version-done
182 }
183
184 install_automake() {
185     echo "Downloading, building and installing GNU automake..."
186     [ -f automake-$AUTOMAKE_VERSION.tar.xz ] || curl -O ftp://ftp.gnu.org/gnu/automake/automake-$AUTOMAKE_VERSION.tar.xz || exit 1
187     xzcat automake-$AUTOMAKE_VERSION.tar.xz | tar xf - || exit 1
188     cd automake-$AUTOMAKE_VERSION
189     ./configure || exit 1
190     make $MAKE_BUILD_OPTS || exit 1
191     $DO_MAKE_INSTALL || exit 1
192     cd ..
193     touch automake-$AUTOMAKE_VERSION-done
194 }
195
196 uninstall_automake() {
197     echo "Uninstalling GNU automake:"
198     cd automake-$installed_automake_version
199     $DO_MAKE_UNINSTALL || exit 1
200     make distclean || exit 1
201     cd ..
202     rm automake-$installed_automake_version-done
203 }
204
205 install_libtool() {
206     echo "Downloading, building and installing GNU libtool..."
207     [ -f libtool-$LIBTOOL_VERSION.tar.xz ] || curl -O ftp://ftp.gnu.org/gnu/libtool/libtool-$LIBTOOL_VERSION.tar.xz || exit 1
208     xzcat libtool-$LIBTOOL_VERSION.tar.xz | tar xf - || exit 1
209     cd libtool-$LIBTOOL_VERSION
210     ./configure || exit 1
211     make $MAKE_BUILD_OPTS || exit 1
212     $DO_MAKE_INSTALL || exit 1
213     $DO_MV /usr/local/bin/libtool /usr/local/bin/glibtool
214     $DO_MV /usr/local/bin/libtoolize /usr/local/bin/glibtoolize
215     cd ..
216     touch libtool-$LIBTOOL_VERSION-done
217 }
218
219 uninstall_libtool() {
220     echo "Uninstalling GNU libtool:"
221     cd libtool-$installed_libtool_version
222     $DO_MV /usr/local/bin/glibtool /usr/local/bin/libtool
223     $DO_MV /usr/local/bin/glibtoolize /usr/local/bin/libtoolize
224     $DO_MAKE_UNINSTALL || exit 1
225     make distclean || exit 1
226     cd ..
227     rm libtool-$installed_libtool_version-done
228 }
229
230 install_cmake() {
231     echo "Downloading and installing CMake:"
232     cmake_dir=`expr $CMAKE_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
233     #
234     # NOTE: the "64" in "Darwin64" doesn't mean "64-bit-only"; the
235     # package in question supports both 32-bit and 64-bit x86.
236     #
237     [ -f cmake-$CMAKE_VERSION-Darwin64-universal.dmg ] || curl -O http://www.cmake.org/files/v$cmake_dir/cmake-$CMAKE_VERSION-Darwin64-universal.dmg || exit 1
238     sudo hdiutil attach http://www.cmake.org/files/v2.8/cmake-$CMAKE_VERSION-Darwin64-universal.dmg || exit 1
239     sudo installer -target / -pkg /Volumes/cmake-$CMAKE_VERSION-Darwin64-universal/cmake-$CMAKE_VERSION-Darwin64-universal.pkg || exit 1
240     sudo hdiutil detach /Volumes/cmake-$CMAKE_VERSION-Darwin64-universal
241     touch cmake-$CMAKE_VERSION-done
242 }
243
244 uninstall_cmake() {
245     echo "Uninstalling CMake:"
246     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
247     sudo rm /usr/bin/ccmake
248     sudo rm /usr/bin/cmake
249     sudo rm /usr/bin/cmake-gui
250     sudo rm /usr/bin/cmakexbuild
251     sudo rm /usr/bin/cpack
252     sudo rm /usr/bin/ctest
253     sudo pkgutil --forget com.Kitware.CMake
254     rm cmake-$installed_cmake_version-done
255 }
256
257 install_gettext() {
258     echo "Downloading, building, and installing GNU gettext:"
259     [ -f gettext-$GETTEXT_VERSION.tar.gz ] || curl -O http://ftp.gnu.org/pub/gnu/gettext/gettext-$GETTEXT_VERSION.tar.gz || exit 1
260     gzcat gettext-$GETTEXT_VERSION.tar.gz | tar xf - || exit 1
261     cd gettext-$GETTEXT_VERSION
262     CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=0 $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
263     make $MAKE_BUILD_OPTS || exit 1
264     $DO_MAKE_INSTALL || exit 1
265     cd ..
266     touch gettext-$GETTEXT_VERSION-done
267 }
268
269 uninstall_gettext() {
270     echo "Uninstalling GNU gettext:"
271     cd gettext-$installed_gettext_version
272     $DO_MAKE_UNINSTALL || exit 1
273     make distclean || exit 1
274     cd ..
275     rm gettext-$installed_gettext_version-done
276 }
277
278 install_pkg_config() {
279     echo "Downloading, building, and installing pkg-config:"
280     [ -f pkg-config-$PKG_CONFIG_VERSION.tar.gz ] || curl -O http://pkgconfig.freedesktop.org/releases/pkg-config-$PKG_CONFIG_VERSION.tar.gz || exit 1
281     gzcat pkg-config-$PKG_CONFIG_VERSION.tar.gz | tar xf - || exit 1
282     cd pkg-config-$PKG_CONFIG_VERSION
283     ./configure --with-internal-glib || exit 1
284     make $MAKE_BUILD_OPTS || exit 1
285     $DO_MAKE_INSTALL || exit 1
286     cd ..
287     touch pkg-config-$PKG_CONFIG_VERSION-done
288 }
289
290 uninstall_pkg_config() {
291     echo "Uninstalling pkg-config:"
292     cd pkg-config-$installed_pkg_config_version
293     $DO_MAKE_UNINSTALL || exit 1
294     make distclean || exit 1
295     cd ..
296     rm pkg-config-$installed_pkg_config_version-done
297 }
298
299 install_glib() {
300     echo "Downloading, building, and installing GLib:"
301     glib_dir=`expr $GLIB_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
302     GLIB_MAJOR_VERSION="`expr $GLIB_VERSION : '\([0-9][0-9]*\).*'`"
303     GLIB_MINOR_VERSION="`expr $GLIB_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
304     GLIB_DOTDOT_VERSION="`expr $GLIB_VERSION : '[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
305     if [[ $GLIB_MAJOR_VERSION -gt 2 ||
306           $GLIB_MINOR_VERSION -gt 28 ||
307           ($GLIB_MINOR_VERSION -eq 28 && $GLIB_DOTDOT_VERSION -ge 8) ]]
308     then
309         #
310         # Starting with GLib 2.28.8, xz-compressed tarballs are available.
311         #
312         [ -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
313         xzcat glib-$GLIB_VERSION.tar.xz | tar xf - || exit 1
314     else
315         [ -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
316         bzcat glib-$GLIB_VERSION.tar.bz2 | tar xf - || exit 1
317     fi
318     cd glib-$GLIB_VERSION
319     #
320     # OS X ships with libffi, but doesn't provide its pkg-config file;
321     # explicitly specify LIBFFI_CFLAGS and LIBFFI_LIBS, so the configure
322     # script doesn't try to use pkg-config to get the appropriate
323     # C flags and loader flags.
324     #
325     # And, what's worse, at least with the version of Xcode that comes
326     # with Leopard, /usr/include/ffi/fficonfig.h doesn't define MACOSX,
327     # which causes the build of GLib to fail.  If we don't find
328     # "#define.*MACOSX" in /usr/include/ffi/fficonfig.h, explicitly
329     # define it.
330     #
331     # While we're at it, suppress -Wformat-nonliteral to avoid a case
332     # where clang's stricter rules on when not to complain about
333     # non-literal format arguments cause it to complain about code
334     # that's safe but it wasn't told that.  See my comment #25 in
335     # GNOME bug 691608:
336     #
337     #    https://bugzilla.gnome.org/show_bug.cgi?id=691608#c25
338     #
339     # First, determine where the system include files are.  (It's not
340     # necessarily /usr/include.)  There's a bit of a greasy hack here;
341     # pre-5.x versions of the developer tools don't support the
342     # --show-sdk-path option, and will produce no output, so includedir
343     # will be set to /usr/include (in those older versions of the
344     # developer tools, there is a /usr/include directory).
345     #
346     includedir=`xcrun --show-sdk-path 2>/dev/null`/usr/include
347     if grep -qs '#define.*MACOSX' $includedir/ffi/fficonfig.h
348     then
349         # It's defined, nothing to do
350         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
351     else
352         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
353     fi
354
355     #
356     # Apply the fix to GNOME bug 529806:
357     #
358     #    https://bugzilla.gnome.org/show_bug.cgi?id=529806
359     #
360     # if we have a version of GLib prior to 2.30.
361     #
362     if [[ $GLIB_MAJOR_VERSION -eq 2 && $GLIB_MINOR_VERSION -le 30 ]]
363     then
364         patch -p0 <../../macosx-support-lib-patches/glib-gconvert.c.patch || exit 1
365     fi
366     make $MAKE_BUILD_OPTS || exit 1
367     $DO_MAKE_INSTALL || exit 1
368     cd ..
369     touch glib-$GLIB_VERSION-done
370 }
371
372 uninstall_glib() {
373     echo "Uninstalling GLib:"
374     cd glib-$installed_glib_version
375     $DO_MAKE_UNINSTALL || exit 1
376     make distclean || exit 1
377     cd ..
378     rm glib-$installed_glib_version-done
379 }
380
381 install_qt() {
382     echo "Downloading, building, and installing Qt:"
383     QT_MAJOR_VERSION="`expr $QT_VERSION : '\([0-9][0-9]*\).*'`"
384     QT_MINOR_VERSION="`expr $QT_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
385     QT_DOTDOT_VERSION="`expr $QT_VERSION : '[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
386     QT_MAJOR_MINOR_VERSION=$QT_MAJOR_VERSION.$QT_MINOR_VERSION
387     #
388     # What you get for this URL might just be a 302 Found reply, so use
389     # -L so we get redirected.
390     #
391     curl -L -O http://download.qt-project.org/official_releases/qt/$QT_MAJOR_MINOR_VERSION/$QT_VERSION/single/qt-everywhere-opensource-src-$QT_VERSION.tar.gz
392     #
393     # Qt 5.1.x sets QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.6
394     # in qtbase/mkspecs/$TARGET_PLATFORM/qmake.conf
395     # We may need to adjust this manually in the future.
396     #
397     # The -no-c++11 flag is needed to work around
398     # https://bugreports.qt-project.org/browse/QTBUG-30487
399     #
400     tar xf qt-everywhere-opensource-src-$QT_VERSION.tar.gz
401     cd qt-everywhere-opensource-src-$QT_VERSION
402     #
403     # We don't build Qt in its Full Shining Glory, as we don't need all
404     # of its components, and it takes *forever* to build in that form.
405     #
406     # Qt 5.2.0 beta1 fails to build on OS X without -no-xcb due to bug
407     # QTBUG-34382.
408     #
409     # Qt 5.x fails to build on OS X with -no-opengl due to bug
410     # QTBUG-31151.
411     #
412     ./configure -v $qt_sdk_arg -platform $TARGET_PLATFORM \
413         -opensource -confirm-license -no-c++11 -no-dbus \
414         -no-sql-sqlite -no-xcb -nomake examples \
415         -skip qtdoc -skip qtquickcontrols -skip qtwebkit \
416         -skip qtwebkit-examples -skip qtxmlpatterns
417     make || exit 1
418     $DO_MAKE_INSTALL || exit 1
419     cd ..
420     touch qt-$QT_VERSION-done
421 }
422
423 uninstall_qt() {
424     echo "Uninstalling Qt:"
425     cd qt-everywhere-opensource-src-$installed_qt_version
426     $DO_MAKE_UNINSTALL || exit 1
427     #
428     # XXX - "make distclean" doesn't work.  qmake sure does a
429     # good job of constructing Makefiles that work correctly....
430     #
431     #make distclean || exit 1
432     cd ..
433     rm qt-$installed_qt_version-done
434 }
435
436 install_libpng() {
437     echo "Downloading, building, and installing libpng:"
438     #
439     # The FTP site puts libpng x.y.* into a libpngxy directory.
440     #
441     subdir=`echo $PNG_VERSION | sed 's/\([1-9][0-9]*\)\.\([1-9][0-9]*\).*/libpng\1\2'/`
442     [ -f libpng-$PNG_VERSION.tar.xz ] || curl -O ftp://ftp.simplesystems.org/pub/libpng/png/src/$subdir/libpng-$PNG_VERSION.tar.xz
443     xzcat libpng-$PNG_VERSION.tar.xz | tar xf - || exit 1
444     cd libpng-$PNG_VERSION
445     CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
446     make $MAKE_BUILD_OPTS || exit 1
447     $DO_MAKE_INSTALL || exit 1
448     cd ..
449     touch libpng-$PNG_VERSION-done
450 }
451
452 uninstall_libpng() {
453     echo "Uninstalling libpng:"
454     cd libpng-$installed_libpng_version
455     $DO_MAKE_UNINSTALL || exit 1
456     make distclean || exit 1
457     cd ..
458     rm libpng-$installed_libpng_version-done
459 }
460
461 install_libpixman() {
462     echo "Downloading, building, and installing pixman:"
463     [ -f pixman-$PIXMAN_VERSION.tar.gz ] || curl -O http://www.cairographics.org/releases/pixman-$PIXMAN_VERSION.tar.gz
464     gzcat pixman-$PIXMAN_VERSION.tar.gz | tar xf - || exit 1
465     cd pixman-$PIXMAN_VERSION
466     CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
467     make $MAKE_BUILD_OPTS || exit 1
468     $DO_MAKE_INSTALL || exit 1
469     cd ..
470     touch pixman-$PIXMAN_VERSION-done
471 }
472
473 uninstall_pixman() {
474     echo "Uninstalling pixman:"
475     cd pixman-$installed_pixman_version
476     $DO_MAKE_UNINSTALL || exit 1
477     make distclean || exit 1
478     cd ..
479     rm pixman-$installed_pixman_version-done
480 }
481
482 install_cairo() {
483     echo "Downloading, building, and installing Cairo:"
484     CAIRO_MAJOR_VERSION="`expr $CAIRO_VERSION : '\([0-9][0-9]*\).*'`"
485     CAIRO_MINOR_VERSION="`expr $CAIRO_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
486     CAIRO_DOTDOT_VERSION="`expr $CAIRO_VERSION : '[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
487     if [[ $CAIRO_MAJOR_VERSION -gt 1 ||
488           $CAIRO_MINOR_VERSION -gt 12 ||
489           ($CAIRO_MINOR_VERSION -eq 12 && $CAIRO_DOTDOT_VERSION -ge 2) ]]
490     then
491         #
492         # Starting with Cairo 1.12.2, the tarballs are compressed with
493         # xz rather than gzip.
494         #
495         [ -f cairo-$CAIRO_VERSION.tar.xz ] || curl -O http://cairographics.org/releases/cairo-$CAIRO_VERSION.tar.xz || exit 1
496         xzcat cairo-$CAIRO_VERSION.tar.xz | tar xf - || exit 1
497     else
498         [ -f cairo-$CAIRO_VERSION.tar.gz ] || curl -O http://cairographics.org/releases/cairo-$CAIRO_VERSION.tar.gz || exit 1
499         gzcat cairo-$CAIRO_VERSION.tar.gz | tar xf - || exit 1
500     fi
501     cd cairo-$CAIRO_VERSION
502     # CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --enable-quartz=no || exit 1
503     # Maybe follow http://cairographics.org/end_to_end_build_for_mac_os_x/
504     CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --enable-quartz=yes || exit 1
505     #
506     # We must avoid the version of libpng that comes with X11; the
507     # only way I've found to force that is to forcibly set INCLUDES
508     # when we do the build, so that this comes before CAIRO_CFLAGS,
509     # which has -I/usr/X11/include added to it before anything
510     # connected to libpng is.
511     #
512     INCLUDES="-I/usr/local/include/libpng15" make $MAKE_BUILD_OPTS || exit 1
513     $DO_MAKE_INSTALL || exit 1
514     cd ..
515     touch cairo-$CAIRO_VERSION-done
516 }
517
518 uninstall_cairo() {
519     echo "Uninstalling Cairo:"
520     cd cairo-$installed_cairo_version
521     $DO_MAKE_UNINSTALL || exit 1
522     make distclean || exit 1
523     cd ..
524     rm cairo-$installed_cairo_version-done
525 }
526
527 install_atk() {
528     echo "Downloading, building, and installing ATK:"
529     atk_dir=`expr $ATK_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
530     ATK_MAJOR_VERSION="`expr $ATK_VERSION : '\([0-9][0-9]*\).*'`"
531     ATK_MINOR_VERSION="`expr $ATK_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
532     ATK_DOTDOT_VERSION="`expr $ATK_VERSION : '[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
533     if [[ $ATK_MAJOR_VERSION -gt 2 ||
534           ($ATK_MAJOR_VERSION -eq 2 && $ATK_MINOR_VERSION -gt 0) ||
535           ($ATK_MANOR_VERSION -eq 2 && $ATK_MINOR_VERSION -eq 0 && $ATK_DOTDOT_VERSION -ge 1) ]]
536     then
537         #
538         # Starting with ATK 2.0.1, xz-compressed tarballs are available.
539         #
540         [ -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
541         xzcat atk-$ATK_VERSION.tar.xz | tar xf - || exit 1
542     else
543         [ -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
544         bzcat atk-$ATK_VERSION.tar.bz2 | tar xf - || exit 1
545     fi
546     cd atk-$ATK_VERSION
547     CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
548     make $MAKE_BUILD_OPTS || exit 1
549     $DO_MAKE_INSTALL || exit 1
550     cd ..
551     touch atk-$ATK_VERSION-done
552 }
553
554 uninstall_atk() {
555     echo "Uninstalling ATK:"
556     cd atk-$installed_atk_version
557     $DO_MAKE_UNINSTALL || exit 1
558     make distclean || exit 1
559     cd ..
560     rm atk-$installed_atk_version-done
561 }
562
563 install_pango() {
564     echo "Downloading, building, and installing Pango:"
565     pango_dir=`expr $PANGO_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
566     PANGO_MAJOR_VERSION="`expr $PANGO_VERSION : '\([0-9][0-9]*\).*'`"
567     PANGO_MINOR_VERSION="`expr $PANGO_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
568     if [[ $PANGO_MAJOR_VERSION -gt 1 ||
569           $PANGO_MINOR_VERSION -ge 29 ]]
570     then
571         #
572         # Starting with Pango 1.29, the tarballs are compressed with
573         # xz rather than bzip2.
574         #
575         [ -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
576         xzcat pango-$PANGO_VERSION.tar.xz | tar xf - || exit 1
577     else
578         [ -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
579         bzcat pango-$PANGO_VERSION.tar.bz2 | tar xf - || exit 1
580     fi
581     cd pango-$PANGO_VERSION
582     CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
583     make $MAKE_BUILD_OPTS || exit 1
584     $DO_MAKE_INSTALL || exit 1
585     cd ..
586     touch pango-$PANGO_VERSION-done
587 }
588
589 uninstall_pango() {
590     echo "Uninstalling Pango:"
591     cd pango-$installed_pango_version
592     $DO_MAKE_UNINSTALL || exit 1
593     make distclean || exit 1
594     cd ..
595     rm pango-$installed_pango_version-done
596 }
597
598 install_gdk_pixbuf() {
599     echo "Downloading, building, and installing gdk-pixbuf:"
600     gdk_pixbuf_dir=`expr $GDK_PIXBUF_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
601     [ -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
602     xzcat gdk-pixbuf-$GDK_PIXBUF_VERSION.tar.xz | tar xf - || exit 1
603     cd gdk-pixbuf-$GDK_PIXBUF_VERSION
604     #
605     # If we're building using the 10.6 SDK, force the use of libpng12.
606     #
607     # The OS's X11, and corresponding SDK, didn't introduce libpng15,
608     # or pkg-config files, until 10.7, so, for 10.6 have to explicitly
609     # set LIBPNG to override the configure script, and also force the
610     # CFLAGS to look for the header files for libpng12 (note that
611     # -isysroot doesn't affect the arguments to -I, so we need to
612     # include the SDK path explicitly).
613     #
614     if [[ "$sdk_target" = 10.6 ]]
615     then
616         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
617     else
618         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
619     fi
620     make $MAKE_BUILD_OPTS || exit 1
621     $DO_MAKE_INSTALL || exit 1
622     cd ..
623     touch gdk-pixbuf-$GDK_PIXBUF_VERSION-done
624 }
625
626 uninstall_gdk_pixbuf() {
627     echo "Uninstalling gdk-pixbuf:"
628     cd gdk-pixbuf-$installed_gdk_pixbuf_version
629     $DO_MAKE_UNINSTALL || exit 1
630     make distclean || exit 1
631     cd ..
632     rm gdk-pixbuf-$installed_gdk_pixbuf_version-done
633 }
634
635 install_gtk() {
636     echo "Downloading, building, and installing GTK+:"
637     gtk_dir=`expr $GTK_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
638     if [[ $GTK_MAJOR_VERSION -gt 2 ||
639           $GTK_MINOR_VERSION -gt 24 ||
640          ($GTK_MINOR_VERSION -eq 24 && $GTK_DOTDOT_VERSION -ge 5) ]]
641     then
642         #
643         # Starting with GTK+ 2.24.5, the tarballs are compressed with
644         # xz rather than gzip, in addition to bzip2; use xz, as we've
645         # built and installed it, and as xz compresses better than
646         # bzip2 so the tarballs take less time to download.
647         #
648         [ -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
649         xzcat gtk+-$GTK_VERSION.tar.xz | tar xf - || exit 1
650     else
651         [ -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
652         bzcat gtk+-$GTK_VERSION.tar.bz2 | tar xf - || exit 1
653     fi
654     cd gtk+-$GTK_VERSION
655     if [ $DARWIN_MAJOR_VERSION -ge "12" ]
656     then
657         #
658         # GTK+ 2.24.10, at least, doesn't build on Mountain Lion with the
659         # CUPS printing backend - either the CUPS API changed incompatibly
660         # or the backend was depending on non-API implementation details.
661         #
662         # Configure it out, on Mountain Lion and later, for now.
663         # (12 is the Darwin major version number in Mountain Lion.)
664         #
665         # Also, configure out libtiff and libjpeg; configure scripts
666         # just ignore unknown --enable/--disable and --with/--without
667         # options (at least they've always do so up to now).
668         #
669         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
670     else
671         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
672     fi
673     make $MAKE_BUILD_OPTS || exit 1
674     $DO_MAKE_INSTALL || exit 1
675     cd ..
676     touch gtk+-$GTK_VERSION-done
677 }
678
679 uninstall_gtk() {
680     echo "Uninstalling GTK+:"
681     cd gtk+-$installed_gtk_version
682     $DO_MAKE_UNINSTALL || exit 1
683     make distclean || exit 1
684     cd ..
685     rm gtk+-$installed_gtk_version-done
686 }
687
688 install_libsmi() {
689     echo "Downloading, building, and installing libsmi:"
690     [ -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
691     gzcat libsmi-$LIBSMI_VERSION.tar.gz | tar xf - || exit 1
692     cd libsmi-$LIBSMI_VERSION
693     CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
694     make $MAKE_BUILD_OPTS || exit 1
695     $DO_MAKE_INSTALL || exit 1
696     cd ..
697     touch libsmi-$LIBSMI_VERSION-done
698 }
699
700 uninstall_libsmi() {
701     echo "Uninstalling libsmi:"
702     cd libsmi-$installed_libsmi_version
703     $DO_MAKE_UNINSTALL || exit 1
704     make distclean || exit 1
705     cd ..
706     rm libsmi-$installed_libsmi_version-done
707 }
708
709 install_libgpg_error() {
710     echo "Downloading, building, and installing libgpg-error:"
711     [ -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
712     bzcat libgpg-error-$LIBGPG_ERROR_VERSION.tar.bz2 | tar xf - || exit 1
713     cd libgpg-error-$LIBGPG_ERROR_VERSION
714     CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
715     make $MAKE_BUILD_OPTS || exit 1
716     $DO_MAKE_INSTALL || exit 1
717     cd ..
718     touch libgpg-error-$LIBGPG_ERROR_VERSION-done
719 }
720
721 uninstall_libgpg_error() {
722     echo "Uninstalling libgpg-error:"
723     cd libgpg-error-$installed_libgpg_error_version
724     $DO_MAKE_UNINSTALL || exit 1
725     make distclean || exit 1
726     cd ..
727     rm libgpg-error-$installed_libgpg_error_version-done
728 }
729
730 install_libgcrypt() {
731     #
732     # libgpg-error is required for libgcrypt.
733     #
734     if [ -z $LIBGPG_ERROR_VERSION ]
735     then
736         echo "libgcrypt requires libgpg-error, but you didn't install libgpg-error." 1>&2
737         exit 1
738     fi
739
740     echo "Downloading, building, and installing libgcrypt:"
741     [ -f libgcrypt-$LIBGCRYPT_VERSION.tar.gz ] || curl -L -O ftp://ftp.gnupg.org/gcrypt/libgcrypt/libgcrypt-$LIBGCRYPT_VERSION.tar.gz || exit 1
742     gzcat libgcrypt-$LIBGCRYPT_VERSION.tar.gz | tar xf - || exit 1
743     cd libgcrypt-$LIBGCRYPT_VERSION
744     #
745     # The assembler language code is not compatible with the OS X
746     # x86 assembler (or is it an x86-64 vs. x86-32 issue?).
747     #
748     # libgcrypt expects gnu89, not c99/gnu99, semantics for
749     # "inline".  See, for example:
750     #
751     #    http://lists.freebsd.org/pipermail/freebsd-ports-bugs/2010-October/198809.html
752     #
753     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
754     make $MAKE_BUILD_OPTS || exit 1
755     $DO_MAKE_INSTALL || exit 1
756     cd ..
757     touch libgcrypt-$LIBGCRYPT_VERSION-done
758 }
759
760 uninstall_libgcrypt() {
761     echo "Uninstalling libgcrypt:"
762     cd libgcrypt-$installed_libgcrypt_version
763     $DO_MAKE_UNINSTALL || exit 1
764     make distclean || exit 1
765     cd ..
766     rm libgcrypt-$installed_libgcrypt_version-done
767 }
768
769 install_gnutls() {
770     #
771     # GnuTLS requires libgcrypt (or nettle, in newer versions).
772     #
773     if [ -z $LIBGCRYPT_VERSION ]
774     then
775         echo "GnuTLS requires libgcrypt, but you didn't install libgcrypt" 1>&2
776         exit 1
777     fi
778
779     echo "Downloading, building, and installing GnuTLS:"
780     [ -f gnutls-$GNUTLS_VERSION.tar.bz2 ] || curl -L -O http://ftp.gnu.org/gnu/gnutls/gnutls-$GNUTLS_VERSION.tar.bz2 || exit 1
781     bzcat gnutls-$GNUTLS_VERSION.tar.bz2 | tar xf - || exit 1
782     cd gnutls-$GNUTLS_VERSION
783     #
784     # Use libgcrypt, not nettle.
785     # XXX - is there some reason to prefer nettle?  Or does
786     # Wireshark directly use libgcrypt routines?
787     #
788     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
789     make $MAKE_BUILD_OPTS || exit 1
790     #
791     # The pkgconfig file for GnuTLS says "requires zlib", but OS X,
792     # while it supplies zlib, doesn't supply a pkgconfig file for
793     # it.
794     #
795     # Patch the GnuTLS pkgconfig file not to require zlib.
796     # (If the capabilities of GnuTLS that Wireshark uses don't
797     # depend on building GnuTLS with zlib, an alternative would be
798     # to configure it not to use zlib.)
799     #
800     patch -p0 lib/gnutls.pc.in <../../macosx-support-lib-patches/gnutls-pkgconfig.patch || exit 1
801     $DO_MAKE_INSTALL || exit 1
802     cd ..
803     touch gnutls-$GNUTLS_VERSION-done
804 }
805
806 uninstall_gnutls() {
807     echo "Uninstalling GnuTLS:"
808     cd gnutls-$installed_gnutls_version
809     $DO_MAKE_UNINSTALL || exit 1
810     make distclean || exit 1
811     cd ..
812     rm gnutls-$installed_gnutls_version-done
813 }
814
815 install_lua() {
816     echo "Downloading, building, and installing Lua:"
817     [ -f lua-$LUA_VERSION.tar.gz ] || curl -L -O http://www.lua.org/ftp/lua-$LUA_VERSION.tar.gz || exit 1
818     gzcat lua-$LUA_VERSION.tar.gz | tar xf - || exit 1
819     cd lua-$LUA_VERSION
820     make $MAKE_BUILD_OPTS macosx || exit 1
821     $DO_MAKE_INSTALL || exit 1
822     cd ..
823     touch lua-$LUA_VERSION-done
824 }
825
826 uninstall_lua() {
827     echo "Uninstalling Lua:"
828     #
829     # Lua has no "make uninstall", so just remove stuff manually.
830     # There's no configure script, so there's no need for
831     # "make distclean", either; just do "make clean".
832     #
833     (cd /usr/local/bin; $DO_RM -f lua luac)
834     (cd /usr/local/include; $DO_RM -f lua.h luaconf.h lualib.h lauxlib.h lua.hpp)
835     (cd /usr/local/lib; $DO_RM -f liblua.a)
836     (cd /usr/local/man/man1; $DO_RM -f lua.1 luac.1)
837     cd lua-$installed_lua_version
838     make clean || exit 1
839     cd ..
840     rm lua-$installed_lua_version-done
841 }
842
843 install_portaudio() {
844     echo "Downloading, building, and installing PortAudio:"
845     [ -f $PORTAUDIO_VERSION.tgz ] || curl -L -O http://www.portaudio.com/archives/$PORTAUDIO_VERSION.tgz || exit 1
846     gzcat $PORTAUDIO_VERSION.tgz | tar xf - || exit 1
847     cd portaudio
848     #
849     # Un-comment an include that's required on Lion.
850     #
851     patch -p0 include/pa_mac_core.h <../../macosx-support-lib-patches/portaudio-pa_mac_core.h.patch
852     #
853     # Fix a bug that showed up with clang (but is a bug with any
854     # compiler).
855     #
856     patch -p0 src/hostapi/coreaudio/pa_mac_core.c <../../macosx-support-lib-patches/portaudio-pa_mac_core.c.patch
857     #
858     # Disable fat builds - the configure script doesn't work right
859     # with Xcode 4 if you leave them enabled, and we don't build
860     # any other libraries fat (GLib, for example, would be very
861     # hard to build fat), so there's no advantage to having PortAudio
862     # built fat.
863     #
864     # Set the minimum OS X version to 10.4, to suppress some
865     # deprecation warnings.  (Good luck trying to make any of
866     # this build on an OS+Xcode with a pre-10.4 SDK; we don't
867     # worry about the user requesting that.)
868     #
869     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
870     make $MAKE_BUILD_OPTS || exit 1
871     $DO_MAKE_INSTALL || exit 1
872     cd ..
873     touch portaudio-done
874 }
875
876 uninstall_portaudio() {
877     echo "Uninstalling PortAudio:"
878     cd portaudio
879     $DO_MAKE_UNINSTALL || exit 1
880     make distclean || exit 1
881     cd ..
882     rm portaudio-done
883 }
884
885 install_geoip() {
886     echo "Downloading, building, and installing GeoIP API:"
887     [ -f GeoIP-$GEOIP_VERSION.tar.gz ] || curl -L -O http://geolite.maxmind.com/download/geoip/api/c/GeoIP-$GEOIP_VERSION.tar.gz || exit 1
888     gzcat GeoIP-$GEOIP_VERSION.tar.gz | tar xf - || exit 1
889     cd GeoIP-$GEOIP_VERSION
890     CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
891     #
892     # Grr.  Their man pages "helpfully" have an ISO 8859-1
893     # copyright symbol in the copyright notice, but OS X's
894     # default character encoding is UTF-8.  sed on Mountain
895     # Lion barfs at the "illegal character sequence" represented
896     # by an ISO 8859-1 copyright symbol, as it's not a valid
897     # UTF-8 sequence.
898     #
899     # iconv the relevant man pages into UTF-8.
900     #
901     for i in geoipupdate.1.in geoiplookup6.1.in geoiplookup.1.in
902     do
903         iconv -f iso8859-1 -t utf-8 man/"$i" >man/"$i".tmp &&
904             mv man/"$i".tmp man/"$i"
905     done
906     make $MAKE_BUILD_OPTS || exit 1
907     $DO_MAKE_INSTALL || exit 1
908     cd ..
909     touch geoip-$GEOIP_VERSION-done
910 }
911
912 uninstall_geoip() {
913     echo "Uninstalling GeoIP API:"
914     cd GeoIP-$installed_geoip_version
915     $DO_MAKE_UNINSTALL || exit 1
916     make distclean || exit 1
917     cd ..
918     rm geoip-$installed_geoip_version-done
919 }
920
921 install_c_ares() {
922     echo "Downloading, building, and installing C-Ares API:"
923     [ -f c-ares-$CARES_VERSION.tar.gz ] || curl -L -O http://c-ares.haxx.se/download/c-ares-$CARES_VERSION.tar.gz || exit 1
924     gzcat c-ares-$CARES_VERSION.tar.gz | tar xf - || exit 1
925     cd c-ares-$CARES_VERSION
926     CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS"  LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
927     make $MAKE_BUILD_OPTS || exit 1
928     $DO_MAKE_INSTALL || exit 1
929     cd ..
930     touch c-ares-$CARES_VERSION-done
931 }
932
933 uninstall_c_ares() {
934     echo "Uninstalling C-Ares API:"
935     cd c-ares-$installed_cares_version
936     $DO_MAKE_UNINSTALL || exit 1
937     make distclean || exit 1
938     cd ..
939     rm c-ares-$installed_cares_version-done
940 }
941
942 uninstall() {
943     if [ -d macosx-support-libs ]
944     then
945         cd macosx-support-libs
946
947         #
948         # Uninstall items in the reverse order from the order in which they're
949         # installed.  Only uninstall if the download/build/install process
950         # completed; uninstall the version that appears in the name of
951         # the -done file.
952         #
953         # We also do a "make distclean", so that we don't have leftovers from
954         # old configurations.
955         #
956
957         installed_cares_version=`ls c-ares-*-done 2>/dev/null | sed 's/c-ares-\(.*\)-done/\1/'`
958         if [ ! -z "$installed_cares_version" ] ; then
959             uninstall_c_ares
960         fi
961
962         installed_geoip_version=`ls geoip-*-done 2>/dev/null | sed 's/geoip-\(.*\)-done/\1/'`
963         if [ ! -z "$installed_geoip_version" ] ; then
964             uninstall_geoip
965         fi
966
967         if [ "$PORTAUDIO_VERSION" -a -f portaudio-done ] ; then
968             uninstall_portaudio
969         fi
970
971         installed_lua_version=`ls lua-*-done 2>/dev/null | sed 's/lua-\(.*\)-done/\1/'`
972         if [ ! -z "$installed_lua_version" ] ; then
973             uninstall_lua
974         fi
975
976         installed_gnutls_version=`ls gnutls-*-done 2>/dev/null | sed 's/gnutls-\(.*\)-done/\1/'`
977         if [ ! -z "$installed_gnutls_version" ] ; then
978             uninstall_gnutls
979         fi
980
981         installed_libgcrypt_version=`ls libgcrypt-*-done 2>/dev/null | sed 's/libgcrypt-\(.*\)-done/\1/'`
982         if [ ! -z "$installed_libgcrypt_version" ] ; then
983             uninstall_libgcrypt
984         fi
985
986         installed_libgpg_error_version=`ls libgpg-error-*-done 2>/dev/null | sed 's/libgpg-error-\(.*\)-done/\1/'`
987         if [ ! -z "$installed_libgpg_error_version" ] ; then
988             uninstall_libgpg_error
989         fi
990
991         installed_libsmi_version=`ls libsmi-*-done 2>/dev/null | sed 's/libsmi-\(.*\)-done/\1/'`
992         if [ ! -z "$installed_libsmi_version" ] ; then
993             uninstall_libsmi
994         fi
995
996         installed_gtk_version=`ls gtk+-*-done 2>/dev/null | sed 's/gtk+-\(.*\)-done/\1/'`
997         if [ ! -z "$installed_gtk_version" ] ; then
998             uninstall_gtk
999         fi
1000
1001         installed_gdk_pixbuf_version=`ls gdk-pixbuf-*-done 2>/dev/null | sed 's/gdk-pixbuf-\(.*\)-done/\1/'`
1002         if [ ! -z "$installed_gdk_pixbuf_version" ] ; then
1003             uninstall_gdk_pixbuf
1004         fi
1005
1006         installed_pango_version=`ls pango-*-done 2>/dev/null | sed 's/pango-\(.*\)-done/\1/'`
1007         if [ ! -z "$installed_pango_version" ] ; then
1008             uninstall_pango
1009         fi
1010
1011         installed_atk_version=`ls atk-*-done 2>/dev/null | sed 's/atk-\(.*\)-done/\1/'`
1012         if [ ! -z "$installed_atk_version" ] ; then
1013             uninstall_atk
1014         fi
1015
1016         installed_cairo_version=`ls cairo-*-done 2>/dev/null | sed 's/cairo-\(.*\)-done/\1/'`
1017         if [ ! -z "$installed_cairo_version" ] ; then
1018             uninstall_cairo
1019         fi
1020
1021         installed_pixman_version=`ls pixman-*-done 2>/dev/null | sed 's/pixman-\(.*\)-done/\1/'`
1022         if [ ! -z "$installed_pixman_version" ] ; then
1023             uninstall_pixman
1024         fi
1025
1026         installed_libpng_version=`ls libpng-*-done 2>/dev/null | sed 's/libpng-\(.*\)-done/\1/'`
1027         if [ ! -z "$installed_libpng_version" ] ; then
1028             uninstall_libpng
1029         fi
1030
1031         installed_qt_version=`ls qt-*-done 2>/dev/null | sed 's/qt-\(.*\)-done/\1/'`
1032         if [ ! -z "$installed_qt_version" ] ; then
1033             uninstall_qt
1034         fi
1035
1036         installed_glib_version=`ls glib-*-done 2>/dev/null | sed 's/glib-\(.*\)-done/\1/'`
1037         if [ ! -z "$installed_glib_version" ] ; then
1038             uninstall_glib
1039         fi
1040
1041         installed_pkg_config_version=`ls pkg-config-*-done 2>/dev/null | sed 's/pkg-config-\(.*\)-done/\1/'`
1042         if [ ! -z "$installed_pkg_config_version" ] ; then
1043             uninstall_pkg_config
1044         fi
1045
1046         installed_gettext_version=`ls gettext-*-done 2>/dev/null | sed 's/gettext-\(.*\)-done/\1/'`
1047         if [ ! -z "$installed_gettext_version" ] ; then
1048             uninstall_gettext
1049         fi
1050
1051         #
1052         # XXX - really remove this?
1053         # Or should we remember it as installed only if this script
1054         # installed it?
1055         #
1056         installed_cmake_version=`ls cmake-*-done 2>/dev/null | sed 's/cmake-\(.*\)-done/\1/'`
1057         if [ ! -z "$installed_cmake_version" ]; then
1058             uninstall_cmake
1059         fi
1060
1061         installed_libtool_version=`ls libtool-*-done 2>/dev/null | sed 's/libtool-\(.*\)-done/\1/'`
1062         if [ ! -z "$installed_libtool_version" ] ; then
1063             uninstall_libtool
1064         fi
1065
1066         installed_automake_version=`ls automake-*-done 2>/dev/null | sed 's/automake-\(.*\)-done/\1/'`
1067         if [ ! -z "$installed_automake_version" ] ; then
1068             uninstall_automake
1069         fi
1070
1071         installed_autoconf_version=`ls autoconf-*-done 2>/dev/null | sed 's/autoconf-\(.*\)-done/\1/'`
1072         if [ ! -z "$installed_autoconf_version" ] ; then
1073             uninstall_autoconf
1074         fi
1075
1076         installed_xz_version=`ls xz-*-done 2>/dev/null | sed 's/xz-\(.*\)-done/\1/'`
1077         if [ ! -z "$installed_xz_version" ] ; then
1078             uninstall_xz
1079         fi
1080     fi
1081 }
1082
1083 #
1084 # Do we have permission to write in /usr/local?
1085 #
1086 # If so, assume we have permission to write in its subdirectories.
1087 # (If that's not the case, this test needs to check the subdirectories
1088 # as well.)
1089 #
1090 # If not, do "make install", "make uninstall", the removes for Lua,
1091 # and the renames of [g]libtool* with sudo.
1092 #
1093 if [ -w /usr/local ]
1094 then
1095     DO_MAKE_INSTALL="make install"
1096     DO_MAKE_UNINSTALL="make uninstall"
1097     DO_RM="rm"
1098     DO_MV="mv"
1099 else
1100     DO_MAKE_INSTALL="sudo make install"
1101     DO_MAKE_UNINSTALL="sudo make uninstall"
1102     DO_RM="sudo rm"
1103     DO_MV="sudo mv"
1104 fi
1105
1106 #
1107 # If we have SDKs available, the default target OS is the major version
1108 # of the one we're running; get that and strip off the third component
1109 # if present.
1110 #
1111 for i in /Developer/SDKs \
1112     /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs \
1113     /Library/Developer/CommandLineTools/SDKs
1114 do
1115     if [ -d "$i" ]
1116     then
1117         min_osx_target=`sw_vers -productVersion | sed 's/\([0-9]*\)\.\([0-9]*\)\.[0-9]*/\1.\2/'`
1118
1119         #
1120         # That's also the OS whose SDK we'd be using.
1121         #
1122         sdk_target=$min_osx_target
1123         break
1124     fi
1125 done
1126
1127 #
1128 # Parse command-line flags:
1129 #
1130 # -h - print help.
1131 # -t <target> - build libraries so that they'll work on the specified
1132 # version of OS X and later versions.
1133 # -u - do an uninstall.
1134 #
1135 while getopts ht:u name
1136 do
1137     case $name in
1138     u)
1139         do_uninstall=yes
1140         ;;
1141     t)
1142         min_osx_target="$OPTARG"
1143         ;;
1144     h|?)
1145         echo "Usage: macosx-setup.sh [ -t <target> ] [ -u ]" 1>&1
1146         exit 0
1147         ;;
1148     esac
1149 done
1150
1151 if [ "$do_uninstall" = "yes" ]
1152 then
1153     uninstall
1154     exit 0
1155 fi
1156
1157 #
1158 # Configure scripts tend to set CFLAGS and CXXFLAGS to "-g -O2" if
1159 # invoked without CFLAGS or CXXFLAGS being set in the environment.
1160 #
1161 # However, we *are* setting them in the environment, for our own
1162 # nefarious purposes, so start them out as "-g -O2".
1163 #
1164 CFLAGS="-g -O2"
1165 CXXFLAGS="-g -O2"
1166
1167 #
1168 # To make this work on Leopard (rather than working *on* Snow Leopard
1169 # when building *for* Leopard) will take more work.
1170 #
1171 # For one thing, Leopard's /usr/X11/lib/libXdamage.la claims, at least
1172 # with all software updates applied, that the Xdamage shared library
1173 # is libXdamage.1.0.0.dylib, but it is, in fact, libXdamage.1.1.0.dylib.
1174 # This causes problems when building GTK+, so the script would have to
1175 # fix that file.
1176 #
1177 if [[ $DARWIN_MAJOR_VERSION -le 9 ]]; then
1178     echo "This script does not support any versions of OS X before Snow Leopard" 1>&2 
1179     exit 1
1180 fi
1181
1182 # if no make options are present, set default options
1183 if [ -z "$MAKE_BUILD_OPTS" ] ; then
1184     # by default use 1.5x number of cores for parallel build
1185     MAKE_BUILD_OPTS="-j $(( $(sysctl -n hw.logicalcpu) * 3 / 2))"
1186 fi
1187
1188 #
1189 # If we have a target release, look for the oldest SDK that's for an
1190 # OS equal to or later than that one, and build libraries against it
1191 # rather than against the headers and, more importantly, libraries
1192 # that come with the OS, so that we don't end up with support libraries
1193 # that only work on the OS version on which we built them, not earlier
1194 # versions of the same release, or earlier releases if the minimum is
1195 # earlier.
1196 #
1197 if [ ! -z "$min_osx_target" ]
1198 then
1199     #
1200     # Get the real version - strip off the "10.".
1201     # We'll worry about that if, as, and when there's ever
1202     # an OS XI.
1203     #
1204     deploy_real_version=`echo "$min_osx_target" | sed -n 's/10\.\(.*\)/\1/p'`
1205
1206     #
1207     # Search each directory that might contain SDKs.
1208     #
1209     sdkpath=""
1210     for sdksdir in /Developer/SDKs \
1211         /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs \
1212         /Library/Developer/CommandLineTools/SDKs
1213     do
1214         #
1215         # Get a list of all the SDKs.
1216         #
1217         if ! test -d "$sdksdir"
1218         then
1219             #
1220             # There is no directory with that name.
1221             # Move on to the next one in the list, if any.
1222             #
1223             continue
1224         fi
1225
1226         #
1227         # Get a list of all the SDKs in that directory, if any.
1228         #
1229         sdklist=`(cd "$sdksdir"; ls -d MacOSX10.[0-9]*.sdk 2>/dev/null)`
1230
1231         for sdk in $sdklist
1232         do
1233             #
1234             # Get the real version for this SDK.
1235             #
1236             sdk_real_version=`echo "$sdk" | sed -n 's/MacOSX10\.\(.*\)\.sdk/\1/p'`
1237
1238             #
1239             # Is it for the deployment target or some later release?
1240             #
1241             if test "$sdk_real_version" -ge "$deploy_real_version"
1242             then
1243                 #
1244                 # Yes, use it.
1245                 #
1246                 sdkpath="$sdksdir/$sdk"
1247                 qt_sdk_arg="-sdk $sdk"
1248                 break 2
1249             fi
1250         done
1251     done
1252
1253     if [ -z "$sdkpath" ]
1254     then
1255         echo "macosx-setup.sh: Couldn't find an SDK for OS X $min_osx_target or later" 1>&2
1256         exit 1
1257     fi
1258
1259     SDKPATH="$sdkpath"
1260     sdk_target=10.$sdk_real_version
1261     echo "Using the 10.$sdk_real_version SDK"
1262
1263     #
1264     # Make sure there are links to /usr/local/include and /usr/local/lib
1265     # in the SDK's usr/local.
1266     #
1267     if [ ! -e $SDKPATH/usr/local/include ]
1268     then
1269         if [ ! -d $SDKPATH/usr/local ]
1270         then
1271             sudo mkdir $SDKPATH/usr/local
1272         fi
1273         sudo ln -s /usr/local/include $SDKPATH/usr/local/include
1274     fi
1275     if [ ! -e $SDKPATH/usr/local/lib ]
1276     then
1277         if [ ! -d $SDKPATH/usr/local ]
1278         then
1279             sudo mkdir $SDKPATH/usr/local
1280         fi
1281         sudo ln -s /usr/local/lib $SDKPATH/usr/local/lib
1282     fi
1283
1284     #
1285     # Set the minimum OS version for which to build to the specified
1286     # minimum target OS version, so we don't, for example, end up using
1287     # linker features supported by the OS verson on which we're building
1288     # but not by the target version.
1289     #
1290     VERSION_MIN_FLAGS="-mmacosx-version-min=$min_osx_target"
1291
1292     #
1293     # Compile and link against the SDK.
1294     #
1295     SDKFLAGS="-isysroot $SDKPATH"
1296
1297     if [[ "$min_osx_target" == "10.5" ]]
1298     then
1299         #
1300         # Cairo is part of Mac OS X 10.6 and later.
1301         # The *headers* are supplied by 10.5, but the *libraries*
1302         # aren't, so we have to build it if we're building for 10.5.
1303         #
1304         cairo_not_in_the_os=yes
1305
1306         #
1307         # Build with older versions of the support libraries, as
1308         # were used on the Wireshark Leopard buildbot at one
1309         # point.  (Most of these versions come from the About page
1310         # from Wireshark 1.8.6, the last build done on that buildbot;
1311         # the ATK version isn't reported, so this is a guess.)
1312         #
1313         # If you want to try building with newer versions of
1314         # the libraries, note that:
1315         #
1316         # The version of fontconfig that comes with Leopard doesn't
1317         # support FC_WEIGHT_EXTRABLACK, so we can't use any version
1318         # of Pango newer than 1.22.4.
1319         #
1320         # However, Pango 1.22.4 doesn't work with versions of GLib
1321         # after 2.29.6, because Pango 1.22.4 uses G_CONST_RETURN and
1322         # GLib 2.29.8 and later deprecate it (there doesn't appear to
1323         # be a GLib 2.29.7).  That means we'd either have to patch
1324         # Pango not to use it (just use "const"; G_CONST_RETURN was
1325         # there to allow code to choose whether to use "const" or not),
1326         # or use GLib 2.29.6 or earlier.
1327         #
1328         # GLib 2.29.6 includes an implementation of g_bit_lock() that,
1329         # on x86 (32-bit and 64-bit), uses asms in a fashion
1330         # ("asm volatile goto") that requires GCC 4.5 or later, which
1331         # is later than the compilers that come with Leopard and Snow
1332         # Leopard.  Recent versions of GLib check for that, but 2.29.6
1333         # doesn't, so, if you want to build GLib 2.29.6 on Leopard or
1334         # Snow Leopard, you would have to patch glib/gbitlock.c to do
1335         # what the newer versions of GLib do:
1336         #
1337         #  define a USE_ASM_GOTO macro that indicates whether "asm goto"
1338         #  can be used:
1339         #    #if (defined (i386) || defined (__amd64__))
1340         #      #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
1341         #        #define USE_ASM_GOTO 1
1342         #      #endif
1343         #    #endif
1344         #
1345         #  replace all occurrences of
1346         #
1347         #    #if defined (__GNUC__) && (defined (i386) || defined (__amd64__))
1348         #
1349         #  with
1350         #
1351         #    #ifdef USE_ASM_GOTO
1352         #
1353         # Using GLib 2.29.6 or earlier, however, means that we can't
1354         # use a version of ATK later than 2.3.93, as those versions
1355         # don't work with GLib 2.29.6.  The same applies to gdk-pixbuf;
1356         # versions of gdk-pixbuf after 2.24.1 won't work with GLib
1357         # 2.29.6.
1358         #
1359         # Then you have to make sure that what you've build doesn't
1360         # cause the X server that comes with Leopard to crash; at
1361         # least one attempt at building for Leopard did.
1362         #
1363         # At least if building on Leopard, you might also find
1364         # that, with various older versions of Cairo, including
1365         # 1.6.4 and at least some 1.8.x versions, when you try to
1366         # build it, the build fails because it can't find
1367         # png_set_longjmp_fn().  I vaguely remember dealing with that,
1368         # ages ago, but don't remember what I did.
1369         #
1370         GLIB_VERSION=2.16.3
1371         CAIRO_VERSION=1.6.4
1372         ATK_VERSION=1.24.0
1373         PANGO_VERSION=1.20.2
1374         GTK_VERSION=2.12.9
1375
1376         #
1377         # That version of GTK+ includes gdk-pixbuf.
1378         # XXX - base this on the version of GTK+ requested.
1379         #
1380         GDK_PIXBUF_VERSION=
1381
1382         #
1383         # Libgcrypt 1.5.0 fails to compile due to some problem with an
1384         # asm in rijndael.c, at least with i686-apple-darwin10-gcc-4.2.1
1385         # (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3) when building
1386         # 32-bit.
1387         #
1388         # We try libgcrypt 1.4.3 instead, as that's what shows up in
1389         # the version from the Leopard buildbot.
1390         LIBGCRYPT_VERSION=1.4.3
1391
1392         #
1393         # Build 32-bit while we're at it; Leopard has a bug that
1394         # causes some BPF functions not to work with 64-bit userland
1395         # code, so capturing won't work.
1396         #
1397         CFLAGS="$CFLAGS -arch i386"
1398         CXXFLAGS="$CXXFLAGS -arch i386"
1399         export LDFLAGS="$LDFLAGS -arch i386"
1400     fi
1401 fi
1402
1403 export CFLAGS
1404 export CXXFLAGS
1405
1406 #
1407 # You need Xcode or the command-line tools installed to get the compilers.
1408 #
1409 if [ ! -x /usr/bin/xcodebuild ]; then
1410     echo "Please install Xcode first (should be available on DVD or from http://developer.apple.com/xcode/index.php)."
1411     exit 1
1412 fi
1413
1414 if [ "$QT_VERSION" ]; then
1415     #
1416     # We need Xcode, not just the command-line tools, installed to build
1417     # Qt.
1418     #
1419     if ! /usr/bin/xcrun -find xcrun >/dev/null 2>&1; then
1420         echo "Please install Xcode first (should be available on DVD or from http://developer.apple.com/xcode/index.php)."
1421         echo "The command-line build tools are not sufficient to build Qt."
1422         exit 1
1423     fi
1424 fi
1425 if [ "$GTK_VERSION" ]; then
1426     #
1427     # If we're building with GTK+, you also need the X11 SDK; with at least
1428     # some versions of OS X and Xcode, that is, I think, an optional install.
1429     # (Or it might be installed with X11, but I think *that* is an optional
1430     # install on at least some versions of OS X.)
1431     #
1432     if [ ! -d /usr/X11/include ]; then
1433         echo "Please install X11 and the X11 SDK first."
1434         echo "  You can either use http://xquartz.macosforge.org/, e.g."
1435         echo "  http://xquartz-dl.macosforge.org/SL/XQuartz-$XQUARTZ_VERSION.dmg"
1436         echo "  or the native Apple packages if you are on Lion or below."
1437         exit 1
1438     fi
1439 fi
1440
1441 export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/X11/lib/pkgconfig
1442
1443 #
1444 # Do all the downloads and untarring in a subdirectory, so all that
1445 # stuff can be removed once we've installed the support libraries.
1446 #
1447 if [ ! -d macosx-support-libs ]
1448 then
1449     mkdir macosx-support-libs || exit 1
1450 fi
1451 cd macosx-support-libs
1452
1453 # Start with xz: It is the sole download format of glib later than 2.31.2
1454 #
1455 if [ "$XZ_VERSION" -a ! -f xz-$XZ_VERSION-done ] ; then
1456     install_xz
1457 fi
1458
1459 if [ "$AUTOCONF_VERSION" -a ! -f autoconf-$AUTOCONF_VERSION-done ] ; then
1460     install_autoconf
1461 fi
1462
1463 if [ "$AUTOMAKE_VERSION" -a ! -f automake-$AUTOMAKE_VERSION-done ] ; then
1464     install_automake
1465 fi
1466
1467 if [ "$LIBTOOL_VERSION" -a ! -f libtool-$LIBTOOL_VERSION-done ] ; then
1468     install_libtool
1469 fi
1470
1471 if [ -n "$CMAKE" -a ! -f cmake-$CMAKE_VERSION-done ]; then
1472     install_cmake
1473 fi
1474
1475 #
1476 # Start with GNU gettext; GLib requires it, and OS X doesn't have it
1477 # or a BSD-licensed replacement.
1478 #
1479 # At least on Lion with Xcode 4, _FORTIFY_SOURCE gets defined as 2
1480 # by default, which causes, for example, stpncpy to be defined as
1481 # a hairy macro that collides with the GNU gettext configure script's
1482 # attempts to workaround AIX's lack of a declaration for stpncpy,
1483 # with the result being a huge train wreck.  Define _FORTIFY_SOURCE
1484 # as 0 in an attempt to keep the trains on separate tracks.
1485 #
1486 if [ ! -f gettext-$GETTEXT_VERSION-done ] ; then
1487     install_gettext
1488 fi
1489
1490 #
1491 # GLib depends on pkg-config.
1492 # By default, pkg-config depends on GLib; we break the dependency cycle
1493 # by configuring pkg-config to use its own internal version of GLib.
1494 #
1495 if [ ! -f pkg-config-$PKG_CONFIG_VERSION-done ] ; then
1496     install_pkg_config
1497 fi
1498
1499 if [ ! -f glib-$GLIB_VERSION-done ] ; then
1500     install_glib
1501 fi
1502
1503 #
1504 # Now we have reached a point where we can build everything but
1505 # the GUI (Wireshark).
1506 #
1507 if [ "$QT_VERSION" -a ! -f qt-$QT_VERSION-done ]; then
1508     install_qt
1509 fi
1510
1511 if [ "$GTK_VERSION" ]; then
1512
1513     #
1514     # GTK+ 3 requires a newer Cairo build than the one that comes with
1515     # 10.6, so we build Cairo if we are using GTK+ 3.
1516     #
1517     # In 10.6 and 10.7, it's an X11 library; if we build with "native" GTK+
1518     # rather than X11 GTK+, we might have to build and install Cairo.
1519     # In 10.8 and later, there is no X11, but it's included in Xquartz;
1520     # again, if we build with "native" GTK+, we'd have to build and install
1521     # it.
1522     #
1523     if [[ "$GTK_MAJOR_VERSION" -eq 3 || "$cairo_not_in_the_os" = yes ]]; then
1524         #
1525         # Requirements for Cairo first
1526         #
1527         # The libpng that comes with the X11 for Leopard has a bogus
1528         # pkg-config file that lies about where the header files are,
1529         # which causes other packages not to be able to find its
1530         # headers.
1531         #
1532         # The libpng in later versions is not what the version of
1533         # libpixman we build below wants - it wants libpng15.
1534         #
1535         if [ ! -f libpng-$PNG_VERSION-done ] ; then
1536             install_libpng
1537         fi
1538
1539         #
1540         # The libpixman versions that come with the X11s for Leopard,
1541         # Snow Leopard, and Lion is too old to support Cairo's image
1542         # surface backend feature (which requires pixman-1 >= 0.22.0).
1543         #
1544         # XXX - what about the one that comes with the latest version
1545         # of Xquartz?
1546         #
1547         if [ ! -f pixman-$PIXMAN_VERSION-done ] ; then
1548             install_libpixman
1549         fi
1550
1551         #
1552         # And now Cairo itself.
1553         # XXX - with the libxcb that comes with 10.6,
1554         #
1555         # xcb_discard_reply() is missing, and the build fails.
1556         #
1557         if [ ! -f cairo-$CAIRO_VERSION-done ] ; then
1558             install_cairo
1559         fi
1560     fi
1561
1562     if [ ! -f atk-$ATK_VERSION-done ] ; then
1563         install_atk
1564     fi
1565
1566     if [ ! -f pango-$PANGO_VERSION-done ] ; then
1567         install_pango
1568     fi
1569
1570     if [ "$GDK_PIXBUF_VERSION" -a ! -f gdk-pixbuf-$GDK_PIXBUF_VERSION-done ] ; then
1571         install_gdk_pixbuf
1572     fi
1573
1574     if [ ! -f gtk+-$GTK_VERSION-done ] ; then
1575         install_gtk
1576     fi
1577 fi
1578
1579 #
1580 # Now we have reached a point where we can build everything including
1581 # the GUI (Wireshark), but not with any optional features such as
1582 # SNMP OID resolution, some forms of decryption, Lua scripting, playback
1583 # of audio, or GeoIP mapping of IP addresses.
1584 #
1585 # We now conditionally download optional libraries to support them;
1586 # the default is to download them all.
1587 #
1588
1589 if [ "$LIBSMI_VERSION" -a ! -f libsmi-$LIBSMI_VERSION-done ] ; then
1590     install_libsmi
1591 fi
1592
1593 if [ "$LIBGPG_ERROR_VERSION" -a ! -f libgpg-error-$LIBGPG_ERROR_VERSION-done ] ; then
1594     install_libgpg_error
1595 fi
1596
1597 if [ "$LIBGCRYPT_VERSION" -a ! -f libgcrypt-$LIBGCRYPT_VERSION-done ] ; then
1598     install_libgcrypt
1599 fi
1600
1601 if [ "$GNUTLS_VERSION" -a ! -f gnutls-$GNUTLS_VERSION-done ] ; then
1602     install_gnutls
1603 fi
1604
1605 if [ "$LUA_VERSION" -a ! -f lua-$LUA_VERSION-done ] ; then
1606     install_lua
1607 fi
1608
1609 if [ "$PORTAUDIO_VERSION" -a ! -f portaudio-done ] ; then
1610     install_portaudio
1611 fi
1612
1613 if [ "$GEOIP_VERSION" -a ! -f geoip-$GEOIP_VERSION-done ]
1614 then
1615     install_geoip
1616 fi
1617
1618 if [ "$CARES_VERSION" -a ! -f c-ares-$CARES_VERSION-done ]
1619 then
1620     install_c_ares
1621 fi
1622
1623 echo ""
1624
1625 echo "You are now prepared to build Wireshark. To do so do:"
1626 echo "export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/X11/lib/pkgconfig"
1627 echo ""
1628 if [ -n "$CMAKE" ]; then
1629     echo "mkdir build; cd build"
1630     echo "cmake .."
1631     echo
1632     echo "or"
1633     echo
1634 fi
1635 echo "./autogen.sh"
1636 echo "mkdir build; cd build"
1637 echo "../configure"
1638 echo ""
1639 echo "make $MAKE_BUILD_OPTS"
1640 echo "make install"
1641
1642 echo ""
1643
1644 echo "Make sure you are allowed capture access to the network devices"
1645 echo "See: http://wiki.wireshark.org/CaptureSetup/CapturePrivileges"
1646
1647 echo ""
1648
1649 exit 0