| 1234567891011121314151617181920212223242526272829303132 |
- 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
|