-
Notifications
You must be signed in to change notification settings - Fork 391
/
make.sh
214 lines (198 loc) Β· 5.62 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
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# Copyright 2018 Sen Han <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
OUTPUT_DIR="./output"
CFLAGS="-g -O2 -Wall -Werror"
#EXTRA_CFLAGS=""
OUTPUT_SUFFIX=""
makecc="cc"
if [ "$CC" ]
then
makecc="$CC"
fi
app_list='''
test_aco_tutorial_0
test_aco_tutorial_1
test_aco_tutorial_2
test_aco_tutorial_3 -lpthread
test_aco_tutorial_4
test_aco_tutorial_5
test_aco_tutorial_6
test_aco_synopsis
test_aco_benchmark
'''
gl_opt_no_m32=""
gl_opt_no_valgrind=""
OUTPUT_DIR="$OUTPUT_DIR""//file"
OUTPUT_DIR=`dirname "$OUTPUT_DIR"`
gl_trap_str=""
function error(){
>&2 echo "error: $*"
}
function assert(){
if [ "0" -ne "$?" ]
then
error "$0:""$*"
exit 1
fi
}
function tra(){
gl_trap_str="$gl_trap_str""$1"
trap "$gl_trap_str exit 1;" INT
assert "$LINENO:trap failed:$gl_trap_str:$1"
}
function untra(){
trap - INT
assert "$LINENO:untrap failed:$gl_trap_str:$1"
}
function build_f(){
declare file
declare cflags
declare build_cmd
declare tmp_ret
declare skip_flag
echo "OUTPUT_DIR: $OUTPUT_DIR"
echo "CFLAGS: $CFLAGS"
echo "EXTRA_CFLAGS: $EXTRA_CFLAGS"
echo "ACO_EXTRA_CFLAGS: $ACO_EXTRA_CFLAGS"
echo "OUTPUT_SUFFIX: $OUTPUT_SUFFIX"
echo "$app_list" | grep -Po '.+$' | while read read_in
do
file=`echo $read_in | grep -Po "^[^\s]+"`
cflags=`echo $read_in | sed -r 's/^\s*([^ ]+)(.*)$/\2/'`
if [ -z "$file" ]
then
continue
fi
#echo "<$file>:<$cflags>:$OUTPUT_DIR:$CFLAGS:$EXTRA_CFLAGS:$OUTPUT_SUFFIX"
build_cmd="$makecc $CFLAGS $ACO_EXTRA_CFLAGS $EXTRA_CFLAGS acosw.S aco.c $file.c $cflags -o $OUTPUT_DIR/$file$OUTPUT_SUFFIX"
skip_flag=""
if [ "$gl_opt_no_m32" ]
then
echo "$OUTPUT_SUFFIX" | grep -P "\bm32\b" &>/dev/null
tmp_ret=$?
if [ "$tmp_ret" -eq "0" ]
then
skip_flag="true"
elif [ "$tmp_ret" -eq "1" ]
then
:
else
error "grep failed: $tmp_ret"
exit $tmp_ret
fi
fi
if [ "$gl_opt_no_valgrind" ]
then
echo "$OUTPUT_SUFFIX" | grep -P "\bvalgrind\b" &>/dev/null
tmp_ret=$?
if [ "$tmp_ret" -eq "0" ]
then
skip_flag="true"
elif [ "$tmp_ret" -eq "1" ]
then
:
else
error "grep failed: $tmp_ret"
exit $tmp_ret
fi
fi
if [ "$skip_flag" ]
then
echo "skip $build_cmd"
else
echo " $build_cmd"
$build_cmd
assert "build fail"
fi
done
assert "exit"
}
function usage() {
echo "Usage: $0 [-o <no-m32|no-valgrind>] [-h]" 1>&2
echo '''
Example:
# default build
bash make.sh
# build without the i386 binary output
bash make.sh -o no-m32
# build without the valgrind supported binary output
bash make.sh -o no-valgrind
# build without the valgrind supported and i386 binary output
bash make.sh -o no-valgrind -o no-m32
''' 1>&2
}
gl_opt_value=""
while getopts ":o:h" o; do
case "${o}" in
o)
gl_opt_value=${OPTARG}
if [ "$gl_opt_value" = "no-m32" ]
then
gl_opt_no_m32="true"
elif [ "$gl_opt_value" = "no-valgrind" ]
then
gl_opt_no_valgrind="true"
else
usage
error unknow option value of '-o'
exit 1
fi
;;
h)
usage
exit 0
;;
*)
usage
error unknow option
exit 1
;;
esac
done
shift $((OPTIND-1))
#echo "o = $gl_opt_value"
#echo "gl_opt_no_valgrind:$gl_opt_no_valgrind"
#echo "gl_opt_no_m32:$gl_opt_no_m32"
if [ -e "$OUTPUT_DIR" ]
then
if [ -d "$OUTPUT_DIR" ]
then
:
else
error "\"$OUTPUT_DIR\" is not a directory"
exit 1
fi
else
error "directory \"$OUTPUT_DIR\" doesn't exist"
exit 1
fi
tra "echo;echo build has been interrupted"
# the matrix of the build config for later testing
# -m32 -DACO_CONFIG_SHARE_FPU_MXCSR_ENV -DACO_USE_VALGRIND
# 0 0 0
ACO_EXTRA_CFLAGS="" OUTPUT_SUFFIX="..no_valgrind.standaloneFPUenv" build_f
# 0 0 1
ACO_EXTRA_CFLAGS="-DACO_USE_VALGRIND" OUTPUT_SUFFIX="..valgrind.standaloneFPUenv" build_f
# 0 1 0
ACO_EXTRA_CFLAGS="-DACO_CONFIG_SHARE_FPU_MXCSR_ENV" OUTPUT_SUFFIX="..no_valgrind.shareFPUenv" build_f
# 0 1 1
ACO_EXTRA_CFLAGS="-DACO_CONFIG_SHARE_FPU_MXCSR_ENV -DACO_USE_VALGRIND" OUTPUT_SUFFIX="..valgrind.shareFPUenv" build_f
# 1 0 0
ACO_EXTRA_CFLAGS="-m32" OUTPUT_SUFFIX="..m32.no_valgrind.standaloneFPUenv" build_f
# 1 0 1
ACO_EXTRA_CFLAGS="-m32 -DACO_USE_VALGRIND" OUTPUT_SUFFIX="..m32.valgrind.standaloneFPUenv" build_f
# 1 1 0
ACO_EXTRA_CFLAGS="-m32 -DACO_CONFIG_SHARE_FPU_MXCSR_ENV" OUTPUT_SUFFIX="..m32.no_valgrind.shareFPUenv" build_f
# 1 1 1
ACO_EXTRA_CFLAGS="-m32 -DACO_CONFIG_SHARE_FPU_MXCSR_ENV -DACO_USE_VALGRIND" OUTPUT_SUFFIX="..m32.valgrind.shareFPUenv" build_f