2024-04-14 22:20:29 +08:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
# 设置输入和输出目录
|
|
|
|
|
input_dir="sy"
|
|
|
|
|
output_dir="build"
|
|
|
|
|
lib_dir="lib"
|
|
|
|
|
|
2024-05-19 12:20:56 +08:00
|
|
|
|
CC=riscv64-suse-linux-gcc
|
|
|
|
|
|
2024-04-14 22:20:29 +08:00
|
|
|
|
rm -rf build
|
|
|
|
|
|
|
|
|
|
# 确保输出目录存在
|
|
|
|
|
mkdir -p "$output_dir"
|
|
|
|
|
|
2024-05-19 12:20:56 +08:00
|
|
|
|
rm -f ./lib/sylib.o
|
|
|
|
|
rm -f ./lib/libsysy.so
|
|
|
|
|
|
2024-06-14 10:59:45 +08:00
|
|
|
|
${CC} -fPIC -c ./lib/sylib.c -o ./lib/sylib.o
|
2024-05-19 12:20:56 +08:00
|
|
|
|
${CC} -shared ./lib/sylib.o -o ./lib/libsysy.so
|
2024-04-14 22:20:29 +08:00
|
|
|
|
|
|
|
|
|
# 遍历sy目录下的所有文件
|
|
|
|
|
for file in "$input_dir"/*.c; do
|
2024-06-14 10:59:45 +08:00
|
|
|
|
# 检查文件是否存在
|
|
|
|
|
if [ -f "$file" ]; then
|
|
|
|
|
# 获取文件名(不含路径)
|
|
|
|
|
filename=$(basename -- "$file")
|
|
|
|
|
# 移除文件扩展名,假设输出的可执行文件不需要扩展名
|
|
|
|
|
basename="${filename%.*}"
|
|
|
|
|
|
|
|
|
|
# 编译文件,链接库libsysy.a,设置头文件路径为lib/sylib.h
|
|
|
|
|
clang "$file" -I "$lib_dir" -L"$lib_dir" -lsylib -o "$output_dir/$basename"
|
|
|
|
|
fi
|
2024-04-14 22:20:29 +08:00
|
|
|
|
done
|