If CODE_SIGN_IDENTITY is set use it to sign the app bundle and the
[metze/wireshark/wip.git] / packaging / macosx / osx-app.sh
index 1dee5927840aedd77ba997962fb6ee6c54b48344..dc55bef916d63987333f9a37745603043a69ee78 100755 (executable)
@@ -43,6 +43,8 @@ plist="./Info.plist"
 util_dir="./Utilities"
 cli_dir="$util_dir/Command Line"
 chmodbpf_dir="$util_dir/ChmodBPF"
+exclude_prefixes="/System/|/Library/|/usr/lib/|/usr/X11/|/opt/X11/|@rpath|@executable_path"
+
 
 # "qt" or "gtk"
 ui_toolkit="gtk"
@@ -208,6 +210,9 @@ resdir=`pwd`
 pkgexec="$package/Contents/MacOS"
 pkgres="$package/Contents/Resources"
 pkgbin="$pkgexec"
+if [ "$ui_toolkit" = "gtk" ] ; then
+       pkgbin="$pkgres/bin"
+fi
 # Should pkglib be Contents/Frameworks instead?
 #pkglib="$pkgres/lib"
 pkglib="$package/Contents/Frameworks"
@@ -247,14 +252,16 @@ echo -e "\nFilling app bundle and utility directory...\n"
 # Wireshark executables
 if [ "$ui_toolkit" = "gtk" ] ; then
        cp -v utility-launcher "$cli_dir/$binary"
-       for binary in $binary_list ; do
+       for binary in $binary_list wireshark ; do
                # Copy the binary to its destination
                dest_path="$pkgbin/$binary-bin"
                cp -v "$binary_path/$binary" "$dest_path"
                # TODO Add a "$verbose" variable and command line switch, which sets wether these commands are verbose or not
 
-               ln -sv ./wireshark "$pkgbin/$binary"
-               ln -sv ./wireshark "$cli_dir/$binary"
+               if [ "$binary" != "wireshark" ] ; then
+                       ln -sv ./wireshark "$pkgbin/$binary"
+                       ln -sv ./wireshark "$cli_dir/$binary"
+               fi
        done
 elif [ "$ui_toolkit" = "qt" ] ; then
        for binary in $binary_list ; do
@@ -290,14 +297,14 @@ cp "$plist" "$package/Contents/Info.plist"
 res_list="
        Wireshark.icns
        Wiresharkdoc.icns
-       bin
-       openDoc
 "
 
 if [ "$ui_toolkit" = "gtk" ] ; then
        res_list="
                $res_list
+               bin
                etc
+               openDoc
                script
                MenuBar.nib
                ProgressWindow.nib
@@ -408,7 +415,14 @@ fi
 
 while $endl; do
        echo -e "Looking for dependencies. Round" $a
-       libs="`otool -L $lib_dep_search_list 2>/dev/null | fgrep compatibility | cut -d\( -f1 | grep $LIBPREFIX | sort | uniq`"
+       libs="`\
+               otool -L $lib_dep_search_list 2>/dev/null \
+               | fgrep compatibility \
+               | cut -d\( -f1 \
+               | egrep -v "$exclude_prefixes" \
+               | sort \
+               | uniq \
+               `"
        cp -vn $libs "$pkglib"
        let "a+=1"
        nnfiles=`ls "$pkglib" | wc -l`
@@ -477,7 +491,15 @@ rpathify_file () {
                        # system on which the bundle will be installed,
                        # and should be referred to by their full pathnames.
                        #
-                       libs="`otool -L $1 | egrep "$LIBPREFIX.* \(compatibility" | cut -d\( -f1`"
+                       libs="`\
+                               otool -L $1 \
+                               | fgrep compatibility \
+                               | cut -d\( -f1 \
+                               | egrep -v "$exclude_prefixes" \
+                               | sort \
+                               | uniq \
+                               `"
+
                        for lib in $libs; do
                                #
                                # Get the file name of the library.
@@ -536,6 +558,10 @@ rpathify_files () {
        rpathify_dir "$pkgbin" "*"
 }
 
+if [ "$ui_toolkit" = "qt" ] ; then
+       macdeployqt "$package" -verbose=2
+fi
+
 PATHLENGTH=`echo $LIBPREFIX | wc -c`
 if [ "$PATHLENGTH" -ge "6" ]; then
        # If the LIBPREFIX path is long enough to allow 
@@ -553,8 +579,10 @@ else
 
 fi
 
-if [ "$ui_toolkit" = "qt" ] ; then
-       macdeployqt "$package" -verbose=2
+if [ -n "$CODE_SIGN_IDENTITY" ] ; then
+       echo -e "Signing $package"
+       codesign --sign "$CODE_SIGN_IDENTITY" --verbose "$package" || exit 1
+       codesign --verify --verbose "$package" || exit 1
 fi
 
 exit 0