]> git.tdb.fi Git - gldbg.git/blob - Makefile
Add a flavor system to allow addition of other OpenGL versions
[gldbg.git] / Makefile
1 # $Id$
2
3 ifeq ($(FLAVOR),)
4 FLAVOR := gl
5 endif
6
7 CPPFLAGS := -I. -Isource -Iflavors/$(FLAVOR)/source
8 CFLAGS := -ggdb -Wall -Wextra
9 CXXFLAGS := $(CFLAGS)
10
11 PACKAGES_gldbg := mspcore mspstrings mspio mspfs
12
13 FLAVOR_ROOT := flavors/$(FLAVOR)
14 VPATH := $(FLAVOR_ROOT)
15
16 SOURCES_libgldbg := source/gldecoder.c \
17         source/glprint.c \
18         source/enums.c \
19         source/arraysize.c \
20         source/tmpalloc.c
21 SOURCES_glwrap := source/glwrap.c \
22         source/glwrap_funcs.c \
23         source/arraysize.c
24 SOURCES_gldump := source/gldump.c
25 SOURCES_gldbg := source/gldbg.cpp \
26         source/commandinterpreter.cpp \
27         source/tracer.cpp \
28         source/process.cpp \
29         source/glstate.cpp \
30         source/texturestate.cpp \
31         source/bufferstate.cpp \
32         source/profiler.cpp \
33         source/arraystate.cpp
34 TEMPLATES := source/functions.enum.t \
35         source/gldecoder.funcs.t \
36         source/gldecoder.struct.t \
37         source/glprint.funcs.t \
38         source/glwrap.funcs.t \
39         source/enums.table.t
40
41 rename = $(addprefix $(1)/,$(addsuffix $(2),$(basename $(notdir $(3)))))
42 objs = $(call rename,temp,.o,$(1))
43 deps = $(call rename,temp,.d,$(1))
44 gen = $(call rename,gensrc,,$(1))
45
46 GENSOURCES := $(call gen,$(TEMPLATES))
47 SOURCES_all := $(sort $(SOURCES_libgldbg) $(SOURCES_glwrap) $(SOURCES_gldump) $(SOURCES_gldbg))
48
49 OBJECTS_libgldbg := $(call objs,$(SOURCES_libgldbg))
50 OBJECTS_glwrap := $(call objs,$(SOURCES_glwrap))
51 OBJECTS_gldump := $(call objs,$(SOURCES_gldump))
52 OBJECTS_gldbg := $(call objs,$(SOURCES_gldbg))
53
54 OBJECTS_all := $(call objs,$(SOURCES_all))
55 DEPS_all := $(call deps,$(SOURCES_all) $(TEMPLATES))
56
57 .PHONY: all
58 all: glwrap.so gldump gldbg
59
60 include flavors/$(FLAVOR)/flavor.mk
61
62 $(OBJECTS_gldbg): CXXFLAGS += $(shell pkg-config --cflags $(PACKAGES_gldbg))
63 gldbg: LIBS += $(shell pkg-config --libs $(PACKAGES_gldbg)) -lreadline
64 gldump gldbg: LIBS += ./libgldbg.a
65
66 glwrap.so: $(OBJECTS_glwrap)
67         $(CC) -shared -o $@ $^ $(LIBS) $(LDFLAGS)
68
69 gldump: $(OBJECTS_gldump) libgldbg.a
70         $(CC) -o $@ $^ $(LIBS) $(LDFLAGS)
71
72 gldbg: $(OBJECTS_gldbg) libgldbg.a
73         $(CXX) -o $@ $^ $(LIBS) $(LDFLAGS)
74
75 libgldbg.a: $(OBJECTS_libgldbg)
76         $(AR) rc $@ $^
77
78 temp/%.o: source/%.c temp/.created
79         $(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<
80
81 temp/%.o: source/%.cpp temp/.created
82         $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) -o $@ $<
83
84 temp/.created:
85         mkdir -p temp
86         touch $@
87
88 gensrc/%: source/%.t gensrc/.created generate.py
89         python ./generate.py $< $(APIS) >$@
90
91 gensrc/.created:
92         mkdir -p gensrc
93         touch $@
94
95 -include $(DEPS_all)
96
97 temp/%.d: source/%.c temp/.created
98         $(CC) $(CPPFLAGS) -MM -MF $@ -MT $(call rename,temp,.o,$<) -MG $<
99
100 temp/%.d: source/%.cpp temp/.created
101         $(CXX) $(CPPFLAGS) -MM -MF $@ -MT $(call rename,temp,.o,$<) -MG $<
102
103 temp/%.d: source/%.t temp/.created
104         python ./generate.py --depends=$(call rename,gensrc,,$<) $< $(APIS) >$@
105
106 .PHONY: clean
107 clean:
108         $(RM) $(DEPS_all)
109         $(RM) $(OBJECTS_all)
110         $(RM) gensrc/enums.table $(GENSOURCES)
111         $(RM) glwrap.so libgldbg.a gldump gldbg