-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
61 lines (42 loc) · 1.32 KB
/
Makefile
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
TARGET_EXEC := agbemu
CC := gcc
CFLAGS := -Wall -Wimplicit-fallthrough -Wno-format -Werror
CFLAGS_RELEASE := -O3 -flto
CFLAGS_DEBUG := -g
CPPFLAGS := -MP -MMD
LDFLAGS := -lm -lSDL2 -lz
ifeq ($(shell uname),Darwin)
CPPFLAGS += -I/opt/homebrew/include
LDFLAGS := -L/opt/homebrew/lib $(LDFLAGS)
endif
BUILD_DIR := build
SRC_DIR := src
DEBUG_DIR := $(BUILD_DIR)/debug
RELEASE_DIR := $(BUILD_DIR)/release
SRCS := $(shell find $(SRC_DIR) -name '*.c')
SRCS := $(SRCS:$(SRC_DIR)/%=%)
OBJS_DEBUG := $(SRCS:%.c=$(DEBUG_DIR)/%.o)
DEPS_DEBUG := $(OBJS_DEBUG:.o=.d)
OBJS_RELEASE := $(SRCS:%.c=$(RELEASE_DIR)/%.o)
DEPS_RELEASE := $(OBJS_RELEASE:.o=.d)
.PHONY: release, debug, clean
release: CFLAGS += $(CFLAGS_RELEASE)
release: $(RELEASE_DIR)/$(TARGET_EXEC)
debug: CFLAGS += $(CFLAGS_DEBUG)
debug: $(DEBUG_DIR)/$(TARGET_EXEC)
$(RELEASE_DIR)/$(TARGET_EXEC): $(OBJS_RELEASE)
$(CC) -o $@ $(CFLAGS) $(CPPFLAGS) $^ $(LDFLAGS)
cp $@ $(TARGET_EXEC)
$(RELEASE_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(dir $@)
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
$(DEBUG_DIR)/$(TARGET_EXEC): $(OBJS_DEBUG)
$(CC) -o $@ $(CFLAGS) $(CPPFLAGS) $^ $(LDFLAGS)
cp $@ $(TARGET_EXEC)d
$(DEBUG_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(dir $@)
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
clean:
rm -rf $(BUILD_DIR) $(TARGET_EXEC)
-include $(DEPS_DEBUG)
-include $(DEPS_RELEASE)