# 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"