-
Notifications
You must be signed in to change notification settings - Fork 14
/
bootstrap
executable file
·189 lines (157 loc) · 4.9 KB
/
bootstrap
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
#!/bin/bash
#set -x
scriptroot="$(cd "$(dirname "$0")" && pwd)"
printf "Bootstrap is at %s\n" "$scriptroot"
. "$scriptroot/toolchain/build-crossgcc-versions"
printf "Using gcc version: %s\n" "$gccver"
if [[ -z $TARGET ]]; then
TARGET=x86_64-dgos
echo TARGET not in environment, assumed $TARGET
fi
NPROC="$(nproc)"
function help() {
echo "-c Clean build"
echo "-o Optimized"
echo "-l LTO optimized"
echo "-q Quiet"
:
}
lto=
optimized=
cleanbuild=
quiet=
while getopts colh?qj arg
do
case $arg in
c ) cleanbuild=1 ; shift ;;
o ) optimized=1 ; shift ;;
l ) lto=1 ; shift ;;
q ) quiet=1 ; shift ;;
h ) help && exit ;;
? ) help && exit ;;
* ) echo "unrecognized option '$arg'" ; exit 1 ;;
esac
done
toolchain_build_dir=toolchain_build
toolchain_install_dir=toolchain_install
if ! [[ -z $cleanbuild ]]; then
echo "Cleaning toolchain_build/build" \
" $toolchain_build_dir/src $toolchain_install_dir..."
rm -rf "$toolchain_build_dir/build" "$toolchain_build_dir/src" \
"$toolchain_build_dir/build.log" "$toolchain_install_dir" || exit
fi
if ! which $TARGET-g++ || [[ ! -f toolchain_install/bin/$TARGET-g++ ]]; then
time AR=gcc-ar RANLIB=gcc-ranlib \
"$scriptroot/toolchain/build-crossgcc.bash" -a "$TARGET" \
-o toolchain_build \
-p toolchain_install -q || exit
printf "Toolchain built successfully\n"
fi
printf '# Run this command in a shell to use this: . ./set_toolchain_path\n' \
| tee "$toolchain_install_dir/set_toolchain_path" || exit
rm -f set_toolchain_path || exit
ln -rs "$toolchain_install_dir/set_toolchain_path" set_toolchain_path || exit
printf 'export PATH="%s/toolchain_install/bin:$PATH"\n' "$PWD" \
| tee -a set_toolchain_path || exit
toolchain_stdlib=$([[ -d $toolchain_install_dir ]] &&
find "$toolchain_install_dir" -type f -name stdbool.h |
grep -v freestand)
toolchain_ldscripts=$([[ -d $toolchain_install_dir ]] &&
find "$toolchain_install_dir" -type d -name ldscripts)
toolchain_include_dir=${toolchain_stdlib%/*}
toolchain_lib_dir=${toolchain_ldscripts%/*}
if [[ -z $toolchain_install_dir ]]; then
printf "No toolchain install dir\n"
exit 1
fi
if [[ -z $toolchain_include_dir ]]; then
printf "No toolchain include dir\n"
exit 1
fi
if [[ -z $toolchain_lib_dir ]]; then
printf "No toolchain lib dir\n"
exit 1
fi
printf "#This is automatically generated by bootstrap\n" > toolchain_config.mk
printf "TOOLCHAIN_DIR=$PWD/%s\n" "$toolchain_install_dir" \
>> toolchain_config.mk
printf "TOOLCHAIN_INCLUDE_PATH=$PWD/%s\n" "$toolchain_include_dir" \
>> toolchain_config.mk
printf "TOOLCHAIN_LIB_PATH=$PWD/%s\n" "$toolchain_lib_dir" \
>> toolchain_config.mk
export PATH="$PATH"":""$PWD/toolchain_install/bin"
printf "PATH=%s\n" "$PATH"
function join_by {
local IFS="$1"
shift
printf "%s" "$*"
}
export AR="$TARGET-gcc-ar"
export RANLIB="$TARGET-gcc-ranlib"
export NM="$TARGET-gcc-nm"
(cd -- "$scriptroot" &&
autoreconf -f &&
git submodule update --init) || exit
echo Bootstrapping sysroot
compileflags=( "-nostdlib" "-nostartfiles" )
configureflags=()
if [[ -n $lto ]]; then
echo "Enabling LTO"
configureflags+=("--enable-optimize")
configureflags+=("--enable-lto")
elif [[ -n $optimized ]]; then
echo "Enabling optimized"
configureflags+=("--enable-optimize")
fi
rm -rf sysroot || exit
"$scriptroot/configure" --host "$TARGET" \
CFLAGS="$(join_by ' ' ${compileflags[@]})" \
CXXFLAGS="$CFLAGS" \
LDFLAGS="$CFLAGS" \
$(join_by ' ' ${configureflags[@]}) "$@" && \
make -j "$NPROC" \
sysroot/lib/crt0.o \
sysroot/lib/32/crt0.o \
sysroot/lib/crt0pc32.o \
sysroot/lib/32/crt0pc32.o \
sysroot/lib/crt0pc64.o \
sysroot/lib/32/crt0pc64.o \
sysroot/lib/crt0pc80.o \
sysroot/lib/32/crt0pc80.o \
sysroot/lib/libc.a \
sysroot/lib/32/libc.a \
sysroot/lib/libm.a \
sysroot/lib/32/libm.a \
sysroot/lib/libstdc++.a \
sysroot/lib/32/libstdc++.a \
startupcode
if [[ -d sysroot/include ]]; then
echo Copying include files to toolchain install
cp -R -u -t "toolchain_install/lib/gcc/$TARGET/$gccver/include" \
sysroot/include/* && \
echo Successfully copied include files || exit
fi
if [[ -d sysroot/lib ]]; then
echo Copying lib files to toolchain install
cp -R -u -t "toolchain_install/lib/gcc/$TARGET/$gccver/" \
sysroot/lib/* && \
echo Successfully copied lib files || exit
fi
make -j "$NPROC" usrlib_headers || exit
echo Copying include files to toolchain install
cp -R -u -t "toolchain_install/lib/gcc/$TARGET/$gccver/include" \
sysroot/include/* && \
echo Successfully copied include files || exit
echo Copying lib files to toolchain install
cp -R -u -t "toolchain_install/lib/gcc/$TARGET/$gccver/" \
sysroot/lib/* && \
echo Successfully copied lib files || exit
compileflags=( "--sysroot sysroot" )
configureflags=()
echo flags: "${compileflags[@]}"
CFLAGS="$(join_by ' ' ${compileflags[@]})" \
CXXFLAGS="$CFLAGS" \
LDFLAGS="$CFLAGS" \
"$scriptroot/configure" --host "$TARGET" \
$(join_by ' ' "${configureflags[@]}") "$@" || exit
echo Completed successfully