Don't assume the system include files are under /usr/include; trick the
[jelmer/wireshark.git] / macosx-setup.sh
1 #!/bin/sh
2 # Setup development environment on Mac OS X (tested with 10.6.8 and Xcode 3.2.6)
3 #
4 # $Id$
5 #
6 # Trying to follow "Building Wireshark on SnowLeopard"
7 # given by Michael Tuexen at
8 # http://nplab.fh-muenster.de/groups/wiki/wiki/fb7a4/Building_Wireshark_on_SnowLeopard.html
9 #
10
11 DARWIN_MAJOR_VERSION=`uname -r | sed 's/\([0-9]*\).*/\1/'`
12
13 #
14 # To make this work on Leopard will take a lot of work.
15 #
16 # First of all, Leopard's /usr/X11/lib/libXdamage.la claims, at least
17 # with all software updates applied, that the Xdamage shared library
18 # is libXdamage.1.0.0.dylib, but it is, in fact, libXdamage.1.1.0.dylib.
19 # This causes problems when building GTK+, so the script would have to
20 # fix that file.
21 #
22 # Second of all, the version of fontconfig that comes with Leopard
23 # doesn't support FC_WEIGHT_EXTRABLACK, so we can't use any version
24 # of Pango newer than 1.22.4.
25 #
26 # However, Pango 1.22.4 doesn't work with versions of GLib after
27 # 2.29.6, because Pango 1.22.4 uses G_CONST_RETURN and GLib 2.29.8
28 # and later deprecate it (there doesn't appear to be a GLib 2.29.7).
29 # That means we'd either have to patch Pango not to use it (just
30 # use "const"; G_CONST_RETURN was there to allow code to choose whether
31 # to use "const" or not), or use GLib 2.29.6 or earlier.
32 #
33 # GLib 2.29.6 includes an implementation of g_bit_lock() that, on x86
34 # (32-bit and 64-bit), uses asms in a fashion ("asm volatile goto") that
35 # doesn't work with the Apple version of GCC 4.0.1, which is the compiler
36 # you get with Leopard+updates.  Apparently, that requires GCC 4.5 or
37 # later; recent versions of GLib check for that, but 2.29.6 doesn't.
38 # Therefore, we would have to patch glib/gbitlock.c to do what the
39 # newer versions of GLib do:
40 #
41 #  define a USE_ASM_GOTO macro that indicates whether "asm goto"
42 #  can be used:
43 #    #if (defined (i386) || defined (__amd64__))
44 #      #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
45 #        #define USE_ASM_GOTO 1
46 #      #endif
47 #    #endif
48 #
49 #  replace all occurrences of
50 #
51 #    #if defined (__GNUC__) && (defined (i386) || defined (__amd64__))
52 #
53 #  with
54 #
55 #    #ifdef USE_ASM_GOTO
56 #
57 # Using GLib 2.29.6 or earlier, however, would mean that we can't
58 # use a version of ATK later than 2.3.93, as those versions don't
59 # work with GLib 2.29.6.  The same applies to gdk-pixbuf; versions
60 # of gdk-pixbuf after 2.24.1 won't work with GLib 2.29.6.
61 #
62 # Once you've set this script up to use the older versions of the
63 # libraries, and built and installed them, you find that Wireshark,
64 # when built with them, crashes the X server that comes with Leopard,
65 # at least with all updates from Apple.  Maybe patching Pango rather
66 # than going with an older version of Pango would work.
67 #
68 # The Leopard Wireshark buildbot uses GTK+ 2.12.9, Cairo 1.6.4,
69 # Pango 1.20.2, and GLib 2.16.3, with an unknown version of ATK,
70 # and, I think, without gdk-pixbuf, as it hadn't been made a
71 # separate library from GTK+ as of GTK+ 2.12.9.  Its binaries
72 # don't crash the X server.
73 #
74 # However, if you try various older versions of Cairo, including
75 # 1.6.4 and at least some 1.8.x versions, when you try to build
76 # it, the build fails because it can't find png_set_longjmp_fn().
77 # I vaguely remember dealing with that, ages ago, but don't
78 # remember what I did; fixing *that* is left as an exercise for
79 # the reader.
80 #
81 # Oh, and if you're building with a version of GTK+ that doesn't
82 # have the gdk-pixbuf stuff in a separate library, you probably
83 # don't want to bother downloading or installing the gdk-pixbuf
84 # library, *and* you will need to configure GTK+ with
85 # --without-libtiff and --without-libjpeg (as we currently do
86 # with gdk-pixbuf).
87 #
88 if [[ $DARWIN_MAJOR_VERSION -le 9 ]]; then
89         echo "This script does not support any versions of OS X before Snow Leopard" 1>&2 
90         exit 1
91 fi
92
93 # To set up a GTK3 environment
94 # GTK3=1
95 # To build cmake
96 # CMAKE=1
97 #
98 # To build all libraries as 32-bit libraries uncomment the following three lines.
99 # export CFLAGS="$CFLAGS -arch i386"
100 # export CXXFLAGS="$CXXFLAGS -arch i386"
101 # export LDFLAGS="$LDFLAGS -arch i386"
102 #
103
104 # if no make options are present, set default options
105 if [ -z "$MAKE_BUILD_OPTS" ] ; then
106     # by default use 1.5x number of cores for parallel build
107     MAKE_BUILD_OPTS="-j $(( $(sysctl -n hw.logicalcpu) * 3 / 2))"
108 fi
109
110 #
111 # Versions to download and install.
112 #
113 # The following libraries and tools are required.
114 #
115 GETTEXT_VERSION=0.18.2
116 GLIB_VERSION=2.36.0
117 PKG_CONFIG_VERSION=0.28
118 ATK_VERSION=2.8.0
119 PANGO_VERSION=1.30.1
120 PNG_VERSION=1.5.14
121 PIXMAN_VERSION=0.26.0
122 CAIRO_VERSION=1.12.2
123 GDK_PIXBUF_VERSION=2.28.0
124 if [ -z "$GTK3" ]; then
125   GTK_VERSION=2.24.17
126 else
127   GTK_VERSION=3.5.2
128 fi
129
130 #
131 # Some package need xz to unpack their current source.
132 # xz is not available on OSX (Snow Leopard).
133 #
134 XZ_VERSION=5.0.4
135
136 # In case we want to build with cmake
137 CMAKE_VERSION=2.8.10.2
138
139 #
140 # The following libraries are optional.
141 # Comment them out if you don't want them, but note that some of
142 # the optional libraries are required by other optional libraries.
143 #
144 LIBSMI_VERSION=0.4.8
145 #
146 # libgpg-error is required for libgcrypt.
147 #
148 LIBGPG_ERROR_VERSION=1.10
149 #
150 # libgcrypt is required for GnuTLS.
151 # XXX - the link for "Libgcrypt source code" at
152 # http://www.gnupg.org/download/#libgcrypt is for 1.5.0, and is a bzip2
153 # file, but http://directory.fsf.org/project/libgcrypt/ lists only
154 # 1.4.6.
155 #
156 LIBGCRYPT_VERSION=1.5.0
157 GNUTLS_VERSION=2.12.19
158 # Stay with Lua 5.1 when updating until the code has been changed
159 # to support 5.2
160 LUA_VERSION=5.1.5
161 PORTAUDIO_VERSION=pa_stable_v19_20111121
162 #
163 # XXX - they appear to have an unversioned gzipped tarball for the
164 # current version; should we just download that, with some other
165 # way of specifying whether to download the GeoIP API?
166 #
167 GEOIP_VERSION=1.4.8
168
169 # GNU auto tools
170 AUTOCONF_VERSION=2.69
171 AUTOMAKE_VERSION=1.13.3
172 LIBTOOL_VERSION=2.4.2
173
174 #
175 # You need Xcode installed to get the compilers.
176 #
177 if [ ! -x /usr/bin/xcodebuild ]; then
178         echo "Please install Xcode first (should be available on DVD or from http://developer.apple.com/xcode/index.php)."
179         exit 1
180 fi
181
182 #
183 # You also need the X11 SDK; with at least some versions of OS X and
184 # Xcode, that is, I think, an optional install.  (Or it might be
185 # installed with X11, but I think *that* is an optional install on
186 # at least some versions of OS X.)
187 #
188 if [ ! -d /usr/X11/include ]; then
189         echo "Please install X11 and the X11 SDK first."
190         exit 1
191 fi
192
193 #
194 # Do we have permission to write in /usr/local?
195 #
196 # If so, assume we have permission to write in its subdirectories.
197 # (If that's not the case, this test needs to check the subdirectories
198 # as well.)
199 #
200 # If not, do "make install" with sudo.
201 #
202 if [ -w /usr/local ]
203 then
204         DO_MAKE_INSTALL="make install"
205 else
206         DO_MAKE_INSTALL="sudo make install"
207 fi
208
209 export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/X11/lib/pkgconfig
210
211 #
212 # Do all the downloads and untarring in a subdirectory, so all that
213 # stuff can be removed once we've installed the support libraries.
214 #
215 if [ ! -d macosx-support-libs ]
216 then
217         mkdir macosx-support-libs || exit 1
218 fi
219 cd macosx-support-libs
220
221 # Start with xz: It is the sole download format of glib later than 2.31.2
222 #
223 if [ "$XZ_VERSION" -a ! -f xz-$XZ_VERSION-done ] ; then
224     echo "Downloading, building, and installing xz:"
225     [ -f xz-$XZ_VERSION.tar.bz2 ] || curl -O http://tukaani.org/xz/xz-$XZ_VERSION.tar.bz2 || exit 1
226     bzcat xz-$XZ_VERSION.tar.bz2 | tar xf - || exit 1
227     cd xz-$XZ_VERSION
228     CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=0" ./configure || exit 1
229     make $MAKE_BUILD_OPTS || exit 1
230     $DO_MAKE_INSTALL || exit 1
231     cd ..
232     touch xz-$XZ_VERSION-done
233 fi
234
235 if [ "$AUTOCONF_VERSION" -a ! -f autoconf-$AUTOCONF_VERSION-done ] ; then
236     echo "Downloading, building and installing GNU autoconf..."
237     [ -f autoconf-$AUTOCONF_VERSION.tar.xz ] || curl -O ftp://ftp.gnu.org/gnu/autoconf/autoconf-$AUTOCONF_VERSION.tar.xz || exit 1
238     xzcat autoconf-$AUTOCONF_VERSION.tar.xz | tar xf - || exit 1
239     cd autoconf-$AUTOCONF_VERSION
240     ./configure || exit 1
241     make $MAKE_BUILD_OPTS || exit 1
242     $DO_MAKE_INSTALL || exit 1
243     cd ..
244     touch autoconf-$AUTOCONF_VERSION-done
245 fi
246
247 if [ "$AUTOMAKE_VERSION" -a ! -f automake-$AUTOMAKE_VERSION-done ] ; then
248     echo "Downloading, building and installing GNU automake..."
249     [ -f automake-$AUTOMAKE_VERSION.tar.xz ] || curl -O ftp://ftp.gnu.org/gnu/automake/automake-$AUTOMAKE_VERSION.tar.xz || exit 1
250     xzcat automake-$AUTOMAKE_VERSION.tar.xz | tar xf - || exit 1
251     cd automake-$AUTOMAKE_VERSION
252     ./configure || exit 1
253     make $MAKE_BUILD_OPTS || exit 1
254     $DO_MAKE_INSTALL || exit 1
255     cd ..
256     touch automake-$AUTOMAKE_VERSION-done
257 fi
258
259 if [ "$LIBTOOL_VERSION" -a ! -f libtool-$LIBTOOL_VERSION-done ] ; then
260     echo "Downloading, building and installing GNU libtool..."
261     [ -f libtool-$LIBTOOL_VERSION.tar.xz ] || curl -O ftp://ftp.gnu.org/gnu/libtool/libtool-$LIBTOOL_VERSION.tar.xz || exit 1
262     xzcat libtool-$LIBTOOL_VERSION.tar.xz | tar xf - || exit 1
263     cd libtool-$LIBTOOL_VERSION
264     ./configure || exit 1
265     make $MAKE_BUILD_OPTS || exit 1
266     $DO_MAKE_INSTALL || exit 1
267     mv /usr/local/bin/libtool /usr/local/bin/glibtool
268     mv /usr/local/bin/libtoolize /usr/local/bin/glibtoolize
269     cd ..
270     touch libtool-$LIBTOOL_VERSION-done
271 fi
272
273 if [ -n "$CMAKE" -a ! -f cmake-$CMAKE_VERSION-done ]; then
274   echo "Downloading, building, and installing CMAKE:"
275   cmake_dir=`expr $CMAKE_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
276   [ -f cmake-$CMAKE_VERSION.tar.gz ] || curl -O http://www.cmake.org/files/v$cmake_dir/cmake-$CMAKE_VERSION.tar.gz || exit 1
277   gzcat cmake-$CMAKE_VERSION.tar.gz | tar xf - || exit 1
278   cd cmake-$CMAKE_VERSION
279   ./bootstrap || exit 1
280   make $MAKE_BUILD_OPTS || exit 1
281   $DO_MAKE_INSTALL || exit 1
282   cd ..
283   touch cmake-$CMAKE_VERSION-done
284 fi
285
286 #
287 # Start with GNU gettext; GLib requires it, and OS X doesn't have it
288 # or a BSD-licensed replacement.
289 #
290 # At least on Lion with Xcode 4, _FORTIFY_SOURCE gets defined as 2
291 # by default, which causes, for example, stpncpy to be defined as
292 # a hairy macro that collides with the GNU gettext configure script's
293 # attempts to workaround AIX's lack of a declaration for stpncpy,
294 # with the result being a huge train wreck.  Define _FORTIFY_SOURCE
295 # as 0 in an attempt to keep the trains on separate tracks.
296 #
297 if [ ! -f gettext-$GETTEXT_VERSION-done ] ; then
298     echo "Downloading, building, and installing GNU gettext:"
299     [ -f gettext-$GETTEXT_VERSION.tar.gz ] || curl -O http://ftp.gnu.org/pub/gnu/gettext/gettext-$GETTEXT_VERSION.tar.gz || exit 1
300     gzcat gettext-$GETTEXT_VERSION.tar.gz | tar xf - || exit 1
301     cd gettext-$GETTEXT_VERSION
302     CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=0" ./configure || exit 1
303     make $MAKE_BUILD_OPTS || exit 1
304     $DO_MAKE_INSTALL || exit 1
305     cd ..
306     touch gettext-$GETTEXT_VERSION-done
307 fi
308
309 if [ ! -f glib-$GLIB_VERSION-done ] ; then
310     echo "Downloading, building, and installing GLib:"
311     glib_dir=`expr $GLIB_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
312     [ -f glib-$GLIB_VERSION.tar.xz ] || curl -L -O http://ftp.gnome.org/pub/gnome/sources/glib/$glib_dir/glib-$GLIB_VERSION.tar.xz || exit 1
313     xzcat glib-$GLIB_VERSION.tar.xz | tar xf - || exit 1
314     cd glib-$GLIB_VERSION
315     #
316     # OS X ships with libffi, but doesn't provide its pkg-config file;
317     # explicitly specify LIBFFI_CFLAGS and LIBFFI_LIBS, so the configure
318     # script doesn't try to use pkg-config to get the appropriate
319     # CFLAGS and LIBS.
320     #
321     # And, what's worse, at least with the version of Xcode that comes
322     # with Leopard, /usr/include/ffi/fficonfig.h doesn't define MACOSX,
323     # which causes the build of GLib to fail.  If we don't find
324     # "#define.*MACOSX" in /usr/include/ffi/fficonfig.h, explictly
325     # define it.
326     #
327     # While we're at it, suppress -Wformat-nonliteral to avoid a clang
328     # bug where it issues bogus warnings.
329     #
330     # First, determine where the system include files are.  (It's not
331     # necessarily /usr/include.)
332     #
333     testfile=/tmp/test$$.c
334     trap "rm -f $testfile" 0
335     echo "#include <ffi/ffi.h>" > $testfile
336     includedir=`gcc -M $testfile | sed -n -e 's;[\\];;' -e 's/^ *//' -e 's/ *$//' -e 's;/ffi/ffi\.h;;p'`
337     rm -f $testfile
338     if grep -qs '#define.*MACOSX' $includedir/ffi/fficonfig.h
339     then
340         # It's defined, nothing to do
341         CFLAGS="$CFLAGS -Wno-format-nonliteral" LIBFFI_CFLAGS="$CFLAGS -I$includedir/ffi" LIBFFI_LIBS="$LDFLAGS -lffi" ./configure || exit 1
342         CFLAGS="$CFLAGS -Wno-format-nonliteral" LIBFFI_CFLAGS="$CFLAGS -I$includedir/ffi" LIBFFI_LIBS="$LDFLAGS -lffi" env | egrep LIBFFI_CFLAGS
343     else
344         CFLAGS="$CFLAGS -DMACOSX -Wno-format-nonliteral" LIBFFI_CFLAGS="$CFLAGS -I$includedir/ffi" LIBFFI_LIBS="LDFLAGS-lffi" ./configure || exit 1
345         CFLAGS="$CFLAGS -DMACOSX -Wno-format-nonliteral" LIBFFI_CFLAGS="$CFLAGS -I$includedir/ffi" LIBFFI_LIBS="LDFLAGS-lffi" env | egrep LIBFFI_CFLAGS
346     fi
347     make $MAKE_BUILD_OPTS || exit 1
348     # Apply patch: we depend on libffi, but pkg-config doesn't get told.
349     patch -p0 <../../macosx-support-lib-patches/glib-pkgconfig.patch || exit 1
350     $DO_MAKE_INSTALL || exit 1
351     cd ..
352     touch glib-$GLIB_VERSION-done
353 fi
354
355 if [ ! -f pkg-config-$PKG_CONFIG_VERSION-done ] ; then
356     echo "Downloading, building, and installing pkg-config:"
357     [ -f pkg-config-$PKG_CONFIG_VERSION.tar.gz ] || curl -O http://pkgconfig.freedesktop.org/releases/pkg-config-$PKG_CONFIG_VERSION.tar.gz || exit 1
358     gzcat pkg-config-$PKG_CONFIG_VERSION.tar.gz | tar xf - || exit 1
359     cd pkg-config-$PKG_CONFIG_VERSION
360     # Avoid another pkgconfig call
361     GLIB_CFLAGS="$CFLAGS -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include" GLIB_LIBS="$LDFLAGS -L/usr/local/lib -lglib-2.0 -lintl" ./configure || exit 1
362     make $MAKE_BUILD_OPTS || exit 1
363     $DO_MAKE_INSTALL || exit 1
364     cd ..
365     touch pkg-config-$PKG_CONFIG_VERSION-done
366 fi
367
368 #
369 # Now we have reached a point where we can build everything but
370 # the GUI (Wireshark).
371 #
372 # Cairo is part of Mac OS X 10.6 and 10.7.
373 # The *headers* are supplied by 10.5, but the *libraries* aren't, so
374 # we have to build it on 10.5.
375 # GTK+ 3 requires a newer Cairo build than the one that comes with
376 # 10.6, so we build Cairo if we are using GTK+ 3.
377 # In 10.6 and 10.7, it's an X11 library; if we build with "native" GTK+
378 # rather than X11 GTK+, we might have to build and install Cairo.
379 # The major version number of Darwin in 10.5 is 9.
380 #
381 if [[ -n "$GTK3" || $DARWIN_MAJOR_VERSION = "9" ]]; then
382   #
383   # Requirements for Cairo first
384   #
385   # The libpng that comes with the X11 for leopard has a bogus
386   # pkg-config file that lies about where the header files are,
387   # which causes other packages not to be able to find its
388   # headers.
389   #
390   if [ ! -f libpng-$PNG_VERSION-done ] ; then
391       echo "Downloading, building, and installing libpng:"
392       [ -f libpng-$PNG_VERSION.tar.xz ] || curl -O ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng-$PNG_VERSION.tar.xz
393       xzcat libpng-$PNG_VERSION.tar.xz | tar xf - || exit 1
394       cd libpng-$PNG_VERSION
395       ./configure || exit 1
396       make $MAKE_BUILD_OPTS || exit 1
397       $DO_MAKE_INSTALL || exit 1
398       cd ..
399         touch libpng-$PNG_VERSION-done
400     fi
401
402   #
403   # The libpixman that comes with the X11 for Leopard is too old
404   # to support Cairo's image surface backend feature (which requires
405   # pixman-1 >= 0.22.0).
406   #
407   if [ ! -f pixman-$PIXMAN_VERSION-done ] ; then
408       echo "Downloading, building, and installing pixman:"
409       [ -f pixman-$PIXMAN_VERSION.tar.gz ] || curl -O http://www.cairographics.org/releases/pixman-$PIXMAN_VERSION.tar.gz
410       gzcat pixman-$PIXMAN_VERSION.tar.gz | tar xf - || exit 1
411       cd pixman-$PIXMAN_VERSION
412       ./configure || exit 1
413       make $MAKE_BUILD_OPTS || exit 1
414       $DO_MAKE_INSTALL || exit 1
415       cd ..
416       touch pixman-$PIXMAN_VERSION-done
417   fi
418
419   #
420   # And now Cairo itself.
421   #
422   if [ ! -f cairo-$CAIRO_VERSION-done ] ; then
423       echo "Downloading, building, and installing Cairo:"
424       CAIRO_MAJOR_VERSION="`expr $CAIRO_VERSION : '\([0-9][0-9]*\).*'`"
425       CAIRO_MINOR_VERSION="`expr $CAIRO_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
426       CAIRO_DOTDOT_VERSION="`expr $CAIRO_VERSION : '[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
427       if [[ $CAIRO_MAJOR_VERSION -gt 1 ||
428             $CAIRO_MINOR_VERSION -gt 12 ||
429            ($CAIRO_MINOR_VERSION -eq 12 && $CAIRO_DOTDOT_VERSION -ge 2) ]]
430       then
431         #
432         # Starting with Cairo 1.12.2, the tarballs are compressed with
433         # xz rather than gzip.
434         #
435           [ -f cairo-$CAIRO_VERSION.tar.xz ] || curl -O http://cairographics.org/releases/cairo-$CAIRO_VERSION.tar.xz || exit 1
436           xzcat cairo-$CAIRO_VERSION.tar.xz | tar xf - || exit 1
437       else
438           [ -f cairo-$CAIRO_VERSION.tar.gz ] || curl -O http://cairographics.org/releases/cairo-$CAIRO_VERSION.tar.gz || exit 1
439           gzcat cairo-$CAIRO_VERSION.tar.gz | tar xf - || exit 1
440       fi
441       cd cairo-$CAIRO_VERSION
442       #./configure --enable-quartz=no || exit 1
443       # Maybe follow http://cairographics.org/end_to_end_build_for_mac_os_x/
444       ./configure --enable-quartz=yes || exit 1
445       #
446       # We must avoid the version of libpng that comes with X11; the
447       # only way I've found to force that is to forcibly set INCLUDES
448       # when we do the build, so that this comes before CAIRO_CFLAGS,
449       # which has -I/usr/X11/include added to it before anything
450       # connected to libpng is.
451       #
452       INCLUDES="-I/usr/local/include/libpng15" make $MAKE_BUILD_OPTS || exit 1
453       $DO_MAKE_INSTALL || exit 1
454       cd ..
455       touch cairo-$CAIRO_VERSION-done
456   fi
457 fi
458
459 if [ ! -f atk-$ATK_VERSION-done ] ; then
460     echo "Downloading, building, and installing ATK:"
461     atk_dir=`expr $ATK_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
462     [ -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
463     xzcat atk-$ATK_VERSION.tar.xz | tar xf - || exit 1
464     cd atk-$ATK_VERSION
465     ./configure || exit 1
466     make $MAKE_BUILD_OPTS || exit 1
467     $DO_MAKE_INSTALL || exit 1
468     cd ..
469     touch atk-$ATK_VERSION-done
470 fi
471
472 if [ ! -f pango-$PANGO_VERSION-done ] ; then
473     echo "Downloading, building, and installing Pango:"
474     pango_dir=`expr $PANGO_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
475     PANGO_MAJOR_VERSION="`expr $PANGO_VERSION : '\([0-9][0-9]*\).*'`"
476     PANGO_MINOR_VERSION="`expr $PANGO_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
477     if [[ $PANGO_MAJOR_VERSION -gt 1 ||
478           $PANGO_MINOR_VERSION -ge 29 ]]
479     then
480         #
481         # Starting with Pango 1.29, the tarballs are compressed with
482         # xz rather than bzip2.
483         #
484         [ -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
485         xzcat pango-$PANGO_VERSION.tar.xz | tar xf - || exit 1
486     else
487         [ -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
488         gzcat pango-$PANGO_VERSION.tar.bz2 | tar xf - || exit 1
489     fi
490     cd pango-$PANGO_VERSION
491     ./configure || exit 1
492     make $MAKE_BUILD_OPTS || exit 1
493     $DO_MAKE_INSTALL || exit 1
494     cd ..
495     touch pango-$PANGO_VERSION-done
496 fi
497
498 if [ ! -f gdk-pixbuf-$GDK_PIXBUF_VERSION-done ] ; then
499     echo "Downloading, building, and installing gdk-pixbuf:"
500     gdk_pixbuf_dir=`expr $GDK_PIXBUF_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
501     [ -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
502     xzcat gdk-pixbuf-$GDK_PIXBUF_VERSION.tar.xz | tar xf - || exit 1
503     cd gdk-pixbuf-$GDK_PIXBUF_VERSION
504     ./configure --without-libtiff --without-libjpeg || exit 1
505     make $MAKE_BUILD_OPTS || exit 1
506     $DO_MAKE_INSTALL || exit 1
507     cd ..
508     touch gdk-pixbuf-$GDK_PIXBUF_VERSION-done
509 fi
510
511 if [ ! -f gtk+-$GTK_VERSION-done ] ; then
512     echo "Downloading, building, and installing GTK+:"
513     gtk_dir=`expr $GTK_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
514     GTK_MAJOR_VERSION="`expr $GTK_VERSION : '\([0-9][0-9]*\).*'`"
515     GTK_MINOR_VERSION="`expr $GTK_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
516     GTK_DOTDOT_VERSION="`expr $GTK_VERSION : '[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
517     if [[ $GTK_MAJOR_VERSION -gt 2 ||
518           $GTK_MINOR_VERSION -gt 24 ||
519          ($GTK_MINOR_VERSION -eq 24 && $GTK_DOTDOT_VERSION -ge 5) ]]
520     then
521         #
522         # Starting with GTK+ 2.24.5, the tarballs are compressed with
523         # xz rather than gzip, in addition to bzip2; use xz, as we've
524         # built and installed it, and as xz compresses better than
525         # bzip2 so the tarballs take less time to download.
526         #
527         [ -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
528         xzcat gtk+-$GTK_VERSION.tar.xz | tar xf - || exit 1
529     else
530         [ -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
531         gzcat gtk+-$GTK_VERSION.tar.bz2 | tar xf - || exit 1
532     fi
533     cd gtk+-$GTK_VERSION
534     if [ $DARWIN_MAJOR_VERSION -ge "12" ]
535     then
536         #
537         # GTK+ 2.24.10, at least, doesn't build on Mountain Lion with the
538         # CUPS printing backend - either the CUPS API changed incompatibly
539         # or the backend was depending on non-API implementation details.
540         #
541         # Configure it out, on Mountain Lion and later, for now.
542         # (12 is the Darwin major version number in Mountain Lion.)
543         #
544         ./configure --disable-cups || exit 1
545     else
546         ./configure || exit 1
547     fi
548     make $MAKE_BUILD_OPTS || exit 1
549     $DO_MAKE_INSTALL || exit 1
550     cd ..
551     touch gtk+-$GTK_VERSION-done
552 fi
553
554 #
555 # Now we have reached a point where we can build everything including
556 # the GUI (Wireshark), but not with any optional features such as
557 # SNMP OID resolution, some forms of decryption, Lua scripting, playback
558 # of audio, or GeoIP mapping of IP addresses.
559 #
560 # We now conditionally download optional libraries to support them;
561 # the default is to download them all.
562 #
563
564 if [ "$LIBSMI_VERSION" -a ! -f libsmi-$LIBSMI_VERSION-done ] ; then
565         echo "Downloading, building, and installing libsmi:"
566         [ -f libsmi-$LIBSMI_VERSION.tar.gz ] || curl -L -O ftp://ftp.ibr.cs.tu-bs.de/pub/local/libsmi/libsmi-$LIBSMI_VERSION.tar.gz || exit 1
567         gzcat libsmi-$LIBSMI_VERSION.tar.gz | tar xf - || exit 1
568         cd libsmi-$LIBSMI_VERSION
569         ./configure || exit 1
570         make $MAKE_BUILD_OPTS || exit 1
571         $DO_MAKE_INSTALL || exit 1
572         cd ..
573         touch libsmi-$LIBSMI_VERSION-done
574 fi
575
576 if [ "$LIBGPG_ERROR_VERSION" -a ! -f libgpg-error-$LIBGPG_ERROR_VERSION-done ] ; then
577         echo "Downloading, building, and installing libgpg-error:"
578         [ -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
579         bzcat libgpg-error-$LIBGPG_ERROR_VERSION.tar.bz2 | tar xf - || exit 1
580         cd libgpg-error-$LIBGPG_ERROR_VERSION
581         ./configure || exit 1
582         make $MAKE_BUILD_OPTS || exit 1
583         $DO_MAKE_INSTALL || exit 1
584         cd ..
585         touch libgpg-error-$LIBGPG_ERROR_VERSION-done
586 fi
587
588 if [ "$LIBGCRYPT_VERSION" -a ! -f libgcrypt-$LIBGCRYPT_VERSION-done ] ; then
589         #
590         # libgpg-error is required for libgcrypt.
591         #
592         if [ -z $LIBGPG_ERROR_VERSION ]
593         then
594                 echo "libgcrypt requires libgpg-error, but you didn't install libgpg-error." 1>&2
595                 exit 1
596         fi
597
598         echo "Downloading, building, and installing libgcrypt:"
599         [ -f libgcrypt-$LIBGCRYPT_VERSION.tar.gz ] || curl -L -O ftp://ftp.gnupg.org/gcrypt/libgcrypt/libgcrypt-$LIBGCRYPT_VERSION.tar.gz || exit 1
600         gzcat libgcrypt-$LIBGCRYPT_VERSION.tar.gz | tar xf - || exit 1
601         cd libgcrypt-$LIBGCRYPT_VERSION
602         #
603         # The assembler language code is not compatible with the OS X
604         # x86 assembler (or is it an x86-64 vs. x86-32 issue?).
605         #
606         # libgcrypt expects gnu89, not c99/gnu99, semantics for
607         # "inline".  See, for example:
608         #
609         #       http://lists.freebsd.org/pipermail/freebsd-ports-bugs/2010-October/198809.html
610         #
611         CFLAGS="$CFLAGS -std=gnu89" ./configure --disable-asm || exit 1
612         make $MAKE_BUILD_OPTS || exit 1
613         $DO_MAKE_INSTALL || exit 1
614         cd ..
615         touch libgcrypt-$LIBGCRYPT_VERSION-done
616 fi
617
618 if [ "$GNUTLS_VERSION" -a ! -f gnutls-$GNUTLS_VERSION-done ] ; then
619         #
620         # GnuTLS requires libgcrypt (or nettle, in newer versions).
621         #
622         if [ -z $LIBGCRYPT_VERSION ]
623         then
624                 echo "GnuTLS requires libgcrypt, but you didn't install libgcrypt" 1>&2
625                 exit 1
626         fi
627
628         echo "Downloading, building, and installing GnuTLS:"
629         [ -f gnutls-$GNUTLS_VERSION.tar.bz2 ] || curl -L -O http://ftp.gnu.org/gnu/gnutls/gnutls-$GNUTLS_VERSION.tar.bz2 || exit 1
630         bzcat gnutls-$GNUTLS_VERSION.tar.bz2 | tar xf - || exit 1
631         cd gnutls-$GNUTLS_VERSION
632         #
633         # Use libgcrypt, not nettle.
634         # XXX - is there some reason to prefer nettle?  Or does
635         # Wireshark directly use libgcrypt routines?
636         #
637         ./configure --with-libgcrypt --without-p11-kit || exit 1
638         make $MAKE_BUILD_OPTS || exit 1
639         #
640         # The pkgconfig file for GnuTLS says "requires zlib", but OS X,
641         # while it supplies zlib, doesn't supply a pkgconfig file for
642         # it.
643         #
644         # Patch the GnuTLS pkgconfig file not to require zlib.
645         # (If the capabilities of GnuTLS that Wireshark uses don't
646         # depend on building GnuTLS with zlib, an alternative would be
647         # to configure it not to use zlib.)
648         #
649         patch -p0 lib/gnutls.pc.in <../../macosx-support-lib-patches/gnutls-pkgconfig.patch || exit 1
650         $DO_MAKE_INSTALL || exit 1
651         cd ..
652         touch gnutls-$GNUTLS_VERSION-done
653 fi
654
655 if [ "$LUA_VERSION" -a ! -f lua-$LUA_VERSION-done ] ; then
656         echo "Downloading, building, and installing Lua:"
657         [ -f lua-$LUA_VERSION.tar.gz ] || curl -L -O http://www.lua.org/ftp/lua-$LUA_VERSION.tar.gz || exit 1
658         gzcat lua-$LUA_VERSION.tar.gz | tar xf - || exit 1
659         cd lua-$LUA_VERSION
660         make $MAKE_BUILD_OPTS macosx || exit 1
661         $DO_MAKE_INSTALL || exit 1
662         cd ..
663         touch lua-$LUA_VERSION-done
664 fi
665
666 if [ "$PORTAUDIO_VERSION" -a ! -f portaudio-done ] ; then
667         echo "Downloading, building, and installing PortAudio:"
668         [ -f $PORTAUDIO_VERSION.tgz ] || curl -L -O http://www.portaudio.com/archives/$PORTAUDIO_VERSION.tgz || exit 1
669         gzcat $PORTAUDIO_VERSION.tgz | tar xf - || exit 1
670         cd portaudio
671         #
672         # Un-comment an include that's required on Lion.
673         #
674         patch -p0 include/pa_mac_core.h <../../macosx-support-lib-patches/portaudio-pa_mac_core.h.patch
675         #
676         # Fix a bug that showed up with clang (but is a bug with any
677         # compiler).
678         #
679         patch -p0 src/hostapi/coreaudio/pa_mac_core.c <../../macosx-support-lib-patches/portaudio-pa_mac_core.c.patch
680         #
681         # Disable fat builds - the configure script doesn't work right
682         # with Xcode 4 if you leave them enabled, and we don't build
683         # any other libraries fat (GLib, for example, would be very
684         # hard to build fat), so there's no advantage to having PortAudio
685         # built fat.
686         #
687         # Set the minimum OS X version to 10.4, to suppress some
688         # deprecation warnings.
689         #
690         CFLAGS="$CFLAGS -mmacosx-version-min=10.4" ./configure --disable-mac-universal || exit 1
691         make $MAKE_BUILD_OPTS || exit 1
692         $DO_MAKE_INSTALL || exit 1
693         cd ..
694         touch portaudio-done
695 fi
696
697 if [ "$GEOIP_VERSION" -a ! -f geoip-$GEOIP_VERSION-done ]
698 then
699         echo "Downloading, building, and installing GeoIP API:"
700         [ -f GeoIP-$GEOIP_VERSION.tar.gz ] || curl -L -O http://geolite.maxmind.com/download/geoip/api/c/GeoIP-$GEOIP_VERSION.tar.gz || exit 1
701         gzcat GeoIP-$GEOIP_VERSION.tar.gz | tar xf - || exit 1
702         cd GeoIP-$GEOIP_VERSION
703         ./configure || exit 1
704         #
705         # Grr.  Their man pages "helpfully" have an ISO 8859-1
706         # copyright symbol in the copyright notice, but OS X's
707         # default character encoding is UTF-8.  sed on Mountain
708         # Lion barfs at the "illegal character sequence" represented
709         # by an ISO 8859-1 copyright symbol, as it's not a valid
710         # UTF-8 sequence.
711         #
712         # iconv the relevant man pages into UTF-8.
713         #
714         for i in geoipupdate.1.in geoiplookup6.1.in geoiplookup.1.in
715         do
716                 iconv -f iso8859-1 -t utf-8 man/"$i" >man/"$i".tmp &&
717                     mv man/"$i".tmp man/"$i"
718         done
719         make $MAKE_BUILD_OPTS || exit 1
720         $DO_MAKE_INSTALL || exit 1
721         cd ..
722         touch geoip-$GEOIP_VERSION-done
723 fi
724
725 echo ""
726
727 echo "You are now prepared to build Wireshark. To do so do:"
728 echo "export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/X11/lib/pkgconfig"
729 echo ""
730 if [ -n "$CMAKE" ]; then
731   echo "mkdir build; cd build"
732   echo "cmake .."
733   echo
734   echo "or"
735   echo
736 fi
737 echo "./autogen.sh"
738 echo "mkdir build; cd build"
739 echo "../configure"
740 echo ""
741 echo "make $MAKE_BUILD_OPTS"
742 echo "make install"
743
744 echo ""
745
746 echo "Make sure you are allowed capture access to the network devices"
747 echo "See: http://wiki.wireshark.org/CaptureSetup/CapturePrivileges"
748
749 echo ""
750
751 exit 0