From a214e58f2c67d4fba0dbe03eab588d237d5f2cd4 Mon Sep 17 00:00:00 2001 From: my name Date: Sun, 14 Jun 2026 04:01:52 +0200 Subject: [PATCH] setup make file to compile .c into /build --- qscr/c/files/parser/kvparser/Makefile | 32 +++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 qscr/c/files/parser/kvparser/Makefile diff --git a/qscr/c/files/parser/kvparser/Makefile b/qscr/c/files/parser/kvparser/Makefile new file mode 100644 index 0000000..57e2ddf --- /dev/null +++ b/qscr/c/files/parser/kvparser/Makefile @@ -0,0 +1,32 @@ +CC = gcc +CFLAGS = -Wall -Wextra -g +TARGET = cout + +# Directories +BUILD_DIR = build + +# Source files +SRCS = $(wildcard *.c) +# This transforms "main.c" into "build/main.o" +OBJS = $(patsubst %.c, $(BUILD_DIR)/%.o, $(SRCS)) + +# Default target +all: $(TARGET) + +# Link the object files in the build directory into the final executable +$(TARGET): $(OBJS) + $(CC) $(OBJS) -o $(TARGET) + +# Compile .c files into .o files inside the build directory +$(BUILD_DIR)/%.o: %.c | $(BUILD_DIR) + $(CC) $(CFLAGS) -c $< -o $@ + +# Create the build directory if it doesn't exist +$(BUILD_DIR): + mkdir -p $(BUILD_DIR) + +# Clean up the build directory and the executable +clean: + rm -rf $(BUILD_DIR) $(TARGET) + +.PHONY: all clean