blob: 8abc50acfee8cc48daaadaf25b4ef5f67d31ed85 (
plain)
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
|
#!/bin/sh -e
export CC=clang
export CXX=clang++
export LD=ld.lld
export MAPLE=$(pwd)/maple
export THREADS=$(nproc)
export HOST=x86_64-unknown-linux-musl
# A simplified FHS variant with symlinks for backwards compatibility ~ahill
# TODO: Where does /usr/com fit into all of this (shared state directory)? ~ahill
mkdir -p $MAPLE/bin
mkdir -p $MAPLE/boot
mkdir -p $MAPLE/boot/EFI/BOOT/
mkdir -p $MAPLE/dev
mkdir -p $MAPLE/etc
mkdir -p $MAPLE/home
mkdir -p $MAPLE/lib
# TODO: Does it make sense to have this long-term? Anything that depends on
# libc++ fails to link without it, but this should be fixed via a
# configuration change in LLVM. ~ahill
ln -s . $MAPLE/lib/$HOST
mkdir -p $MAPLE/maple/sources
mkdir -p $MAPLE/mnt
mkdir -p $MAPLE/proc
mkdir -p $MAPLE/run
mkdir -p $MAPLE/sbin
mkdir -p $MAPLE/sys
mkdir -p $MAPLE/tmp
mkdir -p $MAPLE/usr
ln -s ../bin $MAPLE/usr/bin
mkdir -p $MAPLE/usr/include
ln -s ../lib $MAPLE/usr/lib
ln -s ../lib $MAPLE/usr/libexec
ln -s ../sbin $MAPLE/usr/sbin
mkdir -p $MAPLE/usr/share
mkdir -p $MAPLE/var
mkdir -p $MAPLE/var/cache
mkdir -p $MAPLE/var/lib
ln -s ../run/lock $MAPLE/var/lock
mkdir -p $MAPLE/var/log
ln -s ../run $MAPLE/var/run
mkdir -p $MAPLE/var/spool
mkdir -p $MAPLE/var/tmp
mkdir -p build
cd build
# LLVM Build
tar xf ../sources/llvm-project-*.tar*
cd llvm-project-*/
cmake -B stage1 -G Ninja -S llvm \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=$MAPLE/maple/tools \
-DCLANG_DEFAULT_CXX_STDLIB=libc++ \
-DCLANG_DEFAULT_RTLIB=compiler-rt \
-DCLANG_DEFAULT_UNWINDLIB=libunwind \
-DCOMPILER_RT_USE_BUILTINS_LIBRARY=ON \
-DLIBCXX_CXX_ABI=libcxxabi \
-DLIBCXX_HAS_MUSL_LIBC=ON \
-DLIBCXX_USE_COMPILER_RT=ON \
-DLIBCXXABI_USE_COMPILER_RT=ON \
-DLIBCXXABI_USE_LLVM_UNWINDER=ON \
-DLIBUNWIND_ENABLE_ASSERTIONS=OFF \
-DLIBUNWIND_USE_COMPILER_RT=ON \
-DLLVM_BUILD_LLVM_DYLIB=ON \
-DLLVM_ENABLE_LIBCXX=ON \
-DLLVM_ENABLE_PROJECTS="clang;lld;llvm" \
-DLLVM_ENABLE_RUNTIMES="compiler-rt;libunwind;libcxxabi;libcxx" \
-DLLVM_HOST_TRIPLE=$HOST \
-DLLVM_INSTALL_BINUTILS_SYMLINKS=ON \
-DLLVM_INSTALL_UTILS=ON \
-DLLVM_LINK_LLVM_DYLIB=ON \
-DLLVM_TARGETS_TO_BUILD=X86 \
-DCMAKE_BUILD_WITH_INSTALL_RPATH=ON
cmake --build stage1
cmake --install stage1
cd ..
export CC="$MAPLE/maple/tools/bin/clang"
export CXX="$MAPLE/maple/tools/bin/clang++"
export CFLAGS="-O3 -march=skylake -pipe --sysroot=$MAPLE"
export CXXFLAGS="$CFLAGS"
export LD=$MAPLE/maple/tools/bin/ld.lld
export PATH="$MAPLE/maple/tools/bin:$PATH"
# Linux Headers
tar xf ../sources/linux-*.tar*
cd linux-*/
LLVM=1 make -j $THREADS mrproper
LLVM=1 make -j $THREADS headers_install INSTALL_HDR_PATH=$MAPLE/usr
cd ..
# musl Build
tar xf ../sources/musl-*.tar*
cd musl-*/
./configure --disable-static --includedir=/usr/include --prefix=""
make -j $THREADS
make -j $THREADS install DESTDIR=$MAPLE
# NOTE: musl provides static libraries for POSIX libraries such as libm, but
# fails to provide shared versions which will breaks builds later on.
# Granted, they are useless since libc.so contains all the functionality
# we need, but it is needed for compatibility. As of April 5th, 2025, zsh
# is known to be misconfigured as a result of missing libraries. ~ahill
for lib in $(grep "EMPTY_LIB_NAMES =" Makefile | sed "s/EMPTY_LIB_NAMES = //"); do
ln -s libc.so $MAPLE/lib/lib$lib.so
done
# NOTE: musl has some witchcraft associated with it that allows it to function
# as an implementation of ldd. Honestly, the idea of a library with as an
# entry point is something I have never thought of before, but I'm
# interested in exploring the possibilities. ~ahill
ln -s /lib/ld-musl-x86_64.so.1 $MAPLE/bin/ldd
cd ..
# dash Build
tar xf ../sources/dash-*.tar*
cd dash-*/
./configure \
--datarootdir=/usr/share \
--exec-prefix="" \
--includedir=/usr/include \
--libexecdir=/lib \
--prefix="" \
--sharedstatedir=/usr/com
make -j $THREADS
make -j $THREADS install DESTDIR=$MAPLE
ln -s dash $MAPLE/bin/sh
cd ..
# m4 Build
tar xf ../sources/m4-*.tar*
cd m4-*/
./configure \
--datarootdir=/usr/share \
--disable-nls \
--enable-c++ \
--includedir=/usr/include \
--libexecdir=/lib \
--prefix="" \
--sharedstatedir=/usr/com
make -j $THREADS
make -j $THREADS install DESTDIR=$MAPLE
cd ..
# Coreutils Build
tar xf ../sources/coreutils-*.tar*
cd coreutils-*/
./configure \
--datarootdir=/usr/share \
--disable-nls \
--enable-install-program=hostname \
--includedir=/usr/include \
--libexecdir=/lib \
--prefix="" \
--sharedstatedir=/usr/com
make -j $THREADS
make -j $THREADS install DESTDIR=$MAPLE
cd ..
# Diffutils Build
tar xf ../sources/diffutils-*.tar*
cd diffutils-*/
./configure \
--disable-nls \
--exec-prefix="" \
--libexecdir=/lib \
--localstatedir=/var \
--prefix=/usr \
--sysconfdir=/etc
make -j $THREADS
make -j $THREADS install DESTDIR=$MAPLE
cd ..
# Findutils Build
tar xf ../sources/findutils-*.tar*
cd findutils-*/
./configure \
--datarootdir=/usr/share \
--disable-nls \
--exec-prefix="" \
--libexecdir=/lib \
--localstatedir=/var \
--prefix=/usr \
--sysconfdir=/etc
make -j $THREADS
make -j $THREADS install DESTDIR=$MAPLE
cd ..
# Grep Build
tar xf ../sources/grep-*.tar*
cd grep-*/
./configure \
--datarootdir=/usr/share \
--disable-nls \
--exec-prefix="" \
--libexecdir=/lib \
--localstatedir=/var \
--prefix=/usr \
--sysconfdir=/etc
make -j $THREADS
make -j $THREADS install DESTDIR=$MAPLE
cd ..
# Gzip Build
tar xf ../sources/gzip-*.tar*
cd gzip-*/
./configure \
--datarootdir=/usr/share \
--exec-prefix="" \
--libexecdir=/lib \
--localstatedir=/var \
--prefix=/usr \
--sysconfdir=/etc
make -j $THREAD
make -j $THREAD install DESTDIR=$MAPLE
cd ..
# Make Build
tar xf ../sources/make-*.tar*
cd make-*/
./configure \
--datarootdir=/usr/share \
--disable-nls \
--enable-year2038 \
--exec-prefix="" \
--libexecdir=/lib \
--localstatedir=/var \
--prefix=/usr \
--sysconfdir=/etc
make -j $THREAD
make -j $THREAD install DESTDIR=$MAPLE
cd ..
# Sed Build
tar xf ../sources/sed-*.tar*
cd sed-*/
./configure \
--datarootdir=/usr/share \
--disable-i18n \
--disable-nls \
--exec-prefix="" \
--libexecdir=/lib \
--localstatedir=/var \
--prefix=/usr \
--sysconfdir=/etc
make -j $THREAD
make -j $THREAD install DESTDIR=$MAPLE
cd ..
# Tar Build
tar xf ../sources/tar-*.tar*
cd tar-*/
./configure \
--datarootdir=/usr/share \
--disable-nls \
--exec-prefix="" \
--libexecdir=/lib \
--localstatedir=/var \
--prefix=/usr \
--sysconfdir=/etc
make -j $THREAD
make -j $THREAD install DESTDIR=$MAPLE
cd ..
# Xz Build
tar xf ../sources/xz-*.tar*
cd xz-*/
./configure \
--datarootdir=/usr/share \
--disable-doc \
--disable-nls \
--disable-static \
--enable-year2038 \
--exec-prefix="" \
--libexecdir=/lib \
--localstatedir=/var \
--prefix=/usr \
--sysconfdir=/etc
make -j $THREAD
make -j $THREAD install DESTDIR=$MAPLE
cd ..
# Gawk Build
tar xf ../sources/gawk-*.tar*
cd gawk-*/
./configure \
--disable-mpfr \
--disable-nls \
--exec-prefix="" \
--libexecdir=/lib \
--localstatedir=/var \
--prefix=/usr \
--sysconfdir=/etc
make -j $THREADS
make -j $THREADS install DESTDIR=$MAPLE
cd ..
# LLVM Build (Stage 2)
# NOTE: We are removing the sysroot option from CFLAGS and CXXFLAGS to prevent a
# potential conflict with CMake. Adapted from Nick's contribution. ~ahill
export CFLAGS=$(echo $CFLAGS | sed "s/--sysroot=\S*//")
export CXXFLAGS=$(echo $CXXFLAGS | sed "s/--sysroot=\S*//")
tar xf ../sources/llvm-project-*.tar*
cd llvm-project-*/
TOOLCHAIN_FILE=$HOST-maple-clang.cmake
# NOTE: First time doing this. Did I do it right? ~ahill
echo "set(CMAKE_SYSTEM_NAME Linux)" > $TOOLCHAIN_FILE
echo "set(CMAKE_SYSROOT $MAPLE)" >> $TOOLCHAIN_FILE
echo "set(CMAKE_C_COMPILER_TARGET $HOST)" >> $TOOLCHAIN_FILE
echo "set(CMAKE_CXX_COMPILER_TARGET $HOST)" >> $TOOLCHAIN_FILE
echo "set(CMAKE_C_FLAGS_INIT \"$CFLAGS\")" >> $TOOLCHAIN_FILE
echo "set(CMAKE_CXX_FLAGS_INIT \"$CXXFLAGS\")" >> $TOOLCHAIN_FILE
echo "set(CMAKE_LINKER_TYPE LLD)" >> $TOOLCHAIN_FILE
echo "set(CMAKE_C_COMPILER \"$CC\")" >> $TOOLCHAIN_FILE
echo "set(CMAKE_CXX_COMPILER \"$CXX\")" >> $TOOLCHAIN_FILE
echo "set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)" >> $TOOLCHAIN_FILE
echo "set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)" >> $TOOLCHAIN_FILE
echo "set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)" >> $TOOLCHAIN_FILE
echo "set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)" >> $TOOLCHAIN_FILE
# TODO: Is it possible to prevent CMake from building static libraries? ~ahill
# NOTE: compiler-rt fails to build on musl because execinfo.h is missing.
# Disabling COMPILER_RT_BUILD_GWP_ASAN works. ~ahill
# See also: https://github.com/llvm/llvm-project/issues/60687
cmake -B stage2 -G Ninja -S llvm \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=$MAPLE/usr \
-DCMAKE_TOOLCHAIN_FILE=$(pwd)/$TOOLCHAIN_FILE \
-DCLANG_DEFAULT_CXX_STDLIB=libc++ \
-DCLANG_DEFAULT_RTLIB=compiler-rt \
-DCLANG_DEFAULT_UNWINDLIB=libunwind \
-DCLANG_VENDOR=Maple \
-DCOMPILER_RT_BUILD_GWP_ASAN=OFF \
-DCOMPILER_RT_USE_BUILTINS_LIBRARY=ON \
-DLIBCXX_CXX_ABI=libcxxabi \
-DLIBCXX_HAS_MUSL_LIBC=ON \
-DLIBCXX_USE_COMPILER_RT=ON \
-DLIBCXXABI_USE_COMPILER_RT=ON \
-DLIBCXXABI_USE_LLVM_UNWINDER=ON \
-DLIBUNWIND_ENABLE_ASSERTIONS=OFF \
-DLIBUNWIND_USE_COMPILER_RT=ON \
-DLLVM_BUILD_LLVM_DYLIB=ON \
-DLLVM_ENABLE_LIBCXX=ON \
-DLLVM_ENABLE_LLD=ON \
-DLLVM_ENABLE_PROJECTS="clang;lld;lldb;llvm" \
-DLLVM_ENABLE_RUNTIMES="compiler-rt;libunwind;libcxxabi;libcxx" \
-DLLVM_ENABLE_ZSTD=OFF \
-DLLVM_HOST_TRIPLE=$HOST \
-DLLVM_INSTALL_BINUTILS_SYMLINKS=ON \
-DLLVM_INSTALL_UTILS=ON \
-DLLVM_LINK_LLVM_DYLIB=ON \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DCMAKE_BUILD_WITH_INSTALL_RPATH=ON
cmake --build stage2
cmake --install stage2
ln -s clang $MAPLE/bin/cc
ln -s clang++ $MAPLE/bin/c++
ln -s ld.lld $MAPLE/bin/ld
cd ..
cd ..
# Copy the necessary configuration files to the bootstrap
cp limine.conf $MAPLE/boot/
cp linux.$(uname -m).config $MAPLE/maple/
|