-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild_mac.sh
More file actions
executable file
·136 lines (122 loc) · 4.52 KB
/
Copy pathbuild_mac.sh
File metadata and controls
executable file
·136 lines (122 loc) · 4.52 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
#!/bin/bash
# Build MorseRunner for macOS (Apple M1 / aarch64).
# lazbuild uses FPC 3.2.2 which generates ppaslink.sh with the new ld-prime
# linker that rejects FPC's ObjC metadata format. We intercept the link step
# and substitute ld-classic (which ships alongside ld on Xcode / CommandLineTools).
set -e
cd "$(dirname "$0")"
LD_NEW=/Library/Developer/CommandLineTools/usr/bin/ld
LD_OLD=/Library/Developer/CommandLineTools/usr/bin/ld-classic
PPASLINK=lib/aarch64-darwin/ppaslink.sh
BINARY=lib/aarch64-darwin/MorseRunner
if [ ! -x "$LD_OLD" ]; then
echo "ERROR: $LD_OLD not found — cannot build without ld-classic"
exit 1
fi
build_app_bundle() {
echo "=== Building MorseRunner.app bundle ==="
APP=MorseRunner.app
MACOS="$APP/Contents/MacOS"
RES="$APP/Contents/Resources"
mkdir -p "$MACOS" "$RES"
cp "$BINARY" "$MACOS/MorseRunner"
codesign --force --deep -s - "$MACOS/MorseRunner" 2>/dev/null || true
[ -f MorseRunner.icns ] && cp MorseRunner.icns "$RES/"
for f in *.LIST *.DTA; do
[ -f "$f" ] && cp "$f" "$RES/"
done
for f in *.txt; do
[ -f "$f" ] && [ "$f" != "*.txt" ] && cp "$f" "$RES/"
done
cat > "$APP/Contents/Info.plist" << '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>CFBundleExecutable</key>
<string>MorseRunner</string>
<key>CFBundleIdentifier</key>
<string>com.morserunner.MorseRunner</string>
<key>CFBundleName</key>
<string>Morse Runner</string>
<key>CFBundleVersion</key>
<string>1.85.3</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>LSMinimumSystemVersion</key>
<string>11.0</string>
<key>CFBundleIconFile</key>
<string>MorseRunner</string>
<key>NSHighResolutionCapable</key>
<true/>
</dict>
</plist>
PLIST
codesign --force --deep -s - "$APP" 2>/dev/null || true
echo "=== MorseRunner.app bundle ready ==="
}
# Ensure AudioBackend2.o is present and up-to-date
if [ ! -f mac/VCL/AudioBackend2.o ] || [ mac/VCL/AudioBackend2.m -nt mac/VCL/AudioBackend2.o ]; then
echo "=== Rebuilding AudioBackend2.o ==="
/Library/Developer/CommandLineTools/usr/bin/clang -c \
-fPIC \
-arch arm64 \
-mmacosx-version-min=11.0 \
-fno-objc-arc \
-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk \
-o mac/VCL/AudioBackend2.o \
mac/VCL/AudioBackend2.m
fi
# Delete the binary so lazbuild is forced to relink even when only
# implementation code (e.g. Paint procedures) changed with no interface change.
rm -f "$BINARY"
# Sync .lfm files from source into the output dir. The lpi puts $(ProjOutDir)
# first in FPC's include path, so FPC reads .lfm resources from there — edits
# to mac/*.lfm must be mirrored here before building.
mkdir -p lib/aarch64-darwin
for lfm in mac/*.lfm mac/VCL/*.lfm; do
[ -f "$lfm" ] && cp "$lfm" "lib/aarch64-darwin/$(basename "$lfm")"
done
# Delete all project .ppu files so FPC always does a clean recompile of
# project units. Incremental builds with selective ppu deletion cause
# persistent checksum mismatch cascades (ArrlFd ↔ ContestFactory ↔ Main).
# LCL/RTL ppus in ~/.lazarus are untouched, so those still cache correctly.
rm -f lib/aarch64-darwin/*.ppu
# Run lazbuild. It will compile Pascal → assemble → then try to link with the
# new ld and fail. We catch that failure, patch ppaslink.sh, and re-run link.
# Output is captured; only shown on a real compile failure (missing ppaslink.sh).
echo "=== Compiling ==="
LAZLOG=$(mktemp)
/Applications/Lazarus/lazbuild MorseRunner.lpi \
--ws=cocoa \
--compiler=/usr/local/bin/fpc \
--cpu=aarch64 \
--os=darwin \
> "$LAZLOG" 2>&1 || true # ignore error; we'll check if ppaslink.sh needs patching
# If lazbuild succeeded (produced binary directly), great.
if [ -x "$BINARY" ] && [ "$BINARY" -nt "$PPASLINK" ]; then
echo "=== Build successful (no ld patch needed) ==="
rm -f "$LAZLOG"
build_app_bundle
exit 0
fi
# Patch ppaslink.sh to use ld-classic
# Note: Lazarus 3.7+ writes ppaslink.sh into the unit output dir, not project root
if [ ! -f "$PPASLINK" ]; then
echo "ERROR: compile step failed — lazbuild output:"
cat "$LAZLOG"
rm -f "$LAZLOG"
exit 1
fi
rm -f "$LAZLOG"
if grep -q "$LD_NEW " "$PPASLINK" && ! grep -q "ld-classic" "$PPASLINK"; then
echo "=== Patching ppaslink.sh: ld → ld-classic ==="
sed -i '' "s|${LD_NEW} |${LD_OLD} |g" "$PPASLINK"
fi
echo "=== Linking with ld-classic ==="
bash "$PPASLINK"
if [ ! -x "$BINARY" ]; then
echo "ERROR: MorseRunner not produced"
exit 1
fi
build_app_bundle