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