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