From Anders:
[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 # $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 you have many CPU cores, you can increase this number for more
105 # parallel compilation.
106 MAKE_BUILD_OPTS="-j 3"
107
108 #
109 # Versions to download and install.
110 #
111 # The following libraries and tools are required.
112 #
113 GETTEXT_VERSION=0.18.2
114 GLIB_VERSION=2.36.0
115 PKG_CONFIG_VERSION=0.28
116 ATK_VERSION=2.8.0
117 PANGO_VERSION=1.30.1
118 PNG_VERSION=1.5.14
119 PIXMAN_VERSION=0.26.0
120 CAIRO_VERSION=1.12.2
121 GDK_PIXBUF_VERSION=2.28.0
122 if [ -z "$GTK3" ]; then
123   GTK_VERSION=2.24.17
124 else
125   GTK_VERSION=3.5.2
126 fi
127
128 #
129 # Some package need xz to unpack their current source.
130 # xz is not available on OSX (Snow Leopard).
131 #
132 XZ_VERSION=5.0.4
133
134 # In case we want to build with cmake
135 CMAKE_VERSION=2.8.10.2
136
137 #
138 # The following libraries are optional.
139 # Comment them out if you don't want them, but note that some of
140 # the optional libraries are required by other optional libraries.
141 #
142 LIBSMI_VERSION=0.4.8
143 #
144 # libgpg-error is required for libgcrypt.
145 #
146 LIBGPG_ERROR_VERSION=1.10
147 #
148 # libgcrypt is required for GnuTLS.
149 # XXX - the link for "Libgcrypt source code" at
150 # http://www.gnupg.org/download/#libgcrypt is for 1.5.0, and is a bzip2
151 # file, but http://directory.fsf.org/project/libgcrypt/ lists only
152 # 1.4.6.
153 #
154 LIBGCRYPT_VERSION=1.5.0
155 GNUTLS_VERSION=2.12.19
156 # Stay with Lua 5.1 when updating until the code has been changed
157 # to support 5.2
158 LUA_VERSION=5.1.5
159 PORTAUDIO_VERSION=pa_stable_v19_20111121
160 #
161 # XXX - they appear to have an unversioned gzipped tarball for the
162 # current version; should we just download that, with some other
163 # way of specifying whether to download the GeoIP API?
164 #
165 GEOIP_VERSION=1.4.8
166
167 # GNU auto tools
168 AUTOCONF_VERSION=2.69
169 AUTOMAKE_VERSION=1.13.3
170 LIBTOOL_VERSION=2.4.2
171
172 #
173 # You need Xcode installed to get the compilers.
174 #
175 if [ ! -x /usr/bin/xcodebuild ]; then
176         echo "Please install Xcode first (should be available on DVD or from http://developer.apple.com/xcode/index.php)."
177         exit 1
178 fi
179
180 #
181 # You also need the X11 SDK; with at least some versions of OS X and
182 # Xcode, that is, I think, an optional install.  (Or it might be
183 # installed with X11, but I think *that* is an optional install on
184 # at least some versions of OS X.)
185 #
186 if [ ! -d /usr/X11/include ]; then
187         echo "Please install X11 and the X11 SDK first."
188         exit 1
189 fi
190
191 #
192 # Do we have permission to write in /usr/local?
193 #
194 # If so, assume we have permission to write in its subdirectories.
195 # (If that's not the case, this test needs to check the subdirectories
196 # as well.)
197 #
198 # If not, do "make install" with sudo.
199 #
200 if [ -w /usr/local ]
201 then
202         DO_MAKE_INSTALL="make install"
203 else
204         DO_MAKE_INSTALL="sudo make install"
205 fi
206
207 export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/X11/lib/pkgconfig
208
209 #
210 # Do all the downloads and untarring in a subdirectory, so all that
211 # stuff can be removed once we've installed the support libraries.
212 #
213 if [ ! -d macosx-support-libs ]
214 then
215         mkdir macosx-support-libs || exit 1
216 fi
217 cd macosx-support-libs
218
219 # Start with xz: It is the sole download format of glib later than 2.31.2
220 #
221 if [ "$XZ_VERSION" -a ! -f xz-$XZ_VERSION-done ] ; then
222     echo "Downloading, building, and installing xz:"
223     [ -f xz-$XZ_VERSION.tar.bz2 ] || curl -O http://tukaani.org/xz/xz-$XZ_VERSION.tar.bz2 || exit 1
224     bzcat xz-$XZ_VERSION.tar.bz2 | tar xf - || exit 1
225     cd xz-$XZ_VERSION
226     CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=0" ./configure || exit 1
227     make $MAKE_BUILD_OPTS || exit 1
228     $DO_MAKE_INSTALL || exit 1
229     cd ..
230     touch xz-$XZ_VERSION-done
231 fi
232
233 if [ "$AUTOCONF_VERSION" -a ! -f autoconf-$AUTOCONF_VERSION-done ] ; then
234     echo "Downloading, building and installing GNU autoconf..."
235     [ -f autoconf-$AUTOCONF_VERSION.tar.xz ] || curl -O ftp://ftp.gnu.org/gnu/autoconf/autoconf-$AUTOCONF_VERSION.tar.xz || exit 1
236     xzcat autoconf-$AUTOCONF_VERSION.tar.xz | tar xf - || exit 1
237     cd autoconf-$AUTOCONF_VERSION
238     ./configure || exit 1
239     make $MAKE_BUILD_OPTS || exit 1
240     $DO_MAKE_INSTALL || exit 1
241     cd ..
242     touch autoconf-$AUTOCONF_VERSION-done
243 fi
244
245 if [ "$AUTOMAKE_VERSION" -a ! -f automake-$AUTOMAKE_VERSION-done ] ; then
246     echo "Downloading, building and installing GNU automake..."
247     [ -f automake-$AUTOMAKE_VERSION.tar.xz ] || curl -O ftp://ftp.gnu.org/gnu/automake/automake-$AUTOMAKE_VERSION.tar.xz || exit 1
248     xzcat automake-$AUTOMAKE_VERSION.tar.xz | tar xf - || exit 1
249     cd automake-$AUTOMAKE_VERSION
250     ./configure || exit 1
251     make $MAKE_BUILD_OPTS || exit 1
252     $DO_MAKE_INSTALL || exit 1
253     cd ..
254     touch automake-$AUTOMAKE_VERSION-done
255 fi
256
257 if [ "$LIBTOOL_VERSION" -a ! -f libtool-$LIBTOOL_VERSION-done ] ; then
258     echo "Downloading, building and installing GNU libtool..."
259     [ -f libtool-$LIBTOOL_VERSION.tar.xz ] || curl -O ftp://ftp.gnu.org/gnu/libtool/libtool-$LIBTOOL_VERSION.tar.xz || exit 1
260     xzcat libtool-$LIBTOOL_VERSION.tar.xz | tar xf - || exit 1
261     cd libtool-$LIBTOOL_VERSION
262     ./configure || exit 1
263     make $MAKE_BUILD_OPTS || exit 1
264     $DO_MAKE_INSTALL || exit 1
265     mv /usr/local/bin/libtool /usr/local/bin/glibtool
266     mv /usr/local/bin/libtoolize /usr/local/bin/glibtoolize
267     cd ..
268     touch libtool-$LIBTOOL_VERSION-done
269 fi
270
271 if [ -n "$CMAKE" -a ! -f cmake-$CMAKE_VERSION-done ]; then
272   echo "Downloading, building, and installing CMAKE:"
273   cmake_dir=`expr $CMAKE_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
274   [ -f cmake-$CMAKE_VERSION.tar.gz ] || curl -O http://www.cmake.org/files/v$cmake_dir/cmake-$CMAKE_VERSION.tar.gz || exit 1
275   gzcat cmake-$CMAKE_VERSION.tar.gz | tar xf - || exit 1
276   cd cmake-$CMAKE_VERSION
277   ./bootstrap || exit 1
278   make $MAKE_BUILD_OPTS || exit 1
279   $DO_MAKE_INSTALL || exit 1
280   cd ..
281   touch cmake-$CMAKE_VERSION-done
282 fi
283
284 #
285 # Start with GNU gettext; GLib requires it, and OS X doesn't have it
286 # or a BSD-licensed replacement.
287 #
288 # At least on Lion with Xcode 4, _FORTIFY_SOURCE gets defined as 2
289 # by default, which causes, for example, stpncpy to be defined as
290 # a hairy macro that collides with the GNU gettext configure script's
291 # attempts to workaround AIX's lack of a declaration for stpncpy,
292 # with the result being a huge train wreck.  Define _FORTIFY_SOURCE
293 # as 0 in an attempt to keep the trains on separate tracks.
294 #
295 if [ ! -f gettext-$GETTEXT_VERSION-done ] ; then
296     echo "Downloading, building, and installing GNU gettext:"
297     [ -f gettext-$GETTEXT_VERSION.tar.gz ] || curl -O http://ftp.gnu.org/pub/gnu/gettext/gettext-$GETTEXT_VERSION.tar.gz || exit 1
298     gzcat gettext-$GETTEXT_VERSION.tar.gz | tar xf - || exit 1
299     cd gettext-$GETTEXT_VERSION
300     CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=0" ./configure || exit 1
301     make $MAKE_BUILD_OPTS || exit 1
302     $DO_MAKE_INSTALL || exit 1
303     cd ..
304     touch gettext-$GETTEXT_VERSION-done
305 fi
306
307 if [ ! -f glib-$GLIB_VERSION-done ] ; then
308     echo "Downloading, building, and installing GLib:"
309     glib_dir=`expr $GLIB_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
310     [ -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
311     xzcat glib-$GLIB_VERSION.tar.xz | tar xf - || exit 1
312     cd glib-$GLIB_VERSION
313     #
314     # OS X ships with libffi, but doesn't provide its pkg-config file;
315     # explicitly specify LIBFFI_CFLAGS and LIBFFI_LIBS, so the configure
316     # script doesn't try to use pkg-config to get the appropriate
317     # CFLAGS and LIBS.
318     #
319     # And, what's worse, at least with the version of Xcode that comes
320     # with Leopard, /usr/include/ffi/fficonfig.h doesn't define MACOSX,
321     # which causes the build of GLib to fail.  If we don't find
322     # "#define.*MACOSX" in /usr/include/ffi/fficonfig.h, explictly
323     # define it.
324     #
325     if grep -qs '#define.*MACOSX' /usr/include/ffi/fficonfig.h
326     then
327         # It's defined, nothing to do
328         LIBFFI_CFLAGS="$CFLAGS -I/usr/include/ffi" LIBFFI_LIBS="$LDFLAGS -lffi" ./configure || exit 1
329     else
330         CFLAGS="$CFLAGS -DMACOSX" LIBFFI_CFLAGS="$CFLAGS -I/usr/include/ffi" LIBFFI_LIBS="LDFLAGS-lffi" ./configure || exit 1
331     fi
332     make $MAKE_BUILD_OPTS || exit 1
333     # Apply patch: we depend on libffi, but pkg-config doesn't get told.
334     patch -p0 <../../macosx-support-lib-patches/glib-pkgconfig.patch || exit 1
335     $DO_MAKE_INSTALL || exit 1
336     cd ..
337     touch glib-$GLIB_VERSION-done
338 fi
339
340 if [ ! -f pkg-config-$PKG_CONFIG_VERSION-done ] ; then
341     echo "Downloading, building, and installing pkg-config:"
342     [ -f pkg-config-$PKG_CONFIG_VERSION.tar.gz ] || curl -O http://pkgconfig.freedesktop.org/releases/pkg-config-$PKG_CONFIG_VERSION.tar.gz || exit 1
343     gzcat pkg-config-$PKG_CONFIG_VERSION.tar.gz | tar xf - || exit 1
344     cd pkg-config-$PKG_CONFIG_VERSION
345     # Avoid another pkgconfig call
346     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
347     make $MAKE_BUILD_OPTS || exit 1
348     $DO_MAKE_INSTALL || exit 1
349     cd ..
350     touch pkg-config-$PKG_CONFIG_VERSION-done
351 fi
352
353 #
354 # Now we have reached a point where we can build everything but
355 # the GUI (Wireshark).
356 #
357 # Cairo is part of Mac OS X 10.6 and 10.7.
358 # The *headers* are supplied by 10.5, but the *libraries* aren't, so
359 # we have to build it on 10.5.
360 # GTK+ 3 requires a newer Cairo build than the one that comes with
361 # 10.6, so we build Cairo if we are using GTK+ 3.
362 # In 10.6 and 10.7, it's an X11 library; if we build with "native" GTK+
363 # rather than X11 GTK+, we might have to build and install Cairo.
364 # The major version number of Darwin in 10.5 is 9.
365 #
366 if [[ -n "$GTK3" || $DARWIN_MAJOR_VERSION = "9" ]]; then
367   #
368   # Requirements for Cairo first
369   #
370   # The libpng that comes with the X11 for leopard has a bogus
371   # pkg-config file that lies about where the header files are,
372   # which causes other packages not to be able to find its
373   # headers.
374   #
375   if [ ! -f libpng-$PNG_VERSION-done ] ; then
376       echo "Downloading, building, and installing libpng:"
377       [ -f libpng-$PNG_VERSION.tar.xz ] || curl -O ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng-$PNG_VERSION.tar.xz
378       xzcat libpng-$PNG_VERSION.tar.xz | tar xf - || exit 1
379       cd libpng-$PNG_VERSION
380       ./configure || exit 1
381       make $MAKE_BUILD_OPTS || exit 1
382       $DO_MAKE_INSTALL || exit 1
383       cd ..
384         touch libpng-$PNG_VERSION-done
385     fi
386
387   #
388   # The libpixman that comes with the X11 for Leopard is too old
389   # to support Cairo's image surface backend feature (which requires
390   # pixman-1 >= 0.22.0).
391   #
392   if [ ! -f pixman-$PIXMAN_VERSION-done ] ; then
393       echo "Downloading, building, and installing pixman:"
394       [ -f pixman-$PIXMAN_VERSION.tar.gz ] || curl -O http://www.cairographics.org/releases/pixman-$PIXMAN_VERSION.tar.gz
395       gzcat pixman-$PIXMAN_VERSION.tar.gz | tar xf - || exit 1
396       cd pixman-$PIXMAN_VERSION
397       ./configure || exit 1
398       make $MAKE_BUILD_OPTS || exit 1
399       $DO_MAKE_INSTALL || exit 1
400       cd ..
401       touch pixman-$PIXMAN_VERSION-done
402   fi
403
404   #
405   # And now Cairo itself.
406   #
407   if [ ! -f cairo-$CAIRO_VERSION-done ] ; then
408       echo "Downloading, building, and installing Cairo:"
409       CAIRO_MAJOR_VERSION="`expr $CAIRO_VERSION : '\([0-9][0-9]*\).*'`"
410       CAIRO_MINOR_VERSION="`expr $CAIRO_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
411       CAIRO_DOTDOT_VERSION="`expr $CAIRO_VERSION : '[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
412       if [[ $CAIRO_MAJOR_VERSION -gt 1 ||
413             $CAIRO_MINOR_VERSION -gt 12 ||
414            ($CAIRO_MINOR_VERSION -eq 12 && $CAIRO_DOTDOT_VERSION -ge 2) ]]
415       then
416         #
417         # Starting with Cairo 1.12.2, the tarballs are compressed with
418         # xz rather than gzip.
419         #
420           [ -f cairo-$CAIRO_VERSION.tar.xz ] || curl -O http://cairographics.org/releases/cairo-$CAIRO_VERSION.tar.xz || exit 1
421           xzcat cairo-$CAIRO_VERSION.tar.xz | tar xf - || exit 1
422       else
423           [ -f cairo-$CAIRO_VERSION.tar.gz ] || curl -O http://cairographics.org/releases/cairo-$CAIRO_VERSION.tar.gz || exit 1
424           gzcat cairo-$CAIRO_VERSION.tar.gz | tar xf - || exit 1
425       fi
426       cd cairo-$CAIRO_VERSION
427       #./configure --enable-quartz=no || exit 1
428       # Maybe follow http://cairographics.org/end_to_end_build_for_mac_os_x/
429       ./configure --enable-quartz=yes || exit 1
430       #
431       # We must avoid the version of libpng that comes with X11; the
432       # only way I've found to force that is to forcibly set INCLUDES
433       # when we do the build, so that this comes before CAIRO_CFLAGS,
434       # which has -I/usr/X11/include added to it before anything
435       # connected to libpng is.
436       #
437       INCLUDES="-I/usr/local/include/libpng15" make $MAKE_BUILD_OPTS || exit 1
438       $DO_MAKE_INSTALL || exit 1
439       cd ..
440       touch cairo-$CAIRO_VERSION-done
441   fi
442 fi
443
444 if [ ! -f atk-$ATK_VERSION-done ] ; then
445     echo "Downloading, building, and installing ATK:"
446     atk_dir=`expr $ATK_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
447     [ -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
448     xzcat atk-$ATK_VERSION.tar.xz | tar xf - || exit 1
449     cd atk-$ATK_VERSION
450     ./configure || exit 1
451     make $MAKE_BUILD_OPTS || exit 1
452     $DO_MAKE_INSTALL || exit 1
453     cd ..
454     touch atk-$ATK_VERSION-done
455 fi
456
457 if [ ! -f pango-$PANGO_VERSION-done ] ; then
458     echo "Downloading, building, and installing Pango:"
459     pango_dir=`expr $PANGO_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
460     PANGO_MAJOR_VERSION="`expr $PANGO_VERSION : '\([0-9][0-9]*\).*'`"
461     PANGO_MINOR_VERSION="`expr $PANGO_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
462     if [[ $PANGO_MAJOR_VERSION -gt 1 ||
463           $PANGO_MINOR_VERSION -ge 29 ]]
464     then
465         #
466         # Starting with Pango 1.29, the tarballs are compressed with
467         # xz rather than bzip2.
468         #
469         [ -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
470         xzcat pango-$PANGO_VERSION.tar.xz | tar xf - || exit 1
471     else
472         [ -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
473         gzcat pango-$PANGO_VERSION.tar.bz2 | tar xf - || exit 1
474     fi
475     cd pango-$PANGO_VERSION
476     ./configure || exit 1
477     make $MAKE_BUILD_OPTS || exit 1
478     $DO_MAKE_INSTALL || exit 1
479     cd ..
480     touch pango-$PANGO_VERSION-done
481 fi
482
483 if [ ! -f gdk-pixbuf-$GDK_PIXBUF_VERSION-done ] ; then
484     echo "Downloading, building, and installing gdk-pixbuf:"
485     gdk_pixbuf_dir=`expr $GDK_PIXBUF_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
486     [ -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
487     xzcat gdk-pixbuf-$GDK_PIXBUF_VERSION.tar.xz | tar xf - || exit 1
488     cd gdk-pixbuf-$GDK_PIXBUF_VERSION
489     ./configure --without-libtiff --without-libjpeg || exit 1
490     make $MAKE_BUILD_OPTS || exit 1
491     $DO_MAKE_INSTALL || exit 1
492     cd ..
493     touch gdk-pixbuf-$GDK_PIXBUF_VERSION-done
494 fi
495
496 if [ ! -f gtk+-$GTK_VERSION-done ] ; then
497     echo "Downloading, building, and installing GTK+:"
498     gtk_dir=`expr $GTK_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
499     GTK_MAJOR_VERSION="`expr $GTK_VERSION : '\([0-9][0-9]*\).*'`"
500     GTK_MINOR_VERSION="`expr $GTK_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
501     GTK_DOTDOT_VERSION="`expr $GTK_VERSION : '[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
502     if [[ $GTK_MAJOR_VERSION -gt 2 ||
503           $GTK_MINOR_VERSION -gt 24 ||
504          ($GTK_MINOR_VERSION -eq 24 && $GTK_DOTDOT_VERSION -ge 5) ]]
505     then
506         #
507         # Starting with GTK+ 2.24.5, the tarballs are compressed with
508         # xz rather than gzip, in addition to bzip2; use xz, as we've
509         # built and installed it, and as xz compresses better than
510         # bzip2 so the tarballs take less time to download.
511         #
512         [ -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
513         xzcat gtk+-$GTK_VERSION.tar.xz | tar xf - || exit 1
514     else
515         [ -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
516         gzcat gtk+-$GTK_VERSION.tar.bz2 | tar xf - || exit 1
517     fi
518     cd gtk+-$GTK_VERSION
519     if [ $DARWIN_MAJOR_VERSION -ge "12" ]
520     then
521         #
522         # GTK+ 2.24.10, at least, doesn't build on Mountain Lion with the
523         # CUPS printing backend - either the CUPS API changed incompatibly
524         # or the backend was depending on non-API implementation details.
525         #
526         # Configure it out, on Mountain Lion and later, for now.
527         # (12 is the Darwin major version number in Mountain Lion.)
528         #
529         ./configure --disable-cups || exit 1
530     else
531         ./configure || exit 1
532     fi
533     make $MAKE_BUILD_OPTS || exit 1
534     $DO_MAKE_INSTALL || exit 1
535     cd ..
536     touch gtk+-$GTK_VERSION-done
537 fi
538
539 #
540 # Now we have reached a point where we can build everything including
541 # the GUI (Wireshark), but not with any optional features such as
542 # SNMP OID resolution, some forms of decryption, Lua scripting, playback
543 # of audio, or GeoIP mapping of IP addresses.
544 #
545 # We now conditionally download optional libraries to support them;
546 # the default is to download them all.
547 #
548
549 if [ "$LIBSMI_VERSION" -a ! -f libsmi-$LIBSMI_VERSION-done ] ; then
550         echo "Downloading, building, and installing libsmi:"
551         [ -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
552         gzcat libsmi-$LIBSMI_VERSION.tar.gz | tar xf - || exit 1
553         cd libsmi-$LIBSMI_VERSION
554         ./configure || exit 1
555         make $MAKE_BUILD_OPTS || exit 1
556         $DO_MAKE_INSTALL || exit 1
557         cd ..
558         touch libsmi-$LIBSMI_VERSION-done
559 fi
560
561 if [ "$LIBGPG_ERROR_VERSION" -a ! -f libgpg-error-$LIBGPG_ERROR_VERSION-done ] ; then
562         echo "Downloading, building, and installing libgpg-error:"
563         [ -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
564         bzcat libgpg-error-$LIBGPG_ERROR_VERSION.tar.bz2 | tar xf - || exit 1
565         cd libgpg-error-$LIBGPG_ERROR_VERSION
566         ./configure || exit 1
567         make $MAKE_BUILD_OPTS || exit 1
568         $DO_MAKE_INSTALL || exit 1
569         cd ..
570         touch libgpg-error-$LIBGPG_ERROR_VERSION-done
571 fi
572
573 if [ "$LIBGCRYPT_VERSION" -a ! -f libgcrypt-$LIBGCRYPT_VERSION-done ] ; then
574         #
575         # libgpg-error is required for libgcrypt.
576         #
577         if [ -z $LIBGPG_ERROR_VERSION ]
578         then
579                 echo "libgcrypt requires libgpg-error, but you didn't install libgpg-error." 1>&2
580                 exit 1
581         fi
582
583         echo "Downloading, building, and installing libgcrypt:"
584         [ -f libgcrypt-$LIBGCRYPT_VERSION.tar.gz ] || curl -L -O ftp://ftp.gnupg.org/gcrypt/libgcrypt/libgcrypt-$LIBGCRYPT_VERSION.tar.gz || exit 1
585         gzcat libgcrypt-$LIBGCRYPT_VERSION.tar.gz | tar xf - || exit 1
586         cd libgcrypt-$LIBGCRYPT_VERSION
587         #
588         # The assembler language code is not compatible with the OS X
589         # x86 assembler (or is it an x86-64 vs. x86-32 issue?).
590         #
591         ./configure --disable-asm || exit 1
592         make $MAKE_BUILD_OPTS || exit 1
593         $DO_MAKE_INSTALL || exit 1
594         cd ..
595         touch libgcrypt-$LIBGCRYPT_VERSION-done
596 fi
597
598 if [ "$GNUTLS_VERSION" -a ! -f gnutls-$GNUTLS_VERSION-done ] ; then
599         #
600         # GnuTLS requires libgcrypt (or nettle, in newer versions).
601         #
602         if [ -z $LIBGCRYPT_VERSION ]
603         then
604                 echo "GnuTLS requires libgcrypt, but you didn't install libgcrypt" 1>&2
605                 exit 1
606         fi
607
608         echo "Downloading, building, and installing GnuTLS:"
609         [ -f gnutls-$GNUTLS_VERSION.tar.bz2 ] || curl -L -O http://ftp.gnu.org/gnu/gnutls/gnutls-$GNUTLS_VERSION.tar.bz2 || exit 1
610         bzcat gnutls-$GNUTLS_VERSION.tar.bz2 | tar xf - || exit 1
611         cd gnutls-$GNUTLS_VERSION
612         #
613         # Use libgcrypt, not nettle.
614         # XXX - is there some reason to prefer nettle?  Or does
615         # Wireshark directly use libgcrypt routines?
616         #
617         ./configure --with-libgcrypt --without-p11-kit || exit 1
618         make $MAKE_BUILD_OPTS || exit 1
619         #
620         # The pkgconfig file for GnuTLS says "requires zlib", but OS X,
621         # while it supplies zlib, doesn't supply a pkgconfig file for
622         # it.
623         #
624         # Patch the GnuTLS pkgconfig file not to require zlib.
625         # (If the capabilities of GnuTLS that Wireshark uses don't
626         # depend on building GnuTLS with zlib, an alternative would be
627         # to configure it not to use zlib.)
628         #
629         patch -p0 lib/gnutls.pc.in <../../macosx-support-lib-patches/gnutls-pkgconfig.patch || exit 1
630         $DO_MAKE_INSTALL || exit 1
631         cd ..
632         touch gnutls-$GNUTLS_VERSION-done
633 fi
634
635 if [ "$LUA_VERSION" -a ! -f lua-$LUA_VERSION-done ] ; then
636         echo "Downloading, building, and installing Lua:"
637         [ -f lua-$LUA_VERSION.tar.gz ] || curl -L -O http://www.lua.org/ftp/lua-$LUA_VERSION.tar.gz || exit 1
638         gzcat lua-$LUA_VERSION.tar.gz | tar xf - || exit 1
639         cd lua-$LUA_VERSION
640         make $MAKE_BUILD_OPTS macosx || exit 1
641         $DO_MAKE_INSTALL || exit 1
642         cd ..
643         touch lua-$LUA_VERSION-done
644 fi
645
646 if [ "$PORTAUDIO_VERSION" -a ! -f portaudio-done ] ; then
647         echo "Downloading, building, and installing PortAudio:"
648         [ -f $PORTAUDIO_VERSION.tgz ] || curl -L -O http://www.portaudio.com/archives/$PORTAUDIO_VERSION.tgz || exit 1
649         gzcat $PORTAUDIO_VERSION.tgz | tar xf - || exit 1
650         cd portaudio
651         #
652         # Un-comment an include that's required on Lion.
653         #
654         patch -p0 include/pa_mac_core.h <../../macosx-support-lib-patches/portaudio-pa_mac_core.h.patch
655         #
656         # Disable fat builds - the configure script doesn't work right
657         # with Xcode 4 if you leave them enabled, and we don't build
658         # any other libraries fat (GLib, for example, would be very
659         # hard to build fat), so there's no advantage to having PortAudio
660         # built fat.
661         #
662         # Set the minimum OS X version to 10.4, to suppress some
663         # deprecation warnings.
664         #
665         CFLAGS="$CFLAGS -mmacosx-version-min=10.4" ./configure --disable-mac-universal || exit 1
666         make $MAKE_BUILD_OPTS || exit 1
667         $DO_MAKE_INSTALL || exit 1
668         cd ..
669         touch portaudio-done
670 fi
671
672 if [ "$GEOIP_VERSION" -a ! -f geoip-$GEOIP_VERSION-done ]
673 then
674         echo "Downloading, building, and installing GeoIP API:"
675         [ -f GeoIP-$GEOIP_VERSION.tar.gz ] || curl -L -O http://geolite.maxmind.com/download/geoip/api/c/GeoIP-$GEOIP_VERSION.tar.gz || exit 1
676         gzcat GeoIP-$GEOIP_VERSION.tar.gz | tar xf - || exit 1
677         cd GeoIP-$GEOIP_VERSION
678         ./configure || exit 1
679         #
680         # Grr.  Their man pages "helpfully" have an ISO 8859-1
681         # copyright symbol in the copyright notice, but OS X's
682         # default character encoding is UTF-8.  sed on Mountain
683         # Lion barfs at the "illegal character sequence" represented
684         # by an ISO 8859-1 copyright symbol, as it's not a valid
685         # UTF-8 sequence.
686         #
687         # iconv the relevant man pages into UTF-8.
688         #
689         for i in geoipupdate.1.in geoiplookup6.1.in geoiplookup.1.in
690         do
691                 iconv -f iso8859-1 -t utf-8 man/"$i" >man/"$i".tmp &&
692                     mv man/"$i".tmp man/"$i"
693         done
694         make $MAKE_BUILD_OPTS || exit 1
695         $DO_MAKE_INSTALL || exit 1
696         cd ..
697         touch geoip-$GEOIP_VERSION-done
698 fi
699
700 echo ""
701
702 echo "You are now prepared to build Wireshark. To do so do:"
703 echo "export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/X11/lib/pkgconfig"
704 echo ""
705 if [ -n "$CMAKE" ]; then
706   echo "mkdir build; cd build"
707   echo "cmake .."
708   echo
709   echo "or"
710   echo
711 fi
712 echo "./autogen.sh"
713 echo "mkdir build; cd build"
714 echo "../configure"
715 echo ""
716 echo "make $MAKE_BUILD_OPTS"
717 echo "make install"
718
719 echo ""
720
721 echo "Make sure you are allowed capture access to the network devices"
722 echo "See: http://wiki.wireshark.org/CaptureSetup/CapturePrivileges"
723
724 echo ""
725
726 exit 0