This repository has been archived by the owner on Apr 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
compiler.sh
executable file
·158 lines (145 loc) · 3.21 KB
/
compiler.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
#!/bin/sh
set -e
# Directories
BASE=$(pwd)
BUILD=$BASE/build
PREFIX=$BUILD/gcc
# Variables
JOPT=$1
if [ "$JOPT" = "" ]; then
read -p "-j flag is not set. Are you sure? [y/N]: " ans
[ "$ans" = y ] || [ "$ans" = Y ] || exit 1
fi
# Create dirs
mkdir -p $BUILD
mkdir -p $PREFIX
# args:
# check file
# name of step
# build function
cond_build() {
if [ ! -f $1 ]; then
echo Running: $2
$3 $1
else
echo Skipping: $2
fi
}
# Step 1: Get kernel headers
headers() {
cd compiler/linux
export KERNEL=kernel
make ARCH=arm INSTALL_HDR_PATH=$PREFIX/arm-linux-gnueabihf headers_install
cd $BASE
touch $1
}
# Step 2: Compile binutils
binutils() {
cd compiler/binutils-gdb
mkdir -p build
cd build
../configure \
--prefix=$PREFIX \
--target=arm-linux-gnueabihf \
--with-arch=armv6 \
--with-fpu=vpf \
--with-float=hard \
--disable-gdb \
--disable-werror \
--disable-multilib
make $JOPT
make install
cd $BASE
touch $1
}
# Step 3: Begin compiling gcc
gcc_stage1() {
cd compiler/gcc
contrib/download_prerequisites
mkdir -p build
cd build
../configure \
--prefix=$PREFIX \
--target=arm-linux-gnueabihf \
--enable-languages=c,c++ \
--with-arch=armv6 \
--with-fpu=vfp \
--with-float=hard \
--disable-gcov \
--enable-threads \
--with-glibc-version=2.36 \
--disable-multilib \
--disable-libsanitizer
make $JOPT all-gcc
make install-gcc
cd $BASE
touch $1
}
# Step 4: Begin compiling glibc
glibc_stage1() {
cd compiler/glibc
mkdir -p build
cd build
CC=$PREFIX/bin/arm-linux-gnueabihf-gcc \
LD=$PREFIX/bin/arm-linux-gnueabihf-ld \
AR=$PREFIX/bin/arm-linux-gnueabihf-ar \
RANLIB=$PREFIX/bin/arm-linux-gnueabihf-ranlib \
../configure \
--prefix=$PREFIX/arm-linux-gnueabihf \
--build=$MACHTYPE \
--host=arm-linux-gnueabihf \
--target=arm-linux-gnueabihf \
--with-arch=armv6 \
--with-fpu=vfp \
--with-float=hard \
--disable-profile \
--disable-werror \
--disable-multilib \
libc_cv_forced_unwind=yes \
libc_cv_cxx_link_ok=no
make install-bootstrap-headers=yes install-headers
make $JOPT csu/subdir_lib
install csu/crt1.o csu/crti.o csu/crtn.o $PREFIX/arm-linux-gnueabihf/lib
$PREFIX/bin/arm-linux-gnueabihf-gcc \
-nostdlib \
-nostartfiles \
-shared \
-x c /dev/null \
-o $PREFIX/arm-linux-gnueabihf/lib/libc.so
mkdir -p $PREFIX/arm-linux-gnueabihf/include/gnu
touch $PREFIX/arm-linux-gnueabihf/include/gnu/stubs.h
cd $BASE
touch $1
}
# Step 5: Compile libgcc
gcc_stage2() {
cd compiler/gcc/build
make $JOPT all-target-libgcc
make install-target-libgcc
cd $BASE
touch $1
}
# Step 6: Finish compiling glibc
glibc_stage2() {
cd compiler/glibc/build
make $JOPT
make install
cd $BASE
touch $1
}
# Step 7: Finish building gcc
gcc_final() {
cd compiler/gcc/build
make $JOPT
make install
cd $BASE
touch $1
}
# Build
cond_build $BUILD/.compiler_headers "copy kernel headers" headers
cond_build $BUILD/.compiler_binutils "binutils" binutils
cond_build $BUILD/.compiler_gcc_stage1 "gcc stage 1" gcc_stage1
cond_build $BUILD/.compiler_glibc_stage1 "glibc stage 1" glibc_stage1
cond_build $BUILD/.compiler_gcc_stage2 "gcc stage 2" gcc_stage2
cond_build $BUILD/.compiler_glibc_stage2 "glibc stage 2" glibc_stage2
cond_build $BUILD/.compiler_gcc_final "gcc final stage" gcc_final