-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompile.sh
More file actions
executable file
·40 lines (31 loc) · 1.1 KB
/
compile.sh
File metadata and controls
executable file
·40 lines (31 loc) · 1.1 KB
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
#!/bin/bash
main() {
# Check if the correct number of arguments is provided
if [[ $# -ne 1 ]]; then
echo "ERROR: You need to input the path to the .c file"
exit 1
fi
# Get the path of the .c file and determine the filename (without extension)
src_path=$1
filename=$(basename "$src_path" .c)
# Define the output directory and file
output_dir="/home/dyl-syzygy/Student42/lib.ft/exp"
output="${output_dir}/${filename}"
# Check if the source file exists
if [[ ! -f "$src_path" ]]; then
echo "ERROR: The source file does not exist: $src_path"
exit 1
fi
# Ensure the output directory exists
mkdir -p "$output_dir"
# Compile the source file and link the math library
gcc -o "$output" -Wall -Werror -Wextra "$src_path" -lm
# Check if compilation was successful
if [[ $? -ne 0 ]]; then
echo "ERROR: Compilation failed for $filename. Please check your C code."
exit 1
fi
echo "Compilation successful! Executable created at $output"
}
# Call the main function with the provided argument
main "$@"