|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +# WeatherWidget macOS Build Script |
| 5 | +# Builds a universal .app bundle and optionally a .dmg |
| 6 | + |
| 7 | +APP_NAME="WeatherWidget" |
| 8 | +BINARY_NAME="weatherwidget" |
| 9 | +BUNDLE_ID="com.weatherwidget" |
| 10 | +CMD_PATH="./cmd/weatherwidget/" |
| 11 | +APP_ICON="assets/icons/clear.png" |
| 12 | +VERSION="${1:-dev}" |
| 13 | + |
| 14 | +echo "==> Building WeatherWidget $VERSION for macOS..." |
| 15 | + |
| 16 | +# Build both architectures |
| 17 | +echo " Compiling darwin/amd64..." |
| 18 | +CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -v -ldflags="-s -w -X main.version=$VERSION" -o "$BINARY_NAME-darwin-amd64" "$CMD_PATH" |
| 19 | + |
| 20 | +echo " Compiling darwin/arm64..." |
| 21 | +CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 go build -v -ldflags="-s -w -X main.version=$VERSION" -o "$BINARY_NAME-darwin-arm64" "$CMD_PATH" |
| 22 | + |
| 23 | +# Assemble .app bundle |
| 24 | +APP_BUNDLE="$APP_NAME-$VERSION.app" |
| 25 | +echo "==> Assembling $APP_BUNDLE..." |
| 26 | + |
| 27 | +rm -rf "$APP_BUNDLE" |
| 28 | +mkdir -p "$APP_BUNDLE/Contents/MacOS" |
| 29 | +mkdir -p "$APP_BUNDLE/Contents/Resources" |
| 30 | + |
| 31 | +# Universal binary |
| 32 | +lipo -create -output "$APP_BUNDLE/Contents/MacOS/$BINARY_NAME" \ |
| 33 | + "$BINARY_NAME-darwin-amd64" \ |
| 34 | + "$BINARY_NAME-darwin-arm64" |
| 35 | +chmod +x "$APP_BUNDLE/Contents/MacOS/$BINARY_NAME" |
| 36 | + |
| 37 | +# Build .icns |
| 38 | +ICONSET="/tmp/$APP_NAME.iconset" |
| 39 | +rm -rf "$ICONSET" |
| 40 | +mkdir -p "$ICONSET" |
| 41 | +sips -z 16 16 "$APP_ICON" --out "$ICONSET/icon_16x16.png" > /dev/null |
| 42 | +sips -z 32 32 "$APP_ICON" --out "$ICONSET/icon_16x16@2x.png" > /dev/null |
| 43 | +sips -z 32 32 "$APP_ICON" --out "$ICONSET/icon_32x32.png" > /dev/null |
| 44 | +sips -z 64 64 "$APP_ICON" --out "$ICONSET/icon_32x32@2x.png" > /dev/null |
| 45 | +sips -z 128 128 "$APP_ICON" --out "$ICONSET/icon_128x128.png" > /dev/null |
| 46 | +sips -z 256 256 "$APP_ICON" --out "$ICONSET/icon_128x128@2x.png" > /dev/null |
| 47 | +sips -z 256 256 "$APP_ICON" --out "$ICONSET/icon_256x256.png" > /dev/null |
| 48 | +sips -z 512 512 "$APP_ICON" --out "$ICONSET/icon_256x256@2x.png" > /dev/null |
| 49 | +cp "$APP_ICON" "$ICONSET/icon_512x512.png" |
| 50 | +sips -z 512 512 "$APP_ICON" --out "$ICONSET/icon_512x512@2x.png" > /dev/null |
| 51 | +iconutil -c icns "$ICONSET" -o "$APP_BUNDLE/Contents/Resources/$APP_NAME.icns" |
| 52 | +rm -rf "$ICONSET" |
| 53 | + |
| 54 | +# Write Info.plist |
| 55 | +cat > "$APP_BUNDLE/Contents/Info.plist" <<EOF |
| 56 | +<?xml version="1.0" encoding="UTF-8"?> |
| 57 | +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
| 58 | +<plist version="1.0"> |
| 59 | +<dict> |
| 60 | + <key>CFBundleName</key> |
| 61 | + <string>$APP_NAME</string> |
| 62 | + <key>CFBundleDisplayName</key> |
| 63 | + <string>$APP_NAME</string> |
| 64 | + <key>CFBundleIdentifier</key> |
| 65 | + <string>$BUNDLE_ID</string> |
| 66 | + <key>CFBundleVersion</key> |
| 67 | + <string>$VERSION</string> |
| 68 | + <key>CFBundleShortVersionString</key> |
| 69 | + <string>$VERSION</string> |
| 70 | + <key>CFBundleExecutable</key> |
| 71 | + <string>$BINARY_NAME</string> |
| 72 | + <key>CFBundleIconFile</key> |
| 73 | + <string>$APP_NAME</string> |
| 74 | + <key>CFBundlePackageType</key> |
| 75 | + <string>APPL</string> |
| 76 | + <key>CFBundleSignature</key> |
| 77 | + <string>????</string> |
| 78 | + <key>NSHighResolutionCapable</key> |
| 79 | + <true/> |
| 80 | + <key>NSSupportsAutomaticGraphicsSwitching</key> |
| 81 | + <true/> |
| 82 | + <key>LSMinimumSystemVersion</key> |
| 83 | + <string>11.0</string> |
| 84 | + <key>LSUIElement</key> |
| 85 | + <false/> |
| 86 | +</dict> |
| 87 | +</plist> |
| 88 | +EOF |
| 89 | + |
| 90 | +echo "==> Created: $APP_BUNDLE" |
| 91 | + |
| 92 | +# Build .dmg |
| 93 | +DMG_NAME="$APP_NAME-$VERSION.dmg" |
| 94 | +echo "==> Creating $DMG_NAME..." |
| 95 | +rm -f "$DMG_NAME" |
| 96 | +hdiutil create -volname "$APP_NAME $VERSION" \ |
| 97 | + -srcfolder "$APP_BUNDLE" \ |
| 98 | + -ov -format UDZO \ |
| 99 | + -o "$DMG_NAME" |
| 100 | + |
| 101 | +echo "" |
| 102 | +echo "==> Build complete!" |
| 103 | +echo " App: $APP_BUNDLE" |
| 104 | +echo " DMG: $DMG_NAME" |
| 105 | +echo "" |
| 106 | +echo " To install: open $DMG_NAME and drag to /Applications" |
| 107 | + |
| 108 | +# Cleanup intermediate binaries |
| 109 | +rm -f "$BINARY_NAME-darwin-amd64" "$BINARY_NAME-darwin-arm64" |
0 commit comments