-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
65 lines (51 loc) · 1.49 KB
/
Makefile
File metadata and controls
65 lines (51 loc) · 1.49 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# -----------------------------
# Project settings
# -----------------------------
CC := gcc
CFLAGS := -Wall -Wextra -Wno-unused-parameter -O2
DBGFLAGS := -Wall -Wextra -Wno-unused-parameter -g -O0
LDFLAGS :=
SRC_DIR := src
OUT_DIR := bin
TARGET := $(OUT_DIR)/galo
DEBUG_TARGET := $(OUT_DIR)/galo_debug
# -----------------------------
# Automatic source discovery
# -----------------------------
SOURCES := $(wildcard $(SRC_DIR)/*.c)
OBJECTS := $(patsubst $(SRC_DIR)/%.c,$(OUT_DIR)/%.o,$(SOURCES))
DEBUG_OBJECTS := $(patsubst $(SRC_DIR)/%.c,$(OUT_DIR)/%.debug.o,$(SOURCES))
# -----------------------------
# Default targets
# -----------------------------
all: $(TARGET)
debug: $(DEBUG_TARGET)
# -----------------------------
# Link
# -----------------------------
$(TARGET): $(OBJECTS)
$(CC) $^ -o $@ $(LDFLAGS)
$(DEBUG_TARGET): $(DEBUG_OBJECTS)
$(CC) $^ -o $@ $(LDFLAGS)
# -----------------------------
# Compile rules
# -----------------------------
$(OUT_DIR)/%.o: $(SRC_DIR)/%.c | $(OUT_DIR)
$(CC) $(CFLAGS) -c $< -o $@
$(OUT_DIR)/%.debug.o: $(SRC_DIR)/%.c | $(OUT_DIR)
$(CC) $(DBGFLAGS) -c $< -o $@
# -----------------------------
# Create output directory
# -----------------------------
$(OUT_DIR):
mkdir -p $(OUT_DIR)
# -----------------------------
# Utility targets
# -----------------------------
clean:
rm -rf $(OUT_DIR)
run: $(TARGET)
./$(TARGET) $(filter-out $@,$(MAKECMDGOALS))
run-debug: $(DEBUG_TARGET)
gdb ./$(DEBUG_TARGET)
.PHONY: all debug clean run run-debug