From 5cf4479b591bce68657a938b201114680839ec92 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 15 Jun 2010 10:29:05 +0000 Subject: [PATCH] Add dependency generation to generate.py Replace patsubst cascades with a better solution Add enums.table.t to TEMPLATES in Makefile Mark the "all" target as phony and make it the first target --- Makefile | 26 ++++++++++++++++---------- generate.py | 23 ++++++++++++++++++++--- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index c1860bd..3fda9ec 100644 --- a/Makefile +++ b/Makefile @@ -28,11 +28,13 @@ TEMPLATES := source/functions.enum.t \ source/gldecoder.funcs.t \ source/gldecoder.struct.t \ source/glprint.funcs.t \ - source/glwrap.funcs.t + source/glwrap.funcs.t \ + source/enums.table.t -objs = $(patsubst source/%.cpp,temp/%.o,$(patsubst source/%.c,temp/%.o,$(1))) -deps = $(patsubst source/%.cpp,temp/%.d,$(patsubst source/%.c,temp/%.d,$(1))) -gen = $(patsubst source/%.t,gensrc/%,$(1)) +rename = $(addprefix $(1)/,$(addsuffix $(2),$(basename $(notdir $(3))))) +objs = $(call rename,temp,.o,$(1)) +deps = $(call rename,temp,.d,$(1)) +gen = $(call rename,gensrc,,$(1)) GENSOURCES := $(call gen,$(TEMPLATES)) SOURCES_all := $(sort $(SOURCES_libgldbg) $(SOURCES_glwrap) $(SOURCES_gldump) $(SOURCES_gldbg)) @@ -43,14 +45,15 @@ OBJECTS_gldump := $(call objs,$(SOURCES_gldump)) OBJECTS_gldbg := $(call objs,$(SOURCES_gldbg)) OBJECTS_all := $(call objs,$(SOURCES_all)) -DEPS_all := $(call deps,$(SOURCES_all)) +DEPS_all := $(call deps,$(SOURCES_all) $(TEMPLATES)) + +.PHONY: all +all: glwrap.so gldump gldbg $(OBJECTS_gldbg): CXXFLAGS += $(shell pkg-config --cflags $(PACKAGES_gldbg)) gldbg: LIBS += $(shell pkg-config --libs $(PACKAGES_gldbg)) -lreadline gldump gldbg: LIBS += ./libgldbg.a -all: glwrap.so gldump gldbg - glwrap.so: $(OBJECTS_glwrap) $(CC) -shared -o $@ $^ $(LIBS) $(LDFLAGS) @@ -73,7 +76,7 @@ temp/.created: mkdir -p temp touch $@ -gensrc/%: source/%.t gensrc/.created generate.py gl.api gl.tm gl.io gl.spec glx.api glx.tm glx.io glx.spec glxext.spec +gensrc/%: source/%.t gensrc/.created generate.py python ./generate.py $< gl.api glx.api >$@ gensrc/.created: @@ -83,10 +86,13 @@ gensrc/.created: -include $(DEPS_all) temp/%.d: source/%.c temp/.created - $(CC) $(CPPFLAGS) -MM -MF $@ -MT $(patsubst source/%.c,temp/%.o,$<) -MG $< + $(CC) $(CPPFLAGS) -MM -MF $@ -MT $(call rename,temp,.o,$<) -MG $< temp/%.d: source/%.cpp temp/.created - $(CXX) $(CPPFLAGS) -MM -MF $@ -MT $(patsubst source/%.cpp,temp/%.o,$<) -MG $< + $(CXX) $(CPPFLAGS) -MM -MF $@ -MT $(call rename,temp,.o,$<) -MG $< + +temp/%.d: source/%.t temp/.created + python ./generate.py --depends=$(call rename,gensrc,,$<) $< gl.api glx.api >$@ .PHONY: clean clean: diff --git a/generate.py b/generate.py index e30f6d1..0f9c569 100755 --- a/generate.py +++ b/generate.py @@ -3,6 +3,7 @@ import sys import os +import optparse class InputFile: def __init__(self, fn): @@ -423,9 +424,25 @@ def read_enums(fn, prefix): return enums -template = Template(sys.argv[1]) +parser = optparse.OptionParser() +parser.add_option("--depends", dest="depends", default=False) +(options, args) = parser.parse_args() + +template = Template(args[0]) apis = [] -for i in sys.argv[2:]: +for i in args[1:]: apis.append(Api(i)) -template.process(apis) +if options.depends: + deps = args[:] + if template.mode=="functions": + for api in apis: + deps += api.specs + deps.append(api.typemap) + deps.append(api.iomap) + elif template.mode=="enums": + for api in apis: + deps += api.enumspecs + sys.stdout.write("%s: %s\n"%(options.depends, " ".join(deps))) +else: + template.process(apis) -- 2.45.2