Explorar el Código

setup make file to compile .c into /build

my name hace 5 meses
padre
commit
a214e58f2c
Se han modificado 1 ficheros con 32 adiciones y 0 borrados
  1. 32 0
      qscr/c/files/parser/kvparser/Makefile

+ 32 - 0
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