-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make.sh
executable file
·141 lines (119 loc) · 3.29 KB
/
make.sh
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
#!/bin/bash
# SPDX-FileCopyrightText: © 2022 Ryan C Schmidt <https://github.com/ryandesign>
#
# SPDX-License-Identifier: MIT
set -euo pipefail
if [[ ${BASH_SOURCE[0]} = */* ]]; then
cd -- "${BASH_SOURCE%/*}/" || exit
fi
sourcedir="$PWD"
: "${RETRO68:=/opt/local/libexec/Retro68}"
: "${RESINFO:="$RETRO68"/bin/ResInfo}"
: "${REZ:="$RETRO68"/bin/Rez}"
: "${CMAKE:=cmake}"
: "${CMAKE_BUILD_TYPE:=RelWithDebInfo}"
: "${BUILD_DIR:=build}"
: "${BUILD_TYPE_DIR:="$BUILD_DIR/$CMAKE_BUILD_TYPE"}"
: "${CMAKE_BUILD_PARALLEL_LEVEL:=$(sysctl -n hw.activecpu 2>/dev/null || nproc 2>/dev/null || echo 1)}"
: "${JOBS:="$CMAKE_BUILD_PARALLEL_LEVEL"}"
: "${TERM:=dumb}"
build_68k=0
build_ppc=0
build_fat=0
while (($# > 0)); do
case $1 in
68k)
build_68k=1
;;
ppc)
build_ppc=1
;;
fat)
build_fat=1
;;
*)
printf 'unknown option %s\n' "$1" >&2
exit 1
esac
shift
done
if ((!build_68k && !build_ppc && !build_fat)); then
build_fat=1
fi
if ((build_fat)); then
build_68k=1
build_ppc=1
fi
build_dir_68k="$BUILD_TYPE_DIR/m68k"
build_dir_ppc="$BUILD_TYPE_DIR/powerpc"
build_dir_fat="$BUILD_TYPE_DIR/fat"
common_cmake_flags=(
-S "$sourcedir"
-DCMAKE_BUILD_TYPE="$CMAKE_BUILD_TYPE"
-DCMAKE_VERBOSE_MAKEFILE=ON
)
heading() {
local -r msg="${1:-}"
local -r msglen=${#msg}
local -r cols=$(tput cols)
local -r leftlen=$(((cols-msglen)/2-1))
local -r rightlen=$((leftlen+msglen%2))
local i
for ((i=0; i<leftlen; ++i)) {
printf '='
}
printf ' %s ' "$msg"
for ((i=0; i<rightlen; ++i)) {
printf '='
}
printf '\n'
}
if ((build_68k)); then
heading 'Building for 68K'
mkdir -p "$build_dir_68k"
"$CMAKE" \
-DCMAKE_TOOLCHAIN_FILE="$RETRO68"/m68k-apple-macos/cmake/retro68.toolchain.cmake \
-B "$build_dir_68k" \
"${common_cmake_flags[@]}"
"$CMAKE" \
--build "$build_dir_68k" \
-- -j"$JOBS"
fi
if ((build_ppc)); then
heading 'Building for PowerPC'
mkdir -p "$build_dir_ppc"
"$CMAKE" \
-DCMAKE_TOOLCHAIN_FILE="$RETRO68"/powerpc-apple-macos/cmake/retroppc.toolchain.cmake \
-B "$build_dir_ppc" \
"${common_cmake_flags[@]}"
"$CMAKE" \
--build "$build_dir_ppc" \
-- -j"$JOBS"
fi
make_fat() {
local -r name="$1"
local -r step_number="${2:-1}"
local -r total_steps="${3:-1}"
local -r type="$("$RESINFO" --type "$build_dir_68k/src/$name.bin" | sed -E "s/^'(.{4,})'$/\1/")"
local -r creator="$("$RESINFO" --creator "$build_dir_68k/src/$name.bin" | sed -E "s/^'(.{4,})'$/\1/")"
set -x
"$REZ" \
--define CFRAG_NAME="\"$name\"" \
--copy "$build_dir_68k/src/$name.bin" \
--data "$build_dir_ppc/src/$name.pef" \
--output "$build_dir_fat/src/$name.bin" \
--cc "$build_dir_fat/src/%$name.ad" \
--cc "$build_dir_fat/src/$name.APPL" \
--cc "$build_dir_fat/src/$name.dsk" \
--type "$type" \
--creator "$creator" \
--include "$RETRO68"/RIncludes \
"$RETRO68"/RIncludes/RetroPPCAPPL.r || return $?
{ set +x; } 2>/dev/null
printf '[%3d%%] Created fat binary for %s\n' "$((100*step_number/total_steps))" "$name"
}
if ((build_fat)); then
heading 'Building fat binary'
mkdir -p "$build_dir_fat/src"
make_fat 'app'
fi