-
Notifications
You must be signed in to change notification settings - Fork 0
/
make.cross
executable file
·249 lines (206 loc) · 5.09 KB
/
make.cross
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
#!/bin/bash
# $ARCH can be passed in 4 ways:
# - make.i386 # make it a symlink to this script
# - make.cross ARCH=i386
# - cd obj-i386; make.cross
# - export ARCH=i386; make.cross
if [[ ! "$0" =~ 'make.cross' && "$0" =~ make\.([a-z0-9_]+) ]]; then
export ARCH="${BASH_REMATCH[1]}"
elif [[ "$*" =~ ARCH=([a-z0-9_]+) ]]; then
export ARCH="${BASH_REMATCH[1]}"
elif [[ ${PWD##*-} =~ ^(i386|x86_64|alpha|arm|arm64|avr32|blackfin|c6x|cris|frv|h8300|hexagon|ia64|m32r|m68k|microblaze|mips|mn10300|openrisc|parisc|powerpc|s390|score|sh|sh64|sparc|sparc32|sparc64|tile|tilepro|tilegx|um|unicore32|xtensa)$ ]]; then
export ARCH=${PWD##*-}
elif [[ ! $ARCH ]]; then
export ARCH=x86_64
fi
[[ "$*" =~ ARCH=([a-z0-9_]+) ]] && [[ $ARCH != ${BASH_REMATCH[1]} ]] && {
echo "Conflicting ARCH specified! $ARCH ${BASH_REMATCH[1]}"
exit 1
}
shopt -s nullglob
install_packages()
{
[[ ! -x /usr/bin/xz || ! -x /usr/bin/lftp ]] && {
if [[ -x /usr/bin/apt-get ]]; then
echo apt-get install xz-utils lftp
sudo apt-get install xz-utils lftp
else
echo Please install: xz-utils lftp
exit 1
fi
}
}
download_extract()
{
local URL="$1"
echo lftpget -c $URL
lftpget -c $URL
local file=$(basename $URL)
echo tar Jxf $file -C $HOME/local
tar Jxf $file -C $HOME/local
}
install_crosstool()
{
local URL=https://www.kernel.org/pub/tools/crosstool/files/bin
local list=/tmp/crosstool-files
[[ -s $list ]] || {
local os_bit=$(getconf LONG_BIT)
if [[ $os_bit = 32 ]]; then
local os_arch=i686
else
local os_arch=x86_64
fi
lftp -c "open $URL && find $os_arch > $list" || exit
}
local file=$(grep "${gcc_arch}.*\.tar\.xz" $list | tail -1)
[[ $file ]] || {
echo "Cannot find $gcc_arch under $URL check $list"
exit 1
}
download_extract "$URL/$file"
}
install_linaro()
{
local URL='http://releases.linaro.org/14.08/components/toolchain/binaries'
local file='gcc-linaro-aarch64-linux-gnu-4.9-2014.08_linux.tar.xz'
download_extract "$URL/$file"
local dir=$HOME/local/$(basename $file .tar.xz)
local cross_gcc_version=($dir/bin/${gcc_arch}-gcc-*.*.*)
local cross_gcc_version=${cross_gcc_version##*-}
echo mkdir -p $HOME/local/gcc-$cross_gcc_version
mkdir -p $HOME/local/gcc-$cross_gcc_version
echo mv $dir $HOME/local/gcc-$cross_gcc_version/$gcc_arch
mv $dir $HOME/local/gcc-$cross_gcc_version/$gcc_arch
}
install_crosstool1()
{
local URL=http://chat.vectorindia.net/crosstool/
local list=/tmp/crosstool-files1
[[ -s $list ]] || {
local os_bit=$(getconf LONG_BIT)
if [[ $os_bit = 32 ]]; then
local os_arch=i686
else
local os_arch=x86_64
fi
lftp -c "open $URL && find $os_arch > $list" || exit
}
local file=$(grep "${gcc_arch}.*\.tar\.xz" $list | tail -1)
[[ $file ]] || {
echo "Cannot find $gcc_arch under $URL check $list"
return
}
download_extract "$URL/$file"
}
install_cross_compiler()
{
# install_packages
install_crosstool
}
install_cross_compiler1()
{
# install_packages
if [[ $gcc_arch =~ 'aarch64' ]]; then
install_linaro
else
install_crosstool1
fi
}
setup_crosstool()
{
local gcc_arch
local gcc_exec
case $ARCH in
i386|x86_64)
gcc_arch=
;;
um)
gcc_arch=
;;
arm)
gcc_arch=arm-unknown-linux-gnueabi
;;
arm64)
gcc_arch=aarch64-linux-gnu
;;
powerpc)
gcc_arch=powerpc64-linux
;;
blackfin)
gcc_arch=bfin-uclinux
;;
sh)
gcc_arch=sh4-linux
;;
parisc)
if grep -s -q 'CONFIG_64BIT=y' $SRC_ROOT/arch/parisc/configs/$config; then
gcc_arch=hppa64-linux
else
gcc_arch=hppa-linux
fi
;;
openrisc)
gcc_arch=or32-linux
;;
s390)
gcc_arch=s390x-linux
;;
tile|tilegx)
gcc_arch=tilegx-linux
;;
tilepro)
gcc_arch=tilepro-linux-gnu
;;
mn10300)
gcc_arch=am33_2.0-linux
;;
h8300)
gcc_arch=h8300-elf
;;
*)
gcc_arch=$ARCH-linux
;;
esac
if [[ $gcc_arch ]]; then
gcc_exec=($HOME/local/gcc-*/${gcc_arch}/bin/${gcc_arch}-gcc)
[[ -x $gcc_exec ]] || install_cross_compiler1
gcc_exec=($HOME/local/gcc-*/${gcc_arch}/bin/${gcc_arch}-gcc)
[[ -x $gcc_exec ]] || install_cross_compiler
gcc_exec=($HOME/local/gcc-*/${gcc_arch}/bin/${gcc_arch}-gcc)
[[ -x $gcc_exec ]] || {
echo "No cross compiler for $ARCH"
exit
}
# use highest available version
gcc_exec=${gcc_exec[-1]}
opt_cross="CROSS_COMPILE=${gcc_exec%gcc}"
else
opt_cross=
fi
# export PATH=$PATH:$HOME/gcc-*/${gcc_arch}/bin
echo $PATH
}
#rm -f /tmp/crosstool-files
#rm -f /tmp/crosstool-files1
#rm -rf $HOME/local/gcc-4.6.3-nolibc/bfin-uclinux
#rm -rf $HOME/local/gcc-4.9.0-nolibc/powerpc64-linux
setup_crosstool
[[ "$*" =~ (-j|--jobs) ]] || {
nr_cpu=$(getconf _NPROCESSORS_CONF)
opt_jobs="--jobs=$((nr_cpu * 2))"
}
[[ "$*" =~ "ARCH=$ARCH" ]] || {
opt_arch="ARCH=$ARCH"
}
if [ -d obj-$ARCH ]; then
export KBUILD_OUTPUT=obj-$ARCH
O=KBUILD_OUTPUT=obj-$ARCH
fi
[[ -f .make-env ]] && source ./.make-env
if [[ -d source && -L source ]]; then
echo make -C source O=$PWD $opt_arch $opt_cross $subarch $opt_jobs "$@"
exec make -C source O=$PWD $opt_arch $opt_cross $subarch $opt_jobs "$@"
else
echo make $O $opt_arch $opt_cross $subarch $opt_jobs "$@"
exec make $O $opt_arch $opt_cross $subarch $opt_jobs "$@"
fi