From Johannes Berg
[obnox/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 #
12 # Versions to download and install.
13 #
14 # The following libraries are required.
15 #
16 GETTEXT_VERSION=0.18.1.1
17 GLIB_VERSION=2.29.8
18 #
19 # pkg-config 0.26 appears to have broken the "we have our own GLib"
20 # stuff, even if you explicitly set GLIB_CFLAGS and GLIB_LIBS.
21 # Life's too short to work around the circular dependency in a script,
22 # so we use 0.25 instead.
23 #
24 PKG_CONFIG_VERSION=0.26
25 ATK_VERSION=2.0.1
26 PANGO_VERSION=1.29.3
27 GDK_PIXBUF_VERSION=2.23.4
28 GTK_VERSION=2.24.5
29
30 #
31 # The following libraries are optional.
32 # Comment them out if you don't want them, but note that some of
33 # the optional libraries are required by other optional libraries.
34 #
35 LIBSMI_VERSION=0.4.8
36 #
37 # libgpg-error is required for libgcrypt.
38 #
39 LIBGPG_ERROR_VERSION=1.10
40 #
41 # libgcrypt is required for GnuTLS.
42 # XXX - the link for "Libgcrypt source code" at
43 # http://www.gnupg.org/download/#libgcrypt is for 1.5.0, and is a bzip2
44 # file, but http://directory.fsf.org/project/libgcrypt/ lists only
45 # 1.4.6.
46 #
47 LIBGCRYPT_VERSION=1.4.6
48 GNUTLS_VERSION=2.12.7
49 LUA_VERSION=5.1.4
50 PORTAUDIO_VERSION=pa_stable_v19_20110326
51 #
52 # XXX - they appear to have an unversioned gzipped tarball for the
53 # current version; should we just download that, with some other
54 # way of specifying whether to download the GeoIP API?
55 #
56 GEOIP_VERSION=1.4.8
57
58 #
59 # You need Xcode installed to get the compilers.
60 #
61 if [ ! -x /usr/bin/xcodebuild ]; then
62         echo "Please install Xcode first (should be available on DVD or from http://developer.apple.com/xcode/index.php)."
63         exit 1
64 fi
65
66 #
67 # You also need the X11 SDK; with at least some versions of OS X and
68 # Xcode, that is, I think, an optional install.  (Or it might be
69 # installed with X11, but I think *that* is an optional install on
70 # at least some versions of OS X.)
71 #
72 if [ ! -d /usr/X11/include ]; then
73         echo "Please install X11 and the X11 SDK first."
74         exit 1
75 fi
76
77 #
78 # Do we have permission to write in /usr/local?
79 #
80 # If so, assume we have permission to write in its subdirectories.
81 # (If that's not the case, this test needs to check the subdirectories
82 # as well.)
83 #
84 # If not, do "make install" with sudo.
85 #
86 if [ -w /usr/local ]
87 then
88         DO_MAKE_INSTALL="make install"
89 else
90         DO_MAKE_INSTALL="sudo make install"
91 fi
92
93 export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/X11/lib/pkgconfig
94
95 #
96 # Do all the downloads and untarring in a subdirectory, so all that
97 # stuff can be removed once we've installed the support libraries.
98 #
99 if [ ! -d macosx-support-libs ]
100 then
101         mkdir macosx-support-libs || exit 1
102 fi
103 cd macosx-support-libs
104
105 #
106 # Start with GNU gettext; GLib requires it, and OS X doesn't have it
107 # or a BSD-licensed replacement.
108 #
109 # At least on Lion with Xcode 4, _FORTIFY_SOURCE gets defined as 2
110 # by default, which causes, for example, stpncpy to be defined as
111 # a hairy macro that collides with the GNU gettext configure script's
112 # attempts to workaround AIX's lack of a declaration for stpncpy,
113 # with the result being a huge train wreck.  Define _FORTIFY_SOURCE
114 # as 0 in an attempt to keep the trains on separate tracks.
115 #
116 echo "Downloading, building, and installing GNU gettext:"
117 curl -O http://ftp.gnu.org/pub/gnu/gettext/gettext-$GETTEXT_VERSION.tar.gz || exit 1
118 tar xf gettext-$GETTEXT_VERSION.tar.gz || exit 1
119 cd gettext-$GETTEXT_VERSION
120 CFLAGS="-D_FORTIFY_SOURCE=0" ./configure || exit 1
121 make -j 3 || exit 1
122 $DO_MAKE_INSTALL || exit 1
123 cd ..
124
125 echo "Downloading, building, and installing GLib:"
126 glib_dir=`expr $GLIB_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
127 curl -L -O http://ftp.gnome.org/pub/gnome/sources/glib/$glib_dir/glib-$GLIB_VERSION.tar.bz2 || exit 1
128 bzcat glib-$GLIB_VERSION.tar.bz2 | tar xf - || exit 1
129 cd glib-$GLIB_VERSION
130 #
131 # OS X ships with libffi, but doesn't provide its pkg-config file;
132 # explicitly specify LIBFFI_CFLAGS and LIBFFI_LIBS, so the configure
133 # script doesn't try to use pkg-config to get the appropriate
134 # CFLAGS and LIBS.
135 #
136 LIBFFI_CFLAGS="-I/usr/include/ffi" LIBFFI_LIBS="-L/usr/lib" ./configure || exit 1
137 #
138 # Mac OS X on 64-bit platforms provides libiconv, but in a form that
139 # confuses GLib.
140 #
141 patch -p1 < ../../macosx-support-lib-patches/glib-gconvert.patch || exit 1
142 make -j 3 || exit 1
143 # Apply patch: we depend on libffi, but pkg-config doesn't get told.
144 patch -p0 <../../macosx-support-lib-patches/glib-pkgconfig.patch || exit 1
145 $DO_MAKE_INSTALL || exit 1
146 cd ..
147
148 echo "Downloading, building, and installing pkg-config:"
149 curl -O http://pkgconfig.freedesktop.org/releases/pkg-config-$PKG_CONFIG_VERSION.tar.gz || exit 1
150 tar xf pkg-config-$PKG_CONFIG_VERSION.tar.gz || exit 1
151 cd pkg-config-$PKG_CONFIG_VERSION
152 # Avoid another pkgconfig call
153 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
154 # ./configure || exit 1
155 make -j 3 || exit 1
156 $DO_MAKE_INSTALL || exit 1
157 cd ..
158
159 #
160 # Now we have reached a point where we can build everything but
161 # the GUI (Wireshark).
162 #
163
164 #
165 # Cairo is part of Mac OS X 10.6 (and, I think, 10.5).
166 # However, it's an X11 library; if we build with "native" GTK+ rather
167 # than X11 GTK+, we might have to build and install Cairo.
168 #
169 # echo "Downloading, building, and installing Cairo:"
170 # curl -O http://cairographics.org/releases/cairo-1.10.2.tar.gz || exit 1
171 # tar xvfz cairo-1.10.2.tar.gz || exit 1
172 # cd cairo-1.10.2
173 # ./configure --enable-quartz=no || exit 1
174 # make -j 3 || exit 1
175 # $DO_MAKE_INSTALL || exit 1
176 # cd ..
177
178 echo "Downloading, building, and installing ATK:"
179 atk_dir=`expr $ATK_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
180 curl -O http://ftp.gnome.org/pub/gnome/sources/atk/$atk_dir/atk-$ATK_VERSION.tar.bz2 || exit 1
181 bzcat atk-$ATK_VERSION.tar.bz2 | tar xf - || exit 1
182 cd atk-$ATK_VERSION
183 ./configure || exit 1
184 make -j 3 || exit 1
185 $DO_MAKE_INSTALL || exit 1
186 cd ..
187
188 echo "Downloading, building, and installing Pango:"
189 pango_dir=`expr $PANGO_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
190 curl -L -O http://ftp.gnome.org/pub/gnome/sources/pango/$pango_dir/pango-$PANGO_VERSION.tar.bz2
191 bzcat pango-$PANGO_VERSION.tar.bz2 | tar xf - || exit 1
192 cd pango-$PANGO_VERSION
193 ./configure || exit 1
194 make -j 3 || exit 1
195 $DO_MAKE_INSTALL || exit 1
196 cd ..
197
198 echo "Downloading, building, and installing gdk-pixbuf:"
199 gdk_pixbuf_dir=`expr $GDK_PIXBUF_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
200 curl -L -O http://ftp.gnome.org/pub/gnome/sources/gdk-pixbuf/$gdk_pixbuf_dir/gdk-pixbuf-$GDK_PIXBUF_VERSION.tar.bz2 || exit 1
201 bzcat gdk-pixbuf-$GDK_PIXBUF_VERSION.tar.bz2 | tar xf - || exit 1
202 cd gdk-pixbuf-$GDK_PIXBUF_VERSION
203 ./configure --without-libtiff --without-libjpeg || exit 1
204 make -j 3 || exit 1
205 $DO_MAKE_INSTALL || exit 1
206 cd ..
207
208 echo "Downloading, building, and installing GTK+:"
209 gtk_dir=`expr $GTK_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
210 curl -L -O http://ftp.gnome.org/pub/gnome/sources/gtk+/$gtk_dir/gtk+-$GTK_VERSION.tar.bz2
211 bzcat gtk+-$GTK_VERSION.tar.bz2 | tar xf - || exit 1
212 cd gtk+-$GTK_VERSION
213 ./configure || exit 1
214 make -j 3 || exit 1
215 $DO_MAKE_INSTALL || exit 1
216 cd ..
217
218 #
219 # Now we have reached a point where we can build everything including
220 # the GUI (Wireshark), but not with any optional features such as
221 # SNMP OID resolution, some forms of decryption, Lua scripting, playback
222 # of audio, or GeoIP mapping of IP addresses.
223 #
224 # We now conditionally download optional libraries to support them;
225 # the default is to download them all.
226 #
227
228 if [ ! -z $LIBSMI_VERSION ]
229 then
230         echo "Downloading, building, and installing libsmi:"
231         curl -L -O ftp://ftp.ibr.cs.tu-bs.de/pub/local/libsmi/libsmi-$LIBSMI_VERSION.tar.gz || exit 1
232         tar xf libsmi-$LIBSMI_VERSION.tar.gz || exit 1
233         cd libsmi-$LIBSMI_VERSION
234         ./configure || exit 1
235         make -j 3 || exit 1
236         $DO_MAKE_INSTALL || exit 1
237         cd ..
238 fi
239
240 if [ ! -z $LIBGPG_ERROR_VERSION ]
241 then
242         echo "Downloading, building, and installing libgpg-error:"
243         curl -L -O ftp://ftp.gnupg.org/gcrypt/libgpg-error/libgpg-error-$LIBGPG_ERROR_VERSION.tar.bz2 || exit 1
244         bzcat libgpg-error-$LIBGPG_ERROR_VERSION.tar.bz2 | tar xf - || exit 1
245         cd libgpg-error-$LIBGPG_ERROR_VERSION
246         ./configure || exit 1
247         make -j 3 || exit 1
248         $DO_MAKE_INSTALL || exit 1
249         cd ..
250 fi
251
252 if [ ! -z $LIBGCRYPT_VERSION ]
253 then
254         #
255         # libgpg-error is required for libgcrypt.
256         #
257         if [ -z $LIBGPG_ERROR_VERSION ]
258         then
259                 echo "libgcrypt requires libgpg-error, but you didn't install libgpg-error." 1>&2
260                 exit 1
261         fi
262
263         echo "Downloading, building, and installing libgcrypt:"
264         curl -L -O ftp://ftp.gnupg.org/gcrypt/libgcrypt/libgcrypt-$LIBGCRYPT_VERSION.tar.gz || exit 1
265         tar xf libgcrypt-$LIBGCRYPT_VERSION.tar.gz || exit 1
266         cd libgcrypt-$LIBGCRYPT_VERSION
267         #
268         # The assembler language code is not compatible with the OS X
269         # x86 assembler (or is it an x86-64 vs. x86-32 issue?).
270         #
271         ./configure --disable-asm || exit 1
272         make -j 3 || exit 1
273         $DO_MAKE_INSTALL || exit 1
274         cd ..
275 fi
276
277 if [ ! -z $GNUTLS_VERSION ]
278 then
279         #
280         # GnuTLS requires libgcrypt (or nettle, in newer versions).
281         #
282         if [ -z $LIBGCRYPT_VERSION ]
283         then
284                 echo "GnuTLS requires libgcrypt, but you didn't install libgcrypt" 1>&2
285                 exit 1
286         fi
287
288         echo "Downloading, building, and installing GnuTLS:"
289         curl -L -O http://ftp.gnu.org/gnu/gnutls/gnutls-$GNUTLS_VERSION.tar.bz2 || exit 1
290         bzcat gnutls-$GNUTLS_VERSION.tar.bz2 | tar xf - || exit 1
291         cd gnutls-$GNUTLS_VERSION
292         #
293         # Use libgcrypt, not nettle.
294         # XXX - is there some reason to prefer nettle?  Or does
295         # Wireshark directly use libgcrypt routines?
296         #
297         ./configure --with-libgcrypt || exit 1
298         make -j 3 || exit 1
299         #
300         # The pkgconfig file for GnuTLS says "requires zlib", but OS X,
301         # while it supplies zlib, doesn't supply a pkgconfig file for
302         # it.
303         #
304         # Patch the GnuTLS pkgconfig file not to require zlib.
305         # (If the capabilities of GnuTLS that Wireshark uses don't
306         # depend on building GnuTLS with zlib, an alternative would be
307         # to configure it not to use zlib.)
308         #
309         patch -p0 lib/gnutls.pc <../../macosx-support-lib-patches/gnutls-pkgconfig.patch || exit 1
310         $DO_MAKE_INSTALL || exit 1
311         cd ..
312 fi
313
314 if [ ! -z $LUA_VERSION ]
315 then
316         echo "Downloading, building, and installing Lua:"
317         curl -L -O http://www.lua.org/ftp/lua-$LUA_VERSION.tar.gz || exit 1
318         tar xf lua-$LUA_VERSION.tar.gz || exit 1
319         cd lua-$LUA_VERSION
320         make -j 3 macosx || exit 1
321         $DO_MAKE_INSTALL || exit 1
322         cd ..
323 fi
324
325 if [ ! -z $PORTAUDIO_VERSION ]
326 then
327         echo "Downloading, building, and installing PortAudio:"
328         curl -L -O http://www.portaudio.com/archives/$PORTAUDIO_VERSION.tgz || exit 1
329         tar xf $PORTAUDIO_VERSION.tgz || exit 1
330         cd portaudio
331         ./configure || exit 1
332         make -j 3 || exit 1
333         $DO_MAKE_INSTALL || exit 1
334         cd ..
335 fi
336
337 if [ ! -z $GEOIP_VERSION ]
338 then
339         echo "Downloading, building, and installing GeoIP API:"
340         curl -L -O http://geolite.maxmind.com/download/geoip/api/c/GeoIP-$GEOIP_VERSION.tar.gz || exit 1
341         tar xf GeoIP-$GEOIP_VERSION.tar.gz || exit 1
342         cd GeoIP-$GEOIP_VERSION
343         ./configure || exit 1
344         make -j 3 || exit 1
345         $DO_MAKE_INSTALL || exit 1
346         cd ..
347 fi
348
349 echo ""
350
351 echo "You are now prepared to build Wireshark. To do so do:"
352 echo "./autogen.sh"
353 echo "./configure"
354 echo "make -j 3"
355 echo "make install"
356
357 echo ""
358
359 echo "Make sure you are allowed capture access to the network devices"
360 echo "See: http://wiki.wireshark.org/CaptureSetup/CapturePrivileges"
361
362 echo ""
363
364 exit 0