summaryrefslogtreecommitdiff
blob: bf8011d4992602f8ac77469fe48182a53a82d833 (plain)
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
From: Julian Ospald <hasufell@gentoo.org>
Date: Wed Mar 20 15:05:13 UTC 2013
Subject: build system

* respect system CXXFLAGS
* respect LDFLAGS in linking invocation
* use PKG_CONFIG where possible
* make bundled enet switchable
* fix underlinking on X11

--- 1.1.0.4/source/src/Makefile
+++ 1.1.0.4/source/src/Makefile
@@ -1,32 +1,77 @@
-//CXX=g++-gcc-4.2.3
-CXXFLAGS= -O3 -fomit-frame-pointer
+## options
+# set to YES or NO
+#
+# BUNDLED_ENET=YES (use bundled enet)
+#
+# MINGWBUILD=YES (mingw build)
+
+
+CXXFLAGS ?= -O3 -fomit-frame-pointer
 override CXXFLAGS+= -Wall -fsigned-char
 
+PKG_CONFIG ?= pkg-config
+
 PLATFORM= $(shell uname -s)
 PLATFORM_PREFIX=native
 
-INCLUDES= -I. -Ibot -I../enet/include
+INCLUDES = -I. -Ibot
 
-STRIP=
-ifeq (,$(findstring -g,$(CXXFLAGS)))
-ifeq (,$(findstring -pg,$(CXXFLAGS)))
-  STRIP=strip
-endif
+BUNDLED_ENET ?= YES
+ifeq ($(BUNDLED_ENET),YES)
+INCLUDES += -I../enet/include
+else
+INCLUDES += $(shell $(PKG_CONFIG) --cflags libenet)
 endif
 
+
+STRIP=
+
 MV=mv
 
 ifneq (,$(findstring MINGW,$(PLATFORM)))
+MINGWBUILD=YES
+endif
+
+ifeq ($(MINGWBUILD),YES)
 WINDRES= windres
 CLIENT_INCLUDES= $(INCLUDES) -I../include
 # -lSDL_ttf 
 CLIENT_LIBS= -mwindows -L../lib -lSDL -lSDL_image -lzdll -lopengl32 -lenet -lOpenAL32 -llibvorbisfile -llibintl -lws2_32 -lwinmm
 else
-USRLIB=$(shell if [ -e /usr/lib64 ]; then echo "/usr/lib64"; else echo "/usr/lib"; fi)
 override CXXFLAGS+= -rdynamic
-CLIENT_INCLUDES= $(INCLUDES) -I/usr/include `sdl-config --cflags` -idirafter ../include
+CLIENT_INCLUDES= \
+		 $(INCLUDES) \
+		 -I/usr/include \
+		 `sdl-config --cflags` \
+		 -idirafter ../include \
+		 $(shell $(PKG_CONFIG) --cflags SDL_image) \
+		 $(shell $(PKG_CONFIG) --cflags zlib) \
+		 $(shell $(PKG_CONFIG) --cflags gl) \
+		 $(shell $(PKG_CONFIG) --cflags openal) \
+		 $(shell $(PKG_CONFIG) --cflags vorbisfile) \
+		 $(shell $(PKG_CONFIG) --cflags x11)
+
+ifneq ($(BUNDLED_ENET),YES)
+CLIENT_INCLUDES += $(shell $(PKG_CONFIG) --cflags libenet)
+endif
+
 # -lSDL_ttf 
-CLIENT_LIBS= -L../enet/.libs -lenet -L$(USRLIB) `sdl-config --libs` -lSDL_image -lz -lGL -lopenal -lvorbisfile
+CLIENT_LIBS= \
+	     `sdl-config --libs` \
+	     $(shell $(PKG_CONFIG) --libs SDL_image) \
+	     $(shell $(PKG_CONFIG) --libs zlib) \
+	     $(shell $(PKG_CONFIG) --libs gl) \
+	     $(shell $(PKG_CONFIG) --libs openal) \
+	     $(shell $(PKG_CONFIG) --libs vorbisfile) \
+	     $(shell $(PKG_CONFIG) --libs x11)
+
+
+ifeq ($(BUNDLED_ENET),YES)
+CLIENT_LIBS += -L../enet/.libs -lenet
+else
+CLIENT_LIBS += $(shell $(PKG_CONFIG) --libs libenet)
+endif
+
 endif
 
 CLIENT_OBJS= \
