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