-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
36 lines (28 loc) · 831 Bytes
/
Copy pathmakefile
File metadata and controls
36 lines (28 loc) · 831 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
# 1. Compiler and Flags
CC := gcc
CFLAGS := -Wall -Wextra -g -MMD -MP
TARGET := my_program
# 2. Directory Paths
SRC_DIR := ./src
# 3. Automatic File Detection in repo/src
# Finds all .c files inside repo/src
SRCS := $(wildcard $(SRC_DIR)/*.c)
# Replaces .c extension with .o for object files in the same directory
OBJS := $(SRCS:.c=.o)
# Tracks header dependencies (.d files) in the same directory
DEPS := $(SRCS:.c=.d)
# 4. Build Rules
.PHONY: all clean
# Default rule
all: $(TARGET)
# Link step (creates the executable in the root directory)
$(TARGET): $(OBJS)
$(CC) $(CFLAGS) -o $@ $^
# Compilation step for files inside repo/src
$(SRC_DIR)/%.o: $(SRC_DIR)/%.c
$(CC) $(CFLAGS) -c $< -o $@
# 5. Include Generated Dependencies
-include $(DEPS)
# 6. Cleanup
clean:
rm -f $(TARGET) $(OBJS) $(DEPS)