-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
68 lines (53 loc) · 2.19 KB
/
Makefile
File metadata and controls
68 lines (53 loc) · 2.19 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
CC = gcc
CFLAGS = -Wall -Wextra -Werror -Isrc
SRCS = src/main.c src/dir_ops.c src/file_info.c src/formatting.c src/sorting.c
OBJS = $(SRCS:.c=.o)
TARGET = ls
# Validation: Address Sanitizer
SANITIZE_FLAGS = -fsanitize=address -g
.PHONY: all clean test debug
all: $(TARGET)
build: all
$(TARGET): $(OBJS)
$(CC) $(CFLAGS) -o $@ $^
%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<
clean:
rm -f $(OBJS) $(TARGET)
rm -f tests/*.o tests/test_basic tests/test_permissions tests/test_sorting
debug: CFLAGS += $(SANITIZE_FLAGS)
debug: all
# Test logic - manual compilation of test binaries linking against some src objects (but not main.o)
# We filter out src/main.o from the objects used for testing
TEST_OBJS = src/dir_ops.o src/file_info.o src/formatting.o src/sorting.o
test: $(TEST_OBJS)
$(CC) $(CFLAGS) tests/test_basic.c $(TEST_OBJS) -o tests/test_basic
$(CC) $(CFLAGS) tests/test_permissions.c $(TEST_OBJS) -o tests/test_permissions
$(CC) $(CFLAGS) tests/test_sorting.c $(TEST_OBJS) -o tests/test_sorting
@echo "Running Tests..."
./tests/test_basic // requires some arguments or mocked env usually
# Additional CI targets
format:
@echo "Formatting code..."
@if command -v clang-format >/dev/null; then clang-format -i src/*.c src/*.h tests/*.c; else echo "clang-format not found, skipping"; fi
format-check:
@echo "Checking code formatting..."
@if command -v clang-format >/dev/null; then clang-format -n --Werror src/*.c src/*.h tests/*.c; else echo "clang-format not found, skipping"; fi
lint:
@echo "Running static analysis..."
@if command -v cppcheck >/dev/null; then \
cppcheck --enable=all --error-exitcode=1 --suppress=missingIncludeSystem src/; \
else \
echo "cppcheck not found, skipping"; \
fi
valgrind: debug
@echo "Running memory checks..."
@if command -v valgrind >/dev/null; then valgrind --leak-check=full --error-exitcode=1 ./ls -R src > /dev/null; else echo "valgrind not found, skipping"; fi
integration-test: all
@echo "Running integration tests..."
./examples/usage_examples.sh
coverage:
@echo "Coverage report..."
$(CC) $(CFLAGS) --coverage src/dir_ops.c src/file_info.c src/formatting.c src/sorting.c tests/test_basic.c -o test_cov
./test_cov
@rm -f test_cov test_cov.gcda test_cov.gcno