2025-02-27 15:54:20 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Check if correct number of arguments is provided
|
|
|
|
if [ $# -lt 2 ]; then
|
|
|
|
echo "Usage: $0 <compiler> <optimization_flag>"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
COMPILER=$1
|
2025-02-27 16:21:46 +00:00
|
|
|
FLAGS=$2
|
2025-02-27 15:54:20 +00:00
|
|
|
|
|
|
|
# Check if there are any .c files in the directory
|
|
|
|
if ls *.c &> /dev/null; then
|
|
|
|
for file in *.c; do
|
2025-02-27 16:21:46 +00:00
|
|
|
obj_file="${file%}_${COMPILER}_${FLAGS}"
|
|
|
|
obj_file=$(echo "$obj_file" | sed 's/[^a-zA-Z0-9]/_/g' | sed 's/_\+/-/g')
|
2025-02-27 15:54:20 +00:00
|
|
|
echo "Compiling $file -> $obj_file with $COMPILER and $OPTIMIZATION_FLAG"
|
2025-02-27 16:21:46 +00:00
|
|
|
$COMPILER -c "$file" $FLAGS -o "../obj/$obj_file.o"
|
2025-02-27 15:54:20 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Compilation failed for $file"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
echo "All files compiled successfully."
|
|
|
|
else
|
|
|
|
echo "No .c files found in the current directory."
|
|
|
|
exit 2
|
|
|
|
fi
|