CTree/Makefile
2024-12-28 21:48:32 +01:00

65 lines
1.3 KiB
Makefile

# Compiler
CC ?= gcc
# GITHASH := $(shell git rev-parse --short HEAD | echo "")
#
# Compiler flags
CFLAGS := -Wall -Wextra -Wpedantic -Wunused -std=c99 -Isrc
# Directories
SRC_DIR := src
BUILD_DIR := build
# Source files
SRCS := $(wildcard $(SRC_DIR)/*.c)
# Header files (used for formatting)
HEADERS := $(wildcard $(SRC_DIR)/*.h)
# Object files
OBJS := $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.o,$(SRCS))
# Target executable
TARGET := $(BUILD_DIR)/CTree
# Default target
all: $(TARGET)
test/test.o: test/test.c
test/test.elf: test/test.o src/tree.o
$(CC) $(CFLAGS) $^ -o $@
test: test/test.elf
./test/test.elf
# Rule to build the target executable
$(TARGET): $(OBJS)
$(CC) $(CFLAGS) $^ -o $@
# Rule to build object files
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(BUILD_DIR)
$(CC) $(CFLAGS) -c $< -o $@
# Run rule
run: $(TARGET)
./$(TARGET)
fmt:
clang-format -i $(SRCS) $(HEADERS)
clean:
rm -rf $(BUILD_DIR) $(TARGET) test/test.o tester docs
docs:
PROJECT_NUMBER=git-$(GITHASH) doxygen Doxyfile
cppcheck:
cppcheck --enable=all --inconclusive --std=c99 --language=c --platform=unix64 --suppress=missingIncludeSystem $(SRCS) test/test.c
valgrind: $(TARGET)
valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes ./$(TARGET)
# Mark rules as phony
.PHONY: all run clean docs docs test