-makeversion.py
[xonotic/netradiant.git] / Makefile
1 CFLAGS = -W -Wall -Wcast-align -Wcast-qual -Wno-unused-parameter -g3 -fPIC
2 CXXFLAGS = $(CFLAGS) -Wno-non-virtual-dtor -Wreorder -fno-exceptions -fno-rtti
3 CPPFLAGS_COMMON = -DPOSIX -DXWINDOWS -D_DEBUG -D_LINUX
4 LDFLAGS_COMMON = 
5 LDFLAGS_DLL = -fPIC -Wl,-fini,fini_stub -static-libgcc -ldl
6
7 EXE = x86
8 A = a
9 DLL = so
10 NETAPI = berkley
11
12 RADIANT_ABOUTMSG = Custom build
13
14 LDD ?= ldd
15 FIND ?= find
16 RANLIB ?= ranlib
17 AR ?= ar
18 MKDIR ?= mkdir -p
19
20 TEE_STDERR ?= | tee /dev/stderr
21
22 CPPFLAGS_GLIB = `pkg-config glib-2.0 --cflags`
23 LIBS_GLIB = `pkg-config glib-2.0 --libs`
24
25 CPPFLAGS_XML = `xml2-config --cflags`
26 LIBS_XML = `xml2-config --libs`
27
28 CPPFLAGS_PNG = `libpng-config --cflags`
29 LIBS_PNG = `libpng-config --libs`
30
31 CPPFLAGS_GTK = `pkg-config gtk+-2.0 --cflags`
32 LIBS_GTK = `pkg-config gtk+-2.0 --libs`
33
34 CPPFLAGS_GTKGLEXT = `pkg-config gtkglext-1.0 --cflags`
35 LIBS_GTKGLEXT = `pkg-config gtkglext-1.0 --libs`
36
37 LDFLAGS := $(LDFLAGS_COMMON)
38
39 # from qe3.cpp: const char* const EXECUTABLE_TYPE = 
40 # from qe3.cpp: #if defined(__linux__) || defined (__FreeBSD__)
41 # from qe3.cpp: "x86"
42 # from qe3.cpp: #elif defined(__APPLE__)
43 # from qe3.cpp: "ppc"
44 # from qe3.cpp: #elif defined(WIN32)
45 # from qe3.cpp: "exe"
46 # from qe3.cpp: #else
47 # from qe3.cpp: #error "unknown platform"
48 # from qe3.cpp: #endif
49 # from qe3.cpp: ;
50
51 .PHONY: all
52 all: \
53         makeversion \
54         install/q3map2.$(EXE) \
55         install/q3data.$(EXE) \
56         install/radiant.$(EXE) \
57         install/modules/archivezip.$(DLL) \
58         install/modules/entity.$(DLL) \
59         install/modules/image.$(DLL) \
60         install/modules/imagepng.$(DLL) \
61         install/modules/mapq3.$(DLL) \
62         install/modules/md3model.$(DLL) \
63         install/modules/model.$(DLL) \
64         install/modules/shaders.$(DLL) \
65         install/modules/vfspk3.$(DLL) \
66
67 .PHONY: clean
68 clean:
69         $(FIND) . \( -name \*.o -o -name \*.$(SO) -o -name \*.$(A) -o -name \*.$(EXE) \) -exec $(RM) {} \;
70
71 %.$(EXE):
72         dir=$@; $(MKDIR) $${dir%/*}
73         $(CXX) -o $@ $^ $(LDFLAGS) $(LIBS)
74         [ -z "$(LDD)" ] || [ -z "`$(LDD) -r $@ 2>&1 >/dev/null $(TEE_STDERR)`" ] || { $(RM) $@; exit 1; }
75
76 %.$(A):
77         $(AR) rc $@ $^
78         $(RANLIB) $@
79
80 %.$(DLL):
81         dir=$@; $(MKDIR) $${dir%/*}
82         $(CXX) -shared -o $@ $^ $(LDFLAGS) $(LDFLAGS_DLL) $(LIBS)
83         [ -z "$(LDD)" ] || [ -z "`$(LDD) -r $@ 2>&1 >/dev/null $(TEE_STDERR)`" ] || { $(RM) $@; exit 1; }
84
85 install/q3map2.$(EXE): LIBS := $(LIBS_XML) $(LIBS_GLIB) $(LIBS_PNG)
86 install/q3map2.$(EXE): CPPFLAGS := $(CPPFLAGS_COMMON) $(CPPFLAGS_XML) $(CPPFLAGS_GLIB) $(CPPFLAGS_PNG) -Itools/quake3/common -Ilibs -Iinclude
87 install/q3map2.$(EXE): \
88         tools/quake3/common/cmdlib.o \
89         tools/quake3/common/imagelib.o \
90         tools/quake3/common/inout.o \
91         tools/quake3/common/mutex.o \
92         tools/quake3/common/polylib.o \
93         tools/quake3/common/scriplib.o \
94         tools/quake3/common/threads.o \
95         tools/quake3/common/unzip.o \
96         tools/quake3/common/vfs.o \
97         tools/quake3/common/md4.o \
98         tools/quake3/q3map2/brush.o \
99         tools/quake3/q3map2/brush_primit.o \
100         tools/quake3/q3map2/bspfile_abstract.o \
101         tools/quake3/q3map2/bspfile_ibsp.o \
102         tools/quake3/q3map2/bspfile_rbsp.o \
103         tools/quake3/q3map2/bsp.o \
104         tools/quake3/q3map2/convert_ase.o \
105         tools/quake3/q3map2/convert_map.o \
106         tools/quake3/q3map2/decals.o \
107         tools/quake3/q3map2/facebsp.o \
108         tools/quake3/q3map2/fog.o \
109         tools/quake3/q3map2/image.o \
110         tools/quake3/q3map2/leakfile.o \
111         tools/quake3/q3map2/light_bounce.o \
112         tools/quake3/q3map2/lightmaps_ydnar.o \
113         tools/quake3/q3map2/light.o \
114         tools/quake3/q3map2/light_trace.o \
115         tools/quake3/q3map2/light_ydnar.o \
116         tools/quake3/q3map2/main.o \
117         tools/quake3/q3map2/map.o \
118         tools/quake3/q3map2/mesh.o \
119         tools/quake3/q3map2/model.o \
120         tools/quake3/q3map2/patch.o \
121         tools/quake3/q3map2/path_init.o \
122         tools/quake3/q3map2/portals.o \
123         tools/quake3/q3map2/prtfile.o \
124         tools/quake3/q3map2/shaders.o \
125         tools/quake3/q3map2/surface_extra.o \
126         tools/quake3/q3map2/surface_foliage.o \
127         tools/quake3/q3map2/surface_fur.o \
128         tools/quake3/q3map2/surface_meta.o \
129         tools/quake3/q3map2/surface.o \
130         tools/quake3/q3map2/tjunction.o \
131         tools/quake3/q3map2/tree.o \
132         tools/quake3/q3map2/visflow.o \
133         tools/quake3/q3map2/vis.o \
134         tools/quake3/q3map2/writebsp.o \
135         libmathlib.$(A) \
136         libl_net.$(A) \
137         libjpeg6.$(A) \
138         libpicomodel.$(A) \
139         libddslib.$(A) \
140
141 libmathlib.$(A): CPPFLAGS := $(CPPFLAGS_COMMON) -Ilibs
142 libmathlib.$(A): \
143         libs/mathlib/mathlib.o \
144         libs/mathlib/bbox.o \
145         libs/mathlib/line.o \
146         libs/mathlib/m4x4.o \
147         libs/mathlib/ray.o \
148
149 libl_net.$(A): CPPFLAGS := $(CPPFLAGS_COMMON) -Ilibs
150 libl_net.$(A): \
151         libs/l_net/l_net.o \
152         libs/l_net/l_net_$(NETAPI).o \
153
154 libjpeg6.$(A): CPPFLAGS := $(CPPFLAGS_COMMON) -Ilibs/jpeg6 -Ilibs
155 libjpeg6.$(A): \
156         libs/jpeg6/jcomapi.o \
157         libs/jpeg6/jdcoefct.o \
158         libs/jpeg6/jdinput.o \
159         libs/jpeg6/jdpostct.o \
160         libs/jpeg6/jfdctflt.o \
161         libs/jpeg6/jpgload.o \
162         libs/jpeg6/jdapimin.o \
163         libs/jpeg6/jdcolor.o \
164         libs/jpeg6/jdmainct.o \
165         libs/jpeg6/jdsample.o \
166         libs/jpeg6/jidctflt.o \
167         libs/jpeg6/jutils.o \
168         libs/jpeg6/jdapistd.o \
169         libs/jpeg6/jddctmgr.o \
170         libs/jpeg6/jdmarker.o \
171         libs/jpeg6/jdtrans.o \
172         libs/jpeg6/jmemmgr.o \
173         libs/jpeg6/jdatasrc.o \
174         libs/jpeg6/jdhuff.o \
175         libs/jpeg6/jdmaster.o \
176         libs/jpeg6/jerror.o \
177         libs/jpeg6/jmemnobs.o \
178
179 libpicomodel.$(A): CPPFLAGS := $(CPPFLAGS_COMMON) -Ilibs
180 libpicomodel.$(A): \
181         libs/picomodel/picointernal.o \
182         libs/picomodel/picomodel.o \
183         libs/picomodel/picomodules.o \
184         libs/picomodel/pm_3ds.o \
185         libs/picomodel/pm_ase.o \
186         libs/picomodel/pm_md3.o \
187         libs/picomodel/pm_obj.o \
188         libs/picomodel/pm_ms3d.o \
189         libs/picomodel/pm_mdc.o \
190         libs/picomodel/pm_fm.o \
191         libs/picomodel/pm_md2.o \
192         libs/picomodel/pm_lwo.o \
193         libs/picomodel/pm_terrain.o \
194         libs/picomodel/lwo/clip.o \
195         libs/picomodel/lwo/envelope.o \
196         libs/picomodel/lwo/list.o \
197         libs/picomodel/lwo/lwio.o \
198         libs/picomodel/lwo/lwo2.o \
199         libs/picomodel/lwo/lwob.o \
200         libs/picomodel/lwo/pntspols.o \
201         libs/picomodel/lwo/surface.o \
202         libs/picomodel/lwo/vecmath.o \
203         libs/picomodel/lwo/vmap.o \
204
205 libddslib.$(A): CPPFLAGS := $(CPPFLAGS_COMMON) -Ilibs
206 libddslib.$(A): \
207         libs/ddslib/ddslib.o \
208
209 install/q3data.$(EXE): LIBS := $(LIBS_XML) $(LIBS_GLIB)
210 install/q3data.$(EXE): CPPFLAGS := $(CPPFLAGS_COMMON) $(CPPFLAGS_XML) $(CPPFLAGS_GLIB) -Itools/quake3/common -Ilibs -Iinclude
211 install/q3data.$(EXE): \
212         tools/quake3/common/aselib.o \
213         tools/quake3/common/bspfile.o \
214         tools/quake3/common/cmdlib.o \
215         tools/quake3/common/imagelib.o \
216         tools/quake3/common/inout.o \
217         tools/quake3/common/md4.o \
218         tools/quake3/common/scriplib.o \
219         tools/quake3/common/trilib.o \
220         tools/quake3/common/unzip.o \
221         tools/quake3/common/vfs.o \
222         tools/quake3/q3data/3dslib.o \
223         tools/quake3/q3data/compress.o \
224         tools/quake3/q3data/images.o \
225         tools/quake3/q3data/md3lib.o \
226         tools/quake3/q3data/models.o \
227         tools/quake3/q3data/p3dlib.o \
228         tools/quake3/q3data/polyset.o \
229         tools/quake3/q3data/q3data.o \
230         tools/quake3/q3data/stripper.o \
231         tools/quake3/q3data/video.o \
232         libmathlib.$(A) \
233         libl_net.$(A) \
234
235 install/radiant.$(EXE): LIBS := -ldl -lGL -static-libgcc $(LIBS_XML) $(LIBS_GLIB) $(LIBS_GTK) $(LIBS_GTKGLEXT)
236 install/radiant.$(EXE): CPPFLAGS := $(CPPFLAGS_COMMON) $(CPPFLAGS_XML) $(CPPFLAGS_GLIB) $(CPPFLAGS_GTK) $(CPPFLAGS_GTKGLEXT) -Ilibs -Iinclude
237 #install/radiant.$(EXE): LDFLAGS := -fPIC -Wl,-fini,fini_stub $(LDFLAGS_COMMON)
238 install/radiant.$(EXE): \
239         radiant/autosave.o \
240         radiant/brush.o \
241         radiant/brushmanip.o \
242         radiant/brushmodule.o \
243         radiant/brushnode.o \
244         radiant/brushtokens.o \
245         radiant/brushxml.o \
246         radiant/brush_primit.o \
247         radiant/build.o \
248         radiant/camwindow.o \
249         radiant/clippertool.o \
250         radiant/commands.o \
251         radiant/console.o \
252         radiant/csg.o \
253         radiant/dialog.o \
254         radiant/eclass.o \
255         radiant/eclass_def.o \
256         radiant/eclass_doom3.o \
257         radiant/eclass_fgd.o \
258         radiant/eclass_xml.o \
259         radiant/entity.o \
260         radiant/entityinspector.o \
261         radiant/entitylist.o \
262         radiant/environment.o \
263         radiant/error.o \
264         radiant/feedback.o \
265         radiant/filetypes.o \
266         radiant/filters.o \
267         radiant/findtexturedialog.o \
268         radiant/glwidget.o \
269         radiant/grid.o \
270         radiant/groupdialog.o \
271         radiant/gtkdlgs.o \
272         radiant/gtkmisc.o \
273         radiant/help.o \
274         radiant/image.o \
275         radiant/main.o \
276         radiant/mainframe.o \
277         radiant/map.o \
278         radiant/mru.o \
279         radiant/nullmodel.o \
280         radiant/parse.o \
281         radiant/patch.o \
282         radiant/patchdialog.o \
283         radiant/patchmanip.o \
284         radiant/patchmodule.o \
285         radiant/plugin.o \
286         radiant/pluginapi.o \
287         radiant/pluginmanager.o \
288         radiant/pluginmenu.o \
289         radiant/plugintoolbar.o \
290         radiant/points.o \
291         radiant/preferencedictionary.o \
292         radiant/preferences.o \
293         radiant/qe3.o \
294         radiant/qgl.o \
295         radiant/referencecache.o \
296         radiant/renderer.o \
297         radiant/renderstate.o \
298         radiant/scenegraph.o \
299         radiant/stacktrace.o \
300         radiant/select.o \
301         radiant/selection.o \
302         radiant/server.o \
303         radiant/shaders.o \
304         radiant/sockets.o \
305         radiant/surfacedialog.o \
306         radiant/texmanip.o \
307         radiant/textures.o \
308         radiant/texwindow.o \
309         radiant/timer.o \
310         radiant/treemodel.o \
311         radiant/undo.o \
312         radiant/url.o \
313         radiant/view.o \
314         radiant/watchbsp.o \
315         radiant/winding.o \
316         radiant/windowobservers.o \
317         radiant/xmlstuff.o \
318         radiant/xywindow.o \
319         libmathlib.$(A) \
320         libcmdlib.$(A) \
321         libl_net.$(A) \
322         libprofile.$(A) \
323         libgtkutil.$(A) \
324         libxmllib.$(A) \
325
326 libcmdlib.$(A): CPPFLAGS := $(CPPFLAGS_COMMON) -Ilibs
327 libcmdlib.$(A): \
328         libs/cmdlib/cmdlib.o \
329
330 libprofile.$(A): CPPFLAGS := $(CPPFLAGS_COMMON) -Ilibs -Iinclude
331 libprofile.$(A): \
332         libs/profile/profile.o \
333         libs/profile/file.o \
334
335 libgtkutil.$(A): CPPFLAGS := $(CPPFLAGS_COMMON) $(CPPFLAGS_GLIB) $(CPPFLAGS_GTK) $(CPPFLAGS_GTKGLEXT) -Ilibs -Iinclude
336 libgtkutil.$(A): \
337         libs/gtkutil/accelerator.o \
338         libs/gtkutil/button.o \
339         libs/gtkutil/clipboard.o \
340         libs/gtkutil/closure.o \
341         libs/gtkutil/container.o \
342         libs/gtkutil/cursor.o \
343         libs/gtkutil/dialog.o \
344         libs/gtkutil/entry.o \
345         libs/gtkutil/frame.o \
346         libs/gtkutil/filechooser.o \
347         libs/gtkutil/glfont.o \
348         libs/gtkutil/glwidget.o \
349         libs/gtkutil/image.o \
350         libs/gtkutil/idledraw.o \
351         libs/gtkutil/menu.o \
352         libs/gtkutil/messagebox.o \
353         libs/gtkutil/nonmodal.o \
354         libs/gtkutil/paned.o \
355         libs/gtkutil/pointer.o \
356         libs/gtkutil/toolbar.o \
357         libs/gtkutil/widget.o \
358         libs/gtkutil/window.o \
359         libs/gtkutil/xorrectangle.o \
360
361 libxmllib.$(A): CPPFLAGS := $(CPPFLAGS_COMMON) $(CPPFLAGS_XML) $(CPPFLAGS_GLIB) -Ilibs -Iinclude
362 libxmllib.$(A): \
363         libs/xml/ixml.o \
364         libs/xml/xmlparser.o \
365         libs/xml/xmlwriter.o \
366         libs/xml/xmlelement.o \
367         libs/xml/xmltextags.o \
368
369 install/modules/archivezip.$(DLL): LIBS := -lz
370 install/modules/archivezip.$(DLL): CPPFLAGS := $(CPPFLAGS_COMMON) -Ilibs -Iinclude
371 install/modules/archivezip.$(DLL): \
372         plugins/archivezip/plugin.o \
373         plugins/archivezip/archive.o \
374         plugins/archivezip/pkzip.o \
375         plugins/archivezip/zlibstream.o \
376
377 install/modules/entity.$(DLL): CPPFLAGS := $(CPPFLAGS_COMMON) -Ilibs -Iinclude
378 install/modules/entity.$(DLL): \
379         plugins/entity/plugin.o \
380         plugins/entity/entity.o \
381         plugins/entity/eclassmodel.o \
382         plugins/entity/generic.o \
383         plugins/entity/group.o \
384         plugins/entity/light.o \
385         plugins/entity/miscmodel.o \
386         plugins/entity/doom3group.o \
387         plugins/entity/skincache.o \
388         plugins/entity/angle.o \
389         plugins/entity/angles.o \
390         plugins/entity/colour.o \
391         plugins/entity/filters.o \
392         plugins/entity/model.o \
393         plugins/entity/namedentity.o \
394         plugins/entity/origin.o \
395         plugins/entity/scale.o \
396         plugins/entity/targetable.o \
397         plugins/entity/rotation.o \
398         plugins/entity/modelskinkey.o \
399
400 install/modules/image.$(DLL): CPPFLAGS := $(CPPFLAGS_COMMON) -Ilibs -Iinclude
401 install/modules/image.$(DLL): \
402         plugins/image/bmp.o \
403         plugins/image/jpeg.o \
404         plugins/image/image.o \
405         plugins/image/pcx.o \
406         plugins/image/tga.o \
407         plugins/image/dds.o \
408         libjpeg6.$(A) \
409         libddslib.$(A) \
410
411 install/modules/imagepng.$(DLL): LIBS := $(LIBS_PNG)
412 install/modules/imagepng.$(DLL): CPPFLAGS := $(CPPFLAGS_COMMON) $(CPPFLAGS_PNG) -Ilibs -Iinclude
413 install/modules/imagepng.$(DLL): \
414         plugins/imagepng/plugin.o \
415
416 install/modules/mapq3.$(DLL): CPPFLAGS := $(CPPFLAGS_COMMON) -Ilibs -Iinclude
417 install/modules/mapq3.$(DLL): \
418         plugins/mapq3/plugin.o \
419         plugins/mapq3/parse.o \
420         plugins/mapq3/write.o \
421
422 install/modules/md3model.$(DLL): CPPFLAGS := $(CPPFLAGS_COMMON) -Ilibs -Iinclude
423 install/modules/md3model.$(DLL): \
424         plugins/md3model/plugin.o \
425         plugins/md3model/mdl.o \
426         plugins/md3model/md3.o \
427         plugins/md3model/md2.o \
428         plugins/md3model/mdc.o \
429         plugins/md3model/mdlimage.o \
430         plugins/md3model/md5.o \
431
432 install/modules/model.$(DLL): CPPFLAGS := $(CPPFLAGS_COMMON) -Ilibs -Iinclude
433 install/modules/model.$(DLL): \
434         plugins/model/plugin.o \
435         plugins/model/model.o \
436         libpicomodel.$(A) \
437
438 install/modules/shaders.$(DLL): LIBS := $(LIBS_GLIB)
439 install/modules/shaders.$(DLL): CPPFLAGS := $(CPPFLAGS_COMMON) $(CPPFLAGS_GLIB) -Ilibs -Iinclude
440 install/modules/shaders.$(DLL): \
441         plugins/shaders/plugin.o \
442         plugins/shaders/shaders.o \
443
444 install/modules/vfspk3.$(DLL): LIBS := $(LIBS_GLIB)
445 install/modules/vfspk3.$(DLL): CPPFLAGS := $(CPPFLAGS_COMMON) $(CPPFLAGS_GLIB) -Ilibs -Iinclude
446 install/modules/vfspk3.$(DLL): \
447         plugins/vfspk3/archive.o \
448         plugins/vfspk3/vfs.o \
449         plugins/vfspk3/vfspk3.o \
450
451 .PHONY: makeversion
452 makeversion:
453         set -ex; \
454         ver=`cat include/version.default`; \
455         major=`echo $$ver | cut -d . -f 2`; \
456         minor=`echo $$ver | cut -d . -f 3 | cut -d - -f 1`; \
457         echo "// generated header, see Makefile" > include/version.h; \
458         echo "#define RADIANT_VERSION \"$$ver\"" >> include/version.h; \
459         echo "#define RADIANT_MAJOR_VERSION \"$$major\"" >> include/version.h; \
460         echo "#define RADIANT_MINOR_VERSION \"$$minor\"" >> include/version.h; \
461         echo "$$major" > include/RADIANT_MAJOR; \
462         echo "$$minor" > include/RADIANT_MINOR; \
463         echo "$$ver" > include/version; \
464         echo "// generated header, see Makefile" > include/aboutmsg.h; \
465         echo "#define RADIANT_ABOUTMSG \"$(RADIANT_ABOUTMSG)\"" >> include/aboutmsg.h; \
466