sysy/scripts/cmpl.sh

34 lines
839 B
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 设置输入和输出目录
input_dir="sy"
output_dir="build"
lib_dir="lib"
CC=riscv64-suse-linux-gcc
rm -rf build
# 确保输出目录存在
mkdir -p "$output_dir"
rm -f ./lib/sylib.o
rm -f ./lib/libsysy.so
${CC} -fPIC -c ./lib/sylib.c -o ./lib/sylib.o
${CC} -shared ./lib/sylib.o -o ./lib/libsysy.so
# 遍历sy目录下的所有文件
for file in "$input_dir"/*.c; do
# 检查文件是否存在
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
done