6 # osx-app [-s] [-l /path/to/libraries] -bp /path/to/wireshark/bin -p /path/to/Info.plist
8 # This script attempts to build an Wireshark.app package for OS X, resolving
9 # dynamic libraries, etc.
10 # It strips the executable and libraries if '-s' is given.
11 # It adds python modules if the '-py option' is given
12 # The Info.plist file can be found in the base wireshark directory once
13 # configure has been run.
16 # Kees Cook <kees@outflux.net>
17 # Michael Wybrow <mjwybrow@users.sourceforge.net>
18 # Jean-Olivier Irisson <jo.irisson@gmail.com>
20 # Copyright (C) 2005 Kees Cook
21 # Copyright (C) 2005-2007 Michael Wybrow
22 # Copyright (C) 2007 Jean-Olivier Irisson
24 # Released under GNU GPL, read the file 'COPYING' for more information
26 # Thanks to GNUnet's "build_app" script for help with library dep resolution.
27 # https://gnunet.org/svn/GNUnet/contrib/OSX/build_app
30 # When packaging Wireshark for OS X, configure should be run with the
31 # "--enable-osxapp" option which sets the correct paths for support
32 # files inside the app bundle.
37 binary_path="/tmp/inst/bin"
39 util_dir="./Utilities"
40 cli_dir="$util_dir/Command Line"
41 startup_dir="$util_dir/Startup"
57 # Location for libraries (MacPorts defaults to /opt/local)
58 if [ -z $LIBPREFIX ]; then
59 LIBPREFIX="/opt/local"
64 #----------------------------------------------------------
68 Create an app bundle for OS X
71 $0 [-s] [-l /path/to/libraries] -bp /path/to/wireshark/binaries -p /path/to/Info.plist
75 display this help message
77 strip the libraries and executables from debugging symbols
79 specify the path to the librairies Wireshark depends on
80 (typically /sw or /opt/local)
82 specify the path to the Wireshark binaries. By default it
85 specify the path to Info.plist. Info.plist can be found
86 in the base directory of the source code once configure
90 $0 -s -l /opt/local -bp ../../Build/bin -p Info.plist
95 # Parse command line arguments
96 #----------------------------------------------------------
115 echo "Invalid command line option: $1"
121 echo -e "\nCREATE WIRESHARK APP BUNDLE\n"
124 if [ ! -e "$LIBPREFIX" ]; then
125 echo "Cannot find the directory containing the libraires: $LIBPREFIX" >&2
129 for binary in wireshark $binary_list ; do
130 if [ ! -x "$binary_path/$binary" ]; then
131 echo "Couldn't find $binary (or it's not executable)" >&2
136 if [ ! -f "$plist" ]; then
137 echo "Need plist file" >&2
142 # Handle some version specific details.
143 VERSION=`/usr/bin/sw_vers | grep ProductVersion | cut -f2 -d'.'`
144 if [ "$VERSION" -ge "4" ]; then
145 # We're on Tiger (10.4) or later.
146 # XCode behaves a little differently in Tiger and later.
147 XCODEFLAGS="-configuration Deployment"
148 SCRIPTEXECDIR="ScriptExec/build/Deployment/ScriptExec.app/Contents/MacOS"
151 # Panther (10.3) or earlier.
152 XCODEFLAGS="-buildstyle Deployment"
153 SCRIPTEXECDIR="ScriptExec/build/ScriptExec.app/Contents/MacOS"
158 # Package always has the same name. Version information is stored in
159 # the Info.plist file which is filled in by the configure script.
160 package="Wireshark.app"
162 # Remove a previously existing package if necessary
163 if [ -d $package ]; then
164 echo "Removing previous Wireshark.app"
168 # Remove a previously existing utility directory if necessary
169 if [ -d "$util_dir" ]; then
170 echo "Removing $util_dir directory"
174 # Set the 'macosx' directory, usually the current directory.
179 #----------------------------------------------------------
180 pkgexec="$package/Contents/MacOS"
181 pkgres="$package/Contents/Resources"
184 pkgplugin="$pkglib/wireshark/plugins"
188 mkdir -p "$pkgplugin"
191 mkdir -p "$startup_dir"
193 # Build and add the launcher
194 #----------------------------------------------------------
196 # Build fails if CC happens to be set (to anything other than CompileC)
199 cd "$resdir/ScriptExec"
200 echo -e "Building launcher...\n"
201 xcodebuild $XCODEFLAGS clean build
203 cp "$resdir/$SCRIPTEXECDIR/ScriptExec" "$pkgexec/Wireshark"
206 # Copy all files into the bundle
207 #----------------------------------------------------------
208 echo -e "\nFilling app bundle and utility directory...\n"
210 # Wireshark executables
211 for binary in $binary_list ; do
212 # Copy the binary to its destination
213 dest_path="$pkgbin/$binary-bin"
214 cp -v "$binary_path/$binary" "$dest_path"
215 # TODO Add a "$verbose" variable and command line switch, which sets wether these commands are verbose or not
219 cp -v utility-launcher "$cli_dir/$binary"
222 ln -sv ./wireshark "$pkgbin/$binary"
223 ln -sv ./wireshark "$cli_dir/$binary"
229 cp -v ChmodBPF/* "$startup_dir"
231 # The rest of the Wireshark installation (we handled bin above)
234 --exclude lib/wireshark/plugins/ \
235 "$binary_path/.."/* "$pkgres"
237 # Remove the version number from the plugin path
238 find "$binary_path/../lib/wireshark/plugins" -type f \
239 -exec cp -fv "{}" "$pkgplugin/" \;
241 cp "$plist" "$package/Contents/Info.plist"
243 # Icons and the rest of the script framework
244 rsync -av --exclude ".svn" "$resdir"/Resources/* "$package"/Contents/Resources/
246 # PkgInfo must match bundle type and creator code from Info.plist
247 echo "APPLWshk" > $package/Contents/PkgInfo
249 # Pull in extra requirements for Pango and GTK
250 pkgetc="$package/Contents/Resources/etc"
251 mkdir -p $pkgetc/pango
252 cp $LIBPREFIX/etc/pango/pangox.aliases $pkgetc/pango/
253 # Need to adjust path and quote in case of spaces in path.
254 sed -e "s,$LIBPREFIX,\"\${CWD},g" -e 's,\.so ,.so" ,g' $LIBPREFIX/etc/pango/pango.modules > $pkgetc/pango/pango.modules
255 cat > $pkgetc/pango/pangorc <<END_PANGO
257 ModuleFiles=\${HOME}/.wireshark-etc/pango.modules
259 AliasFiles=\${HOME}/.wireshark-etc/pangox.aliases
262 # We use a modified fonts.conf file so only need the dtd
263 mkdir -p $pkgetc/fonts
264 cp $LIBPREFIX/etc/fonts/fonts.dtd $pkgetc/fonts/
265 cp -r $LIBPREFIX/etc/fonts/conf.avail $pkgetc/fonts/
266 cp -r $LIBPREFIX/etc/fonts/conf.d $pkgetc/fonts/
268 mkdir -p $pkgetc/gtk-2.0
269 sed -e "s,$LIBPREFIX,\${CWD},g" $LIBPREFIX/etc/gtk-2.0/gdk-pixbuf.loaders > $pkgetc/gtk-2.0/gdk-pixbuf.loaders
270 sed -e "s,$LIBPREFIX,\${CWD},g" $LIBPREFIX/etc/gtk-2.0/gtk.immodules > $pkgetc/gtk-2.0/gtk.immodules
272 for item in gnome-vfs-mime-magic gnome-vfs-2.0
274 cp -r $LIBPREFIX/etc/$item $pkgetc/
277 pango_version=`pkg-config --variable=pango_module_version pango`
278 mkdir -p $pkglib/pango/$pango_version/modules
279 cp $LIBPREFIX/lib/pango/$pango_version/modules/*.so $pkglib/pango/$pango_version/modules/
281 gtk_version=`pkg-config --variable=gtk_binary_version gtk+-2.0`
282 mkdir -p $pkglib/gtk-2.0/$gtk_version/{engines,immodules,loaders}
283 cp -r $LIBPREFIX/lib/gtk-2.0/$gtk_version/* $pkglib/gtk-2.0/$gtk_version/
285 mkdir -p $pkglib/gnome-vfs-2.0/modules
286 cp $LIBPREFIX/lib/gnome-vfs-2.0/modules/*.so $pkglib/gnome-vfs-2.0/modules/
288 # Find out libs we need from fink, darwinports, or from a custom install
289 # (i.e. $LIBPREFIX), then loop until no changes.
293 lib_dep_search_list="
294 $pkglib/gtk-2.0/$gtk_version/loaders/*
295 $pkglib/gtk-2.0/$gtk_version/immodules/*
296 $pkglib/gtk-2.0/$gtk_version/engines/*.so
297 $pkglib/pango/$pango_version/modules/*
298 $pkglib/gnome-vfs-2.0/modules/*
299 $package/Contents/Resources/lib/*
303 echo -e "Looking for dependencies. Round" $a
304 libs="`otool -L $lib_dep_search_list 2>/dev/null | fgrep compatibility | cut -d\( -f1 | grep $LIBPREFIX | sort | uniq`"
305 cp -f $libs "$pkglib"
307 nnfiles=`ls "$pkglib" | wc -l`
308 if [ $nnfiles = $nfiles ]; then
315 # Add extra libraries of necessary
316 for libfile in $EXTRALIBS
318 cp -f $libfile "$pkglib"
321 # Strip libraries and executables if requested
322 #----------------------------------------------------------
323 if [ "$strip" = "true" ]; then
324 echo -e "\nStripping debugging symbols...\n"
325 chmod +w "$pkglib"/*.dylib
326 strip -x "$pkglib"/*.dylib
330 # NOTE: This works for all the dylibs but causes GTK to crash at startup.
331 # Instead we leave them with their original install_names and set
332 # DYLD_LIBRARY_PATH within the app bundle before running Wireshark.
335 # # Fix a given executable or library to be relocatable
336 # if [ ! -d "$1" ]; then
338 # libs="`otool -L $1 | fgrep compatibility | cut -d\( -f1`"
339 # for lib in $libs; do
341 # base=`echo $lib | awk -F/ '{print $NF}'`
342 # first=`echo $lib | cut -d/ -f1-3`
343 # to=@executable_path/../lib/$base
344 # if [ $first != /usr/lib -a $first != /usr/X11R6 ]; then
345 # /usr/bin/install_name_tool -change $lib $to $1
346 # if [ "`echo $lib | fgrep libcrypto`" = "" ]; then
347 # /usr/bin/install_name_tool -id $to ../lib/$base
348 # for ll in $libs; do
349 # base=`echo $ll | awk -F/ '{print $NF}'`
350 # first=`echo $ll | cut -d/ -f1-3`
351 # to=@executable_path/../lib/$base
352 # if [ $first != /usr/lib -a $first != /usr/X11R6 -a "`echo $ll | fgrep libcrypto`" = "" ]; then
353 # /usr/bin/install_name_tool -change $ll $to ../lib/$base
363 #(cd "$package/Contents/MacOS/bin"