CTree/Makefile

48 lines
797 B
Makefile
Raw Normal View History

2024-03-27 05:08:39 +01:00
# Compiler
CC := gcc
# Compiler flags
2024-03-27 10:02:32 +01:00
CFLAGS := -Wall -Wextra -Wpedantic -std=c2x
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)
# 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
.PHONY: all run clean