CTree/Makefile

66 lines
1.3 KiB
Makefile
Raw Normal View History

2024-03-27 05:08:39 +01:00
# Compiler
2024-12-28 21:48:32 +01:00
CC ?= gcc
2024-05-05 14:56:23 +02:00
2024-12-28 21:48:32 +01:00
# GITHASH := $(shell git rev-parse --short HEAD | echo "")
#
2024-03-27 05:08:39 +01:00
# Compiler flags
2024-12-28 21:48:32 +01:00
CFLAGS := -Wall -Wextra -Wpedantic -Wunused -std=c99 -Isrc
2024-03-27 05:08:39 +01:00
# Directories
SRC_DIR := src
BUILD_DIR := build
# Source files
SRCS := $(wildcard $(SRC_DIR)/*.c)
2024-03-27 06:39:47 +01:00
# Header files (used for formatting)
HEADERS := $(wildcard $(SRC_DIR)/*.h)
2024-03-27 05:08:39 +01:00
# Object files
OBJS := $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.o,$(SRCS))
# Target executable
TARGET := $(BUILD_DIR)/CTree
2024-03-27 05:08:39 +01:00
# Default target
all: $(TARGET)
2024-12-28 21:48:32 +01:00
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
2024-03-27 05:08:39 +01:00
# 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)
2024-03-27 06:39:47 +01:00
fmt:
clang-format -i $(SRCS) $(HEADERS)
2024-03-27 05:08:39 +01:00
clean:
2024-12-28 21:48:32 +01:00
rm -rf $(BUILD_DIR) $(TARGET) test/test.o tester docs
2024-03-27 05:08:39 +01:00
2024-04-24 01:34:33 +02:00
docs:
2024-05-05 14:56:23 +02:00
PROJECT_NUMBER=git-$(GITHASH) doxygen Doxyfile
2024-04-24 01:34:33 +02:00
2024-05-02 02:16:24 +02:00
cppcheck:
2024-12-28 21:48:32 +01:00
cppcheck --enable=all --inconclusive --std=c99 --language=c --platform=unix64 --suppress=missingIncludeSystem $(SRCS) test/test.c
2024-05-02 02:16:24 +02:00
valgrind: $(TARGET)
valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes ./$(TARGET)
2024-03-27 05:08:39 +01:00
# Mark rules as phony
2024-12-28 21:48:32 +01:00
.PHONY: all run clean docs docs test