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 b01d5601007d10f794e703d4e20d39f75bc109e1..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"
@@ -207,7 +209,10 @@ resdir=`pwd`
 #----------------------------------------------------------
 pkgexec="$package/Contents/MacOS"
 pkgres="$package/Contents/Resources"
-pkgbin="$pkgres/bin"
+pkgbin="$pkgexec"
+if [ "$ui_toolkit" = "gtk" ] ; then
+       pkgbin="$pkgres/bin"
+fi
 # Should pkglib be Contents/Frameworks instead?
 #pkglib="$pkgres/lib"
 pkglib="$package/Contents/Frameworks"
@@ -245,16 +250,25 @@ fi
 echo -e "\nFilling app bundle and utility directory...\n"
 
 # Wireshark executables
-cp -v utility-launcher "$cli_dir/$binary"
-for binary in $binary_list ; 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"
-done
+if [ "$ui_toolkit" = "gtk" ] ; then
+       cp -v utility-launcher "$cli_dir/$binary"
+       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
+
+               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
+               # Copy the binary to its destination
+               cp -v "$binary_path/$binary" "$pkgexec"
+       done
+fi
 
 # ChmodBPF
 mkdir -p "$chmodbpf_dir"
@@ -283,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
@@ -401,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`
@@ -470,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.
@@ -529,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 
@@ -546,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