-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
44 lines (31 loc) · 1.15 KB
/
Copy pathMakefile
File metadata and controls
44 lines (31 loc) · 1.15 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
# Assets are loaded relative to SDL_GetBasePath(), i.e. the directory of the
# executable, so the asset directories are symlinked next to the binary.
# Everything in build/ is generated, so it can be deleted at any time.
SRC_DIR := Rpg-SDL
BUILD_DIR := build
TARGET := $(BUILD_DIR)/rpg-sdl
SOURCES := $(wildcard $(SRC_DIR)/*.cpp)
OBJECTS := $(patsubst $(SRC_DIR)/%.cpp,$(BUILD_DIR)/%.o,$(SOURCES))
DEPS := $(OBJECTS:.o=.d)
ASSETS := fonts graphics music map
ASSET_LINKS := $(addprefix $(BUILD_DIR)/,$(ASSETS))
SDL_LIBS := sdl2 SDL2_image SDL2_ttf SDL2_mixer
CXX ?= g++
# -MMD -MP writes the .d files that rebuild an object when a header it includes changes
CXXFLAGS += -std=c++14 -O2 -Wall -MMD -MP $(shell pkg-config --cflags $(SDL_LIBS))
LDLIBS += $(shell pkg-config --libs $(SDL_LIBS))
all: $(TARGET) $(ASSET_LINKS)
$(TARGET): $(OBJECTS)
$(CXX) $(OBJECTS) $(LDLIBS) -o $@
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp | $(BUILD_DIR)
$(CXX) $(CXXFLAGS) -c $< -o $@
$(ASSET_LINKS): $(BUILD_DIR)/%: $(SRC_DIR)/% | $(BUILD_DIR)
ln -sfn ../$(SRC_DIR)/$* $@
$(BUILD_DIR):
mkdir -p $@
run: all
./$(TARGET)
clean:
rm -rf $(BUILD_DIR)
-include $(DEPS)
.PHONY: all run clean