forked from jsdf/pce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pcejs_build
executable file
·188 lines (149 loc) · 3.97 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
188
#!/bin/bash
set -eo pipefail
declare -a ARCHS=("macplus")
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
echo "using PCEJS_EMSDK_PATH=$PCEJS_EMSDK_PATH"
}
# 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
target=$2
if [[ -n $target ]]; then
echo "building commonjs module for target $target";
else
echo "target not specified";
exit 1;
fi
./scripts/module_build.sh "$target"
;;
"example") # Build example
target=$2
if [[ -n $target ]]; then
echo "building example for target $target";
else
echo "target not specified";
exit 1;
fi
./example/run_example.sh "$target"
;;
"default")
if [[ -z $reset ]]; then
$pcejs_build remake
else
$pcejs_build configure em
$pcejs_build make
fi
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"