-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
78 lines (65 loc) · 2.67 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
# -----------------------------------Constants----------------------------------
AllWarnings = -Wall -Wextra -pedantic
SomeWarnings = -Wall -Wextra
LittleWarnings = -Wall
NoWarnings =
# -----------------------------------Constants----------------------------------
Mode = DEBUG_MODE
# ----------------------------------Debug-mode----------------------------------
ifeq ($(Mode), DEBUG_MODE)
ModeLinkerOptions = -g -fsanitize=address -fno-optimize-sibling-calls
ModeCompilerOptions = -O0 -g -fsanitize=address -fno-optimize-sibling-calls
endif
# ----------------------------------Debug-mode----------------------------------
# ---------------------------------Release-mode---------------------------------
ifeq ($(Mode), RELEASE_MODE)
ModeLinkerOptions =
ModeCompilerOptions = -O3
endif
# ---------------------------------Release-mode---------------------------------
# ------------------------------------Options-----------------------------------
LIBS = sdl2 sdl2_ttf sdl2_image
CXX = clang++
LXXFLAGS = $(shell pkg-config --libs $(LIBS)) $(ModeLinkerOptions)
CXXFLAGS = $(shell pkg-config --cflags $(LIBS)) $(ModeCompilerOptions) $(NoWarnings) -std=c++17
# ------------------------------------Options-----------------------------------
# -------------------------------------Files------------------------------------
LibsDir = libs
IncludeDir = include
SrcDir = src
BinDir = bin
IntDir = $(BinDir)/intermediates
rwildcard = $(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
LibArchives = $(LibsDir)/sml/sml.a
Deps = $(call rwildcard,$(IncludeDir),*.h)
CppSrc = $(notdir $(call rwildcard,$(SrcDir),*.cpp))
Objs = $(addprefix $(IntDir)/, $(CppSrc:.cpp=.o))
OutputDir = sgl
OutputFile = sgl.a
# -------------------------------------Files------------------------------------
# ----------------------------------Make rules----------------------------------
.PHONY: install
ifneq ($(OutputPrefix),)
install: init build
mkdir -p $(OutputPrefix)/$(OutputDir)
mkdir -p $(OutputPrefix)/$(OutputDir)
cp $(BinDir)/$(OutputFile) $(OutputPrefix)/$(OutputDir)
cp -a $(IncludeDir)/. $(OutputPrefix)/$(OutputDir)
else
install:
@echo "[ERROR] Output directory not specified!"
endif
.PHONY: build
build: $(LibArchives) $(Objs) $(Deps)
ar ru $(BinDir)/$(OutputFile) $(Objs)
vpath %.cpp $(dir $(call rwildcard,$(SrcDir),*.cpp))
$(IntDir)/%.o: %.cpp $(Deps)
$(CXX) -I $(IncludeDir) -I $(LibsDir) -c $< $(CXXFLAGS) -o $@
.PHONY: init
init:
mkdir -p bin/intermediates
mkdir -p libs
.PHONY: clean
clean:
rm -f $(call rwildcard,$(IntDir),*.o) $(BinDir)/$(OutputFile)
# ----------------------------------Make rules----------------------------------