]> git.tdb.fi Git - gldbg.git/blob - Makefile
Enable bidirectional communication between gldbg and glwrap.so
[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         source/packet.c \
22         source/functions.c
23 SOURCES_glwrap := source/glwrap.c \
24         source/glwrap_funcs.c \
25         source/arraysize.c \
26         source/packet.c \
27         source/tmpalloc.c
28 SOURCES_gldump := source/gldump.c
29 SOURCES_gldbg := source/gldbg.cpp \
30         source/commandinterpreter.cpp \
31         source/process.cpp \
32         source/tool.cpp
33 SOURCES_tracer := source/tracer.cpp
34 SOURCES_profiler := source/profiler.cpp
35 SOURCES_inspector := source/inspector.cpp \
36         source/glstate.cpp \
37         source/arraystate.cpp \
38         source/texturestate.cpp \
39         source/bufferstate.cpp
40 TEMPLATES := source/functions.enum.t \
41         source/functions.table.t \
42         source/gldecoder.funcs.t \
43         source/gldecoder.struct.t \
44         source/glprint.funcs.t \
45         source/glwrap.funcs.t \
46         source/enums.table.t
47
48 rename = $(addprefix $(1)/,$(addsuffix $(2),$(basename $(notdir $(3)))))
49 objs = $(call rename,temp,.o,$(1))
50 deps = $(call rename,temp,.d,$(1))
51 gen = $(call rename,gensrc,,$(1))
52
53 .PHONY: all
54 all: glwrap.so gldump gldbg
55
56 include flavors/$(FLAVOR)/flavor.mk
57
58 SOURCES_gldbg += $(foreach tool,$(TOOLS),$(SOURCES_$(tool)))
59 GENSOURCES := $(call gen,$(TEMPLATES))
60 SOURCES_all := $(sort $(SOURCES_libgldbg) $(SOURCES_glwrap) $(SOURCES_gldump) $(SOURCES_gldbg))
61
62 OBJECTS_libgldbg := $(call objs,$(SOURCES_libgldbg))
63 OBJECTS_glwrap := $(call objs,$(SOURCES_glwrap))
64 OBJECTS_gldump := $(call objs,$(SOURCES_gldump))
65 OBJECTS_gldbg := $(call objs,$(SOURCES_gldbg))
66
67 OBJECTS_all := $(call objs,$(SOURCES_all))
68 DEPS_all := $(call deps,$(SOURCES_all) $(TEMPLATES))
69
70 $(OBJECTS_gldbg): CXXFLAGS += $(shell pkg-config --cflags $(PACKAGES_gldbg))
71 gldbg: LIBS += $(shell pkg-config --libs $(PACKAGES_gldbg)) -lreadline
72 gldump gldbg: LIBS += ./libgldbg.a
73 glwrap.so: LDFLAGS += -s
74
75 glwrap.so: $(OBJECTS_glwrap) glwrap.ld
76         $(CC) -shared -o $@ $^ $(LIBS) $(LDFLAGS)
77
78 gldump: $(OBJECTS_gldump) libgldbg.a
79         $(CC) -o $@ $^ $(LIBS) $(LDFLAGS)
80
81 gldbg: $(OBJECTS_gldbg) libgldbg.a
82         $(CXX) -o $@ $^ $(LIBS) $(LDFLAGS)
83
84 libgldbg.a: $(OBJECTS_libgldbg)
85         $(AR) rc $@ $^
86
87 temp/%.o: source/%.c temp/.created
88         $(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<
89
90 temp/%.o: source/%.cpp temp/.created
91         $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) -o $@ $<
92
93 temp/.created:
94         mkdir -p temp
95         touch $@
96
97 gensrc/%: source/%.t gensrc/.created generate.py
98         python ./generate.py $< $(APIS) >$@
99
100 gensrc/.created:
101         mkdir -p gensrc
102         touch $@
103
104 -include $(DEPS_all)
105
106 temp/%.d: source/%.c temp/.created
107         $(CC) $(CPPFLAGS) -MM -MF $@ -MT $(call rename,temp,.o,$<) -MG $<
108
109 temp/%.d: source/%.cpp temp/.created
110         $(CXX) $(CPPFLAGS) -MM -MF $@ -MT $(call rename,temp,.o,$<) -MG $<
111
112 temp/%.d: source/%.t temp/.created
113         python ./generate.py --depends=$(call rename,gensrc,,$<) $< $(APIS) >$@
114
115 .PHONY: clean
116 clean:
117         $(RM) $(DEPS_all)
118         $(RM) $(OBJECTS_all)
119         $(RM) gensrc/enums.table $(GENSOURCES)
120         $(RM) glwrap.so libgldbg.a gldump gldbg