summaryrefslogtreecommitdiff
path: root/exe2app.bash
blob: f1c8b7f77b454cffa2df272f1c7587a8d3add8c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash

SCR=$(basename $0)

unset IFS

function usage()
{
    echo "$SCR: usage $SCR -x executable "
    echo "                                 -i icon"
    echo "                                 -o app"
    echo "                                 -v version"
    echo "                                 -n bundle_identifier"
    echo "                                 -c creator_code (4 chars)"
}

function log()
{
    echo "$SCR: $*"
}

while getopts x:i:o:v:n:c: arg ; do
    case "$arg" in
        x)
            EXE="$OPTARG"
            ;;
        i)
            ICON="$OPTARG"
            ;;
        o)
            APP="$OPTARG".app
            ;;
        v)
            VERSION="$OPTARG"
            ;;
        n)
            BUNDLE_ID="$OPTARG"
            ;;
        c)
            CREATOR="$OPTARG"
            ;;
        *)
            usage
            exit 1
            ;;
    esac
done

if [ -z "$EXE" -o -z "$ICON" -o -z "$APP" \
        -o -z "$VERSION" -o -z "$BUNDLE_ID" -o -z "$CREATOR" ] ; then
    usage
    exit 1
fi

APPNAME=$(basename "$APP" .app)
EXENAME=$(basename "$EXE")

log Generating $APPNAME from $EXE

mkdir -p "$APP/Contents"
mkdir -p "$APP/Contents/MacOS"
mkdir -p "$APP/Contents/libs"
mkdir -p "$APP/Contents/Resources"

# Copy executable
#
cp "$EXE" "$APP/Contents/MacOS"

# Patch executable
dylibbundler -b -x "$APP/Contents/MacOS/$EXENAME" -d "$APP/Contents/libs"

# Create icons
#
makeicns -in "$ICON" -out "$APP/Contents/Resources/$APPNAME.icns"

# Create the plist file
#
cat > "$APP/Contents/Info.plist" << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleName</key>
<string>$APPNAME</string>
<key>CFBundleDisplayName</key>
<string>$APPNAME</string>
<key>CFBundleIdentifier</key>
<string>$BUNDLE_ID</string>
<key>CFBundleVersion</key>
<string>$VERSION</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>$CREATOR</string>
<key>CFBundleExecutable</key>
<string>$EXENAME</string>
<key>CFBundleIconFile</key>
<string>$APPNAME.icns</string>
</dict>
</plist>
EOF