forked from unbgames/DigAlanDig
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
197 lines (154 loc) · 6.02 KB
/
Makefile
File metadata and controls
197 lines (154 loc) · 6.02 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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#---------------------------------------------------------------------
# Assume-se uma distribuição Linux como sistema operacional padrão
#---------------------------------------------------------------------
# O compilador
CC = g++
# Comando para remover pastas
RMDIR = rm -rdf
# Comando para remover arquivos
RM = rm -f
# "Flags" para geração automática de dependências
DEP_FLAGS = -MM -MT $@ -MT $(BIN_PATH)/$(*F).o -MP -MF $@
# Bibliotecas a serem linkadas
LIBS = -lSDL2 -lSDL2_image -lSDL2_mixer -lm
# Caminho dos includes
INC_PATHS = -I$(INC_PATH) -I$(EXT_PATH) $(addprefix -I,$(SDL_INC_PATH))
# Diretivas de compilacao
FLAGS = -std=c++11 -Wall -pedantic -Wextra -Wno-unused-parameter -Werror=init-self
# Diretivas extras para debug
DFLAGS = -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -fsanitize=address,undefined -fno-sanitize-recover -ggdb -O0 -DDEBUG
# Diretivas extras para release
RFLAGS = -O3 -mtune=native
# Diretivas extras para release com simbolos de debug
RDFLAGS = -O3 -mtune=native -ggdb -DDEBUG
# Diretivas extras para release com otimizacoes mais agressivas
RFFLAGS = -Ofast -flto -mtune=native -s
# Diretivas extras para binário mais portável
GFLAGS = -O2 -flto -march=k8 -mtune=generic -s
INC_PATH = include
EXT_PATH = extern
SRC_PATH = src
BIN_PATH = bin
DEP_PATH = dep
# Uma lista de arquivos por extensão:
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)))
# Nome do executável
EXEC = JOGO
ifeq ($(NAME), GIT)
EXEC = $(shell git describe --tags --dirty --long)
endif
#---------------------------------------------------------------------
# Caso o sistema seja windows
#---------------------------------------------------------------------
ifeq ($(OS),Windows_NT)
# Comando para remover um diretório recursivamente
RMDIR = rd /s /q
# Comando para deletar um único arquivo
RM = del /q
# Possíveis Path da SDL. Caso seja possível ter mais de um local, adicione com espaço entre eles
# Por ex.: SDL_PATHs = C:/SDL2 D:/Tools/SDL2 C:/dev-tools/SDL2
SDL_PATHS = C:/x86_64-w64-mingw32 C:/Tools/msys64/mingw64
SDL_INC_PATH += $(addsuffix /include,$(SDL_PATHS))
LINK_PATH = $(addprefix -L,$(addsuffix /lib,$(SDL_PATHS)))
FLAGS += -mwindows
DFLAGS += -mconsole
LIBS := -lmingw32 -lSDL2main $(LIBS)
# Nome do executável
EXEC := $(EXEC).exe
else
UNAME_S := $(shell uname -s)
#---------------------------------------------------------------------
# Caso o sistema seja Mac
#---------------------------------------------------------------------
ifeq ($(UNAME_S), Darwin)
#LIBS = -lm -framework SDL2 -framework SDL2_image -framework SDL2_mixer
LIBS = -L/opt/local/lib -lSDL2 -lSDL2_image -lSDL2_mixer -lm
endif
endif
#---------------------------------------------------------------------
# Cross-compile de Linux para Windows (estático)
#---------------------------------------------------------------------
ifeq ($(TARGET), WIN)
CC = x86_64-w64-mingw32-g++
BIN_PATH = binw
PATH := /usr/local/cross-tools/x86_64-w64-mingw32/bin:$(PATH)
INC_PATHS = -I$(INC_PATH) -I$(EXT_PATH) -I/usr/local/cross-tools/x86_64-w64-mingw32/include -Dmain=SDL_main
#LINK_PATH = $(shell sdl2-config --static-libs) -static-libstdc++ -lz -logg -lvorbis -lpng -ljpeg
LINK_PATH = -L/usr/local/cross-tools//x86_64-w64-mingw32/lib --static -lmingw32 -lSDL2main -lSDL2 -mwindows -Wl,--no-undefined -lm -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lversion -luuid -static-libgcc -static-libstdc++ -lSDL2 -lSDL2_image -lSDL2_mixer -lfreetype -lm -ljpeg -lpng -lz -lwinmm -lvorbisfile -lvorbis -logg -lm
RC_FILE = jogo.rc
RES_FILE = jogo.res
OBJ_FILES += $(BIN_PATH)/$(RES_FILE)
EXEC := $(EXEC).exe
endif
##############################################################################################
.PRECIOUS: $(DEP_FILES)
.PHONY: release debug clean folders help
# Regra geral
all: FLAGS += $(RDFLAGS)
all: $(EXEC)
# Gera o executável
$(EXEC): $(OBJ_FILES)
$(CC) -o $@ $^ $(LINK_PATH) $(LIBS) $(FLAGS)
# Gera os arquivos objetos
$(BIN_PATH)/%.o: $(DEP_PATH)/%.d | folders
$(CC) $(INC_PATHS) $(addprefix $(SRC_PATH)/,$(notdir $(<:.d=.cpp))) -c $(FLAGS) -o $@
# Gera os arquivos de dependencia
$(DEP_PATH)/%.d: $(SRC_PATH)/%.cpp | folders
$(CC) $(INC_PATHS) $< $(DEP_FLAGS) $(FLAGS)
# Gera o arquivo res
$(BIN_PATH)/%.res: $(RC_FILE)
x86_64-w64-mingw32-windres $^ -O coff -o $@
clean:
-$(RMDIR) $(DEP_PATH)
-$(RMDIR) $(BIN_PATH)
-$(RM) $(EXEC)
-$(RM) cout.txt cerr.txt jogo.res
release: FLAGS += $(RFLAGS)
release: $(EXEC)
#clang++ anterior a 3.9 possui um bug na hora da linkagem com -flto, usar 3.9+
releasefast: FLAGS += $(RFFLAGS)
releasefast: $(EXEC)
generic: FLAGS += $(GFLAGS)
generic: $(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
android:
rsync -vah src/* ../org.pedro.marmota/app/jni/src/
rsync -vah include/* ../org.pedro.marmota/app/jni/src/
rsync -vah extern/* ../org.pedro.marmota/app/jni/src/
cd ../org.pedro.marmota && ./gradlew assembleDebug
cp ../org.pedro.marmota/app/build/outputs/apk/app-debug.apk $(EXEC).apk
androidrun:
adb install -r $(EXEC).apk
adb shell monkey -p org.pedro.marmota -v 500
adb logcat org.pedro.marmota:I S:* | grep --color=never marmolog
# Regra pra debug
print-% : ; @echo $* = $($*)
help:
ifeq ($(OS), Windows_NT)
@echo.
endif
@echo Available targets:
@echo - release: Builds the release version [default target]
@echo - debug: Builds the debug version
@echo - clean: Cleans generated files
@echo - folders: Generates project directories
@echo - help: Shows this help
ifeq ($(OS), Windows_NT)
@echo.
endif
.SECONDEXPANSION:
-include $$(DEP_FILES)