From 12d5c261245a3d6b8687a8cb87a54a5cb7e0c643 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Wed, 27 Mar 2024 05:08:39 +0100 Subject: [PATCH] Proper makefile --- Makefile | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9d24238 --- /dev/null +++ b/Makefile @@ -0,0 +1,41 @@ +# Compiler +CC := gcc + +# Compiler flags +CFLAGS := -Wall -Wextra -Wpedantic + +# Directories +SRC_DIR := src +BUILD_DIR := build + +# Source files +SRCS := $(wildcard $(SRC_DIR)/*.c) + +# Object files +OBJS := $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.o,$(SRCS)) + +# Target executable +TARGET := CTree + +# 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) + +# Clean rule +clean: + rm -rf $(BUILD_DIR) $(TARGET) + +# Mark rules as phony +.PHONY: all run clean \ No newline at end of file