-
Notifications
You must be signed in to change notification settings - Fork 2
/
build-rtems.sh
executable file
·170 lines (145 loc) · 4.37 KB
/
build-rtems.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
#!/bin/bash
#####################################################################################################################################
#
#script for building the patmos toolchain, and changing the patmos target from patmos-unknown-unknown-elf to patmos-unkwnown-rtems
#
#####################################################################################################################################
pwd=$(pwd)
tcrest_dir=~/t-crest
misc_dir=$tcrest_dir/patmos-misc
build_dir=$tcrest_dir/build-rtems
rtems_dir=$tcrest_dir/rtems
rtems_src_dir=$rtems_dir/rtems-src
rtems_build_dir=$rtems_dir/rtems-build
rtems_install_dir=$rtems_dir/rtems-install
rtems_examples_dir=$rtems_dir/rtems-examples
rtems_bsp=tcrest
old_target=patmos-unknown-unknown-elf
new_target=patmos-unknown-rtems
build_args=
build_rtems=false
build_toolchain=false
build_emulator=false
build_rtems_examples=false
build_llvm_release=true
get_rtems=true
run_bootstrap=false
function add2bashrc(){
echo $1 >> ~/.bashrc
}
function usage(){
cat <<EOT
Usage: $0 [-m] [-t] [-e] [-r] [-h] [-rt]
-h Display help contents
-m Checkout patmos-misc repository
-t Build patmos toolchain except the emulator
-e Build patmos toolchain including the emulator
-r Build rtems for patmos
-rt Download rtems examples
-rs Build rtems for patmos without cloning rtems-src
EOT
}
if [[ ! -d $tcrest_dir ]]; then
mkdir $tcrest_dir
fi
for i in ${@:1}
do
case "$i" in
"-m" | "-M")
rm -rf $misc_dir
git clone https://github.com/t-crest/patmos-misc.git $misc_dir
;;
"-r" | "-R")
build_rtems=true
run_bootstrap=true
;;
"-rs" | "-RS")
build_rtems=true
get_rtems=false
;;
"-rt" | "-RT")
build_rtems_examples=true
;;
"-t" | "-T")
build_toolchain=true
;;
"-e" | "-E")
build_emulator=true
build_toolchain=true
;;
"-h" | "-H")
usage
exit 1
;;
*)
build_args="$build_args $i"
;;
esac
done
if [[ $build_toolchain == "true" ]]; then
if [[ ! -f $misc_dir/build.sh ]]; then
echo "error: "$(basename $misc_dir)" not found"
exit 1
fi
CFGFILE=$misc_dir/build.cfg
sed -e 's/ROOT_DIR=$(pwd)/ROOT_DIR='$(echo $build_dir | awk '{gsub("/", "\\/"); print}')'/g' $misc_dir/build.cfg.dist > $CFGFILE
sed -i 's/TARGET=\"'$old_target'\"/TARGET=\"'$new_target'\"/g' $CFGFILE
sed -i 's/BUILD_EMULATOR=true/BUILD_EMULATOR='$build_emulator'/g' $CFGFILE
sed -i 's/#GOLD_CXXFLAGS/GOLD_CXXFLAGS/g' $CFGFILE
if [[ $build_llvm_release == "true" ]]; then
sed -i 's/LLVM_BUILD_TYPE=Debug/LLVM_BUILD_TYPE=Release/g' $CFGFILE
else
sed -i 's/LLVM_BUILD_TYPE=Release/LLVM_BUILD_TYPE=Debug/g' $CFGFILE
fi
if [ -f $CFGFILE ]; then
source $CFGFILE
fi
$misc_dir/./build.sh $build_args
if [[ $new_target == "patmos-unknown-rtems" ]]; then
./target-change.sh $build_dir
fi
cd $build_dir
build_dir=$(pwd)
cd $pwd
grep -Fxq "export PATH=\${PATH}:"$build_dir"/local/bin" ~/.bashrc
if [[ $? = 1 ]]; then
add2bashrc "export PATH=\${PATH}:"$build_dir"/local/bin"
export PATH=${PATH}":"$build_dir"/local/bin"
fi
grep -Fxq "export PATH=\${PATH}:"$build_dir"/patmos/simulator/build/src" ~/.bashrc
if [[ $? = 1 ]]; then
add2bashrc "export PATH=\${PATH}:"$build_dir"/patmos/simulator/build/src"
export PATH=${PATH}":"$build_dir"/patmos/simulator/build/src"
fi
fi
if [[ $build_rtems == "true" ]]; then
if [[ $get_rtems == "true" ]]; then
if [[ -d $rtems_src_dir ]]; then
echo "error: "$(basename $rtems_src_dir)" not empty directory"
exit 1
fi
git clone https://github.com/t-crest/rtems.git $rtems_src_dir
fi
if [[ $run_bootstrap == "true" ]]; then
cd $rtems_src_dir
./bootstrap -p
./bootstrap
fi
rm -rf $rtems_build_dir
mkdir $rtems_build_dir
rm -rf $rtems_install_dir
mkdir $rtems_install_dir
cd $rtems_install_dir
rtems_install_dir=$(pwd)
cd $rtems_build_dir
$rtems_src_dir/configure --target=patmos-unknown-rtems --disable-posix --disable-networking --disable-cxx --enable-tests --enable-rtemsbsp=$rtems_bsp --prefix=$rtems_install_dir
make install
grep -Fxv "export RTEMS_MAKEFILE_PATH="$rtems_install_dir"/patmos-unknown-rtems/"$rtems_bsp ~/.bashrc > tmp.txt
mv tmp.txt ~/.bashrc
add2bashrc "export RTEMS_MAKEFILE_PATH="$rtems_install_dir"/patmos-unknown-rtems/"$rtems_bsp
export RTEMS_MAKEFILE_PATH"="$rtems_install_dir"/patmos-unknown-rtems/"$rtems_bsp
#rm -rf $pwd
fi
if [[ $build_rtems_examples == "true" ]]; then
git clone https://github.com/RTEMS/examples-v2 $rtems_examples_dir
fi