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