This repository has been archived by the owner on Jan 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
stage1.sh
executable file
·288 lines (288 loc) · 10.4 KB
/
stage1.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
276
277
278
279
280
281
282
283
284
285
286
287
288
#!/bin/bash
#
# Build the environment which will be used to build the full OS later.
set -e
# Disabling hashing is useful so the newly built tools are detected.
set +h
# Ensure retrieve-sources.sh has been run first.
if [ ! -d sources ]; then
echo "Error: You must run retrieve-sources.sh first!" >&2
exit 1
fi
# Starting message.
echo "Starting Stage 1 Build..."
# Setup the environment.
MASSOS="$PWD"/massos-rootfs
PATH="$MASSOS"/tools/bin:$PATH
SRC="$MASSOS"/sources
CONFIG_SITE="$MASSOS"/usr/share/config.site
export MASSOS MASSOS_TARGET PATH SRC CONFIG_SITE
# Build in parallel using all available CPU cores.
export MAKEFLAGS="-j$(nproc)"
# Compiler flags for MassOS. We prefer to optimise for size.
CFLAGS="-Os -pipe"
CXXFLAGS="-Os -pipe"
export CFLAGS CXXFLAGS
# Setup the basic filesystem structure.
mkdir -p "$MASSOS"/{etc,var}
mkdir -p "$MASSOS"/usr/{bin,lib,sbin}
# Ensure the filesystem structure is unified.
ln -sf usr/bin "$MASSOS"/bin
ln -sf usr/lib "$MASSOS"/lib
ln -sf usr/sbin "$MASSOS"/sbin
ln -sf lib "$MASSOS"/usr/lib64
ln -sf usr/lib "$MASSOS"/lib64
# Directory where source tarballs will be placed while building.
# Temporary toolchain directory.
mkdir "$MASSOS"/tools
# Move sources into the temporary environment.
mv sources "$SRC"
# Copy patches into the temporary environment.
mkdir -p "$SRC"/patches
cp patches/* "$SRC"/patches
# Copy systemd units into the temporary environment.
cp -r utils/systemd-units "$SRC"
# Change to the sources directory.
cd "$SRC"
# Binutils (Initial build for bootstrapping).
tar -xf binutils-2.39.tar.xz
cd binutils-2.39
mkdir build; cd build
CFLAGS="-O2" CXXFLAGS="-O2" ../configure --prefix="$MASSOS"/tools --with-sysroot="$MASSOS" --target=x86_64-stage1-linux-gnu --with-pkgversion="MassOS Binutils 2.39" --enable-relro --disable-gprofng --disable-nls --disable-werror
make
make -j1 install
cd ../..
rm -rf binutils-2.39
# GCC (Initial build for bootstrapping).
tar -xf gcc-12.2.0.tar.xz
cd gcc-12.2.0
mkdir -p gmp mpfr mpc isl
tar -xf ../gmp-6.2.1.tar.xz -C gmp --strip-components=1
tar -xf ../mpfr-4.1.0.tar.xz -C mpfr --strip-components=1
tar -xf ../mpc-1.2.1.tar.gz -C mpc --strip-components=1
tar -xf ../isl-0.25.tar.xz -C isl --strip-components=1
sed -i '/m64=/s/lib64/lib/' gcc/config/i386/t-linux64
mkdir build; cd build
CFLAGS="-O2" CXXFLAGS="-O2" ../configure --prefix="$MASSOS"/tools --target=x86_64-stage1-linux-gnu --enable-languages=c,c++ --with-pkgversion="MassOS GCC 12.2.0" --with-glibc-version=2.36 --with-sysroot="$MASSOS" --with-newlib --without-headers --enable-default-ssp --enable-linker-build-id --disable-decimal-float --disable-libatomic --disable-libgomp --disable-libquadmath --disable-libssp --disable-libstdcxx --disable-libvtv --disable-multilib --disable-nls --disable-shared --disable-threads
make
make install
cat ../gcc/{limitx,glimits,limity}.h > "$MASSOS"/tools/lib/gcc/x86_64-stage1-linux-gnu/12.2.0/install-tools/include/limits.h
cd ../..
rm -rf gcc-12.2.0
# Linux API Headers.
tar -xf linux-6.0.tar.xz
cd linux-6.0
make headers
find usr/include -name '.*' -delete
rm -f usr/include/Makefile
cp -r usr/include "$MASSOS"/usr
cd ..
rm -rf linux-6.0
# Glibc
tar -xf glibc-2.36.tar.xz
cd glibc-2.36
patch -Np1 -i ../patches/glibc-2.36-multiplefixes.patch
mkdir build; cd build
echo "rootsbindir=/usr/sbin" > configparms
CFLAGS="-O2" CXXFLAGS="-O2" ../configure --prefix=/usr --host=x86_64-stage1-linux-gnu --build=$(../scripts/config.guess) --enable-kernel=3.2 --disable-default-pie --with-headers="$MASSOS"/usr/include libc_cv_slibdir=/usr/lib
make
make DESTDIR="$MASSOS" install
ln -sf ld-linux-x86-64.so.2 "$MASSOS"/usr/lib/ld-lsb-x86-64.so.3
sed '/RTLDLIST=/s@/usr@@g' -i "$MASSOS"/usr/bin/ldd
"$MASSOS"/tools/libexec/gcc/x86_64-stage1-linux-gnu/$(x86_64-stage1-linux-gnu-gcc -dumpversion)/install-tools/mkheaders
cd ../..
rm -rf glibc-2.36
# libstdc++ from GCC (Could not be built with bootstrap GCC).
tar -xf gcc-12.2.0.tar.xz
cd gcc-12.2.0
mkdir build; cd build
CFLAGS="-O2" CXXFLAGS="-O2" ../libstdc++-v3/configure --prefix=/usr --host=x86_64-stage1-linux-gnu --build=$(../config.guess) --disable-multilib --disable-nls --disable-libstdcxx-pch --with-gxx-include-dir=/tools/x86_64-stage1-linux-gnu/include/c++/$(x86_64-stage1-linux-gnu-gcc -dumpversion)
make
make DESTDIR="$MASSOS" install
cd ../..
rm -rf gcc-12.2.0
# m4.
tar -xf m4-1.4.19.tar.xz
cd m4-1.4.19
./configure --prefix=/usr --host=x86_64-stage1-linux-gnu --build=$(build-aux/config.guess)
make
make DESTDIR="$MASSOS" install
cd ..
rm -rf m4-1.4.19
# Ncurses.
tar -xf ncurses-6.3.tar.gz
cd ncurses-6.3
sed -i 's/mawk//' configure
mkdir build; cd build
../configure
make -C include
make -C progs tic
cd ..
./configure --prefix=/usr --host=x86_64-stage1-linux-gnu --build=$(./config.guess) --mandir=/usr/share/man --with-cxx-shared --with-manpage-format=normal --with-shared --without-ada --without-debug --without-normal --enable-widec --disable-stripping
make
make DESTDIR="$MASSOS" TIC_PATH=$(pwd)/build/progs/tic install
echo "INPUT(-lncursesw)" > "$MASSOS"/usr/lib/libncurses.so
cd ..
rm -rf ncurses-6.3
# Bash.
tar -xf bash-5.2.tar.gz
cd bash-5.2
./configure --prefix=/usr --host=x86_64-stage1-linux-gnu --build=$(support/config.guess) --without-bash-malloc
make
make DESTDIR="$MASSOS" install
ln -sf bash "$MASSOS"/bin/sh
cd ..
rm -rf bash-5.2
# Coreutils.
tar -xf coreutils-9.1.tar.xz
cd coreutils-9.1
./configure --prefix=/usr --host=x86_64-stage1-linux-gnu --build=$(build-aux/config.guess) --enable-install-program=hostname --enable-no-install-program=kill,uptime --with-packager="MassOS"
make
make DESTDIR="$MASSOS" install
mv "$MASSOS"/usr/bin/chroot "$MASSOS"/usr/sbin
mkdir -p "$MASSOS"/usr/share/man/man8
mv "$MASSOS"/usr/share/man/man1/chroot.1 "$MASSOS"/usr/share/man/man8/chroot.8
sed -i 's/"1"/"8"/' "$MASSOS"/usr/share/man/man8/chroot.8
cd ..
rm -rf coreutils-9.1
# Diffutils.
tar -xf diffutils-3.8.tar.xz
cd diffutils-3.8
./configure --prefix=/usr --host=x86_64-stage1-linux-gnu
make
make DESTDIR="$MASSOS" install
cd ..
rm -rf diffutils-3.8
# File
tar -xf file-5.43.tar.gz
cd file-5.43
mkdir build; cd build
../configure --disable-bzlib --disable-libseccomp --disable-xzlib --disable-zlib
make
cd ..
./configure --prefix=/usr --host=x86_64-stage1-linux-gnu --build=$(./config.guess)
make FILE_COMPILE=$(pwd)/build/src/file
make DESTDIR="$MASSOS" install
cd ..
rm -rf file-5.43
# Findutils.
tar -xf findutils-4.9.0.tar.xz
cd findutils-4.9.0
./configure --prefix=/usr --localstatedir=/var/lib/locate --host=x86_64-stage1-linux-gnu --build=$(build-aux/config.guess)
make
make DESTDIR="$MASSOS" install
cd ..
rm -rf findutils-4.9.0
# Gawk.
tar -xf gawk-5.1.0.tar.xz
cd gawk-5.1.0
./configure --prefix=/usr --host=x86_64-stage1-linux-gnu --build=$(./config.guess)
make
make DESTDIR="$MASSOS" install
cd ..
rm -rf gawk-5.1.0
# Grep.
tar -xf grep-3.8.tar.xz
cd grep-3.8
./configure --prefix=/usr --host=x86_64-stage1-linux-gnu
make
make DESTDIR="$MASSOS" install
cd ..
rm -rf grep-3.8
# Gzip.
tar -xf gzip-1.12.tar.xz
cd gzip-1.12
./configure --prefix=/usr --host=x86_64-stage1-linux-gnu
make
make DESTDIR="$MASSOS" install
cd ..
rm -rf gzip-1.12
# Make.
tar -xf make-4.3.tar.gz
cd make-4.3
./configure --prefix=/usr --host=x86_64-stage1-linux-gnu --build=$(build-aux/config.guess) --without-guile
make
make DESTDIR="$MASSOS" install
cd ..
rm -rf make-4.3
# Patch.
tar -xf patch-2.7.6.tar.xz
cd patch-2.7.6
./configure --prefix=/usr --host=x86_64-stage1-linux-gnu --build=$(build-aux/config.guess)
make
make DESTDIR="$MASSOS" install
cd ..
rm -rf patch-2.7.6
# Sed.
tar -xf sed-4.8.tar.xz
cd sed-4.8
./configure --prefix=/usr --host=x86_64-stage1-linux-gnu
make
make DESTDIR="$MASSOS" install
cd ..
rm -rf sed-4.8
# Tar.
tar -xf tar-1.34.tar.xz
cd tar-1.34
./configure --prefix=/usr --host=x86_64-stage1-linux-gnu --build=$(build-aux/config.guess) --program-prefix=g
make
make DESTDIR="$MASSOS" install
ln -sf gtar "$MASSOS"/usr/bin/tar
cd ..
rm -rf tar-1.34
# XZ.
tar -xf xz-5.2.7.tar.xz
cd xz-5.2.7
./configure --prefix=/usr --host=x86_64-stage1-linux-gnu --build=$(build-aux/config.guess) --disable-static
make
make DESTDIR="$MASSOS" install
cd ..
rm -rf xz-5.2.7
# Binutils (For stage 2, built using our new bootstrap toolchain).
tar -xf binutils-2.39.tar.xz
cd binutils-2.39
sed -i '6009s/$add_dir//' ltmain.sh
mkdir build; cd build
CFLAGS="-O2" CXXFLAGS="-O2" ../configure --prefix=/usr --host=x86_64-stage1-linux-gnu --build=$(../config.guess) --with-pkgversion="MassOS Binutils 2.39" --enable-relro --enable-shared --disable-gprofng --disable-nls --disable-werror
make
make -j1 DESTDIR="$MASSOS" install
cd ../..
rm -rf binutils-2.39
# GCC (For stage 2, built using our new bootstrap toolchain).
tar -xf gcc-12.2.0.tar.xz
cd gcc-12.2.0
mkdir -p gmp mpfr mpc isl
tar -xf ../gmp-6.2.1.tar.xz -C gmp --strip-components=1
tar -xf ../mpfr-4.1.0.tar.xz -C mpfr --strip-components=1
tar -xf ../mpc-1.2.1.tar.gz -C mpc --strip-components=1
tar -xf ../isl-0.25.tar.xz -C isl --strip-components=1
sed -i '/m64=/s/lib64/lib/' gcc/config/i386/t-linux64
sed -i '/thread_header =/s/@.*@/gthr-posix.h/' libgcc/Makefile.in libstdc++-v3/include/Makefile.in
mkdir build; cd build
CFLAGS="-O2" CXXFLAGS="-O2" ../configure --prefix=/usr --host=x86_64-stage1-linux-gnu --build=$(../config.guess) --target=x86_64-stage1-linux-gnu LDFLAGS_FOR_TARGET=-L"$PWD/x86_64-stage1-linux-gnu/libgcc" --with-build-sysroot="$MASSOS" --enable-languages=c,c++ --with-pkgversion="MassOS GCC 12.2.0" --enable-default-ssp --enable-initfini-array --enable-linker-build-id --disable-nls --disable-multilib --disable-decimal-float --disable-libatomic --disable-libgomp --disable-libquadmath --disable-libssp --disable-libvtv
make
make DESTDIR="$MASSOS" install
ln -sf gcc "$MASSOS"/usr/bin/cc
cd ../..
rm -rf gcc-12.2.0
cd ../..
# Remove bootstrap toolchain directory.
rm -rf "$MASSOS"/tools
# Remove temporary system documentation.
rm -rf "$MASSOS"/usr/share/{info,man,doc}/*
# Copy extra utilities and configuration files into the environment.
cp -r utils/etc/* "$MASSOS"/etc
cp utils/massos-release "$MASSOS"/etc
cp utils/programs/{adduser,mass-chroot,mkinitramfs,mklocales,set-default-tar} "$MASSOS"/usr/sbin
cp utils/programs/{un,}zman "$MASSOS"/usr/bin
cp utils/programs/massos-release.c "$SRC"
cp -r utils/build-configs/* "$SRC"
cp -r logo/* "$SRC"
cp utils/builtins "$SRC"
cp -r utils/extra-package-licenses "$SRC"
cp -r backgrounds "$SRC"
cp -r utils/man "$SRC"
cp LICENSE "$SRC"
cp build-system.sh "$SRC"
echo -e "\nThe Stage 1 bootstrap system was built successfully."
echo "To build the full MassOS system, now run './stage2.sh' AS ROOT."