Skinny: fix dissector registration for SSL
[metze/wireshark/wip.git] / packaging / macosx / osx-app.sh
1 #!/bin/bash
2 #
3 # USAGE
4 # osx-app [-s] [-l /path/to/libraries] -bp /path/to/wireshark/bin -p /path/to/Info.plist
5 #
6 # This script attempts to build an Wireshark.app bundle for OS X, resolving
7 # dynamic libraries, etc.
8 # It strips the executable and libraries if '-s' is given.
9 # The Info.plist file can be found in the base wireshark directory once
10 # configure has been run.
11 #
12 # AUTHORS
13 #                Kees Cook <kees@outflux.net>
14 #                Michael Wybrow <mjwybrow@users.sourceforge.net>
15 #                Jean-Olivier Irisson <jo.irisson@gmail.com>
16 #
17 # Copyright (C) 2005 Kees Cook
18 # Copyright (C) 2005-2007 Michael Wybrow
19 # Copyright (C) 2007 Jean-Olivier Irisson
20 #
21 # Released under GNU GPL, read the file 'COPYING' for more information
22 #
23 # Thanks to GNUnet's "build_app" script for help with library dep resolution.
24 #               https://gnunet.org/svn/GNUnet/contrib/OSX/build_app
25 #
26 # NB:
27 # This originally came from Inkscape; Inkscape's configure script has an
28 # "--enable-osxapp", which causes some of Inkscape's installation data
29 # files to have OS X-ish paths under Contents/Resources of the bundle
30 # or under /Library/Application Support.  We don't have such an option;
31 # we just put them in "bin", "etc", "lib", and "share" directories
32 # under Contents/Resources, rather than in the "bin", "etc", "lib",
33 # and "share" directories under the installation directory.
34 #
35
36 # Defaults
37 strip=false
38 binary_path="/tmp/inst/bin"
39 plist="./Info.plist"
40 exclude_prefixes="/System/|/Library/|/usr/lib/|/usr/X11/|/opt/X11/|@rpath|@executable_path"
41 create_bundle=false
42
43 # Bundle always has the same name. Version information is stored in
44 # the Info.plist file which is filled in by the configure script.
45 bundle="Wireshark.app"
46
47 # "qt" or "gtk"
48 ui_toolkit="qt"
49 # Name of the Wireshark executable
50 wireshark_bin_name="wireshark"
51
52 binary_list="
53         capinfos
54         dftest
55         dumpcap
56         editcap
57         mergecap
58         randpkt
59         rawshark
60         text2pcap
61         tshark
62         extcap/androiddump
63 "
64 cs_binary_list=
65
66 # Location for libraries (macosx-setup.sh defaults to whatever the
67 # various support libraries use as their standard installation location,
68 # which is /usr/local)
69 if [ -z $LIBPREFIX ]; then
70         LIBPREFIX="/usr/local"
71 fi
72
73
74 # Help message
75 #----------------------------------------------------------
76 help()
77 {
78 echo -e "
79 Create an app bundle for OS X
80
81 USAGE
82         $0 [-s] [-l /path/to/libraries] [-qt] -bp /path/to/wireshark/binaries -p /path/to/Info.plist
83
84 OPTIONS
85         -h,--help
86                 Display this help message.
87         -s
88                 Strip the libraries and executables from debugging symbols.
89         -l,--libraries
90                 Specify the path to the libraries Wireshark depends on
91                 (typically /sw or /opt/local). By default it is
92                 /usr/local.
93         -cb,--create-bundle
94                 Create the application bundle (Wireshark.app). This flag
95                 should be supplied when building using Autotools. It
96                 should not be specified when building using CMake.
97         -bp,--binary-path
98                 Specify the path to the Wireshark binaries. By default it
99                 is /tmp/inst/bin.
100         -p,--plist
101                 Specify the path to Info.plist. Info.plist can be found
102                 in the base directory of the source code once configure
103                 has been run.
104         -sdkroot
105                 Specify the root of the SDK to use.
106         -qt,--qt-flavor
107                 Use the Qt flavor. This is the default.
108         -gtk,--gtk-flavor
109                 Use the GTK+ flavor.
110
111 EXAMPLE
112         $0 -s -l /opt/local -bp ../../Build/bin -p Info.plist -sdkroot /Developer/SDKs/MacOSX10.5.sdk
113 "
114 }
115
116
117 # Parse command line arguments
118 #----------------------------------------------------------
119 while [ "$1" != "" ]
120 do
121         case $1 in
122                 -s)
123                         strip=true ;;
124                 -l|--libraries)
125                         LIBPREFIX="$2"
126                         shift 1 ;;
127                 -bp|--binary-path)
128                         binary_path="$2"
129                         shift 1 ;;
130                 -cb|--create-bundle)
131                         create_bundle=true;;
132                 -p|--plist)
133                         plist="$2"
134                         shift 1 ;;
135                 -qt|--qt-flavor)
136                         ui_toolkit="qt"
137                         wireshark_bin_name="wireshark"
138                         ;;
139                 -gtk|--gtk-flavor)
140                         ui_toolkit="gtk"
141                         wireshark_bin_name="wireshark-gtk"
142                         ;;
143                 -h|--help)
144                         help
145                         exit 0 ;;
146                 -sdkroot)
147                         sdkroot="$2"
148                         shift 1 ;;
149                 *)
150                         echo "Invalid command line option: $1"
151                         exit 2 ;;
152         esac
153         shift 1
154 done
155
156 # Safety tests
157 if [ ! -e "$LIBPREFIX" ]; then
158         echo "Cannot find the directory containing the libraries: $LIBPREFIX" >&2
159         exit 1
160 fi
161
162 if [ "$create_bundle" = "true" ]; then
163         echo -e "\nCREATE WIRESHARK APP BUNDLE\n"
164
165         for binary in $wireshark_bin_name $binary_list ; do
166                 binary=$( basename $binary )
167                 if [ ! -x "$binary_path/$binary" ]; then
168                         echo "Couldn't find $binary (or it's not executable)" >&2
169                         exit 1
170                 fi
171         done
172
173         if [ ! -f "$plist" ]; then
174                 echo "Need plist file" >&2
175                 exit 1
176         fi
177 elif [ ! -d "$bundle" ] ; then
178         echo "$bundle not found" >&2
179         exit 1
180 fi
181
182 if [ "$ui_toolkit" = "qt" ] ; then
183         for i in 5 ""
184         do
185                 qt_frameworks_dir=`pkg-config --libs Qt${i}Core | sed -e 's/-F//' -e 's/ -framework.*//'`
186                 if [ ! -z "$qt_frameworks_dir" ] ; then
187                         # found it
188                         break;
189                 fi
190         done
191         if [ -z "$qt_frameworks_dir" ] ; then
192                 echo "Can't find the Qt frameworks directory" >&2
193                 exit 1
194         fi
195
196         #
197         # Leave the Qt frameworks out of the special processing.
198         #
199         exclude_prefixes="$exclude_prefixes|$qt_frameworks_dir"
200 fi
201
202 # Package paths
203 pkgexec="$bundle/Contents/MacOS"
204 pkgres="$bundle/Contents/Resources"
205 pkgbin="$pkgexec"
206 pkglib="$bundle/Contents/Frameworks"
207 pkgplugin="$bundle/Contents/PlugIns/wireshark"
208
209 # Set the 'macosx' directory, usually the current directory.
210 resdir=`pwd`
211
212 # Create the application bundle.
213 # This is only used by Autotools. This can be removed if we start using
214 # CMake exclusively.
215 create_bundle() {
216         # Handle some version specific details.
217         VERSION=`/usr/bin/sw_vers | grep ProductVersion | cut -f2 -d'.'`
218         if [ "$VERSION" -ge "4" ]; then
219                 # We're on Tiger (10.4) or later.
220                 # XCode behaves a little differently in Tiger and later.
221                 XCODEFLAGS="-configuration Deployment"
222                 SCRIPTEXECDIR="ScriptExec/build/Deployment/ScriptExec.app/Contents/MacOS"
223                 EXTRALIBS=""
224         else
225                 # Panther (10.3) or earlier.
226                 XCODEFLAGS="-buildstyle Deployment"
227                 SCRIPTEXECDIR="ScriptExec/build/ScriptExec.app/Contents/MacOS"
228                 EXTRALIBS=""
229         fi
230
231         # Set the SDK root, if an SDK was specified.
232         # (-sdk is only supported by the xcodebuild in the version of the
233         # developer tools that came with Snow Leopard and later versions)
234         if [ ! -z "$sdkroot" ]
235         then
236                 XCODEFLAGS="$XCODEFLAGS SDKROOT=$sdkroot"
237         fi
238
239         # Remove a previously existing bundle if necessary
240         if [ -d $bundle ]; then
241                 echo "Removing previous $bundle"
242                 rm -Rf $bundle
243         fi
244
245         # Remove a previously existing utility directory if necessary
246         if [ -d "$util_dir" ]; then
247                 echo "Removing $util_dir directory"
248                 rm -Rf "$util_dir"
249         fi
250
251         # Prepare Package
252         #----------------------------------------------------------
253
254         #
255         # For Qt, the Wireshark binary is the main binary of the app bundle.
256         # For GTK+, the Wireshark binary is wireshark-bin in
257         # Contents/Resources/bin, so some of the above setting have to change.
258         #
259         if [ "$ui_toolkit" = "gtk" ] ; then
260                 pkgbin="$pkgres/bin"
261                 pkglib="$pkgres/lib"
262         fi
263
264         mkdir -p "$pkgexec"
265         mkdir -p "$pkgexec/extcap"
266         mkdir -p "$pkgbin"
267         mkdir -p "$pkgplugin"
268
269         if [ "$ui_toolkit" = "qt" ] ; then
270                 cp -v "$binary_path/$wireshark_bin_name" "$pkgexec/Wireshark"
271         else
272         # Build and add the launcher
273         #----------------------------------------------------------
274                 (
275                         # Build fails if CC happens to be set (to anything other than CompileC)
276                         unset CC
277
278                         cd "$resdir/ScriptExec"
279                         echo -e "Building launcher...\n"
280                         xcodebuild $XCODEFLAGS clean build
281                 )
282                 cp "$resdir/$SCRIPTEXECDIR/ScriptExec" "$pkgexec/Wireshark"
283
284         fi
285
286         # Copy all files into the bundle
287         #----------------------------------------------------------
288         echo -e "\nFilling app bundle and utility directory...\n"
289
290         # Wireshark executables
291         if [ "$ui_toolkit" = "gtk" ] ; then
292                 for binary in $binary_list wireshark ; do
293                         # Copy the binary to its destination
294                         dest_path="$pkgbin/$binary-bin"
295                         cs_binary_list="$cs_binary_list $dest_path"
296                         cp -v "$binary_path/$binary" "$dest_path"
297                         # TODO Add a "$verbose" variable and command line switch, which sets wether these commands are verbose or not
298
299                         if [ "$binary" != "wireshark" ] ; then
300                                 ln -sv ./wireshark "$pkgbin/$binary"
301                         fi
302                 done
303         elif [ "$ui_toolkit" = "qt" ] ; then
304                 for binary in $binary_list ; do
305                         bin_dest="$pkgexec"
306                         if [ "$( dirname $binary )" == "extcap" ] ; then
307                                 binary=$( basename $binary )
308                                 bin_dest="$pkgexec/$( dirname $binary )"
309                         fi
310
311                         # Copy the binary to its destination
312                         cp -v "$binary_path/$binary" "$bin_dest"
313                         cs_binary_list="$cs_binary_list $bin_dest/$binary"
314                 done
315         fi
316
317         # The rest of the Wireshark installation (we handled bin above)
318         rsync -av \
319                 --exclude bin/ \
320                 --exclude lib/ \
321                 "$binary_path/.."/* "$pkgres"
322
323         rsync -av $binary_path/../lib/*.dylib "$pkglib/"
324
325         # Copy the plugins from the "make install" location for them
326         # to the plugin directory, removing the version number
327         find "$binary_path/../lib/wireshark/plugins" \
328                 -type f \
329                 \( -name "*.so" -o -name "*.dylib" \) \
330                 -exec cp -fv "{}" "$pkgplugin/" \;
331
332         cp "$plist" "$bundle/Contents/Info.plist"
333
334         # Icons and the rest of the script framework
335         res_list="
336                 Wireshark.icns
337                 Wiresharkdoc.icns
338         "
339
340         if [ "$ui_toolkit" = "gtk" ] ; then
341                 res_list="
342                         $res_list
343                         bin
344                         etc
345                         openDoc
346                         script
347                         MenuBar.nib
348                         ProgressWindow.nib
349                         themes
350                 "
351         fi
352
353         for rl_entry in $res_list ; do
354                 rsync -av "$resdir"/Resources/$rl_entry "$bundle"/Contents/Resources/
355         done
356
357         # PkgInfo must match bundle type and creator code from Info.plist
358         echo "APPLWshk" > $bundle/Contents/PkgInfo
359
360         if [ "$ui_toolkit" = "gtk" ] ; then
361                 echo -e "\nPulling in GTK+ libraries and resources...\n"
362
363                 # Pull in extra requirements for Pango and GTK
364                 pkgetc="$bundle/Contents/Resources/etc"
365                 mkdir -p $pkgetc/pango
366                 cp $LIBPREFIX/etc/pango/pangox.aliases $pkgetc/pango/
367                 # Need to adjust path and quote in case of spaces in path.
368                 sed -e "s,$LIBPREFIX,\"\${CWD},g" -e 's,\.so ,.so" ,g' $LIBPREFIX/etc/pango/pango.modules > $pkgetc/pango/pango.modules
369                 cat > $pkgetc/pango/pangorc <<END_PANGO
370 [Pango]
371 ModuleFiles=\${HOME}/.wireshark-etc/pango.modules
372 [PangoX]
373 AliasFiles=\${HOME}/.wireshark-etc/pangox.aliases
374 END_PANGO
375
376                 # We use a modified fonts.conf file so only need the dtd
377                 mkdir -p $pkgetc/fonts
378                 cp $LIBPREFIX/etc/fonts/fonts.dtd $pkgetc/fonts/
379                 cp -r $LIBPREFIX/etc/fonts/conf.avail $pkgetc/fonts/
380                 cp -r $LIBPREFIX/etc/fonts/conf.d $pkgetc/fonts/
381
382                 mkdir -p $pkgetc/gtk-2.0
383                 #
384                 # In newer versions of GTK+, the gdk-pixbuf library was split off from
385                 # GTK+, and the gdk-pixbuf.loaders file moved, so we check for its
386                 # existence here.
387                 #
388                 # The file is ultimately copied to the user's home directory, with
389                 # the pathnames adjusted to refer to the installed bundle, so we
390                 # always put it in the same location in the installed bundle,
391                 # regardless of where it lives in the machine on which it's built.
392                 #
393                 if [ -e $LIBPREFIX/etc/gtk-2.0/gdk-pixbuf.loaders ]
394                 then
395                         sed -e "s,$LIBPREFIX,\${CWD},g" $LIBPREFIX/etc/gtk-2.0/gdk-pixbuf.loaders > $pkgetc/gtk-2.0/gdk-pixbuf.loaders
396                 fi
397                 sed -e "s,$LIBPREFIX,\${CWD},g" $LIBPREFIX/etc/gtk-2.0/gtk.immodules > $pkgetc/gtk-2.0/gtk.immodules
398
399                 pango_version=`pkg-config --variable=pango_module_version pango`
400                 mkdir -p $pkglib/pango/$pango_version/modules
401                 cp $LIBPREFIX/lib/pango/$pango_version/modules/*.so $pkglib/pango/$pango_version/modules/
402
403                 gtk_version=`pkg-config --variable=gtk_binary_version gtk+-2.0`
404                 mkdir -p $pkglib/gtk-2.0/$gtk_version/{engines,immodules,loaders}
405                 cp -r $LIBPREFIX/lib/gtk-2.0/$gtk_version/* $pkglib/gtk-2.0/$gtk_version/
406
407                 gdk_pixbuf_version=`pkg-config --variable=gdk_pixbuf_binary_version gdk-pixbuf-2.0`
408                 if [ ! -z $gdk_pixbuf_version ]; then
409                         mkdir -p $pkglib/gdk-pixbuf-2.0/$gdk_pixbuf_version/loaders
410                         #
411                         # As per the above, check whether we have a loaders.cache file
412                         # in $LIBPREFIX/lib/gdk-pixbuf-2.0/$gdk_pixbuf_version, as
413                         # that's where the output of gdk-pixbuf-query-loaders gets
414                         # put if gdk-pixbuf and GTK+ are separated.
415                         #
416                         # The file is ultimately copied to the user's home directory,
417                         # with the pathnames adjusted to refer to the installed bundle,
418                         # so we always put it in the same location in the installed
419                         # bundle, regardless of where it lives in the machine on which
420                         # it's built.
421                         #
422                         if [ -e $LIBPREFIX/lib/gdk-pixbuf-2.0/$gdk_pixbuf_version/loaders.cache ]
423                         then
424                                 sed -e "s,$LIBPREFIX,\${CWD},g" $LIBPREFIX/lib/gdk-pixbuf-2.0/$gdk_pixbuf_version/loaders.cache > $pkgetc/gtk-2.0/gdk-pixbuf.loaders
425                         fi
426                         cp -r $LIBPREFIX/lib/gdk-pixbuf-2.0/$gdk_pixbuf_version/loaders/* $pkglib/gdk-pixbuf-2.0/$gdk_pixbuf_version/loaders
427                 fi
428         fi # GTK+ / Qt
429 } # create_bundle
430
431 if [ "$create_bundle" = "true" ]; then
432         create_bundle
433 fi
434
435 if [ -z "$cs_binary_list" ]; then
436         # Assumes Qt.
437         for binary in Wireshark $binary_list ; do
438                 cs_binary_list="$cs_binary_list $pkgexec/$binary"
439         done
440 fi
441
442
443 echo -e "\nFixing up $bundle...\n"
444
445 # Find out libs we need from Fink, MacPorts, or from a custom install
446 # (i.e. $LIBPREFIX), then loop until no changes.
447 a=1
448 nfiles=0
449 endl=true
450 lib_dep_search_list="
451         $pkglib/*
452         $pkgbin/*-bin
453         "
454 if [ "$ui_toolkit" = "gtk" ] ; then
455         lib_dep_search_list="
456                 $lib_dep_search_list
457                 $pkglib/gtk-2.0/$gtk_version/loaders/*
458                 $pkglib/gtk-2.0/$gtk_version/immodules/*
459                 $pkglib/gtk-2.0/$gtk_version/engines/*.so
460                 $pkglib/pango/$pango_version/modules/*
461                 $pkglib/gdk-pixbuf-2.0/$gdk_pixbuf_version/loaders/*
462                 "
463 elif [ "$ui_toolkit" = "qt" ] ; then
464         lib_dep_search_list="
465                 $pkgexec/Wireshark
466                 $lib_dep_search_list
467                 "
468 fi
469
470 while $endl; do
471         echo -e "Looking for dependencies. Round" $a
472         libs="`\
473                 otool -L $lib_dep_search_list 2>/dev/null \
474                 | fgrep compatibility \
475                 | cut -d\( -f1 \
476                 | egrep -v "$exclude_prefixes" \
477                 | sort \
478                 | uniq \
479                 `"
480         cp -vn $libs "$pkglib"
481         let "a+=1"
482         nnfiles=`ls "$pkglib" | wc -l`
483         if [ $nnfiles = $nfiles ]; then
484                 endl=false
485         else
486                 nfiles=$nnfiles
487         fi
488 done
489
490 # Add extra libraries of necessary
491 for libfile in $EXTRALIBS
492 do
493         cp -v -f $libfile "$pkglib"
494 done
495 chmod 755 "$pkglib"/*.dylib
496
497 # Strip libraries and executables if requested
498 #----------------------------------------------------------
499 if [ "$strip" = "true" ]; then
500         echo -e "\nStripping debugging symbols...\n"
501         strip -x "$pkglib"/*.dylib
502         strip -ur "$binpath"
503 fi
504
505 if [ "$ui_toolkit" = "qt" ] ; then
506         #
507         # This may not work on Qt 5.5.0 or 5.5.1:
508         # https://bugreports.qt.io/browse/QTBUG-47868
509         #
510         macdeployqt "$bundle" -verbose=2 || exit 1
511
512         #
513         # The build process added to the Wireshark binary an rpath entry
514         # pointing to the directory containing the Qt frameworks; remove
515         # that entry from the Wireshark binary in the package.
516         #
517         /usr/bin/install_name_tool -delete_rpath "$qt_frameworks_dir" $pkgbin/Wireshark
518 fi
519
520 # NOTE: we must rpathify *all* files, *including* plugins for GTK+ etc.,
521 #       to keep GTK+ from crashing at startup.
522 #
523 rpathify_file () {
524         # Fix a given executable, library, or plugin to be relocatable
525         if [ ! -f "$1" ]; then
526                 return 0;
527         fi
528
529         #
530         # OK, what type of file is this?
531         #
532         filetype=$( otool -hv "$1" | sed -n '4p' | awk '{print $5}' ; exit ${PIPESTATUS[0]} )
533         if [ $? -ne 0 ] ; then
534                 echo "Unable to rpathify $1 in $( pwd ): file type failed."
535                 exit 1
536         fi
537
538         case "$filetype" in
539
540         EXECUTE|DYLIB|BUNDLE)
541                 #
542                 # Executable, library, or plugin.  (Plugins
543                 # can be either DYLIB or BUNDLE; shared
544                 # libraries are DYLIB.)
545                 #
546                 # For DYLIB and BUNDLE, fix the shared
547                 # library identification.
548                 #
549                 if [[ "$filetype" = "DYLIB" || "$filetype" = "BUNDLE" ]]; then
550                         echo "Changing shared library identification of $1"
551                         base=`echo $1 | awk -F/ '{print $NF}'`
552                         #
553                         # The library will end up in a directory in
554                         # the rpath; this is what we should change its
555                         # ID to.
556                         #
557                         to=@rpath/$base
558                         /usr/bin/install_name_tool -id $to $1
559
560                         #
561                         # If we're a library and we depend on something in
562                         # @executable_path/../Frameworks, replace that with
563                         # @rpath.
564                         #
565                         otool -L $1 | grep @executable_path/../Frameworks | awk '{print $1}' | \
566                         while read dep_lib ; do
567                                 base=`echo $dep_lib | awk -F/ '{print $NF}'`
568                                 to="@rpath/$base"
569                                 echo "Changing reference to $dep_lib to $to in $1"
570                                 /usr/bin/install_name_tool -change $dep_lib $to $1
571                         done
572                 fi
573
574                 #
575                 # Find our local rpaths and remove them.
576                 #
577                 otool -l $1 | grep -A2 LC_RPATH \
578                         | awk '$1=="path" && $2 !~ /^@/ {print $2}' \
579                         | egrep -v "$exclude_prefixes" | \
580                 while read lc_rpath ; do
581                         echo "Stripping LC_RPATH $lc_rpath from $1"
582                         install_name_tool -delete_rpath $lc_rpath $1
583                 done
584
585                 #
586                 # Add -Wl,-rpath,@executable_path/../Frameworks
587                 # to the rpath, so it'll find the bundled
588                 # frameworks and libraries if they're referred
589                 # to by @rpath/, rather than having a wrapper
590                 # script tweak DYLD_LIBRARY_PATH.
591                 #
592                 if [[ "$filetype" = "EXECUTE" ]]; then
593                         if [ -d ../Frameworks ] ; then
594                                 framework_path=../Frameworks
595                         elif [ -d ../../Frameworks ] ; then
596                                 framework_path=../../Frameworks
597                         else
598                                 echo "Unable to find relative path to Frameworks for $1 from $( pwd )"
599                                 exit 1
600                         fi
601
602                         echo "Adding @executable_path/$framework_path to rpath of $1"
603                         /usr/bin/install_name_tool -add_rpath @executable_path/$framework_path $1
604                 fi
605
606                 #
607                 # Show the minimum supported version of Mac OS X
608                 # for each executable or library
609                 #
610                 if [[ "$filetype" = "EXECUTE" || "$filetype" = "DYLIB" ]] && [[ "$VERSION" -ge "7" ]] ; then
611                         echo "Minimum Mac OS X version for $1:"
612                         otool -l $1 | grep -A3 LC_VERSION_MIN_MACOSX
613                 fi
614
615                 #
616                 # Get the list of dynamic libraries on which this
617                 # file depends, and select only the libraries that
618                 # are in $LIBPREFIX, as those are the only ones
619                 # that we'll be shipping in the app bundle; the
620                 # other libraries are system-supplied or supplied
621                 # as part of X11, will be expected to be on the
622                 # system on which the bundle will be installed,
623                 # and should be referred to by their full pathnames.
624                 #
625                 libs="`\
626                         otool -L $1 \
627                         | fgrep compatibility \
628                         | cut -d\( -f1 \
629                         | egrep -v "$exclude_prefixes" \
630                         | sort \
631                         | uniq \
632                         `"
633
634                 for lib in $libs; do
635                         #
636                         # Get the file name of the library.
637                         #
638                         base=`echo $lib | awk -F/ '{print $NF}'`
639                         #
640                         # The library will end up in a directory in
641                         # the rpath; this is what we should change its
642                         # file name to.
643                         #
644                         to=@rpath/$base
645                         #
646                         # Change the reference to that library.
647                         #
648                         echo "Changing reference to $lib to $to in $1"
649                         /usr/bin/install_name_tool -change $lib $to $1
650                 done
651                 ;;
652         esac
653 }
654
655 rpathify_dir () {
656         #
657         # Make sure we *have* that directory
658         #
659         if [ -d "$1" ]; then
660                 (cd "$1"
661                 #
662                 # Make sure we *have* files to fix
663                 #
664                 files=`ls $2 2>/dev/null`
665                 if [ ! -z "$files" ]; then
666                         for file in $files; do
667                                 rpathify_file "$file" "`pwd`"
668                         done
669                 fi
670                 )
671                 rf_ret=$?
672                 if [ $rf_ret -ne 0 ] ; then exit $rf_ret ; fi
673         fi
674 }
675
676 rpathify_files () {
677         #
678         # Fix bundle deps
679         #
680         rpathify_dir "$pkglib" "*.dylib"
681         rpathify_dir "$pkgbin" "*"
682         rpathify_dir "$pkgplugin" "*"
683
684         if [ "$ui_toolkit" = "qt" ] ; then
685                 rpathify_dir "$pkgbin/extcap" "*"
686         fi
687
688         if [ "$ui_toolkit" = "gtk" ] ; then
689                 rpathify_dir "$pkglib/gtk-2.0/$gtk_version/loaders" "*.so"
690                 rpathify_dir "$pkglib/gtk-2.0/$gtk_version/engines" "*.so"
691                 rpathify_dir "$pkglib/gtk-2.0/$gtk_version/immodules" "*.so"
692                 rpathify_dir "$pkglib/gtk-2.0/$gtk_version/printbackends" "*.so"
693                 rpathify_dir "$pkglib/gnome-vfs-2.0/modules" "*.so"
694                 rpathify_dir "$pkglib/gdk-pixbuf-2.0/$gtk_version/loaders" "*.so"
695                 rpathify_dir "$pkglib/pango/$pango_version/modules" "*.so"
696         fi
697 }
698
699 PATHLENGTH=`echo $LIBPREFIX | wc -c`
700 if [ "$PATHLENGTH" -ge "6" ]; then
701         # If the LIBPREFIX path is long enough to allow
702         # path rewriting, then do this.
703         # 6 is the length of @rpath, which replaces LIBPREFIX.
704         rpathify_files
705 else
706         echo "Could not rewrite dylib paths for bundled libraries.  This requires" >&2
707         echo "the support libraries to be installed in a PREFIX of at least 6 characters in length." >&2
708         echo "" >&2
709         echo "The bundle will still work if the following line is uncommented in" >&2
710         echo "Wireshark.app/Contents/Resources/bin/{various scripts}:" >&2
711         echo '        export DYLD_LIBRARY_PATH="$TOP/lib"' >&2
712         exit 1
713
714 fi
715
716 codesign_file () {
717         codesign --sign "Developer ID Application: $CODE_SIGN_IDENTITY" --verbose "$1"
718         codesign --verify --verbose "$1" || exit 1
719         spctl --assess --type execute "$1" || exit 1
720 }
721
722 if [ -n "$CODE_SIGN_IDENTITY" ] ; then
723         security find-identity -v -s "$CODE_SIGN_IDENTITY" -p codesigning
724
725         echo "Signing executables"
726         if [ -z "$cs_binary_list" ] ; then
727                 echo "No executables specified for code signing."
728                 exit 1
729         fi
730         for binary in $cs_binary_list ; do
731                 codesign_file "$binary"
732         done
733
734         echo "Signing frameworks"
735         for framework in $pkglib/*.framework/Versions/*/* ; do
736                 codesign_file "$framework"
737         done
738
739         echo "Signing libraries"
740         for library in $pkglib/*.dylib ; do
741                 codesign_file "$library"
742         done
743
744         echo "Signing plugins"
745         for plugin in $pkgplugin/*.so ; do
746                 codesign_file "$plugin"
747         done
748
749         echo "Signing $bundle"
750         codesign_file "$bundle"
751 else
752         echo "Code signing not performed (no identity)"
753 fi
754
755 exit 0