blob: ab0199b0b5704003ba6dc1be0e3cfb0a6e98cfc7 (
plain)
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
|
# Compiler and flags
CC := gcc
CFLAGS := -Wall -Wextra -Werror -std=c99 -pedantic
CFLAGS += -O2
DEBUG_FLAGS := -g -O0 -DDEBUG
LDFLAGS :=
# Directories
SRC_DIR := .
BIN_DIR := .
OBJ_DIR := build
DEP_DIR := $(OBJ_DIR)/.deps
DOC_DIR := docs
# Source files and objects
SOURCES := $(wildcard $(SRC_DIR)/*.c)
OBJECTS := $(SOURCES:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
DEPS := $(OBJECTS:$(OBJ_DIR)/%.o=$(DEP_DIR)/%.d)
# Target executable
TARGET := $(BIN_DIR)/detectCycles
# Phony targets
.PHONY: all clean debug release help docs
# Default target
all: $(TARGET)
# Build executable
$(TARGET): $(OBJECTS)
@mkdir -p $(BIN_DIR)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
@echo "Build complete: $@"
# Compile object files
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(OBJ_DIR) $(DEP_DIR)
$(CC) $(CFLAGS) -MMD -MP \
-MF $(DEP_DIR)/$*.d -c $< -o $@
# Include dependency files
-include $(DEPS)
# Debug build
debug: CFLAGS := $(filter-out -O2,$(CFLAGS)) $(DEBUG_FLAGS)
debug: clean $(TARGET)
@echo "Debug build complete"
# Release build
release: CFLAGS := $(CFLAGS) -DNDEBUG
release: clean $(TARGET)
@echo "Release build complete"
# Generate Doxygen documentation
docs:
@mkdir -p $(DOC_DIR)
@if command -v doxygen >/dev/null 2>&1; then \
doxygen Doxyfile; \
echo "Documentation generated in $(DOC_DIR)/"; \
else \
echo "Error: doxygen not found. Install it and try again."; \
exit 1; \
fi
# Clean build artifacts
clean:
rm -rf $(OBJ_DIR) $(TARGET)
@echo "Clean complete"
# Clean documentation
clean-docs:
rm -rf $(DOC_DIR)
@echo "Documentation cleaned"
# Help message
help:
@echo "Available targets:"
@echo " all - Build the project (default)"
@echo " debug - Build with debug symbols and no optimization"
@echo " release - Build optimized release version"
@echo " docs - Generate Doxygen documentation"
@echo " clean - Remove all build artifacts"
@echo " clean-docs - Remove generated documentation"
@echo " help - Display this help message"
|