-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMakefile
195 lines (159 loc) · 4.05 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
186
187
188
189
190
191
192
193
#!make
LIBS = -lpthread -lGL -lGLEW
INCLUDES = -I. -Iexternals -Iexternals/box2d
LD = ar
CXX = g++
CC = gcc
DEFINES =
CFLAGS = -Wall -pipe
CPPFLAGS = -Wall -pipe -std=c++0x
LDFLAGS =
# where are source files located?
SOURCE_DIRS= blib \
blib/util \
blib/math \
blib/gl \
blib/wm \
blib/wm/widgets \
blib/platform/linux \
externals/box2d/Box2D/Collision \
externals/box2d/Box2D/Collision/Shapes \
externals/box2d/Box2D/Common \
externals/box2d/Box2D/Dynamics \
externals/box2d/Box2D/Dynamics/Contacts \
externals/box2d/Box2D/Dynamics/Joints \
externals/box2d/Box2D/Rope
# Host platform
UNAME=$(shell uname -s | sed -e 's/_.*$$//')
#####
## PLATFORM DETECTION CODE
#####
ifeq ($(PLATFORM),)
UNAME_CPU=$(shell uname -m)
## Cygwin
ifeq ($(UNAME),CYGWIN)
# can't do linux build anyway on cygwin
PLATFORM=win32
endif
## Linux
ifeq ($(UNAME),Linux)
# detect 64bit
ifeq ($(UNAME_CPU),x86_64)
PLATFORM=linux64
else
PLATFORM=linux32
endif
endif
endif
#####
## END OF PLATFORM DETECTION CODE
#####
#####
## PER-PLATFORM SETTINGS
#####
# Linux 32bit
ifeq ($(PLATFORM),linux32)
CFLAGS += -m32
CPPFLAGS += -m32
CC=gcc
CXX=g++
BINARY_EXT=
endif
# Linux 64bit
ifeq ($(PLATFORM),linux64)
CFLAGS += -m64
CPPFLAGS += -m64
CC=gcc
CXX=g++
BINARY_EXT=
endif
# Windows 32bit
ifeq ($(PLATFORM),win32)
# Mh, we don't use GUI only mode, but console instead?
CFLAGS += -mconsole
ifeq ($(UNAME),CYGWIN)
# On cygwin, use provided gcc, but tell to not use cygwin's dlls
CC=gcc
CXX=g++
CFLAGS += -mno-cygwin
else
CC=mingw32-gcc
CXX=mingw32-g++
endif
WINDRES=mingw32-windres
BINARY_EXT=.exe
INCLUDES += -Ilibs/include
LIBS = -L. -lzlib1 -lSDL -lbgd -lopengl32 -lglu32 -lws2_32 -lcomdlg32
# ws2_32.lib sdl.lib sdlmain.lib zlib.lib bgd.lib opengl32.lib glu32.lib
endif
#####
## END OF PER-PLATFORM SETTINGS
#####
## Debug build?
#ifeq ($(DEBUG),)
DEBUG=yes
#endif
ifeq ($(DEBUG),yes)
CFLAGS += -g -ggdb -fstack-protector-all -D_DEBUG -rdynamic
CPPFLAGS += -g -ggdb -fstack-protector-all -D_DEBUG -rdynamic
else
# We suppose everyone have SSE. If this cause problems, switch mfpmath back to 387
CFLAGS += -O3 -fomit-frame-pointer -momit-leaf-frame-pointer -mfpmath=sse
CPPFLAGS += -O3 -fomit-frame-pointer -momit-leaf-frame-pointer -mfpmath=sse
endif
TARGET=blib_$(PLATFORM).a
# Define path where make will find source files :)
VPATH=$(subst ,:,$(SOURCE_DIRS))
# list all source files
SOURCE_ALL=$(foreach dir,$(SOURCE_DIRS),$(wildcard $(dir)/*.c $(dir)/*.cpp))
# list all object files
OBJECTS_ALL=$(patsubst %,obj/%_$(PLATFORM).o,$(basename $(SOURCE_ALL)))
# list all .dep files
DEP_ALL=$(patsubst %,obj/%_$(PLATFORM).dep,$(basename $(filter %.c %.cpp,$(SOURCE_ALL))))
ifeq ($(PLATFORM),win32)
# Fix: Win32 build needs this one
OBJECTS_SRC += obj/src_Script1_rc_$(PLATFORM).o
endif
all: $(TARGET)
clean:
$(RM) `find obj` $(TARGET)
# Depencies
.PHONY: dep
dep: obj/depencies_$(PLATFORM).mak
obj/depencies_$(PLATFORM).mak: $(DEP_ALL)
@echo -e " [DEP] $@ "
@mkdir -p obj/blib
@mkdir -p obj/blib/util
@mkdir -p obj/blib/gl
@mkdir -p obj/blib/math
@mkdir -p obj/blib/platform
@mkdir -p obj/blib/platform/linux
@mkdir -p obj/blib/wm
@mkdir -p obj/blib/wm/widgets
# build depencies for objects
@cat $^ | sed -r -e 's#^([a-zA-Z0-9]+)\.o#obj/\1_$(PLATFORM).o#' >$@
# build depencies for depencies
@cat $^ | sed -r -e 's#^([a-zA-Z0-9]+)\.o#obj/\1_$(PLATFORM).dep#' >>$@
-include obj/depencies_$(PLATFORM).mak
# type-specific targets (compile, target = %.o)
obj/%_$(PLATFORM).o: %.c
@echo -e " [CC] $<"
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
obj/%_rc_$(PLATFORM).o: %.rc
@echo -e " [RC] $<"
$(WINDRES) -I src -i $< -o $@
obj/%_$(PLATFORM).o: %.cpp
@echo -e " [CC] $<"
$(CXX) $(CPPFLAGS) $(INCLUDES) -c -o $@ $<
# depencies
obj/%_$(PLATFORM).dep: %.c
@echo -en " [DEP] $< \r"
$(CC) $(CFLAGS) $(INCLUDES) -MM -MF $@ $<
obj/%_$(PLATFORM).dep: %.cpp
@echo -en " [DEP] $< \r"
$(CXX) $(CPPFLAGS) $(INCLUDES) -MM -MF $@ $<
# Main target
$(TARGET): $(OBJECTS_ALL)
@echo -e " [LD] $@"
$(LD) r $(LDFLAGS) $@ $^
# $(LIBS)