-
Notifications
You must be signed in to change notification settings - Fork 1
/
Build.sh
executable file
·276 lines (218 loc) · 5.5 KB
/
Build.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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#!/bin/ksh
BASE=$(pwd)
export INCLUDE=${BASE}/include
# try find the board
[[ -r .config ]] && source ./.config
[[ ${CONFIG_ARM} =~ y ]] && ARCH=arm
[[ ${CONFIG_BOARD_VERSATILE} =~ y ]] && BOARD=versatile
[[ ${CONFIG_BOARD_REALVIEW} =~ y ]] && BOARD=realview
# set defaults
export ARCH=${ARCH:-arm}
export BOARD=${BOARD:-versatile}
export CROSS_COMPILE=${CROSS_COMPILE:-arm-linux-}
export CC=${CROSS_COMPILE}gcc
export LD=${CROSS_COMPILE}ld
export AS=${CROSS_COMPILE}as
export OBJCOPY=${CROSS_COMPILE}objcopy
[[ ${ARCH} ]] && [[ ! ${CROSS_COMPILE} ]] && {
print "Unknown compiler for architecture $ARCH"
print "Please export CROSS_COMPILE"
exit 1
}
[[ $(whence ${CROSS_COMPILE}gcc) ]] || {
print "I did not find ${CROSS_COMPILE}gcc in $PATH"
print "Please setup your PATH"
exit 1
}
print "Using compiler ${CROSS_COMPILE}gcc for architecture $ARCH"
export DEBFLGS="-g"
# export tool chain you find in toolchain.inc
source arch/${ARCH}/${BOARD}/toolchain.inc
# export directories
DIRS="kernel lib arch/${ARCH}/${BOARD} arch/${ARCH}/common/ arch/${ARCH}/lib domains scripts drivers tests"
mkdir -p objs
function die
{
print $*
exit 1
}
function clean_all
{
for dir in ${DIRS}
do
print cleaning ${dir}
( cd ${dir} ; ./Build.sh clean )
print "done"
done
print "cleaning objects"
rm -rf generated
rm -f os/*.dom
rm -f xhyp xhyp.bin xhyp.ld xhyp.nm
rm -f files.in
rm -f objs/*
rm -f cscope.out cscope.files
print "done"
}
function mrproper
{
clean_all
rm -f .config
rm -rf doc
rm -f include/autoconf.h
}
function save_all
{
set -x
d=${PWD##/*/}
file=${d}_$(date +%Y%m%d_%H%M)_$$.tgz
print "saving directory $d to ../${file}"
#(cd ..; print excluding files in ${d}/TAR.EXCLUDE)
#(cd .. ; d=$(readlink $d); tar zcvf ${file} -X ${d}/TAR.EXCLUDE ${d} )
#[[ -l ../${d} ]] && d=$(readlink $d)
(cd .. ; tar zcvf ${file} ${d} )
exit 0
}
function save_all_all
{
cp /root/OSEO/linux/patches/xhyp.patch patches/
cp /data/linux_xhyp.tgz ports/
cp /data/freertos_xhyp.tgz ports/
d=${PWD##/*/}
file=${d}_$(date +%Y%m%d_%H%M)_$$.tgz
print "saving directory $d to ../${file}"
(cd .. ; d=$(readlink $d); tar zcvf ${file} $d )
exit 0
}
function build_scripts
{
(
cd scripts
./Build.sh $*
)
}
function build_config
{
build_scripts
./scripts/kconfig/mconf Kconfig
}
function help
{
print "
usage:
./Build [option]
Default: Build xhyp
where option is one of
cscope : Build cscope files
scripts : Build configuration scripts
menu : configure using menu
menuconfig: configure using menu
clean : cleanup source tree
mrproper: cleanup source tree and cscope files
save : save tree in ../xhyp_YYYYMMMDDD.tgz
";
}
function build_cscope
{
find . -type f -name "*.c" > cscope.files
find . -type f -name "*.S" >> cscope.files
find . -type f -name "*.h" >> cscope.files
cscope -I ./include -k -b -icscope.files
}
function build_doc
{
mkdir -p doc
doxygen && ( cd doc/latex && make )
exit $?
}
[[ $1 == "help" ]] && help && exit 0
[[ $1 == "cscope" ]] && build_cscope && exit 0
[[ $1 == "scripts" ]] && build_scripts && exit 0
[[ $1 == "menuconfig" ]] && build_config && exit 0
[[ $1 == "menu" ]] && build_config && exit 0
[[ $1 == "config" ]] && build_config && exit 0
[[ $1 == "mrproper" ]] && mrproper && exit 0
[[ $1 == "clean" ]] && clean_all && exit 0
[[ $1 == "save" ]] && save_all && exit 0
[[ $1 == "doc" ]] && build_doc && exit 0
[[ -r .config ]] || {
build_config
}
[[ -r .config ]] || {
print "Please configure using ./Build.sh config"
exit 1
}
#clean_all
source ./.config
i=1
nb_domains=0
while read line
do
line=${line%#*}
[[ $line =~ CONFIG_DOMAIN.= ]] && {
: $(( nb_domains++))
}
[[ $line ]] && export $line
done < .config
[[ -x ./os/Build.sh ]] && {
./os/Build.sh || exit 1
}
./scripts/Build_ld || exit 1
DIRS="lib kernel"
LIBS="lib/xhyp.a lib/mlib.a lib/lib.a"
GENERATED="generated/domain_table.o"
[[ ${CONFIG_SCHED_ARINC} =~ y ]] && {
GENERATED="${GENERATED} generated/arinc_table.o"
./scripts/Build_arinc > generated/arinc_table.c
}
print "Build board dependencies $*"
( cd arch/${ARCH}/${BOARD} && ./Build.sh $* ) || exit 1
print "done"
print "Build arch dependencies $*"
( cd arch/${ARCH}/ && ./Build.sh $* ) || exit 1
print "done"
print "Build standard libraries $*"
( cd lib && ./Build.sh $* ) || exit 1
print "done"
print "Build kernel $*"
( cd kernel && ./Build.sh $* ) || exit 1
print "done"
print "Build drivers $*"
( cd drivers && ./Build.sh $* ) || exit 1
print "Build tests $*"
( cd tests && ./Build.sh $* ) || exit 1
( cd domains && ./Build.sh $* ) || exit 1
i=1
read nb_domains reste < <(ls -d domains/domain?? | wc -l)
while (( i < (nb_domains + 1) ))
do
printf "Linking domain %02d ... " $i
dir=$(printf "domains/domain%02d" $i)
file="${dir}/domain"
[[ -d $dir ]] || { die "${dir} does not exist"
}
[[ -r ${file}.bin ]] || { die "${file} does not exist"
}
${CROSS_COMPILE}objcopy \
--input-target binary \
--output-target elf32-littlearm \
--binary-architecture arm \
--rename-section .data=.dm${i} \
${file}.bin ${file}.ho
DOMAINS="${DOMAINS} ${file}.ho"
: $((i++))
print "done"
done
printf "Compute domain tables ... "
${CC} ${CFLAGS} -c generated/domain_table.c -o generated/domain_table.o
[[ ${CONFIG_SCHED_ARINC} =~ y ]] && {
printf "Compute arinc tables ... "
${CC} ${CFLAGS} -c generated/arinc_table.c -o generated/arinc_table.o
}
printf "Linking xhyp ... "
export LDFLAGS="-Bstatic -T xhyp.ld "
${LD} ${LDFLAGS} ${LIBS} ${GENERATED} ${DOMAINS} -o xhyp
${CROSS_COMPILE}nm xhyp > xhyp.nm
[[ $1 == "clean" ]] && exit 0
build_cscope
print "done"
exit 0