-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild
More file actions
executable file
·90 lines (80 loc) · 1.6 KB
/
build
File metadata and controls
executable file
·90 lines (80 loc) · 1.6 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/sh
# Set default values for variables
CFLAGS="-g -O0 -Wall -Wextra -fsanitize=address -fsanitize=bounds"
BIN_DIR="bin"
SRC_DIR="src"
TEST_DIR="src/test"
# Create the bin directory if it doesn't exist
create_bin_dir() {
[ -d "$BIN_DIR" ] || mkdir "$BIN_DIR"
}
# Build object files from all source files in the source directory
build_objects() {
for src_file in "$SRC_DIR"/*.c
do
obj_file=$(basename "$src_file" .c).o
echo "cc $CFLAGS -c "$src_file" -o "$obj_file""
cc $CFLAGS -c "$src_file" -o "$obj_file"
done
}
# Build the servrian executable
build_servrian() {
create_bin_dir
build_objects
echo "cc $CFLAGS -o "$BIN_DIR/servrian" ./*.o -lcrypt"
cc $CFLAGS -o "$BIN_DIR/servrian" ./*.o -lcrypt
}
# Build the test_hash executable
build_tests() {
create_bin_dir
for src_file in "$TEST_DIR"/*.c
do
bin_file=$(basename "$src_file" .c)
echo "cc $CFLAGS "$src_file" "$SRC_DIR/aux.c" -o "$BIN_DIR/$bin_file" -lcrypt"
cc $CFLAGS "$src_file" "$SRC_DIR/aux.c" -o "$BIN_DIR/$bin_file" -lcrypt
done
}
# Clean build artifacts
clean() {
rm -f ./*.o
rm -rf "$BIN_DIR/*"
}
# Debug build
debug() {
export CFLAGS="$CFLAGS -fsanitize=address"
build_servrian
"$BIN_DIR/servrian"
}
# Compile the project based on the target
main() {
case $1 in
servrian)
build_servrian
;;
release)
export CFLAGS="-Ofast"
main servrian
;;
clean)
clean
;;
test)
build_tests
for test in bin/test_*
do
"$test"
done
;;
test_hash)
build_test_hash
;;
debug)
debug
;;
"" | *)
echo "No target specified. Defaulting to 'release'."
main release
;;
esac
}
main "$@"