-
Notifications
You must be signed in to change notification settings - Fork 153
/
pcejs_build
executable file
·187 lines (147 loc) · 4.03 KB
/
pcejs_build
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
178
179
180
181
182
183
184
185
186
187
#!/bin/bash
set -uo pipefail
declare -a ARCHS=("macplus" "ibmpc" "atarist")
pcejs_load_config () {
if [[ ! -f ./pcejs_build_conf.sh ]]; then
# no existing config file, copy from default
cp ./scripts/pcejs_build_conf_default.sh ./pcejs_build_conf.sh
fi
set -a # all sourced vars are exported
source ./pcejs_build_conf.sh
set +a # restore default behaviour
}
pcejs_save_config () {
(set -o posix; set) | grep "PCEJS_conf_" > ./pcejs_build_conf.sh
}
pcejs_print_config () {
(set -o posix; set) | grep "PCEJS_"
}
pcejs_init_env_from_config () {
# initialise build env from config
# should be called after changing any PCEJS_conf var
source ./scripts/pcejs_build_env.sh
if [[ -z $PCEJS_EMSDK_PATH ]]; then
echo "ERROR: could't resolve emsdk path from env or config"
exit 1
fi
}
# ensure cwd is project root dir
repo_root=$(git rev-parse --show-toplevel)
cd "$repo_root"
pcejs_load_config
pcejs_init_env_from_config
pcejs_build=$0
taskname=${1:-"default"}
echo "start $taskname ${2:-""}"
case "$taskname" in
"env") # Print build environment variables
pcejs_print_config
;;
"init") # Create build config file (./pcejs_build_conf.sh) if none exists
pcejs_save_config
;;
"configure") # Run ./configure for emulator build
platform=${2:-""}
if [[ $platform == "native" ]]; then
export PCEJS_conf_emscripten=""
export PCEJS_conf_prefix="build-native/"
fi
if [[ $platform == "em" ]]; then
export PCEJS_conf_emscripten="yes"
export PCEJS_conf_prefix="build/"
fi
pcejs_init_env_from_config
./scripts/10-configure.sh
pcejs_save_config
;;
"make") # Compile emulator source to LLVM bitcode (clean and make)
./scripts/20-make.sh
;;
"remake") # Recompile only changed files of emulator source to LLVM bitcode
./scripts/21-remake.sh
;;
"clean") # Clean source tree
cleanall=${2:-""}
if [[ -n $cleanall ]]; then
./scripts/a0-clean.sh
else
make clean
fi
;;
"afterbuild") # Convert LLVM bitcode to JS
target=${2:-""}
if [[ -n $target ]]; then
export PCEJS_conf_target=$target
fi
pcejs_init_env_from_config
./scripts/30-afterbuild.sh
;;
"build") # Configure build and compile emulator to JS
target_or_platform=${2:-""}
if [[ $target_or_platform == "native" ]]; then
$pcejs_build configure native
$pcejs_build make
else
if [[ -n $target_or_platform ]]; then
export PCEJS_conf_target=$target_or_platform
fi
pcejs_init_env_from_config
$pcejs_build configure em
$pcejs_build make
$pcejs_build afterbuild "$PCEJS_conf_target"
fi
pcejs_save_config
;;
"rebuild") # Build last target again
target_or_platform=${2:-""}
if [[ $target_or_platform == "native" ]]; then
$pcejs_build remake
elif [[ -n $target_or_platform ]]; then
export PCEJS_conf_target=$target_or_platform
pcejs_init_env_from_config
$pcejs_build remake
$pcejs_build afterbuild "$PCEJS_conf_target"
else
$pcejs_build remake
for arch in "${ARCHS[@]}"; do
$pcejs_build afterbuild "$arch"
done
fi
;;
"module") # Build commonjs module
arch=${2:-""}
echo "building commonjs module for $2"
if [[ -n $arch ]]; then
echo "building commonjs module for arch $arch";
./scripts/module_build.sh "$arch"
else
for arch in "${ARCHS[@]}"; do
echo "building commonjs module for arch $arch";
./scripts/module_build.sh "$arch"
done
fi
;;
"example") # run example
arch=${2:-""}
if [[ -n $arch ]]; then
echo "running example for arch $arch";
else
echo "arch not specified";
exit 1;
fi
./example/run_example.sh "$arch"
;;
"default")
$pcejs_build configure em
$pcejs_build make
for arch in "${ARCHS[@]}"; do
$pcejs_build afterbuild "$arch"
$pcejs_build module "$arch"
done
;;
*)
echo "unknown task: $taskname"
exit 1
;;
esac
echo "end $taskname ${2:-""}"