- Update cmake, gnutls and pixman to current version
[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 # To set up a GTK3 environment
12 # GTK3=1
13 # To build cmake
14 # CMAKE=1
15 #
16 # Versions to download and install.
17 #
18 # The following libraries are required.
19 #
20 GETTEXT_VERSION=0.18.1.1
21 GLIB_VERSION=2.32.3
22 #
23 # pkg-config 0.26 appears to have broken the "we have our own GLib"
24 # stuff, even if you explicitly set GLIB_CFLAGS and GLIB_LIBS.
25 # Life's too short to work around the circular dependency in a script,
26 # so we use 0.25 instead.
27 #
28 PKG_CONFIG_VERSION=0.26
29 ATK_VERSION=2.4.0
30 PANGO_VERSION=1.30.0
31 PNG_VERSION=1.5.10
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 LUA_VERSION=5.2.0
70 PORTAUDIO_VERSION=pa_stable_v19_20111121
71 #
72 # XXX - they appear to have an unversioned gzipped tarball for the
73 # current version; should we just download that, with some other
74 # way of specifying whether to download the GeoIP API?
75 #
76 GEOIP_VERSION=1.4.8
77
78 #
79 # You need Xcode installed to get the compilers.
80 #
81 if [ ! -x /usr/bin/xcodebuild ]; then
82         echo "Please install Xcode first (should be available on DVD or from http://developer.apple.com/xcode/index.php)."
83         exit 1
84 fi
85
86 #
87 # You also need the X11 SDK; with at least some versions of OS X and
88 # Xcode, that is, I think, an optional install.  (Or it might be
89 # installed with X11, but I think *that* is an optional install on
90 # at least some versions of OS X.)
91 #
92 if [ ! -d /usr/X11/include ]; then
93         echo "Please install X11 and the X11 SDK first."
94         exit 1
95 fi
96
97 #
98 # Do we have permission to write in /usr/local?
99 #
100 # If so, assume we have permission to write in its subdirectories.
101 # (If that's not the case, this test needs to check the subdirectories
102 # as well.)
103 #
104 # If not, do "make install" with sudo.
105 #
106 if [ -w /usr/local ]
107 then
108         DO_MAKE_INSTALL="make install"
109 else
110         DO_MAKE_INSTALL="sudo make install"
111 fi
112
113 export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/X11/lib/pkgconfig
114
115 #
116 # Do all the downloads and untarring in a subdirectory, so all that
117 # stuff can be removed once we've installed the support libraries.
118 #
119 if [ ! -d macosx-support-libs ]
120 then
121         mkdir macosx-support-libs || exit 1
122 fi
123 cd macosx-support-libs
124
125 # Start with xz: It is the sole download format of glib later than 2.31.2
126 #
127 echo "Downloading, building, and installing xz:"
128 curl -O http://tukaani.org/xz/xz-$XZ_VERSION.tar.bz2 || exit 1
129 tar xf xz-$XZ_VERSION.tar.bz2 || exit 1
130 cd xz-$XZ_VERSION
131 CFLAGS="-D_FORTIFY_SOURCE=0" ./configure || exit 1
132 make -j 3 || exit 1
133 $DO_MAKE_INSTALL || exit 1
134 cd ..
135
136 if [ -n "$CMAKE" ]; then
137   echo "Downloading, building, and installing CMAKE:"
138   cmake_dir=`expr $CMAKE_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
139   curl -O http://www.cmake.org/files/v$cmake_dir/cmake-$CMAKE_VERSION.tar.gz || exit 1
140   gzcat cmake-$CMAKE_VERSION.tar.gz | tar xf - || exit 1
141   cd cmake-$CMAKE_VERSION
142   ./bootstrap || exit 1
143   make -j 3 || exit 1
144   $DO_MAKE_INSTALL || exit 1
145   cd ..
146 fi
147
148 #
149 # Start with GNU gettext; GLib requires it, and OS X doesn't have it
150 # or a BSD-licensed replacement.
151 #
152 # At least on Lion with Xcode 4, _FORTIFY_SOURCE gets defined as 2
153 # by default, which causes, for example, stpncpy to be defined as
154 # a hairy macro that collides with the GNU gettext configure script's
155 # attempts to workaround AIX's lack of a declaration for stpncpy,
156 # with the result being a huge train wreck.  Define _FORTIFY_SOURCE
157 # as 0 in an attempt to keep the trains on separate tracks.
158 #
159 echo "Downloading, building, and installing GNU gettext:"
160 curl -O http://ftp.gnu.org/pub/gnu/gettext/gettext-$GETTEXT_VERSION.tar.gz || exit 1
161 tar xf gettext-$GETTEXT_VERSION.tar.gz || exit 1
162 cd gettext-$GETTEXT_VERSION
163 CFLAGS="-D_FORTIFY_SOURCE=0" ./configure || exit 1
164 make -j 3 || exit 1
165 $DO_MAKE_INSTALL || exit 1
166 cd ..
167
168 echo "Downloading, building, and installing GLib:"
169 glib_dir=`expr $GLIB_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
170 curl -L -O http://ftp.gnome.org/pub/gnome/sources/glib/$glib_dir/glib-$GLIB_VERSION.tar.xz || exit 1
171 xzcat glib-$GLIB_VERSION.tar.xz | tar xf - || exit 1
172 cd glib-$GLIB_VERSION
173 #
174 # OS X ships with libffi, but doesn't provide its pkg-config file;
175 # explicitly specify LIBFFI_CFLAGS and LIBFFI_LIBS, so the configure
176 # script doesn't try to use pkg-config to get the appropriate
177 # CFLAGS and LIBS.
178 #
179 LIBFFI_CFLAGS="-I/usr/include/ffi" LIBFFI_LIBS="-lffi" ./configure || exit 1
180 make -j 3 || exit 1
181 # Apply patch: we depend on libffi, but pkg-config doesn't get told.
182 patch -p0 <../../macosx-support-lib-patches/glib-pkgconfig.patch || exit 1
183 $DO_MAKE_INSTALL || exit 1
184 cd ..
185
186 echo "Downloading, building, and installing pkg-config:"
187 curl -O http://pkgconfig.freedesktop.org/releases/pkg-config-$PKG_CONFIG_VERSION.tar.gz || exit 1
188 tar xf pkg-config-$PKG_CONFIG_VERSION.tar.gz || exit 1
189 cd pkg-config-$PKG_CONFIG_VERSION
190 # Avoid another pkgconfig call
191 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
192 # ./configure || exit 1
193 make -j 3 || exit 1
194 $DO_MAKE_INSTALL || exit 1
195 cd ..
196
197 #
198 # Now we have reached a point where we can build everything but
199 # the GUI (Wireshark).
200 #
201
202 if [ -n "$GTK3" ]; then
203   #
204   # Cairo is part of Mac OS X 10.6 (and, I think, 10.5).
205   # However, it's an X11 library; if we build with "native" GTK+ rather
206   # than X11 GTK+, we might have to build and install Cairo.
207   # GTK+-3 requires a newer cairo build as well.
208   #
209   # Requirements for cairo first
210   #
211   echo "Downloading, building, and installing libpng:"
212   curl -O ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng-$PNG_VERSION.tar.xz
213   xzcat libpng-$PNG_VERSION.tar.xz | tar xf - || exit 1
214   cd libpng-$PNG_VERSION
215   ./configure || exit 1
216   make -j 3 || exit 1
217   $DO_MAKE_INSTALL || exit 1
218   cd ..
219
220   echo "Downloading, building, and installing pixman:"
221   curl -O http://www.cairographics.org/releases/pixman-$PIXMAN_VERSION.tar.gz
222   gzcat pixman-$PIXMAN_VERSION.tar.gz | tar xf - || exit 1
223   cd pixman-$PIXMAN_VERSION
224   ./configure || exit 1
225   make -j 3 || exit 1
226   $DO_MAKE_INSTALL || exit 1
227   cd ..
228
229   #
230   # And now cairo itself.
231   #
232   echo "Downloading, building, and installing Cairo:"
233   curl -O http://cairographics.org/releases/cairo-$CAIRO_VERSION.tar.xz || exit 1
234   xzcat cairo-$CAIRO_VERSION.tar.xz | tar xf - || exit 1
235   cd cairo-$CAIRO_VERSION
236   #./configure --enable-quartz=no || exit 1
237   # Maybe follow http://cairographics.org/end_to_end_build_for_mac_os_x/
238   ./configure --enable-quartz=yes || exit 1
239   make -j 3 || exit 1
240   $DO_MAKE_INSTALL || exit 1
241   cd ..
242 fi
243
244 echo "Downloading, building, and installing ATK:"
245 atk_dir=`expr $ATK_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
246 curl -O http://ftp.gnome.org/pub/gnome/sources/atk/$atk_dir/atk-$ATK_VERSION.tar.xz || exit 1
247 xzcat atk-$ATK_VERSION.tar.xz | tar xf - || exit 1
248 cd atk-$ATK_VERSION
249 ./configure || exit 1
250 make -j 3 || exit 1
251 $DO_MAKE_INSTALL || exit 1
252 cd ..
253
254 echo "Downloading, building, and installing Pango:"
255 pango_dir=`expr $PANGO_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
256 curl -L -O http://ftp.gnome.org/pub/gnome/sources/pango/$pango_dir/pango-$PANGO_VERSION.tar.xz
257 xzcat pango-$PANGO_VERSION.tar.xz | tar xf - || exit 1
258 cd pango-$PANGO_VERSION
259 ./configure || exit 1
260 make -j 3 || exit 1
261 $DO_MAKE_INSTALL || exit 1
262 cd ..
263
264 echo "Downloading, building, and installing gdk-pixbuf:"
265 gdk_pixbuf_dir=`expr $GDK_PIXBUF_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
266 curl -L -O http://ftp.gnome.org/pub/gnome/sources/gdk-pixbuf/$gdk_pixbuf_dir/gdk-pixbuf-$GDK_PIXBUF_VERSION.tar.xz || exit 1
267 xzcat gdk-pixbuf-$GDK_PIXBUF_VERSION.tar.xz | tar xf - || exit 1
268 cd gdk-pixbuf-$GDK_PIXBUF_VERSION
269 ./configure --without-libtiff --without-libjpeg || exit 1
270 make -j 3 || exit 1
271 $DO_MAKE_INSTALL || exit 1
272 cd ..
273
274 echo "Downloading, building, and installing GTK+:"
275 gtk_dir=`expr $GTK_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
276 curl -L -O http://ftp.gnome.org/pub/gnome/sources/gtk+/$gtk_dir/gtk+-$GTK_VERSION.tar.xz
277 xzcat gtk+-$GTK_VERSION.tar.xz | tar xf - || exit 1
278 cd gtk+-$GTK_VERSION
279 ./configure || exit 1
280 make -j 3 || exit 1
281 $DO_MAKE_INSTALL || exit 1
282 cd ..
283
284 #
285 # Now we have reached a point where we can build everything including
286 # the GUI (Wireshark), but not with any optional features such as
287 # SNMP OID resolution, some forms of decryption, Lua scripting, playback
288 # of audio, or GeoIP mapping of IP addresses.
289 #
290 # We now conditionally download optional libraries to support them;
291 # the default is to download them all.
292 #
293
294 if [ ! -z $LIBSMI_VERSION ]
295 then
296         echo "Downloading, building, and installing libsmi:"
297         curl -L -O ftp://ftp.ibr.cs.tu-bs.de/pub/local/libsmi/libsmi-$LIBSMI_VERSION.tar.gz || exit 1
298         tar xf libsmi-$LIBSMI_VERSION.tar.gz || exit 1
299         cd libsmi-$LIBSMI_VERSION
300         ./configure || exit 1
301         make -j 3 || exit 1
302         $DO_MAKE_INSTALL || exit 1
303         cd ..
304 fi
305
306 if [ ! -z $LIBGPG_ERROR_VERSION ]
307 then
308         echo "Downloading, building, and installing libgpg-error:"
309         curl -L -O ftp://ftp.gnupg.org/gcrypt/libgpg-error/libgpg-error-$LIBGPG_ERROR_VERSION.tar.bz2 || exit 1
310         bzcat libgpg-error-$LIBGPG_ERROR_VERSION.tar.bz2 | tar xf - || exit 1
311         cd libgpg-error-$LIBGPG_ERROR_VERSION
312         ./configure || exit 1
313         make -j 3 || exit 1
314         $DO_MAKE_INSTALL || exit 1
315         cd ..
316 fi
317
318 if [ ! -z $LIBGCRYPT_VERSION ]
319 then
320         #
321         # libgpg-error is required for libgcrypt.
322         #
323         if [ -z $LIBGPG_ERROR_VERSION ]
324         then
325                 echo "libgcrypt requires libgpg-error, but you didn't install libgpg-error." 1>&2
326                 exit 1
327         fi
328
329         echo "Downloading, building, and installing libgcrypt:"
330         curl -L -O ftp://ftp.gnupg.org/gcrypt/libgcrypt/libgcrypt-$LIBGCRYPT_VERSION.tar.gz || exit 1
331         tar xf libgcrypt-$LIBGCRYPT_VERSION.tar.gz || exit 1
332         cd libgcrypt-$LIBGCRYPT_VERSION
333         #
334         # The assembler language code is not compatible with the OS X
335         # x86 assembler (or is it an x86-64 vs. x86-32 issue?).
336         #
337         ./configure --disable-asm || exit 1
338         make -j 3 || exit 1
339         $DO_MAKE_INSTALL || exit 1
340         cd ..
341 fi
342
343 if [ ! -z $GNUTLS_VERSION ]
344 then
345         #
346         # GnuTLS requires libgcrypt (or nettle, in newer versions).
347         #
348         if [ -z $LIBGCRYPT_VERSION ]
349         then
350                 echo "GnuTLS requires libgcrypt, but you didn't install libgcrypt" 1>&2
351                 exit 1
352         fi
353
354         echo "Downloading, building, and installing GnuTLS:"
355         curl -L -O http://ftp.gnu.org/gnu/gnutls/gnutls-$GNUTLS_VERSION.tar.bz2 || exit 1
356         bzcat gnutls-$GNUTLS_VERSION.tar.bz2 | tar xf - || exit 1
357         cd gnutls-$GNUTLS_VERSION
358         #
359         # Use libgcrypt, not nettle.
360         # XXX - is there some reason to prefer nettle?  Or does
361         # Wireshark directly use libgcrypt routines?
362         #
363         ./configure --with-libgcrypt --without-p11-kit || exit 1
364         make -j 3 || exit 1
365         #
366         # The pkgconfig file for GnuTLS says "requires zlib", but OS X,
367         # while it supplies zlib, doesn't supply a pkgconfig file for
368         # it.
369         #
370         # Patch the GnuTLS pkgconfig file not to require zlib.
371         # (If the capabilities of GnuTLS that Wireshark uses don't
372         # depend on building GnuTLS with zlib, an alternative would be
373         # to configure it not to use zlib.)
374         #
375         patch -p0 lib/gnutls.pc.in <../../macosx-support-lib-patches/gnutls-pkgconfig.patch || exit 1
376         $DO_MAKE_INSTALL || exit 1
377         cd ..
378 fi
379
380 if [ ! -z $LUA_VERSION ]
381 then
382         echo "Downloading, building, and installing Lua:"
383         curl -L -O http://www.lua.org/ftp/lua-$LUA_VERSION.tar.gz || exit 1
384         tar xf lua-$LUA_VERSION.tar.gz || exit 1
385         cd lua-$LUA_VERSION
386         make -j 3 macosx || exit 1
387         $DO_MAKE_INSTALL || exit 1
388         cd ..
389 fi
390
391 if [ ! -z $PORTAUDIO_VERSION ]
392 then
393         echo "Downloading, building, and installing PortAudio:"
394         curl -L -O http://www.portaudio.com/archives/$PORTAUDIO_VERSION.tgz || exit 1
395         tar xf $PORTAUDIO_VERSION.tgz || exit 1
396         cd portaudio
397         ./configure || exit 1
398         make -j 3 || exit 1
399         $DO_MAKE_INSTALL || exit 1
400         cd ..
401 fi
402
403 if [ ! -z $GEOIP_VERSION ]
404 then
405         echo "Downloading, building, and installing GeoIP API:"
406         curl -L -O http://geolite.maxmind.com/download/geoip/api/c/GeoIP-$GEOIP_VERSION.tar.gz || exit 1
407         tar xf GeoIP-$GEOIP_VERSION.tar.gz || exit 1
408         cd GeoIP-$GEOIP_VERSION
409         ./configure || exit 1
410         make -j 3 || exit 1
411         $DO_MAKE_INSTALL || exit 1
412         cd ..
413 fi
414
415 echo ""
416
417 echo "You are now prepared to build Wireshark. To do so do:"
418 echo "export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/X11/lib/pkgconfig"
419 echo ""
420 if [ -n "$CMAKE" ]; then
421   echo "mkdir build; cd build"
422   echo "cmake .."
423   echo
424   echo "or"
425   echo
426 fi
427 echo "./autogen.sh"
428 echo "mkdir build; cd build"
429 echo "../configure"
430 echo ""
431 echo "make -j 3"
432 echo "make install"
433
434 echo ""
435
436 echo "Make sure you are allowed capture access to the network devices"
437 echo "See: http://wiki.wireshark.org/CaptureSetup/CapturePrivileges"
438
439 echo ""
440
441 exit 0