-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun
More file actions
executable file
·64 lines (55 loc) · 1.31 KB
/
Copy pathrun
File metadata and controls
executable file
·64 lines (55 loc) · 1.31 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/bash
# Function to show usage
usage() {
echo "Usage: $0 [-a] [-v] source_file [program_arguments...]"
echo " -a: Compile with dependencies (*.c)"
echo " -v: Compile with valgrind (cc -g3 && valgrind ./exec)"
exit 1
}
# Check if no arguments are provided
if [ $# -lt 1 ]; then
usage
fi
# Initialize variables
compile_with_dependencies=false
compile_with_valgrind=false
source_file=""
# Parse options
while getopts ":av" opt; do
case ${opt} in
a )
compile_with_dependencies=true
;;
v )
compile_with_valgrind=true
;;
\? )
usage
;;
esac
done
# Remove parsed options from positional parameters
shift $((OPTIND -1))
# Check if the source file is provided
if [ $# -lt 1 ]; then
usage
else
source_file=$1
shift
fi
# Compile the source file
if $compile_with_dependencies; then
cc -Wall -Werror -Wextra -o exec *.c
elif $compile_with_valgrind; then
cc -Wall -Werror -Wextra -o exec -g3 "$source_file"
else
cc -Wall -Werror -Wextra -o exec "$source_file"
fi
# Run the compiled program with the remaining arguments (if any)
if $compile_with_valgrind; then
valgrind --leak-check=full --show-leak-kinds=all ./exec "$@"
else
./exec "$@"
fi
# Clean up by removing the executable
rm exec