147 lines
6.6 KiB
Bash
Executable File
147 lines
6.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# this is for my mac
|
|
|
|
set -e
|
|
|
|
BUILD_DIR="build"
|
|
echo "🧹 Cleaning up old builds..."
|
|
rm -rf "$BUILD_DIR" .zig-cache
|
|
mkdir -p "$BUILD_DIR"
|
|
mkdir -p "$BUILD_DIR/Linux(x86_64)"
|
|
mkdir -p "$BUILD_DIR/Windows(x86_64)"
|
|
mkdir -p "$BUILD_DIR/Windows(ARM64)"
|
|
mkdir -p "$BUILD_DIR/MacOS(Silicon)"
|
|
mkdir -p "$BUILD_DIR/MacOS(Silicon)/WrldBox.app/"
|
|
mkdir -p "$BUILD_DIR/MacOS(Intel)"
|
|
mkdir -p "$BUILD_DIR/MacOS(Intel)/WrldBox.app/"
|
|
|
|
echo "🚀 Starting multi-platform compilation matrix..."
|
|
echo "--------------------------------------------------------"
|
|
|
|
# 🐧 Build Linux binary using native GCC inside an Ubuntu Docker container
|
|
echo "📦 Building for Linux (x86_64) via GCC in Docker..."
|
|
docker run --rm \
|
|
-v "$(pwd)":/src \
|
|
-w /src \
|
|
ubuntu:22.04 sh -c "
|
|
apt-get update && apt-get install -y gcc xorg-dev libgl1-mesa-dev libopenal-dev libcurl4-gnutls-dev
|
|
|
|
# Include the raylib source files explicitly and fix output name to wrldbox_linux
|
|
gcc -O2 -Wall \
|
|
src/main.c src/world.c src/player.c src/physics.c src/render.c src/collision.c \
|
|
raylib_src/src/rcore.c raylib_src/src/rshapes.c raylib_src/src/rtextures.c \
|
|
raylib_src/src/rtext.c raylib_src/src/rmodels.c raylib_src/src/raudio.c raylib_src/src/rglfw.c \
|
|
-Iinclude -Iraylib_src/src -Iraylib_src/src/external/glfw/include \
|
|
-D_GNU_SOURCE -DPLATFORM_DESKTOP -D_GLFW_X11 \
|
|
-lX11 -lGL -lm -lpthread -ldl -lrt \
|
|
-o wrldbox_linux
|
|
"
|
|
mv wrldbox_linux "$BUILD_DIR/Linux(x86_64)/wrldbox_linux_x86_64"
|
|
|
|
# 🪟 Build Windows binaries natively on your Mac using build.zig
|
|
echo "📦 Building for Windows (x86_64)..."
|
|
zig build -Dtarget=x86_64-windows -Doptimize=ReleaseFast
|
|
mv zig-out/bin/wrldbox.exe "$BUILD_DIR/Windows(x86_64)/wrldbox_win_x86_64.exe"
|
|
|
|
echo "📦 Building for Windows (ARM64)..."
|
|
zig build -Dtarget=aarch64-windows -Doptimize=ReleaseFast
|
|
mv zig-out/bin/wrldbox.exe "$BUILD_DIR/Windows(ARM64)/wrldbox_win_arm64.exe"
|
|
|
|
|
|
# 🍏 Build macOS binaries natively on your Mac using build.zig
|
|
echo "📦 Building for macOS (Apple Silicon)..."
|
|
gcc src/*.c -o wrldboxMacOS \
|
|
-I/opt/homebrew/include \
|
|
-L/opt/homebrew/lib \
|
|
-lraylib \
|
|
-framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo
|
|
|
|
echo "📁 Creating directory structure..."
|
|
mkdir -p "$BUILD_DIR/MacOS(Silicon)/WrldBox.app/Contents/MacOS"
|
|
mkdir -p "$BUILD_DIR/MacOS(Silicon)/WrldBox.app/Contents/Resources"
|
|
|
|
echo "📦 Copying image..."
|
|
# 💡 FIX 1: Changed "else if" to "elif" and added copy command after generation
|
|
if [ -f "build_resources/AppIcon.icns" ]; then
|
|
cp "build_resources/AppIcon.icns" "$BUILD_DIR/MacOS(Silicon)/WrldBox.app/Contents/Resources/"
|
|
elif [ -f "build_resources/appicon.png" ]; then
|
|
echo "🎨 Converting appicon.png to macOS .icns format..."
|
|
mkdir -p build_resources/AppIcon.iconset
|
|
|
|
# Generate the standard sizes macOS requires
|
|
sips -z 16 16 build_resources/appicon.png --out build_resources/AppIcon.iconset/icon_16x16.png > /dev/null 2>&1
|
|
sips -z 32 32 build_resources/appicon.png --out build_resources/AppIcon.iconset/icon_16x16@2x.png > /dev/null 2>&1
|
|
sips -z 32 32 build_resources/appicon.png --out build_resources/AppIcon.iconset/icon_32x32.png > /dev/null 2>&1
|
|
sips -z 64 64 build_resources/appicon.png --out build_resources/AppIcon.iconset/icon_32x32@2x.png > /dev/null 2>&1
|
|
sips -z 128 128 build_resources/appicon.png --out build_resources/AppIcon.iconset/icon_128x128.png > /dev/null 2>&1
|
|
sips -z 256 256 build_resources/appicon.png --out build_resources/AppIcon.iconset/icon_128x128@2x.png > /dev/null 2>&1
|
|
sips -z 256 256 build_resources/appicon.png --out build_resources/AppIcon.iconset/icon_256x256.png > /dev/null 2>&1
|
|
sips -z 512 512 build_resources/appicon.png --out build_resources/AppIcon.iconset/icon_256x256@2x.png > /dev/null 2>&1
|
|
sips -z 512 512 build_resources/appicon.png --out build_resources/AppIcon.iconset/icon_512x512.png > /dev/null 2>&1
|
|
sips -z 1024 1024 build_resources/appicon.png --out build_resources/AppIcon.iconset/icon_512x512@2x.png > /dev/null 2>&1
|
|
|
|
# Compile into the final asset and clean up temporary folder
|
|
iconutil -c icns build_resources/AppIcon.iconset -o build_resources/AppIcon.icns
|
|
rm -rf build_resources/AppIcon.iconset
|
|
|
|
# Copy newly generated icns to the app bundle
|
|
cp "build_resources/AppIcon.icns" "$BUILD_DIR/MacOS(Silicon)/WrldBox.app/Contents/Resources/"
|
|
else
|
|
echo "⚠️ Warning: No icon asset found, skipping icon copy."
|
|
fi
|
|
|
|
echo "📦 Moving binary..."
|
|
cp wrldboxMacOS "$BUILD_DIR/MacOS(Silicon)/WrldBox.app/Contents/MacOS/wrldbox_mac_arm64"
|
|
mv wrldboxMacOS "$BUILD_DIR/MacOS(Silicon)/wrldbox_mac_arm64"
|
|
|
|
# 5. Generate the Info.plist file
|
|
echo "📝 Generating Info.plist..."
|
|
# 💡 FIX 2: Added single quotes around 'EOF' so your XML code is safe from Bash parsing errors
|
|
cat <<'EOF' > "$BUILD_DIR/MacOS(Silicon)/WrldBox.app/Contents/Info.plist"
|
|
<?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>CFBundleDevelopmentRegion</key>
|
|
<string>English</string>
|
|
<key>CFBundleExecutable</key>
|
|
<string>wrldbox_mac_arm64</string>
|
|
<key>CFBundleIconFile</key>
|
|
<string>AppIcon</string>
|
|
<key>CFBundleIdentifier</key>
|
|
<string>wholeworldcoding.com</string>
|
|
<key>CFBundleInfoDictionaryVersion</key>
|
|
<string>6.0</string>
|
|
<key>CFBundleName</key>
|
|
<string>WrldBox</string>
|
|
<key>CFBundlePackageType</key>
|
|
<string>APPL</string>
|
|
<key>CFBundleShortVersionString</key>
|
|
<string>1.0</string>
|
|
<key>CFBundleVersion</key>
|
|
<string>1</string>
|
|
<key>LSMinimumSystemVersion</key>
|
|
<string>11.0</string>
|
|
</dict>
|
|
</plist>
|
|
EOF
|
|
|
|
# 6. Ad-hoc sign the bundle for Apple Silicon security compliance
|
|
echo "🔏 Removing extended attributes..."
|
|
xattr -cr "$BUILD_DIR/MacOS(Silicon)/WrldBox.app"
|
|
find "$BUILD_DIR/MacOS(Silicon)/WrldBox.app" -name "._*" -exec rm -rf {} +
|
|
find "$BUILD_DIR/MacOS(Silicon)/WrldBox.app" -name ".DS_Store" -exec rm -rf {} +
|
|
echo "🔏 Code signing the app bundle..."
|
|
codesign --force --deep --sign - "$BUILD_DIR/MacOS(Silicon)/WrldBox.app"
|
|
|
|
echo "✅ Success! built WrldBox.app for Apple Silicon at $BUILD_DIR/MacOS(Silicon)/WrldBox.app"
|
|
|
|
|
|
echo "📦 Building for macOS (Intel)..."
|
|
zig build -Dtarget=x86_64-macos -Doptimize=ReleaseFast
|
|
mv zig-out/bin/wrldbox "$BUILD_DIR/MacOS(Intel)/wrldbox_mac_x86_64"
|
|
|
|
rm -rf zig-out
|
|
echo "--------------------------------------------------------"
|
|
echo "✅ Done! All targets generated safely inside /$BUILD_DIR/" |