- Allow reseting edt with new function epan_dissect_reset(),
[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 MACOSX_VERSION=`uname -r | sed 's/\([0-9]*\).*/\1/'`
12
13 # To set up a GTK3 environment
14 # GTK3=1
15 # To build cmake
16 # CMAKE=1
17 #
18 # Versions to download and install.
19 #
20 # The following libraries are required.
21 #
22 GETTEXT_VERSION=0.18.1.1
23 GLIB_VERSION=2.32.3
24 #
25 # pkg-config 0.26 appears to have broken the "we have our own GLib"
26 # stuff, even if you explicitly set GLIB_CFLAGS and GLIB_LIBS.
27 #
28 PKG_CONFIG_VERSION=0.26
29 ATK_VERSION=2.4.0
30 PANGO_VERSION=1.30.0
31 PNG_VERSION=1.5.12
32 PIXMAN_VERSION=0.26.0
33 CAIRO_VERSION=1.12.2
34 GDK_PIXBUF_VERSION=2.26.1
35 if [ -z "$GTK3" ]; then
36   GTK_VERSION=2.24.10
37 else
38   GTK_VERSION=3.5.2
39 fi
40
41 #
42 # Some package need xz to unpack their current source.
43 # xz is not available on OSX (Snow Leopard).
44 #
45 XZ_VERSION=5.0.3
46
47 # In case we want to build with cmake
48 CMAKE_VERSION=2.8.8
49
50 #
51 # The following libraries are optional.
52 # Comment them out if you don't want them, but note that some of
53 # the optional libraries are required by other optional libraries.
54 #
55 LIBSMI_VERSION=0.4.8
56 #
57 # libgpg-error is required for libgcrypt.
58 #
59 LIBGPG_ERROR_VERSION=1.10
60 #
61 # libgcrypt is required for GnuTLS.
62 # XXX - the link for "Libgcrypt source code" at
63 # http://www.gnupg.org/download/#libgcrypt is for 1.5.0, and is a bzip2
64 # file, but http://directory.fsf.org/project/libgcrypt/ lists only
65 # 1.4.6.
66 #
67 LIBGCRYPT_VERSION=1.5.0
68 GNUTLS_VERSION=2.12.19
69 # Stay with Lua 5.1 when updating until the code has been changed
70 # to support 5.2
71 LUA_VERSION=5.1.5
72 PORTAUDIO_VERSION=pa_stable_v19_20111121
73 #
74 # XXX - they appear to have an unversioned gzipped tarball for the
75 # current version; should we just download that, with some other
76 # way of specifying whether to download the GeoIP API?
77 #
78 GEOIP_VERSION=1.4.8
79
80 #
81 # You need Xcode installed to get the compilers.
82 #
83 if [ ! -x /usr/bin/xcodebuild ]; then
84         echo "Please install Xcode first (should be available on DVD or from http://developer.apple.com/xcode/index.php)."
85         exit 1
86 fi
87
88 #
89 # You also need the X11 SDK; with at least some versions of OS X and
90 # Xcode, that is, I think, an optional install.  (Or it might be
91 # installed with X11, but I think *that* is an optional install on
92 # at least some versions of OS X.)
93 #
94 if [ ! -d /usr/X11/include ]; then
95         echo "Please install X11 and the X11 SDK first."
96         exit 1
97 fi
98
99 #
100 # Do we have permission to write in /usr/local?
101 #
102 # If so, assume we have permission to write in its subdirectories.
103 # (If that's not the case, this test needs to check the subdirectories
104 # as well.)
105 #
106 # If not, do "make install" with sudo.
107 #
108 if [ -w /usr/local ]
109 then
110         DO_MAKE_INSTALL="make install"
111 else
112         DO_MAKE_INSTALL="sudo make install"
113 fi
114
115 export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/X11/lib/pkgconfig
116
117 #
118 # Do all the downloads and untarring in a subdirectory, so all that
119 # stuff can be removed once we've installed the support libraries.
120 #
121 if [ ! -d macosx-support-libs ]
122 then
123         mkdir macosx-support-libs || exit 1
124 fi
125 cd macosx-support-libs
126
127 # Start with xz: It is the sole download format of glib later than 2.31.2
128 #
129 echo "Downloading, building, and installing xz:"
130 curl -O http://tukaani.org/xz/xz-$XZ_VERSION.tar.bz2 || exit 1
131 tar xf xz-$XZ_VERSION.tar.bz2 || exit 1
132 cd xz-$XZ_VERSION
133 CFLAGS="-D_FORTIFY_SOURCE=0" ./configure || exit 1
134 make -j 3 || exit 1
135 $DO_MAKE_INSTALL || exit 1
136 cd ..
137
138 if [ -n "$CMAKE" ]; then
139   echo "Downloading, building, and installing CMAKE:"
140   cmake_dir=`expr $CMAKE_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
141   curl -O http://www.cmake.org/files/v$cmake_dir/cmake-$CMAKE_VERSION.tar.gz || exit 1
142   gzcat cmake-$CMAKE_VERSION.tar.gz | tar xf - || exit 1
143   cd cmake-$CMAKE_VERSION
144   ./bootstrap || exit 1
145   make -j 3 || exit 1
146   $DO_MAKE_INSTALL || exit 1
147   cd ..
148 fi
149
150 #
151 # Start with GNU gettext; GLib requires it, and OS X doesn't have it
152 # or a BSD-licensed replacement.
153 #
154 # At least on Lion with Xcode 4, _FORTIFY_SOURCE gets defined as 2
155 # by default, which causes, for example, stpncpy to be defined as
156 # a hairy macro that collides with the GNU gettext configure script's
157 # attempts to workaround AIX's lack of a declaration for stpncpy,
158 # with the result being a huge train wreck.  Define _FORTIFY_SOURCE
159 # as 0 in an attempt to keep the trains on separate tracks.
160 #
161 echo "Downloading, building, and installing GNU gettext:"
162 curl -O http://ftp.gnu.org/pub/gnu/gettext/gettext-$GETTEXT_VERSION.tar.gz || exit 1
163 tar xf gettext-$GETTEXT_VERSION.tar.gz || exit 1
164 cd gettext-$GETTEXT_VERSION
165 CFLAGS="-D_FORTIFY_SOURCE=0" ./configure || exit 1
166 make -j 3 || exit 1
167 $DO_MAKE_INSTALL || exit 1
168 cd ..
169
170 echo "Downloading, building, and installing GLib:"
171 glib_dir=`expr $GLIB_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
172 curl -L -O http://ftp.gnome.org/pub/gnome/sources/glib/$glib_dir/glib-$GLIB_VERSION.tar.xz || exit 1
173 xzcat glib-$GLIB_VERSION.tar.xz | tar xf - || exit 1
174 cd glib-$GLIB_VERSION
175 #
176 # OS X ships with libffi, but doesn't provide its pkg-config file;
177 # explicitly specify LIBFFI_CFLAGS and LIBFFI_LIBS, so the configure
178 # script doesn't try to use pkg-config to get the appropriate
179 # CFLAGS and LIBS.
180 #
181 # And, what's worse, at least with the version of Xcode that comes
182 # with Leopard, /usr/include/ffi/fficonfig.h doesn't define MACOSX,
183 # which causes the build of GLib to fail.  If we don't find
184 # "#define.*MACOSX" in /usr/include/ffi/fficonfig.h, explictly
185 # define it.
186 #
187 if grep -qs '#define.*MACOSX' /usr/include/ffi/fficonfig.h
188 then
189         # It's defined, nothing to do
190         LIBFFI_CFLAGS="-I/usr/include/ffi" LIBFFI_LIBS="-lffi" ./configure || exit 1
191 else
192         CFLAGS="-DMACOSX" LIBFFI_CFLAGS="-I/usr/include/ffi" LIBFFI_LIBS="-lffi" ./configure || exit 1
193 fi
194 make -j 3 || exit 1
195 # Apply patch: we depend on libffi, but pkg-config doesn't get told.
196 patch -p0 <../../macosx-support-lib-patches/glib-pkgconfig.patch || exit 1
197 $DO_MAKE_INSTALL || exit 1
198 cd ..
199
200 echo "Downloading, building, and installing pkg-config:"
201 curl -O http://pkgconfig.freedesktop.org/releases/pkg-config-$PKG_CONFIG_VERSION.tar.gz || exit 1
202 tar xf pkg-config-$PKG_CONFIG_VERSION.tar.gz || exit 1
203 cd pkg-config-$PKG_CONFIG_VERSION
204 # Avoid another pkgconfig call
205 GLIB_CFLAGS="-I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include" GLIB_LIBS="-L/usr/local/lib -lglib-2.0 -lintl" ./configure || exit 1
206 # ./configure || exit 1
207 make -j 3 || exit 1
208 $DO_MAKE_INSTALL || exit 1
209 cd ..
210
211 #
212 # Now we have reached a point where we can build everything but
213 # the GUI (Wireshark).
214 #
215 # Cairo is part of Mac OS X 10.6 and 10.7.
216 # The *headers* are supplied by 10.5, but the *libraries* aren't, so
217 # we have to build it on 10.5.
218 # GTK+ 3 requires a newer Cairo build than the one that comes with
219 # 10.6, so we build Cairo if we are using GTK+ 3.
220 # In 10.6 and 10.7, it's an X11 library; if we build with "native" GTK+
221 # rather than X11 GTK+, we might have to build and install Cairo.
222 #
223 if [[ -n "$GTK3" || $MACOSX_VERSION = "9" ]]; then
224   #
225   # Requirements for Cairo first
226   #
227   echo "Downloading, building, and installing libpng:"
228   curl -O ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng-$PNG_VERSION.tar.xz
229   xzcat libpng-$PNG_VERSION.tar.xz | tar xf - || exit 1
230   cd libpng-$PNG_VERSION
231   ./configure || exit 1
232   make -j 3 || exit 1
233   $DO_MAKE_INSTALL || exit 1
234   cd ..
235
236   echo "Downloading, building, and installing pixman:"
237   curl -O http://www.cairographics.org/releases/pixman-$PIXMAN_VERSION.tar.gz
238   gzcat pixman-$PIXMAN_VERSION.tar.gz | tar xf - || exit 1
239   cd pixman-$PIXMAN_VERSION
240   ./configure || exit 1
241   make -j 3 || exit 1
242   $DO_MAKE_INSTALL || exit 1
243   cd ..
244
245   #
246   # And now Cairo itself.
247   #
248   echo "Downloading, building, and installing Cairo:"
249   curl -O http://cairographics.org/releases/cairo-$CAIRO_VERSION.tar.xz || exit 1
250   xzcat cairo-$CAIRO_VERSION.tar.xz | tar xf - || exit 1
251   cd cairo-$CAIRO_VERSION
252   #./configure --enable-quartz=no || exit 1
253   # Maybe follow http://cairographics.org/end_to_end_build_for_mac_os_x/
254   ./configure --enable-quartz=yes || exit 1
255   make -j 3 || exit 1
256   $DO_MAKE_INSTALL || exit 1
257   cd ..
258 fi
259
260 echo "Downloading, building, and installing ATK:"
261 atk_dir=`expr $ATK_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
262 curl -O http://ftp.gnome.org/pub/gnome/sources/atk/$atk_dir/atk-$ATK_VERSION.tar.xz || exit 1
263 xzcat atk-$ATK_VERSION.tar.xz | tar xf - || exit 1
264 cd atk-$ATK_VERSION
265 ./configure || exit 1
266 make -j 3 || exit 1
267 $DO_MAKE_INSTALL || exit 1
268 cd ..
269
270 echo "Downloading, building, and installing Pango:"
271 pango_dir=`expr $PANGO_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
272 curl -L -O http://ftp.gnome.org/pub/gnome/sources/pango/$pango_dir/pango-$PANGO_VERSION.tar.xz
273 xzcat pango-$PANGO_VERSION.tar.xz | tar xf - || exit 1
274 cd pango-$PANGO_VERSION
275 ./configure || exit 1
276 make -j 3 || exit 1
277 $DO_MAKE_INSTALL || exit 1
278 cd ..
279
280 echo "Downloading, building, and installing gdk-pixbuf:"
281 gdk_pixbuf_dir=`expr $GDK_PIXBUF_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
282 curl -L -O http://ftp.gnome.org/pub/gnome/sources/gdk-pixbuf/$gdk_pixbuf_dir/gdk-pixbuf-$GDK_PIXBUF_VERSION.tar.xz || exit 1
283 xzcat gdk-pixbuf-$GDK_PIXBUF_VERSION.tar.xz | tar xf - || exit 1
284 cd gdk-pixbuf-$GDK_PIXBUF_VERSION
285 ./configure --without-libtiff --without-libjpeg || exit 1
286 make -j 3 || exit 1
287 $DO_MAKE_INSTALL || exit 1
288 cd ..
289
290 echo "Downloading, building, and installing GTK+:"
291 gtk_dir=`expr $GTK_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
292 curl -L -O http://ftp.gnome.org/pub/gnome/sources/gtk+/$gtk_dir/gtk+-$GTK_VERSION.tar.xz
293 xzcat gtk+-$GTK_VERSION.tar.xz | tar xf - || exit 1
294 cd gtk+-$GTK_VERSION
295 #
296 # GTK+ 2.24.10, at least, doesn't build on Mountain Lion with the CUPS
297 # printing backend - either the CUPS API changed incompatibly or the
298 # backend was depending on non-API implementation details.
299 #
300 # Configure it out for now.
301 #
302 if [ $MACOSX_VERSION -ge "12" ]
303 then
304         ./configure --disable-cups || exit 1
305 else
306         ./configure || exit 1
307 fi
308 make -j 3 || exit 1
309 $DO_MAKE_INSTALL || exit 1
310 cd ..
311
312 #
313 # Now we have reached a point where we can build everything including
314 # the GUI (Wireshark), but not with any optional features such as
315 # SNMP OID resolution, some forms of decryption, Lua scripting, playback
316 # of audio, or GeoIP mapping of IP addresses.
317 #
318 # We now conditionally download optional libraries to support them;
319 # the default is to download them all.
320 #
321
322 if [ ! -z $LIBSMI_VERSION ]
323 then
324         echo "Downloading, building, and installing libsmi:"
325         curl -L -O ftp://ftp.ibr.cs.tu-bs.de/pub/local/libsmi/libsmi-$LIBSMI_VERSION.tar.gz || exit 1
326         tar xf libsmi-$LIBSMI_VERSION.tar.gz || exit 1
327         cd libsmi-$LIBSMI_VERSION
328         ./configure || exit 1
329         make -j 3 || exit 1
330         $DO_MAKE_INSTALL || exit 1
331         cd ..
332 fi
333
334 if [ ! -z $LIBGPG_ERROR_VERSION ]
335 then
336         echo "Downloading, building, and installing libgpg-error:"
337         curl -L -O ftp://ftp.gnupg.org/gcrypt/libgpg-error/libgpg-error-$LIBGPG_ERROR_VERSION.tar.bz2 || exit 1
338         bzcat libgpg-error-$LIBGPG_ERROR_VERSION.tar.bz2 | tar xf - || exit 1
339         cd libgpg-error-$LIBGPG_ERROR_VERSION
340         ./configure || exit 1
341         make -j 3 || exit 1
342         $DO_MAKE_INSTALL || exit 1
343         cd ..
344 fi
345
346 if [ ! -z $LIBGCRYPT_VERSION ]
347 then
348         #
349         # libgpg-error is required for libgcrypt.
350         #
351         if [ -z $LIBGPG_ERROR_VERSION ]
352         then
353                 echo "libgcrypt requires libgpg-error, but you didn't install libgpg-error." 1>&2
354                 exit 1
355         fi
356
357         echo "Downloading, building, and installing libgcrypt:"
358         curl -L -O ftp://ftp.gnupg.org/gcrypt/libgcrypt/libgcrypt-$LIBGCRYPT_VERSION.tar.gz || exit 1
359         tar xf libgcrypt-$LIBGCRYPT_VERSION.tar.gz || exit 1
360         cd libgcrypt-$LIBGCRYPT_VERSION
361         #
362         # The assembler language code is not compatible with the OS X
363         # x86 assembler (or is it an x86-64 vs. x86-32 issue?).
364         #
365         ./configure --disable-asm || exit 1
366         make -j 3 || exit 1
367         $DO_MAKE_INSTALL || exit 1
368         cd ..
369 fi
370
371 if [ ! -z $GNUTLS_VERSION ]
372 then
373         #
374         # GnuTLS requires libgcrypt (or nettle, in newer versions).
375         #
376         if [ -z $LIBGCRYPT_VERSION ]
377         then
378                 echo "GnuTLS requires libgcrypt, but you didn't install libgcrypt" 1>&2
379                 exit 1
380         fi
381
382         echo "Downloading, building, and installing GnuTLS:"
383         curl -L -O http://ftp.gnu.org/gnu/gnutls/gnutls-$GNUTLS_VERSION.tar.bz2 || exit 1
384         bzcat gnutls-$GNUTLS_VERSION.tar.bz2 | tar xf - || exit 1
385         cd gnutls-$GNUTLS_VERSION
386         #
387         # Use libgcrypt, not nettle.
388         # XXX - is there some reason to prefer nettle?  Or does
389         # Wireshark directly use libgcrypt routines?
390         #
391         ./configure --with-libgcrypt --without-p11-kit || exit 1
392         make -j 3 || exit 1
393         #
394         # The pkgconfig file for GnuTLS says "requires zlib", but OS X,
395         # while it supplies zlib, doesn't supply a pkgconfig file for
396         # it.
397         #
398         # Patch the GnuTLS pkgconfig file not to require zlib.
399         # (If the capabilities of GnuTLS that Wireshark uses don't
400         # depend on building GnuTLS with zlib, an alternative would be
401         # to configure it not to use zlib.)
402         #
403         patch -p0 lib/gnutls.pc.in <../../macosx-support-lib-patches/gnutls-pkgconfig.patch || exit 1
404         $DO_MAKE_INSTALL || exit 1
405         cd ..
406 fi
407
408 if [ ! -z $LUA_VERSION ]
409 then
410         echo "Downloading, building, and installing Lua:"
411         curl -L -O http://www.lua.org/ftp/lua-$LUA_VERSION.tar.gz || exit 1
412         tar xf lua-$LUA_VERSION.tar.gz || exit 1
413         cd lua-$LUA_VERSION
414         make -j 3 macosx || exit 1
415         $DO_MAKE_INSTALL || exit 1
416         cd ..
417 fi
418
419 if [ ! -z $PORTAUDIO_VERSION ]
420 then
421         echo "Downloading, building, and installing PortAudio:"
422         curl -L -O http://www.portaudio.com/archives/$PORTAUDIO_VERSION.tgz || exit 1
423         tar xf $PORTAUDIO_VERSION.tgz || exit 1
424         cd portaudio
425         #
426         # Un-comment an include that's required on Lion.
427         #
428         patch -p0 include/pa_mac_core.h <../../macosx-support-lib-patches/portaudio-pa_mac_core.h.patch
429         #
430         # Disable fat builds - the configure script doesn't work right
431         # with Xcode 4 if you leave them enabled, and we don't build
432         # any other libraries fat (GLib, for example, would be very
433         # hard to build fat), so there's no advantage to having PortAudio
434         # built fat.
435         #
436         # Set the minimum OS X version to 10.4, to suppress some
437         # deprecation warnings.
438         #
439         CFLAGS="-mmacosx-version-min=10.4" ./configure --disable-mac-universal || exit 1
440         make -j 3 || exit 1
441         $DO_MAKE_INSTALL || exit 1
442         cd ..
443 fi
444
445 if [ ! -z $GEOIP_VERSION ]
446 then
447         echo "Downloading, building, and installing GeoIP API:"
448         curl -L -O http://geolite.maxmind.com/download/geoip/api/c/GeoIP-$GEOIP_VERSION.tar.gz || exit 1
449         tar xf GeoIP-$GEOIP_VERSION.tar.gz || exit 1
450         cd GeoIP-$GEOIP_VERSION
451         ./configure || exit 1
452         #
453         # Grr.  Their man pages "helpfully" have an ISO 8859-1
454         # copyright symbol in the copyright notice, but OS X's
455         # default character encoding is UTF-8.  sed on Mountain
456         # Lion barfs at the "illegal character sequence" represented
457         # by an ISO 8859-1 copyright symbol, as it's not a valid
458         # UTF-8 sequence.
459         #
460         # iconv the relevant man pages into UTF-8.
461         #
462         for i in geoipupdate.1.in geoiplookup6.1.in geoiplookup.1.in
463         do
464                 iconv -f iso8859-1 -t utf-8 man/"$i" >man/"$i".tmp &&
465                     mv man/"$i".tmp man/"$i"
466         done
467         make -j 3 || exit 1
468         $DO_MAKE_INSTALL || exit 1
469         cd ..
470 fi
471
472 echo ""
473
474 echo "You are now prepared to build Wireshark. To do so do:"
475 echo "export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/X11/lib/pkgconfig"
476 echo ""
477 if [ -n "$CMAKE" ]; then
478   echo "mkdir build; cd build"
479   echo "cmake .."
480   echo
481   echo "or"
482   echo
483 fi
484 echo "./autogen.sh"
485 echo "mkdir build; cd build"
486 echo "../configure"
487 echo ""
488 echo "make -j 3"
489 echo "make install"
490
491 echo ""
492
493 echo "Make sure you are allowed capture access to the network devices"
494 echo "See: http://wiki.wireshark.org/CaptureSetup/CapturePrivileges"
495
496 echo ""
497
498 exit 0