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