-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
108 lines (79 loc) · 2.47 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
101
102
103
104
105
106
107
108
COMPILER = g++
RMDIR = rm -rdf
RM = rm -f
DEP_FLAGS = -M -MT $@ -MT $(BIN_PATH)/$(*F).o -MP -MF $@
LIBS = -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf -lm
INC_PATHS = -I$(INC_PATH) $(addprefix -I,$(SDL_INC_PATH))
FLAGS = -std=c++11 -Wall -pedantic -Wextra -Wno-unused-parameter -Werror=init-self
DFLAGS = -ggdb -O0 -DDEBUG
RFLAGS = -O3 -mtune=native
INC_PATH = include
SRC_PATH = src
BIN_PATH = bin
DEP_PATH = dep
CPP_FILES = $(wildcard $(SRC_PATH)/*.cpp)
INC_FILES = $(wildcard $(INC_PATH)/*.h)
FILE_NAMES = $(sort $(notdir $(CPP_FILES:.cpp=)) $(notdir $(INC_FILES:.h=)))
DEP_FILES = $(addprefix $(DEP_PATH)/,$(addsuffix .d,$(FILE_NAMES)))
OBJ_FILES = $(addprefix $(BIN_PATH)/,$(notdir $(CPP_FILES:.cpp=.o)))
EXEC = JOGO
# SE FOR WINDOWS
ifeq ($(OS),Windows_NT)
RMDIR = rd /s /q
RM = del /q
#SDL_PATHS = C:/SDL2
SDL_INC_PATH += $(addsuffix /include,$(SDL_PATHS))
LINK_PATH = $(addprefix -L,$(addsuffix /lib,$(SDL_PATHS)))
FLAGS += -mwindows
DFLAGS += -mconsole
LIBS := -lmingw32 -lSDL2main $(LIBS)
EXEC := $(EXEC).exe
else
UNAME_S := $(shell uname -s)
# SE FOR MAC
ifeq ($(UNAME_S), Darwin)
LIBS = -lm -framework SDL2 -framework SDL2_image -framework SDL2_mixer -framework SDL2_ttf
endif
endif
.PRECIOUS: $(DEP_FILES)
.PHONY: release debug clean folders help
all: $(EXEC)
$(EXEC): $(OBJ_FILES)
$(COMPILER) -o $@ $^ $(LINK_PATH) $(LIBS) $(FLAGS)
$(BIN_PATH)/%.o: $(DEP_PATH)/%.d | folders
$(COMPILER) $(INC_PATHS) $(addprefix $(SRC_PATH)/,$(notdir $(<:.d=.cpp))) -c $(FLAGS) -o $@
$(DEP_PATH)/%.d: $(SRC_PATH)/%.cpp | folders
$(COMPILER) $(INC_PATHS) $< $(DEP_FLAGS) $(FLAGS)
clean:
$(RMDIR) $(DEP_PATH)
$(RMDIR) $(BIN_PATH)
$(RM) $(EXEC)
release: FLAGS += $(RFLAGS)
release: $(EXEC)
debug: FLAGS += $(DFLAGS)
debug: $(EXEC)
folders:
ifeq ($(OS), Windows_NT)
@if NOT exist $(DEP_PATH) (mkdir $(DEP_PATH))
@if NOT exist $(BIN_PATH) (mkdir $(BIN_PATH))
@if NOT exist $(INC_PATH) (mkdir $(INC_PATH))
@if NOT exist $(SRC_PATH) (mkdir $(SRC_PATH))
else
@mkdir -p $(DEP_PATH) $(BIN_PATH) $(INC_PATH) $(SRC_PATH)
endif
print-% : ; echo $* = $($*)
help:
ifeq ($(OS), Windows_NT)
echo.
endif
@echo Available targets:
@echo - release: Builds the release version
@echo - debug: Builds the debug version
@echo - clean: Cleans generated files
@echo - folders: Generates project directories
@echo - help: Show help
ifeq ($(OS), Windows_NT)
echo.
endif
.SECONDEXPANSION:
-include $$(DEP_FILES)