-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
39 lines (29 loc) · 718 Bytes
/
Makefile
File metadata and controls
39 lines (29 loc) · 718 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Compiler
CC = gcc
# Compiler flags
CFLAGS = -Wall -Wextra -g -Iincludes
# Directories
SRC_DIR = src
BUILD_DIR = build
INCLUDE_DIR = includes
# Target executable
TARGET = $(BUILD_DIR)/main
# Source and object files
SRCS = $(wildcard $(SRC_DIR)/*.c)
OBJS = $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.o,$(SRCS))
# Default target
all: $(TARGET)
# Link object files to create the executable
$(TARGET): $(OBJS)
$(CC) $(CFLAGS) -o $@ $^
# Compile .c files into .o files in build/
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c | $(BUILD_DIR)
$(CC) $(CFLAGS) -c $< -o $@
# Ensure build directory exists
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
# Clean generated files
clean:
rm -rf $(BUILD_DIR)/*
# Phony targets
.PHONY: all clean