forked from LeoManrique/sm64coopdx-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_ios.sh
More file actions
executable file
·164 lines (146 loc) · 5.38 KB
/
Copy pathbuild_ios.sh
File metadata and controls
executable file
·164 lines (146 loc) · 5.38 KB
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
153
154
155
156
157
158
159
160
161
162
163
164
#!/bin/bash
set -e
# SM64CoopDX iOS Build Script
# Requires: macOS, Xcode + iOS SDK, CMake, make
BUILD_DIR="build-ios"
CONFIG="Release"
IPA_NAME="sm64coopdx.ipa"
# ---- Prerequisites check ----
check_prerequisites() {
if ! command -v cmake &> /dev/null; then
echo "Error: cmake not found. Install with: brew install cmake"
exit 1
fi
if ! command -v xcrun &> /dev/null; then
echo "Error: Xcode command line tools not found. Install with: xcode-select --install"
exit 1
fi
if ! xcrun --sdk iphoneos --show-sdk-path &> /dev/null; then
echo "Error: iOS SDK not found. Install Xcode from the App Store."
exit 1
fi
if ! command -v make &> /dev/null; then
echo "Error: make not found."
exit 1
fi
if [ ! -f "baserom.us.z64" ]; then
echo "Error: baserom.us.z64 not found in repo root."
echo "Place your base ROM as baserom.us.z64 before building."
exit 1
fi
}
# ---- Desktop build (generates assets) ----
desktop() {
echo "==> Building desktop version..."
# Build tools first (Makefile's two-pass restart can miss them)
make -C tools
# Pre-create all build output directories (Makefile's mkdir can miss them on fresh builds)
for dir in src actors levels bin data sound textures text lib include; do
find "$dir" -type d 2>/dev/null | while read d; do mkdir -p "build/us_pc/$d"; done
done
mkdir -p build/us_pc/assets build/us_pc/rsp build/us_pc/include build/us_pc/res
# Pre-generate texture .inc.c files (Makefile can't resolve these deps on fresh builds)
find actors levels textures -name "*.png" | while read png; do
inc="build/us_pc/${png%.png}.inc.c"
if [ ! -f "$inc" ]; then
fmt=$(echo "$png" | sed 's/.*\.\(.*\)\.png/\1/')
mkdir -p "$(dirname "$inc")"
tools/n64graphics -s u8 -i "$inc" -g "$png" -f "$fmt" 2>/dev/null || true
fi
done
# Pre-copy coopnet dylibs into build dir (Makefile's COOPNET_LIBS rule collides with BUILD_DIR target)
if [ "$(uname -m)" = "arm64" ]; then
COOPNET_SRC="lib/coopnet/mac_arm"
else
COOPNET_SRC="lib/coopnet/mac_intel"
fi
cp -f "$COOPNET_SRC/libcoopnet.dylib" "$COOPNET_SRC/libjuice.1.6.2.dylib" build/us_pc/
make -j$(sysctl -n hw.ncpu)
# Post-fix GLEW in app bundle (Makefile hardcodes libGLEW.2.2.0 but brew may ship 2.3+)
APP_MACOS_DIR="build/us_pc/sm64coopdx.app/Contents/MacOS"
if [ -d "$APP_MACOS_DIR" ] && [ ! -f "$APP_MACOS_DIR/libGLEW.dylib" ]; then
GLEW_REF=$(otool -L "$APP_MACOS_DIR/sm64coopdx" 2>/dev/null | awk '/libGLEW/{print $1; exit}')
if [ -n "$GLEW_REF" ] && [ -e "$GLEW_REF" ]; then
cp "$GLEW_REF" "$APP_MACOS_DIR/libGLEW.dylib"
install_name_tool -change "$GLEW_REF" @executable_path/libGLEW.dylib "$APP_MACOS_DIR/sm64coopdx" >/dev/null 2>&1
install_name_tool -id @executable_path/libGLEW.dylib "$APP_MACOS_DIR/libGLEW.dylib" >/dev/null 2>&1
codesign --force --deep --sign - "$APP_MACOS_DIR/libGLEW.dylib" >/dev/null 2>&1
fi
fi
echo "==> Desktop build complete."
}
# ---- Generate Xcode project ----
generate() {
echo "==> Generating Xcode project..."
cmake -B "$BUILD_DIR" -G Xcode \
-DCMAKE_SYSTEM_NAME=iOS \
-DCMAKE_OSX_ARCHITECTURES=arm64 \
-DCMAKE_OSX_DEPLOYMENT_TARGET=15.0
echo "==> Xcode project generated at $BUILD_DIR/"
}
# ---- Build ----
build() {
if [ ! -d "$BUILD_DIR" ]; then
generate
fi
echo "==> Building ($CONFIG)..."
cmake --build "$BUILD_DIR" --config "$CONFIG" -- CODE_SIGNING_ALLOWED=NO
echo "==> Build succeeded."
}
# ---- Clean ----
clean() {
if [ -d "$BUILD_DIR" ]; then
echo "==> Cleaning..."
cmake --build "$BUILD_DIR" --config "$CONFIG" --target clean -- CODE_SIGNING_ALLOWED=NO
echo "==> Clean done."
fi
}
# ---- Package IPA ----
ipa() {
APP_PATH="$BUILD_DIR/$CONFIG-iphoneos/sm64coopdx.app"
if [ ! -d "$APP_PATH" ]; then
echo "Error: App bundle not found. Run './build_ios.sh build' first."
exit 1
fi
echo "==> Packaging IPA..."
TMPDIR=$(mktemp -d)
mkdir -p "$TMPDIR/Payload"
cp -R "$APP_PATH" "$TMPDIR/Payload/"
(cd "$TMPDIR" && zip -r -q "$OLDPWD/$IPA_NAME" Payload/)
rm -rf "$TMPDIR"
echo "==> Created $IPA_NAME ($(du -h "$IPA_NAME" | cut -f1))"
}
# ---- Full pipeline ----
all() {
check_prerequisites
desktop
clean
build
ipa
}
# ---- Usage ----
usage() {
echo "Usage: ./build_ios.sh <command>"
echo ""
echo "Commands:"
echo " generate Generate Xcode project"
echo " build Build the app (Release)"
echo " clean Clean build artifacts"
echo " ipa Package .app into .ipa for sideloading"
echo " desktop Build native desktop (macOS) .app bundle at build/us_pc/sm64coopdx.app"
echo " all Full pipeline: build assets + clean + build iOS + package IPA"
echo ""
echo "Prerequisites:"
echo " - macOS with Xcode and iOS SDK installed"
echo " - CMake (brew install cmake)"
}
# ---- Entry point ----
case "${1:-}" in
generate) check_prerequisites; generate ;;
build) check_prerequisites; build ;;
clean) clean ;;
ipa) ipa ;;
desktop) check_prerequisites; desktop ;;
all) all ;;
*) all ;;
esac