-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
50 lines (37 loc) · 1012 Bytes
/
makefile
File metadata and controls
50 lines (37 loc) · 1012 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
40
41
42
43
44
45
46
47
48
49
50
# Compiler settings
CC = gcc
CFLAGS = -std=c11 -g
INCLUDE_FLAGS = -Iinclude
# Directories
SRC_DIR = src
INCLUDE_DIR = include
BUILD_DIR = build
# Create build directory
$(shell mkdir -p $(BUILD_DIR))
# Source files
MAIN_SRC = main.c
SRCS = $(MAIN_SRC) $(wildcard $(SRC_DIR)/*.c)
# Object files (moved to build directory)
OBJS = $(patsubst %.c,$(BUILD_DIR)/%.o,$(notdir $(SRCS)))
# Dependency files (moved to build directory)
DEPS = $(OBJS:.o=.d)
# Target executable
TARGET = app
# Default target
all: $(TARGET)
# Linking
$(TARGET): $(OBJS)
$(CC) $(CFLAGS) $(INCLUDE_FLAGS) -o $@ $^
# Compilation rule for main
$(BUILD_DIR)/main.o: main.c $(wildcard $(INCLUDE_DIR)/*.h)
$(CC) $(CFLAGS) $(INCLUDE_FLAGS) -MMD -c $< -o $@
# Compilation rule for source files
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c $(wildcard $(INCLUDE_DIR)/*.h)
$(CC) $(CFLAGS) $(INCLUDE_FLAGS) -MMD -c $< -o $@
# Include dependency files
-include $(DEPS)
# Clean up
clean:
rm -rf $(BUILD_DIR) $(TARGET)
# Phony targets
.PHONY: all clean