summaryrefslogtreecommitdiff
path: root/scripts/macos/create_app_bundle.sh
blob: ec3f316f6fad8739bad932f2968c4d1bd6a979b3 (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/bash
# Create macOS App Bundle with Icon
# This creates a proper .app bundle for distribution on macOS

set -e

echo "========================================"
echo "Creating macOS App Bundle"
echo "========================================"
echo ""

# Get script directory
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PROJECT_ROOT="$SCRIPT_DIR/../.."
cd "$PROJECT_ROOT"

# Check if executable exists
if [ ! -f "build/ReiLua" ]; then
    echo "ERROR: ReiLua executable not found!"
    echo "Please run ./scripts/build_dev.sh or ./scripts/build_release.sh first"
    exit 1
fi

# App name (can be customized)
APP_NAME="${1:-ReiLua}"
APP_BUNDLE="${APP_NAME}.app"

echo "Creating app bundle: $APP_BUNDLE"
echo ""

# Create app bundle structure
mkdir -p "$APP_BUNDLE/Contents/MacOS"
mkdir -p "$APP_BUNDLE/Contents/Resources"

# Copy executable
echo "Copying executable..."
cp build/ReiLua "$APP_BUNDLE/Contents/MacOS/$APP_NAME"
chmod +x "$APP_BUNDLE/Contents/MacOS/$APP_NAME"

# Convert icon.ico to .icns if needed
ICNS_FILE="$APP_BUNDLE/Contents/Resources/icon.icns"

if [ -f "icon.ico" ]; then
    echo "Converting icon..."
    
    # Create temporary iconset directory
    mkdir -p icon.iconset
    
    # Use sips to convert and resize (macOS built-in tool)
    # Extract from .ico and create different sizes
    sips -s format png icon.ico --out icon.iconset/icon_512x512.png -z 512 512 2>/dev/null || {
        echo "Note: sips conversion had warnings, using ImageMagick if available..."
        if command -v convert &> /dev/null; then
            convert icon.ico -resize 512x512 icon.iconset/icon_512x512.png
        else
            echo "WARNING: Could not convert icon. Install ImageMagick with: brew install imagemagick"
            echo "         Or provide an icon.png file at 512x512 resolution"
        fi
    }
    
    # Create other required sizes if we have the 512x512 version
    if [ -f "icon.iconset/icon_512x512.png" ]; then
        sips -z 256 256 icon.iconset/icon_512x512.png --out icon.iconset/icon_256x256.png
        sips -z 128 128 icon.iconset/icon_512x512.png --out icon.iconset/icon_128x128.png
        sips -z 64 64   icon.iconset/icon_512x512.png --out icon.iconset/icon_64x64.png
        sips -z 32 32   icon.iconset/icon_512x512.png --out icon.iconset/icon_32x32.png
        sips -z 16 16   icon.iconset/icon_512x512.png --out icon.iconset/icon_16x16.png
        
        # Create @2x versions (retina)
        cp icon.iconset/icon_512x512.png icon.iconset/icon_256x256@2x.png
        cp icon.iconset/icon_256x256.png icon.iconset/icon_128x128@2x.png
        cp icon.iconset/icon_128x128.png icon.iconset/icon_64x64@2x.png
        cp icon.iconset/icon_64x64.png   icon.iconset/icon_32x32@2x.png
        cp icon.iconset/icon_32x32.png   icon.iconset/icon_16x16@2x.png
        
        # Convert to .icns
        iconutil -c icns icon.iconset -o "$ICNS_FILE"
        echo "✓ Icon created: $ICNS_FILE"
    fi
    
    # Clean up
    rm -rf icon.iconset
else
    echo "WARNING: icon.ico not found, app will have no icon"
fi

# Create Info.plist
echo "Creating Info.plist..."
cat > "$APP_BUNDLE/Contents/Info.plist" << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleExecutable</key>
    <string>$APP_NAME</string>
    <key>CFBundleIconFile</key>
    <string>icon.icns</string>
    <key>CFBundleIdentifier</key>
    <string>com.reilua.$APP_NAME</string>
    <key>CFBundleName</key>
    <string>$APP_NAME</string>
    <key>CFBundleDisplayName</key>
    <string>$APP_NAME</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>1.0.0</string>
    <key>CFBundleVersion</key>
    <string>1</string>
    <key>LSMinimumSystemVersion</key>
    <string>10.12</string>
    <key>NSHighResolutionCapable</key>
    <true/>
    <key>NSSupportsAutomaticGraphicsSwitching</key>
    <true/>
</dict>
</plist>
EOF

echo "✓ Info.plist created"
echo ""

# Get app size
APP_SIZE=$(du -sh "$APP_BUNDLE" | cut -f1)

echo "========================================"
echo "App Bundle Created!"
echo "========================================"
echo ""
echo "App:      $APP_BUNDLE"
echo "Size:     $APP_SIZE"
echo "Location: $(pwd)/$APP_BUNDLE"
echo ""
echo "To test:"
echo "  open $APP_BUNDLE"
echo ""
echo "To distribute:"
echo "  1. Zip the .app bundle:"
echo "     zip -r ${APP_NAME}.zip $APP_BUNDLE"
echo ""
echo "  2. Or create a DMG (requires hdiutil):"
echo "     hdiutil create -volname '$APP_NAME' -srcfolder '$APP_BUNDLE' -ov -format UDZO ${APP_NAME}.dmg"
echo ""
echo "The app bundle includes:"
echo "  - Executable: $APP_BUNDLE/Contents/MacOS/$APP_NAME"
if [ -f "$ICNS_FILE" ]; then
echo "  - Icon: $APP_BUNDLE/Contents/Resources/icon.icns"
else
echo "  - Icon: (not available, provide icon.ico or icon.png)"
fi
echo "  - Info.plist with app metadata"
echo ""