@@ -83,17 +128,27 @@
 	bot/bot_waypoint.o \
 	bot/ac_bot.o \
 	bot/ac_bot_ai.o 
-ifneq (,$(findstring MINGW,$(PLATFORM)))
+ifeq ($(MINGWBUILD),YES)
 CLIENT_OBJS+= ../vcpp/SDL_win32_main.o
 endif
 CLIENT_PCH= cube.h.gch
 
-ifneq (,$(findstring MINGW,$(PLATFORM)))
+ifeq ($(MINGWBUILD),YES)
 SERVER_INCLUDES= -DSTANDALONE $(INCLUDES) -I../include
 SERVER_LIBS= -L../lib -lzdll -lenet -llibintl -lws2_32 -lwinmm
 else
-SERVER_INCLUDES= -DSTANDALONE $(INCLUDES)
-SERVER_LIBS= -L../enet/.libs -lenet -lz
+SERVER_INCLUDES= \
+		 -DSTANDALONE \
+		 $(INCLUDES) \
+		 $(shell $(PKG_CONFIG) --cflags zlib)
+
+SERVER_LIBS= $(shell $(PKG_CONFIG) --libs zlib)
+ifeq ($(BUNDLED_ENET),YES)
+SERVER_LIBS += -L../enet/.libs -lenet
+else
+SERVER_LIBS += $(shell $(PKG_CONFIG) --libs libenet)
+endif
+
 endif
 
 SERVER_OBJS= \
@@ -146,7 +201,7 @@
 $(SERVER_OBJS): CXXFLAGS += $(SERVER_INCLUDES)
 $(filter-out $(SERVER_OBJS),$(MASTER_OBJS)): CXXFLAGS += $(SERVER_INCLUDES)
 
-ifneq (,$(findstring MINGW,$(PLATFORM)))
+ifeq ($(MINGWBUILD),YES)
 ../vcpp/%.o:
 	$(CXX) $(CXXFLAGS) -c -o $@ $(subst .o,.c,$@) 
 
@@ -164,14 +219,25 @@
 server_install: server
 
 else
+ifeq ($(BUNDLED_ENET),YES)
 client: libenet $(CLIENT_OBJS)
-	$(CXX) $(CXXFLAGS) -o ac_client $(CLIENT_OBJS) $(CLIENT_LIBS)
+	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o ac_client $(CLIENT_OBJS) $(CLIENT_LIBS)
 
 server: libenet $(SERVER_OBJS)
-	$(CXX) $(CXXFLAGS) -o ac_server $(SERVER_OBJS) $(SERVER_LIBS)  
+	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o ac_server $(SERVER_OBJS) $(SERVER_LIBS)
 
 master: libenet $(MASTER_OBJS)
-	$(CXX) $(CXXFLAGS) -o ac_master $(MASTER_OBJS) $(SERVER_LIBS)  
+	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o ac_master $(MASTER_OBJS) $(SERVER_LIBS)
+else
+client: $(CLIENT_OBJS)
+	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o ac_client $(CLIENT_OBJS) $(CLIENT_LIBS)
+
+server: $(SERVER_OBJS)
+	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o ac_server $(SERVER_OBJS) $(SERVER_LIBS)
+
+master: $(MASTER_OBJS)
+	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o ac_master $(MASTER_OBJS) $(SERVER_LIBS)
+endif
 	
 client_install: client
 	cp ac_client ../../bin_unix/$(PLATFORM_PREFIX)_client