-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
185 lines (79 loc) · 2.61 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
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
APP_BIN = MetalShadowWars
CC = gcc
CXX = g++
CCFLAGS = -Wall -g -std=c11
CXXFLAGS = -Wall -g -std=c++11
LDFLAGS = -lm
INC_FLAGS = -I./include
SRC_PATH = .
OBJ_PATH = obj
BIN_PATH = bin
LIB_PATH = lib
SDL_PATH =
GLUT_PATH =
GL_PATH =
SDL = SDL
# SDL = SDL2
ECHO_CMD = echo
SLASH = /
ifneq ($(SDL_PATH),)
LDFLAGS += -L$(SDL_PATH)/lib
INC_FLAGS += -I$(SDL_PATH)/include
# BIN_FLAGS +=
endif
ifneq ($(GLUT_PATH),)
LDFLAGS += -L$(GLUT_PATH)/lib
INC_FLAGS += -I$(GLUT_PATH)/include
# BIN_FLAGS +=
endif
ifneq ($(GL_PATH),)
LDFLAGS += -L$(GL_PATH)/lib
INC_FLAGS += -I$(GL_PATH)/include
# BIN_FLAGS +=
endif
ifeq ($(OS),Windows_NT)
SDL_FLAGS = -lmingw32 -l$(SDL)main -l$(SDL)
GL_FLAGS = -lopengl32 -lglu32 -lfreeglut
IF_N_EXIST = if not exist
OBJ_FILES2 = $(subst /,\, $(OBJ_FILES))
CLEAN_CMD = for %%x in ($(OBJ_FILES2)) do (if exist %%x (del /q %%x))
CCFLAGS += -D WIN32
CXXFLAGS += -D WIN32
# CXX = x86_64-w64-mingw32-g++
else
IF_N_EXIST = if [ ! -d
THEN = ]; then
ENDIF =; fi
SDL_FLAGS = -l$(SDL)
GL_FLAGS = -lGL -lGLU
CCFLAGS += -D LINUX
CXXFLAGS += -D LINUX
ifeq ($(shell uname),Darwin)
INC_FLAGS += -I/opt/local/include
INC_FLAGS += -I/Library/Frameworks/SDL.framework/Headers -I/Library/Frameworks/SDL_image.framework/Headers -I/Library/Frameworks/SDL_mixer.framework/Headers -I/Library/Frameworks/SDL_ttf.framework/Headers
LDFLAGS += `sdl-config --libs` `sdl-config --cflags`
LDFLAGS += -framework Cocoa -framework OpenGL -lSDL_image -lSDL_mixer -lSDL_ttf -lglut
CCFLAGS += -D OSX
CXXFLAGS += -D OSX
endif
CLEAN_CMD = rm $(OBJ_FILES) $(BIN_PATH)/$(APP_BIN)
endif
SRC_FILES = $(wildcard $(SRC_PATH)/*.cpp) $(wildcard $(SRC_PATH)/*/*.cpp)
OBJ_FILES = $(patsubst $(SRC_PATH)/%.cpp, $(OBJ_PATH)/%.o, $(SRC_FILES))
LDFLAGS += $(SDL_FLAGS) $(GL_FLAGS) -l$(SDL)_image -l$(SDL)_mixer -l$(SDL)_ttf
all: $(BIN_PATH) $(OBJ_PATH) $(OBJ_FILES)
@echo "Building $(APP_BIN)"
$(CXX) $(CXXFLAGS) $(INC_FLAGS) $(OBJ_FILES) $(LDFLAGS) -o $(BIN_PATH)/$(APP_BIN)
@echo "$(APP_BIN) has been created"
$(OBJ_PATH):
@echo "------------Make directory $<---------------------"
$(IF_N_EXIST) "$(OBJ_PATH)" $(THEN) mkdir "$(OBJ_PATH)" $(ENDIF)
$(BIN_PATH):
@echo "------------Make directory $<---------------------"
$(IF_N_EXIST) "$(BIN_PATH)" $(THEN) mkdir "$(BIN_PATH)" $(ENDIF)
$(OBJ_PATH)$(SLASH)%.o: $(SRC_PATH)$(SLASH)%.cpp $(OBJ_PATH)
@echo "------------COMPILATION $< -> $@---------------------"
$(IF_N_EXIST) "$(@D)" $(THEN) mkdir "$(@D)" $(ENDIF)
$(CXX) $(CXXFLAGS) $(INC_FLAGS) -c $< -o $@
clean:
$(CLEAN_CMD)