2024-03-27 05:08:39 +01:00
|
|
|
# Compiler
|
|
|
|
CC := gcc
|
|
|
|
|
|
|
|
# Compiler flags
|
|
|
|
CFLAGS := -Wall -Wextra -Wpedantic
|
|
|
|
|
|
|
|
# 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
|
2024-03-27 06:34:08 +01:00
|
|
|
TARGET := $(BUILD_DIR)/CTree
|
2024-03-27 05:08:39 +01:00
|
|
|
|
|
|
|
# Default target
|
|
|
|
all: $(TARGET)
|
|
|
|
|
|
|
|
# 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 rule
|
|
|
|
clean:
|
|
|
|
rm -rf $(BUILD_DIR) $(TARGET)
|
|
|
|
|
|
|
|
# Mark rules as phony
|
2024-03-27 06:34:08 +01:00
|
|
|
.PHONY: all run clean
|