-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
100 lines (74 loc) · 2.16 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# Pekka Kana 2 by Janne Kivilahti from Piste Gamez (2003-2007)
# https://pistegamez.net/game_pk2.html
#
# Makefile command:
# "make" - Creates Pekka Kana 2 binary
# "make clean" - Removes all objects, executables and dependencies
# Compiler:
CXX = c++
# Optimization:
ifdef DEBUG
$(info ->Debugging symbols enabled)
CXXFLAGS += -g
else
$(info ->Release mode)
CXXFLAGS += -O3
endif
# Warnings:
CXXFLAGS += -Wall
# Standart:
CXXFLAGS += --std=c++17 -fPIC
# SDL2, libzip and lua
CXXFLAGS += -DPK2_USE_ZIP -DPK2_USE_LUA $(shell pkg-config sdl2 libzip lua --cflags)
LDFLAGS += $(shell pkg-config sdl2 libzip lua --libs) -lSDL2_mixer -lSDL2_image
# Version string
PK2_VERSION = $(shell git log -1 --pretty=format:"%s" | grep -o 'v[0-9]\+\.[0-9]\+')
ifeq ($(PK2_VERSION),)
PK2_VERSION = "Unknown_version"
endif
# Portable (data is stored with resorces):
CXXFLAGS += -DPK2_PORTABLE -DPK2_VERSION=\"$(PK2_VERSION)\"
# Commit hash
CXXFLAGS += -DCOMMIT_HASH='"$(shell git rev-parse --short HEAD)"'
#Compile command CXX and CXXFLAGS
COMPILE_COMMAND = $(CXX) $(CXXFLAGS)
# Directories:
SRC_DIR = src/
BIN_DIR = bin/
BUILD_DIR = build/
# Source files:
PK2_SRC = *.cpp */*.cpp */*/*.cpp
PK2_SRC := $(addprefix $(SRC_DIR), $(PK2_SRC))
PK2_SRC := $(wildcard $(PK2_SRC))
# Object files:
PK2_OBJ := $(basename $(PK2_SRC))
PK2_OBJ := $(subst $(SRC_DIR), ,$(PK2_OBJ))
PK2_OBJ := $(addsuffix .o, $(PK2_OBJ))
PK2_OBJ := $(addprefix $(BUILD_DIR), $(PK2_OBJ))
# Dependency files:
DEPENDENCIES := $(PK2_OBJ)
DEPENDENCIES := $(basename $(DEPENDENCIES))
DEPENDENCIES := $(addsuffix .d, $(DEPENDENCIES))
# Binary output:
PK2_BIN = $(BIN_DIR)pekka-kana-2
all: pk2
pk2: $(PK2_BIN)
###########################
$(PK2_BIN): $(PK2_OBJ)
@echo -Linking Pekka Kana 2
@mkdir -p $(dir $@) >/dev/null
@$(CXX) $^ $(LDFLAGS) -o $@
###########################
-include $(DEPENDENCIES)
$(BUILD_DIR)%.o: $(SRC_DIR)%.cpp
@echo -Compiling $<
@mkdir -p $(dir $@) >/dev/null
@$(COMPILE_COMMAND) -I$(SRC_DIR) -o $@ -c $<
@$(COMPILE_COMMAND) -MM -MT $@ -I$(SRC_DIR) $< > $(BUILD_DIR)$*.d
###########################
clean:
@rm -rf $(BIN_DIR)
@rm -rf $(BUILD_DIR)
test:
@echo $(CXXFLAGS)
.PHONY: pk2 clean all test