-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·177 lines (149 loc) · 4.42 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·177 lines (149 loc) · 4.42 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
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/usr/bin/env bash
set -e
full=1
debug=1
release=0
vst=0
standalone=0
clap=0
data=0
hotreload=0
reloadable=0
for arg in "$@"; do
case "$arg" in
full|debug|release|vst|standalone|clap|data|hotreload|reloadable)
declare "$arg=1"
;;
esac
done
echo
[[ $data == 1 ]] && { vst=0; debug=0; full=0; }
[[ $standalone == 1 ]] && { echo "[standalone build]"; vst=0; clap=0; full=0; }
[[ $clap == 1 ]] && { echo "[clap build]"; vst=0; standalone=0; full=0; }
[[ $vst == 1 ]] && { echo "[vst build]"; standalone=0; clap=0; full=0; }
[[ $hotreload == 1 ]] && { echo "[hotreload build]"; full=0; }
[[ $reloadable == 1 ]] && echo "[reloadable version]"
if [[ $release == 1 ]]; then
echo "[release mode]"
debug=0
else
echo "[debug mode]"
fi
echo
CXX=${CXX:-g++}
CC=${CC:-gcc}
command -v "$CXX" >/dev/null || { echo "clang++ not found"; exit 1; }
TOP="$(cd "$(dirname "$0")" && pwd)"
timestamp_ms() {
perl -MTime::HiRes=time -e 'printf "%.0f\n", time()*1000'
}
start_timer() {
START=$(timestamp_ms)
}
stop_timer() {
END=$(timestamp_ms)
ELAPSED=$((END - START))
printf "Elapsed: %d.%03d seconds\n" \
$((ELAPSED / 1000)) \
$((ELAPSED % 1000))
}
data_gen(){
echo "[serialising data]"
pushd helpers >/dev/null
rm -rf build
mkdir build
pushd build >/dev/null
$CC ../resource_generator.c -o resource_generator
./resource_generator ../../Data ../../Source/Data
popd >/dev/null
rm -rf build
popd >/dev/null
}
project_compile() {
datetime=$(date +"%Y%m%d-%H%M%S")
build_dir=build
hotreload_dir=$build_dir/hotreload
mkdir -p "$hotreload_dir"
sources=(
"$TOP/Source/unity1.mm"
"$TOP/Source/unity2.mm"
)
c_sources=(
"$TOP/Source/unity_extern.m"
)
cflags=(-I"$TOP/Source" -Wall -Wno-missing-braces -Wno-multichar -DPUGL_STATIC -march=armv8.1-a)
ldflags=(-framework CoreFoundation -framework Foundation -framework CoreGraphics -framework CoreVideo -framework AppKit)
[[ $reloadable == 1 ]] && cflags+=(-DCOMPLEX_HOTRELOAD_DIR="\"$hotreload_dir\"")
bundle_type="BNDL"
if [[ $hotreload == 1 ]]; then
build_dir=$hotreload_dir
outfile="Complex_${datetime}.dylib"
ldflags+=(-dynamiclib -fPIC)
elif [[ $vst == 1 ]]; then
rm -rf "$hotreload_dir"/*
build_dir=build/vst3
outfile="Complex.vst3"
ldflags+=(-dynamiclib -fPIC)
elif [[ $clap == 1 ]]; then
rm -rf "$hotreload_dir"/*
build_dir=build/clap
outfile="Complex.clap"
cflags+=(-DCOMPLEX_CLAP)
ldflags+=(-dynamiclib -fPIC)
elif [[ $standalone == 1 ]]; then
rm -rf "$hotreload_dir"/*
build_dir=build/standalone
outfile="Complex.app"
bundle_type="APPL"
cflags+=(-DCOMPLEX_STANDALONE)
ldflags+=(-framework CoreAudio -framework CoreMIDI)
fi
if [[ $debug == 1 ]]; then
[[ $hotreload == 0 ]] && build_dir="$build_dir/debug"
cflags+=(-g -O0)
else
[[ $hotreload == 0 ]] && build_dir="$build_dir/release"
cflags+=(-O3 -flto)
fi
[[ $data == 1 ]] && { data_gen; return; }
[[ -d Source/Data ]] || data_gen
mkdir -p "$build_dir"
start_timer
pushd "$build_dir" >/dev/null
if [[ $hotreload == 0 ]]; then
rm -rf ./*
mkdir -p "$outfile"
mkdir -p "$outfile/Contents"
mkdir -p "$outfile/Contents/MacOS"
mkdir -p "$outfile/Contents/Resources"
pushd "$outfile/Contents" >/dev/null
# unquote all strings in the config file because it will interfere with the plist values
tr -d '"' < "$TOP/Source/Third Party/cplug/config.h" > config.h
"$CC" -E -P -x c -Wno-trigraphs -include "./config.h" -DCPLUG_PLUGIN_EXECUTABLE_NAME="$outfile" -DCPLUG_BUNDLE_TYPE="$bundle_type" "$TOP/Helpers/Info.plist.in" -o Info.plist
rm ./config.h
pushd "MacOS" >/dev/null
fi
"$CC" "${cflags[@]}" -std=c99 -o unity_extern.o -c "${c_sources[@]}"
"$CXX" "${cflags[@]}" -std=c++20 "${sources[@]}" unity_extern.o -o "$outfile" "${ldflags[@]}"
rm -f ./*.o
if [[ $hotreload == 0 ]]; then
popd >/dev/null
popd >/dev/null
fi
echo "$PWD"
popd >/dev/null
stop_timer
}
if [[ $full == 1 ]]; then
debug=0
reloadable=0
vst=1; project_compile; vst=0
clap=1; project_compile; clap=0
elif [[ $release == 1 ]]; then
debug=0
project_compile
else
release=0
project_compile
fi
echo