aboutsummaryrefslogtreecommitdiff
path: root/src/Makefile
diff options
context:
space:
mode:
authorMikkel Thestrup <mithe24@student.sdu.dk>2025-12-04 16:15:18 +0100
committerMikkel Thestrup <mithe24@student.sdu.dk>2025-12-04 16:15:18 +0100
commitcd458cd71e7510f72aba67d0a132ebce57d67253 (patch)
tree4b452d7849255360afe1c9fda8754b5ccf472579 /src/Makefile
parent51d1da5bd095fd1b5efdeeda8210651271604427 (diff)
downloadcycle-detector-cd458cd71e7510f72aba67d0a132ebce57d67253.tar.gz
cycle-detector-cd458cd71e7510f72aba67d0a132ebce57d67253.zip
Added Makefile and Doxyfile
Diffstat (limited to '')
-rw-r--r--src/Makefile84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/Makefile b/src/Makefile
new file mode 100644
index 0000000..ab0199b
--- /dev/null
+++ b/src/Makefile
@@ -0,0 +1,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"