This repository has been archived by the owner on Oct 15, 2022. It is now read-only.
forked from MassOS-Linux/MassOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstage1.sh
executable file
·292 lines (292 loc) · 9.49 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
289
290
291
292
#!/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
# Setup the environment.
MASSOS="$PWD"/massos-rootfs
MASSOS_TARGET=x86_64-massos-linux-gnu
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)"
# 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"
# Binutils (Pass 1).
cd "$SRC"
tar -xf binutils-2.38.tar.xz
cd binutils-2.38
mkdir build; cd build
../configure --prefix="$MASSOS"/tools --with-sysroot="$MASSOS" --target=$MASSOS_TARGET --disable-nls --disable-werror
make
make -j1 install
cd ../..
rm -rf binutils-2.38
# GCC (Pass 1).
tar -xf gcc-11.2.0.tar.xz
cd gcc-11.2.0
tar -xf ../gmp-6.2.1.tar.xz
mv gmp-6.2.1 gmp
tar -xf ../mpfr-4.1.0.tar.xz
mv mpfr-4.1.0 mpfr
tar -xf ../mpc-1.2.1.tar.gz
mv mpc-1.2.1 mpc
mkdir build; cd build
../configure --target=$MASSOS_TARGET --prefix="$MASSOS"/tools --enable-languages=c,c++ --with-glibc-version=2.11 --with-sysroot="$MASSOS" --with-newlib --without-headers --enable-default-ssp --enable-initfini-array --disable-nls --disable-shared --disable-multilib --disable-decimal-float --disable-threads --disable-libatomic --disable-libgomp --disable-libquadmath --disable-libssp --disable-libvtv --disable-libstdcxx
make
make install
cd ..
cat gcc/limitx.h gcc/glimits.h gcc/limity.h > `dirname $($MASSOS_TARGET-gcc -print-libgcc-file-name)`/install-tools/include/limits.h
cd ..
rm -rf gcc-11.2.0
# Linux API Headers.
tar -xf linux-5.17.1.tar.xz
cd linux-5.17.1
make headers
find usr/include -name '.*' -delete
rm usr/include/Makefile
cp -r usr/include "$MASSOS"/usr
cd ..
rm -rf linux-5.17.1
# Glibc
tar -xf glibc-2.35.tar.xz
cd glibc-2.35
patch -Np1 -i ../patches/glibc-2.35-FHSCompliance.patch
mkdir build; cd build
echo "rootsbindir=/usr/sbin" > configparms
../configure --prefix=/usr --host=$MASSOS_TARGET --build=$(../scripts/config.guess) --enable-kernel=3.2 --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/$MASSOS_TARGET/*/install-tools/mkheaders
cd ../..
rm -rf glibc-2.35
# libstdc++ from GCC (Pass 1).
tar -xf gcc-11.2.0.tar.xz
cd gcc-11.2.0
mkdir build; cd build
../libstdc++-v3/configure --host=$MASSOS_TARGET --build=$(../config.guess) --prefix=/usr --disable-multilib --disable-nls --disable-libstdcxx-pch --with-gxx-include-dir=/tools/$MASSOS_TARGET/include/c++/$($MASSOS_TARGET-gcc --version | head -n1 | cut -d')' -f2 | sed 's/ //')
make
make DESTDIR="$MASSOS" install
cd ../..
rm -rf gcc-11.2.0
# Compiler flags for MassOS. We prefer to optimise for size.
CFLAGS="-w -Os -pipe"
CXXFLAGS="-w -Os -pipe"
export CFLAGS CXXFLAGS
# m4.
tar -xf m4-1.4.19.tar.xz
cd m4-1.4.19
./configure --prefix=/usr --host=$MASSOS_TARGET --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=$MASSOS_TARGET --build=$(./config.guess) --mandir=/usr/share/man --with-manpage-format=normal --with-shared --without-debug --without-ada --without-normal --enable-widec
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.1.16.tar.gz
cd bash-5.1.16
./configure --prefix=/usr --build=$(support/config.guess) --host=$MASSOS_TARGET --without-bash-malloc
make
make DESTDIR="$MASSOS" install
ln -s bash "$MASSOS"/bin/sh
cd ..
rm -rf bash-5.1.16
# Coreutils.
tar -xf coreutils-9.0.tar.xz
cd coreutils-9.0
./configure --prefix=/usr --host=$MASSOS_TARGET --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.0
# Diffutils.
tar -xf diffutils-3.8.tar.xz
cd diffutils-3.8
./configure --prefix=/usr --host=$MASSOS_TARGET
make
make DESTDIR="$MASSOS" install
cd ..
rm -rf diffutils-3.8
# File
tar -xf file-5.41.tar.gz
cd file-5.41
mkdir build; cd build
../configure --disable-bzlib --disable-libseccomp --disable-xzlib --disable-zlib
make
cd ..
./configure --prefix=/usr --host=$MASSOS_TARGET --build=$(./config.guess)
make FILE_COMPILE=$(pwd)/build/src/file
make DESTDIR="$MASSOS" install
cd ..
rm -rf file-5.41
# Findutils.
tar -xf findutils-4.9.0.tar.xz
cd findutils-4.9.0
./configure --prefix=/usr --localstatedir=/var/lib/locate --host=$MASSOS_TARGET --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
sed -i 's/extras//' Makefile.in
./configure --prefix=/usr --host=$MASSOS_TARGET --build=$(./config.guess)
make
make DESTDIR="$MASSOS" install
cd ..
rm -rf gawk-5.1.0
# Grep.
tar -xf grep-3.7.tar.xz
cd grep-3.7
./configure --prefix=/usr --host=$MASSOS_TARGET
make
make DESTDIR="$MASSOS" install
cd ..
rm -rf grep-3.7
# Gzip.
tar -xf gzip-1.11.tar.xz
cd gzip-1.11
./configure --prefix=/usr --host=$MASSOS_TARGET
make
make DESTDIR="$MASSOS" install
cd ..
rm -rf gzip-1.11
# Make.
tar -xf make-4.3.tar.gz
cd make-4.3
./configure --prefix=/usr --without-guile --host=$MASSOS_TARGET --build=$(build-aux/config.guess)
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=$MASSOS_TARGET --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=$MASSOS_TARGET
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=$MASSOS_TARGET --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.5.tar.xz
cd xz-5.2.5
./configure --prefix=/usr --host=$MASSOS_TARGET --build=$(build-aux/config.guess) --disable-static --docdir=/usr/share/doc/xz-5.2.5
make
make DESTDIR="$MASSOS" install
cd ..
rm -rf xz-5.2.5
# Unset compiler flags for building criticial toolchain tools.
unset CFLAGS CXXFLAGS
# Binutils (Pass 2).
tar -xf binutils-2.38.tar.xz
cd binutils-2.38
sed '6009s/$add_dir//' -i ltmain.sh
mkdir build; cd build
../configure --prefix=/usr --build=$(../config.guess) --host=$MASSOS_TARGET --disable-nls --enable-shared --disable-werror --enable-64-bit-bfd
make
make -j1 DESTDIR="$MASSOS" install
install -m755 libctf/.libs/libctf.so.0.0.0 "$MASSOS"/usr/lib
cd ../..
rm -rf binutils-2.38
# GCC (Pass 2).
tar -xf gcc-11.2.0.tar.xz
cd gcc-11.2.0
tar -xf ../gmp-6.2.1.tar.xz
mv gmp-6.2.1 gmp
tar -xf ../mpfr-4.1.0.tar.xz
mv mpfr-4.1.0 mpfr
tar -xf ../mpc-1.2.1.tar.gz
mv mpc-1.2.1 mpc
mkdir build; cd build
mkdir -p $MASSOS_TARGET/libgcc
ln -s ../../../libgcc/gthr-posix.h $MASSOS_TARGET/libgcc/gthr-default.h
../configure CC_FOR_TARGET=$MASSOS_TARGET-gcc --build=$(../config.guess) --host=$MASSOS_TARGET --prefix=/usr --enable-languages=c,c++ --with-build-sysroot="$MASSOS" --enable-default-ssp --enable-initfini-array --disable-nls --disable-multilib --disable-decimal-float --disable-libatomic --disable-libgomp --disable-libquadmath --disable-libssp --disable-libvtv --disable-libstdcxx
make
make DESTDIR="$MASSOS" install
ln -s gcc "$MASSOS"/usr/bin/cc
cd ../..
rm -rf gcc-11.2.0
cd ../..
# Copy extra utilities and configuration files into the environment.
cp utils/{adduser,mass-chroot,mkinitramfs,mklocales,set-default-tar} "$MASSOS"/usr/sbin
cp utils/{bashrc,dircolors,fstab,group,hostname,hosts,inputrc,locale.conf,locales,lsb-release,massos-release,os-release,passwd,profile,resolv.conf,shells,vconsole.conf} "$MASSOS"/etc
cp utils/{un,}zman "$MASSOS"/usr/bin
cp utils/{busybox,kernel}-config "$SRC"
cp utils/massos-release.c "$SRC"
cp utils/massos-logo.png "$SRC"
cp utils/massos-logo-small.png "$SRC"
cp utils/massos-logo-extrasmall.png "$SRC"
cp utils/massos-logo-notext.png "$SRC"
cp utils/builtins "$SRC"
cp -r utils/extra-package-licenses "$SRC"
cp -r utils/skel "$MASSOS"/etc
mkdir -p "$MASSOS"/etc/profile.d
cp utils/*.sh "$MASSOS"/etc/profile.d
cp -r backgrounds "$SRC"
cp LICENSE "$SRC"
cp build-system.sh "$SRC"
echo -e "\nThe bootstrap system was built successfully."
echo "To build the full MassOS system, now run './stage2.sh' AS ROOT."