-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_sysroot.sh
executable file
·53 lines (40 loc) · 1.93 KB
/
gen_sysroot.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
#!/bin/bash
# Define the source directory for object files (change ./build to your desired path)
src_dir="./build"
# Define paths for copying additional resources
include_source_dir="/home/lind-wasm/glibc/target/include"
crt1_source_path="/home/lind-wasm/glibc/lind_syscall/crt1.o"
lind_syscall_path="/home/lind-wasm/glibc/lind_syscall/lind_syscall.o" # Path to the lind_syscall.o file
# TARGET_TRIPLE = wasm32-wasi
TARGET_TRIPLE=wasm32-wasi-threads
# Define the output archive and sysroot directory
output_archive="sysroot/lib/wasm32-wasi/libc.a"
sysroot_dir="sysroot"
# First, remove the existing sysroot directory to start cleanly
rm -rf "$sysroot_dir"
# Find all .o files recursively in the source directory, ignoring stamp.o
object_files=$(find "$src_dir" -type f -name "*.o" ! \( -name "stamp.o" -o -name "argp-pvh.o" -o -name "repertoire.o" -o -name "static-stubs.o" \))
# Add the lind_syscall.o file to the list of object files
object_files="$object_files $lind_syscall_path"
# Check if object files were found
if [ -z "$object_files" ]; then
echo "No suitable .o files found in '$src_dir'."
exit 1
fi
# Create the sysroot directory structure
mkdir -p "$sysroot_dir/include/wasm32-wasi" "$sysroot_dir/lib/wasm32-wasi"
# Pack all found .o files into a single .a archive
/home/clang+llvm-16.0.4-x86_64-linux-gnu-ubuntu-22.04/bin/llvm-ar rcs "$output_archive" $object_files
/home/clang+llvm-16.0.4-x86_64-linux-gnu-ubuntu-22.04/bin/llvm-ar crs "sysroot/lib/wasm32-wasi/libpthread.a"
# Check if llvm-ar succeeded
if [ $? -eq 0 ]; then
echo "Successfully created $output_archive with the following .o files:"
echo "$object_files"
else
echo "Failed to create the archive."
exit 1
fi
# Copy all files from the external include directory to the new sysroot include directory
cp -r "$include_source_dir"/* "$sysroot_dir/include/wasm32-wasi/"
# Copy the crt1.o file into the new sysroot lib directory
cp "$crt1_source_path" "$sysroot_dir/lib/wasm32-wasi/"