This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project gfxprim.git.
The branch, generate has been updated via 27ea5ba0493ced3a9af7c3d6ee912fe87e78f0e3 (commit) via cce65abc35040e3a3473f476b7d8ca0902f8fbf2 (commit) via 01dcdb50122a43d5a26690c470c9fce2dc80046a (commit) via bc3e7e202aaedf55738f151b598ffc10161881c5 (commit) via af6444d674affcc352f05e1616ad2b6fa4a5dfe8 (commit) via 7f6bea085c6d5bdcef77c514eb41a96aac13e6d1 (commit) via db5988548d394fcf94da3d66ff85c40afd719fc1 (commit) via 665128da4ce856b78beece7af486c561a0a84f58 (commit) from 5e1cf45920d28673d7e1245b9709b65c1724084d (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- http://repo.or.cz/w/gfxprim.git/commit/27ea5ba0493ced3a9af7c3d6ee912fe87e78f...
commit 27ea5ba0493ced3a9af7c3d6ee912fe87e78f0e3 Author: Tomas Gavenciak gavento@ucw.cz Date: Thu May 26 01:44:23 2011 +0200
New generating arch, cont. (incl makefiles)
diff --git a/gen.mk b/gen.mk index 926fd57..28b1bc6 100644 --- a/gen.mk +++ b/gen.mk @@ -6,12 +6,6 @@ $(error LIBNAME not defined, fix your library Makefile) endif
# -# All potential dependencies for generated files -# -GENERATORS=$(shell find ${PYLIBSDIR} -name *.py) -CLEAN+=$(patsubst, %.py, %.pyc, ${GENERATORS}) - -# # Headers goes into include/core/ # INCLUDE_PREFIX=$(TOPDIR)/include/$(LIBNAME)/ @@ -23,7 +17,7 @@ RGENHEADERS=$(addprefix $(INCLUDE_PREFIX),$(GENHEADERS)) CSOURCES+=$(GENSOURCES)
# -# Make the targets build actually +# Make the genrated headers actually build # all: $(RGENHEADERS)
@@ -31,3 +25,13 @@ all: $(RGENHEADERS) # And clean them # CLEAN+=$(GENSOURCES) $(RGENHEADERS) + +# +# Currently, just depend on all python files +# +GENERATORS=$(PYTHON_FILES) + +# +# Generated files depend on python generators and libs +# +%.gen.c %.gen.h: $(GENERATORS) diff --git a/include.mk b/include.mk index 68fab64..ada1072 100644 --- a/include.mk +++ b/include.mk @@ -32,6 +32,13 @@ COMPILE=yes endif
# +# Potential python dependencies for generated files and scripts +# Add .pyc files to CLEAN list +# +PYTHON_FILES=$(shell find "${PYLIBSDIR}" -name *.py) +CLEAN+=$(patsubst, %.py, %.pyc, ${}) + +# # 1. Generate and include dependencies for all C sources # 2. Generate OBJECTS list from CSOURCES list # 3. Adds OBJECTS to CLEAN list diff --git a/pylib/bin/generate_file.py b/pylib/bin/generate_file.py new file mode 100644 index 0000000..ee56e8f --- /dev/null +++ b/pylib/bin/generate_file.py @@ -0,0 +1,22 @@ +#!/usr/bin/python +# +# Main source file generating script +# Collects all known file generators from the generators/ directory +# +# 2011 - Tomas Gavenciak gavento@ucw.cz +# + +import sys +from gfxprim import generators.utils, die + +usage = """Usage: %s [files_to_generate...] +The files are matched only based on path suffixes, but written to given paths. +""" + +def __main__(): + generators.utils.load_generators() + if len(sys.argv) <= 1: + die(usage) + for f in sys.argv[1:]: + generators.utils.generate_file(f) + diff --git a/pylib/gfxprim/generators/__init__.py b/pylib/gfxprim/generators/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pylib/gfxprim/generators/utils.py b/pylib/gfxprim/generators/generator.py similarity index 73% copy from pylib/gfxprim/generators/utils.py copy to pylib/gfxprim/generators/generator.py index 6cc2ddd..e0b4192 100644 --- a/pylib/gfxprim/generators/utils.py +++ b/pylib/gfxprim/generators/generator.py @@ -4,54 +4,12 @@ # 2011 - Tomas Gavenciak gavento@ucw.cz #
-import sys, os +import sys, os, time import jinja2
# List of known CodeGenerator classes known_generators = []
-def generate_file(fname): - "Function trying to generate file `fname` using matching known generator." - matches = [] - for k in known_generators: - if k.matches(fname): - matches.append(k) - if len(matches) == 0: - die("No known generators match '%s'" % (fname,)) - if len(matches) > 1: - die("Multiple generators match '%s': %s" % (fname, str(matches))) - s = matches[0].generate() - with open(fname, "wt") as f: - f.write(s) - -def j2render(tmpl, **kw): - "Internal helper to render jinja2 templates (with StrictUndefined)" - t2 = tmpl.rstrip('n') # Jinja strips the last 'n', so add these later - return jinja2.Template(t2, undefined=jinja2.StrictUndefined).render(**kw) + tmpl[len(t2):] - -#def hmask(bits): -# "Helper returning hex mask for that many bits" -# "WARN: may contain 'L'" -# return hex((1<<bits)-1) - -def c_source_generator(*args, **kwargs): - "Decorator to create C source generators." - def decorate(f): - kwargs['generating_f'] = f - kwargs['register'] = True - g = CSourceGenerator(*args, **kwargs) - return f - return decorate - -def c_header_generator(*args, **kwargs): - "Decorator to create C header generators." - def decorate(f): - kwargs['generating_f'] = f - kwargs['register'] = True - g = CHeaderGenerator(*args, **kwargs) - return f -return decorate - class CodeGenerator(object): "Args:n" "fname (required) - name of the generated file (without path)n" @@ -101,29 +59,37 @@ class CCodeGenerator(CodeGenerator): super(CCodeGenerator, self).__init__(**kwargs) self.authors = kwargs.pop('authors', []) self.descr = kwargs.pop('descr', "") - self.descr_star_lines = ''.join([(' * ' + i + 'n') - for i in self.descr.split('n')]) def gen_base(self): super(CCodeGenerator, self).gen_base() self.head.append(self.r( "/*n" - " * GENERATED SOURCE {{ g.fname }}n" - " * DO NOT MODIFY THIS FILE DIRECTLY! *n" + " * {{ g.fname }}n" " *n" - " * generated for filename suffix '{{ g.fname_suffix }}'n" - " *n" - "{{ g.descr_star_lines }}" + " * GENERATED on {{ date }} for suffix "{{ g.fname_suffix }}"n" + " * DO NOT MODIFY THIS FILE DIRECTLY!n" " *n" + "{% if g.descr %}" + " * {{ g.descr }}n *n" + "{% endif %}" "{% for a in g.authors %}" - " * {{ a }}n" + " * {{ a }}n" "{% endfor %}" - " */nn")) + " */nn", date = time.ctime()))
class CSourceGenerator(CCodeGenerator): def __init__(self, **kwargs): print kwargs super(CSourceGenerator, self).__init__(**kwargs)
+def c_source_generator(*args, **kwargs): + "Decorator to create C source generators." + def decorate(f): + kwargs['generating_f'] = f + kwargs['register'] = True + g = CSourceGenerator(*args, **kwargs) + return f + return decorate + class CHeaderGenerator(CCodeGenerator): def __init__(self, **kwargs): super(CHeaderGenerator, self).__init__(**kwargs) @@ -136,4 +102,11 @@ class CHeaderGenerator(CCodeGenerator): self.foot.append(self.r( "#endif /* {{ g.hdef }} */n"))
- +def c_header_generator(*args, **kwargs): + "Decorator to create C header generators." + def decorate(f): + kwargs['generating_f'] = f + kwargs['register'] = True + g = CHeaderGenerator(*args, **kwargs) + return f + return decorate diff --git a/pylib/gfxprim/generators/utils.py b/pylib/gfxprim/generators/utils.py index 6cc2ddd..ee388f9 100644 --- a/pylib/gfxprim/generators/utils.py +++ b/pylib/gfxprim/generators/utils.py @@ -4,17 +4,20 @@ # 2011 - Tomas Gavenciak gavento@ucw.cz #
-import sys, os +import sys, os, time import jinja2 +from gfxprim.generators.generator import known_generators
-# List of known CodeGenerator classes -known_generators = [] +def load_generators(): + "Load all modules containig generators to allow them to register" + # TODO: write + pass
def generate_file(fname): "Function trying to generate file `fname` using matching known generator." matches = [] for k in known_generators: - if k.matches(fname): + if k.matches_path(fname): matches.append(k) if len(matches) == 0: die("No known generators match '%s'" % (fname,)) @@ -29,111 +32,3 @@ def j2render(tmpl, **kw): t2 = tmpl.rstrip('n') # Jinja strips the last 'n', so add these later return jinja2.Template(t2, undefined=jinja2.StrictUndefined).render(**kw) + tmpl[len(t2):]
-#def hmask(bits): -# "Helper returning hex mask for that many bits" -# "WARN: may contain 'L'" -# return hex((1<<bits)-1) - -def c_source_generator(*args, **kwargs): - "Decorator to create C source generators." - def decorate(f): - kwargs['generating_f'] = f - kwargs['register'] = True - g = CSourceGenerator(*args, **kwargs) - return f - return decorate - -def c_header_generator(*args, **kwargs): - "Decorator to create C header generators." - def decorate(f): - kwargs['generating_f'] = f - kwargs['register'] = True - g = CHeaderGenerator(*args, **kwargs) - return f -return decorate - -class CodeGenerator(object): - "Args:n" - "fname (required) - name of the generated file (without path)n" - "fdir ('') - directory prefix to matchn" - "generating_f (None) - user function called in generate(), should generate contentn" - "register (False) - if true, register in global generator listn" - def __init__(self, **kwargs): - self.fname = kwargs.pop('fname') - self.fdir = kwargs.pop('fdir', "") - self.generating_f = kwargs.pop('generating_f', None) - self.register = kwargs.pop('register', False) - self.fname_suffix = os.path.join(self.fdir, self.fname) - self.head = [] - self.body = [] - self.foot = [] - if self.register: - known_generators.append(self) - def matches_path(self, path): - return path.endswith(self.fname_suffix) - def r(self, s, *args, **kwargs): - return j2render(s, g=self, *args, **kwargs) - def rhead(self, *args, **kwargs): - self.head.append(self.r(*args, **kwargs)) - def rbody(self, *args, **kwargs): - self.body.append(self.r(*args, **kwargs)) - def rfoot(self, *args, **kwargs): - self.foot.append(self.r(*args, **kwargs)) - def generate(self, run_gen_base=True): - self.head = [] - self.body = [] - self.foot = [] - if run_gen_base: - self.gen_base() - # Run user-specified generation - if self.generating_f: - self.generating_f(self) - return ''.join(self.head + self.body + self.foot) - def gen_base(self): - "Fill basic subclass-dependent content into head/body/foot" - pass - -class CCodeGenerator(CodeGenerator): - "Args:n" - "authors ([]) - list of author creditsn" - "descr ("") - (multiline) file descriptionn" - def __init__(self, **kwargs): - super(CCodeGenerator, self).__init__(**kwargs) - self.authors = kwargs.pop('authors', []) - self.descr = kwargs.pop('descr', "") - self.descr_star_lines = ''.join([(' * ' + i + 'n') - for i in self.descr.split('n')]) - def gen_base(self): - super(CCodeGenerator, self).gen_base() - self.head.append(self.r( - "/*n" - " * GENERATED SOURCE {{ g.fname }}n" - " * DO NOT MODIFY THIS FILE DIRECTLY! *n" - " *n" - " * generated for filename suffix '{{ g.fname_suffix }}'n" - " *n" - "{{ g.descr_star_lines }}" - " *n" - "{% for a in g.authors %}" - " * {{ a }}n" - "{% endfor %}" - " */nn")) - -class CSourceGenerator(CCodeGenerator): - def __init__(self, **kwargs): - print kwargs - super(CSourceGenerator, self).__init__(**kwargs) - -class CHeaderGenerator(CCodeGenerator): - def __init__(self, **kwargs): - super(CHeaderGenerator, self).__init__(**kwargs) - self.hdef = 'GP_HEADER_' + self.fname_suffix.replace('.', '_').replace('/', '_').upper() - def gen_base(self): - super(CHeaderGenerator, self).gen_base() - self.head.append(self.r( - "#ifndef {{ g.hdef }}n" - "#define {{ g.hdef }}nn")) - self.foot.append(self.r( - "#endif /* {{ g.hdef }} */n")) - -
http://repo.or.cz/w/gfxprim.git/commit/cce65abc35040e3a3473f476b7d8ca0902f8f...
commit cce65abc35040e3a3473f476b7d8ca0902f8fbf2 Author: Tomas Gavenciak gavento@ucw.cz Date: Thu May 26 01:24:14 2011 +0200
Mid-transposition to cleaner generating infratructure
diff --git a/pylib/gfxprim/core/__init__.py b/pylib/gfxprim/generators/core/__init__.py similarity index 100% rename from pylib/gfxprim/core/__init__.py rename to pylib/gfxprim/generators/core/__init__.py diff --git a/pylib/gfxprim/core/gen_blit.py b/pylib/gfxprim/generators/core/gen_blit.py similarity index 100% rename from pylib/gfxprim/core/gen_blit.py rename to pylib/gfxprim/generators/core/gen_blit.py diff --git a/pylib/gfxprim/core/gen_pixeltype.py b/pylib/gfxprim/generators/core/gen_pixeltype.py similarity index 100% rename from pylib/gfxprim/core/gen_pixeltype.py rename to pylib/gfxprim/generators/core/gen_pixeltype.py diff --git a/pylib/gfxprim/core/make_GP_Blit.py b/pylib/gfxprim/generators/core/make_GP_Blit.py similarity index 100% rename from pylib/gfxprim/core/make_GP_Blit.py rename to pylib/gfxprim/generators/core/make_GP_Blit.py diff --git a/pylib/gfxprim/core/make_GP_Pixel.py b/pylib/gfxprim/generators/core/make_GP_Pixel.py similarity index 100% rename from pylib/gfxprim/core/make_GP_Pixel.py rename to pylib/gfxprim/generators/core/make_GP_Pixel.py diff --git a/pylib/gfxprim/core/make_GP_Pixel_Scale.py b/pylib/gfxprim/generators/core/make_GP_Pixel_Scale.py similarity index 100% rename from pylib/gfxprim/core/make_GP_Pixel_Scale.py rename to pylib/gfxprim/generators/core/make_GP_Pixel_Scale.py diff --git a/pylib/gfxprim/pixeltype.py b/pylib/gfxprim/generators/pixeltype.py similarity index 100% rename from pylib/gfxprim/pixeltype.py rename to pylib/gfxprim/generators/pixeltype.py diff --git a/pylib/gfxprim/generators/utils.py b/pylib/gfxprim/generators/utils.py new file mode 100644 index 0000000..6cc2ddd --- /dev/null +++ b/pylib/gfxprim/generators/utils.py @@ -0,0 +1,139 @@ +# Module with templates and tools for writing generated code, +# especially C source and headers +# +# 2011 - Tomas Gavenciak gavento@ucw.cz +# + +import sys, os +import jinja2 + +# List of known CodeGenerator classes +known_generators = [] + +def generate_file(fname): + "Function trying to generate file `fname` using matching known generator." + matches = [] + for k in known_generators: + if k.matches(fname): + matches.append(k) + if len(matches) == 0: + die("No known generators match '%s'" % (fname,)) + if len(matches) > 1: + die("Multiple generators match '%s': %s" % (fname, str(matches))) + s = matches[0].generate() + with open(fname, "wt") as f: + f.write(s) + +def j2render(tmpl, **kw): + "Internal helper to render jinja2 templates (with StrictUndefined)" + t2 = tmpl.rstrip('n') # Jinja strips the last 'n', so add these later + return jinja2.Template(t2, undefined=jinja2.StrictUndefined).render(**kw) + tmpl[len(t2):] + +#def hmask(bits): +# "Helper returning hex mask for that many bits" +# "WARN: may contain 'L'" +# return hex((1<<bits)-1) + +def c_source_generator(*args, **kwargs): + "Decorator to create C source generators." + def decorate(f): + kwargs['generating_f'] = f + kwargs['register'] = True + g = CSourceGenerator(*args, **kwargs) + return f + return decorate + +def c_header_generator(*args, **kwargs): + "Decorator to create C header generators." + def decorate(f): + kwargs['generating_f'] = f + kwargs['register'] = True + g = CHeaderGenerator(*args, **kwargs) + return f +return decorate + +class CodeGenerator(object): + "Args:n" + "fname (required) - name of the generated file (without path)n" + "fdir ('') - directory prefix to matchn" + "generating_f (None) - user function called in generate(), should generate contentn" + "register (False) - if true, register in global generator listn" + def __init__(self, **kwargs): + self.fname = kwargs.pop('fname') + self.fdir = kwargs.pop('fdir', "") + self.generating_f = kwargs.pop('generating_f', None) + self.register = kwargs.pop('register', False) + self.fname_suffix = os.path.join(self.fdir, self.fname) + self.head = [] + self.body = [] + self.foot = [] + if self.register: + known_generators.append(self) + def matches_path(self, path): + return path.endswith(self.fname_suffix) + def r(self, s, *args, **kwargs): + return j2render(s, g=self, *args, **kwargs) + def rhead(self, *args, **kwargs): + self.head.append(self.r(*args, **kwargs)) + def rbody(self, *args, **kwargs): + self.body.append(self.r(*args, **kwargs)) + def rfoot(self, *args, **kwargs): + self.foot.append(self.r(*args, **kwargs)) + def generate(self, run_gen_base=True): + self.head = [] + self.body = [] + self.foot = [] + if run_gen_base: + self.gen_base() + # Run user-specified generation + if self.generating_f: + self.generating_f(self) + return ''.join(self.head + self.body + self.foot) + def gen_base(self): + "Fill basic subclass-dependent content into head/body/foot" + pass + +class CCodeGenerator(CodeGenerator): + "Args:n" + "authors ([]) - list of author creditsn" + "descr ("") - (multiline) file descriptionn" + def __init__(self, **kwargs): + super(CCodeGenerator, self).__init__(**kwargs) + self.authors = kwargs.pop('authors', []) + self.descr = kwargs.pop('descr', "") + self.descr_star_lines = ''.join([(' * ' + i + 'n') + for i in self.descr.split('n')]) + def gen_base(self): + super(CCodeGenerator, self).gen_base() + self.head.append(self.r( + "/*n" + " * GENERATED SOURCE {{ g.fname }}n" + " * DO NOT MODIFY THIS FILE DIRECTLY! *n" + " *n" + " * generated for filename suffix '{{ g.fname_suffix }}'n" + " *n" + "{{ g.descr_star_lines }}" + " *n" + "{% for a in g.authors %}" + " * {{ a }}n" + "{% endfor %}" + " */nn")) + +class CSourceGenerator(CCodeGenerator): + def __init__(self, **kwargs): + print kwargs + super(CSourceGenerator, self).__init__(**kwargs) + +class CHeaderGenerator(CCodeGenerator): + def __init__(self, **kwargs): + super(CHeaderGenerator, self).__init__(**kwargs) + self.hdef = 'GP_HEADER_' + self.fname_suffix.replace('.', '_').replace('/', '_').upper() + def gen_base(self): + super(CHeaderGenerator, self).gen_base() + self.head.append(self.r( + "#ifndef {{ g.hdef }}n" + "#define {{ g.hdef }}nn")) + self.foot.append(self.r( + "#endif /* {{ g.hdef }} */n")) + + diff --git a/pylib/gfxprim/genutils.py b/pylib/gfxprim/genutils.py deleted file mode 100644 index 281518b..0000000 --- a/pylib/gfxprim/genutils.py +++ /dev/null @@ -1,67 +0,0 @@ -# Module with utils for writing C source and headers -# 2011 - Tomas Gavenciak gavento@ucw.cz - -import sys -import jinja2 -import gfxprim -from gfxprim import die - -def hmask(bits): - "Helper returning hex mask for that many bits" - "WARN: may contain 'L'" - return hex((1<<bits)-1) - - -def j2render(tmpl, **kw): - "Internal helper to render jinja2 templates (with StrictUndefined)" - t2 = tmpl.rstrip('n') # Jinja strips the last 'n', so add these later - return jinja2.Template(t2, undefined=jinja2.StrictUndefined).render(**kw) + tmpl[len(t2):] - - -def gen_headers(header, code, descr, authors, generator, hdef): - "Generate header- and source-file headers" - "TODO - add license" - header.append(j2render( - "/* GENERATED header -- {{ descr }}n" - " * DO NOT MODIFY THIS FILE DIRECTLY! *n" - " *n" - " * generator: {{ generator }}n" - "{% for a in authors %}" - " * {{ a }}n" - "{% endfor %}" - " */nn" - "#ifndef {{ hdef }}n" - "#define {{ hdef }}nn", descr=descr, authors=authors, - generator=generator, hdef=hdef)) - code.append(j2render( - "/* GENERATED header -- {{ descr }}n" - " * DO NOT MODIFY THIS FILE DIRECTLY! *n" - " *n" - " * generator: {{ generator }}n" - "{% for a in authors %}" - " * {{ a }}n" - "{% endfor %}" - " */nn", descr=descr, authors=authors, - generator=generator)) - - -def gen_footers(header, code): - "Generate header-file footer" - header.append("#endif /* Header file #include guard */n") - - -def main_write(*files): - "Helper writing files to argv[1:], " - "usually header to argv[1] and code to argv[2].n" - "Skips writing header resp. code if set to None" - "Expects as many argv params as not-None arguments" - if len(sys.argv) != len(files) + 1: - die("Generator expects %d parameters (output file names).n" % len(files)) - for i in range(len(files)): - p = files[i] - fname = sys.argv[i+1] - sys.stderr.write("Writing generated source to " + fname + "n") - f = open(fname, "wt") - f.write('n'.join(p)) - f.close() -
http://repo.or.cz/w/gfxprim.git/commit/01dcdb50122a43d5a26690c470c9fce2dc800...
commit 01dcdb50122a43d5a26690c470c9fce2dc80046a Author: Tomas Gavenciak gavento@ucw.cz Date: Wed May 25 23:15:06 2011 +0200
Restructure generating system for new build system
diff --git a/config.mk b/config.mk index 6653c55..d9a784d 100644 --- a/config.mk +++ b/config.mk @@ -1,3 +1,9 @@ CFLAGS+=-W -Wall -Wextra -fPIC -ggdb -O2 -std=gnu99 CFLAGS+=-I$(TOPDIR)/include/ LDLIBS+=-ldl + +# path to local module directory +PYLIBSDIR=$(TOPDIR)/pylib + +# Command to run Python with pylib/ modules +PYTHON=PYTHONPATH=$$PYTHONPATH:${PYLIBSDIR} python diff --git a/gen.mk b/gen.mk index 56803bc..926fd57 100644 --- a/gen.mk +++ b/gen.mk @@ -6,6 +6,12 @@ $(error LIBNAME not defined, fix your library Makefile) endif
# +# All potential dependencies for generated files +# +GENERATORS=$(shell find ${PYLIBSDIR} -name *.py) +CLEAN+=$(patsubst, %.py, %.pyc, ${GENERATORS}) + +# # Headers goes into include/core/ # INCLUDE_PREFIX=$(TOPDIR)/include/$(LIBNAME)/ diff --git a/libs/core/Makefile b/libs/core/Makefile index 0ef2e5b..989d786 100644 --- a/libs/core/Makefile +++ b/libs/core/Makefile @@ -1,6 +1,6 @@ TOPDIR=../.. -GENSOURCES=GP_Pixel.gen.c -GENHEADERS=GP_Pixel.gen.h +GENSOURCES=GP_Pixel.gen.c GP_Blit.gen.c +GENHEADERS=GP_Pixel_Scale.gen.h GP_Blit.gen.h GP_Pixel.gen.h CSOURCES=$(filter-out $(wildcard *.gen.c),$(wildcard *.c)) LIBNAME=core
@@ -8,5 +8,15 @@ include $(TOPDIR)/gen.mk include $(TOPDIR)/include.mk include $(TOPDIR)/lib.mk
-GP_Pixel.gen.c $(INCLUDE_PREFIX)GP_Pixel.gen.h: gen/make_GP_Pixel.py - python gen/make_GP_Pixel.py $(INCLUDE_PREFIX)GP_Pixel.gen.h GP_Pixel.gen.c +$(INCLUDE_PREFIX)GP_Pixel.gen.h GP_Pixel.gen.c: ${GENERATORS} + ${PYTHON} "${PYLIBSDIR}/gfxprim/core/make_GP_Pixel.py" + "$(INCLUDE_PREFIX)GP_Pixel.gen.h" "GP_Pixel.gen.c" + +$(INCLUDE_PREFIX)GP_Blit.gen.h GP_Blit.gen.c: ${GENERATORS} + ${PYTHON} "${PYLIBSDIR}/gfxprim/core/make_GP_Blit.py" + "$(INCLUDE_PREFIX)GP_Blit.gen.h" "GP_Blit.gen.c" + +$(INCLUDE_PREFIX)GP_Pixel_Scale.gen.h: ${GENERATORS} + ${PYTHON} "${PYLIBSDIR}/gfxprim/core/make_GP_Pixel_Scale.py" + "$(INCLUDE_PREFIX)GP_Pixel_Scale.gen.h" + diff --git a/libs/core/gen/README b/pylib/gfxprim/README similarity index 100% rename from libs/core/gen/README rename to pylib/gfxprim/README diff --git a/pylib/gfxprim/__init__.py b/pylib/gfxprim/__init__.py new file mode 100644 index 0000000..cacbf91 --- /dev/null +++ b/pylib/gfxprim/__init__.py @@ -0,0 +1,12 @@ +# GfxPrim auxiliary libraries +# Contains C code-generation +# +# 2011 - Tomas Gavenciak gavento@ucw.cz +# + +def die(msg): + "Exit(1) with a message." + sys.stderr.write(msg) + sys.exit(1) + + diff --git a/pylib/gfxprim/core/__init__.py b/pylib/gfxprim/core/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/libs/core/gen/gen_blit.py b/pylib/gfxprim/core/gen_blit.py similarity index 99% rename from libs/core/gen/gen_blit.py rename to pylib/gfxprim/core/gen_blit.py index 519bfb2..26fd3f7 100644 --- a/libs/core/gen/gen_blit.py +++ b/pylib/gfxprim/core/gen_blit.py @@ -2,7 +2,7 @@ # - submodule for blit and friends # 2011 - Tomas Gavenciak gavento@ucw.cz
-from gen_utils import * +from gfxprim.gen_utils import *
## all generated direct blits, for generating GP_Blit() and others generated_blits = [] diff --git a/libs/core/gen/gen_pixeltype.py b/pylib/gfxprim/core/gen_pixeltype.py similarity index 98% rename from libs/core/gen/gen_pixeltype.py rename to pylib/gfxprim/core/gen_pixeltype.py index 683fe87..bfde4f2 100644 --- a/libs/core/gen/gen_pixeltype.py +++ b/pylib/gfxprim/core/gen_pixeltype.py @@ -7,8 +7,9 @@ Such functions accept (and then extend) two list of strins. These should be later joined with "" or " ". """
-from pixeltype import pixeltypes, channels -from gen_utils import * +from gfxprim.pixeltype import pixeltypes, channels +from gfxprim.genutils import * +from gfxprim.genutils import j2render as r
def str_start(ptype): diff --git a/libs/core/gen/make_GP_Blit.py b/pylib/gfxprim/core/make_GP_Blit.py similarity index 84% rename from libs/core/gen/make_GP_Blit.py rename to pylib/gfxprim/core/make_GP_Blit.py index 9d103ac..cda0e33 100644 --- a/libs/core/gen/make_GP_Blit.py +++ b/pylib/gfxprim/core/make_GP_Blit.py @@ -1,11 +1,14 @@ #!/usr/bin/python +# # Script generating GP_Pixel_Blit.gen.c and GP_Pixel_Blit.gen.h +# # 2011 - Tomas Gavenciak gavento@ucw.cz +#
-from pixeltype import * -from gen_blit import * -from gen_utils import * -import defs +from gfxprim.genutils import * +from gfxprim.pixeltype import * +from gfxprim.genutils import j2render as r +from gfxprim.core.gen_pixeltype import *
h = [] c = [] diff --git a/libs/core/gen/make_GP_Pixel.py b/pylib/gfxprim/core/make_GP_Pixel.py similarity index 89% rename from libs/core/gen/make_GP_Pixel.py rename to pylib/gfxprim/core/make_GP_Pixel.py index a0be576..e8f9f9a 100644 --- a/libs/core/gen/make_GP_Pixel.py +++ b/pylib/gfxprim/core/make_GP_Pixel.py @@ -1,11 +1,14 @@ #!/usr/bin/python +# # Script generating GP_Pixel.gen.c and GP_Pixel.gen.h +# # 2011 - Tomas Gavenciak gavento@ucw.cz +#
-from pixeltype import * -from gen_utils import * -from gen_pixeltype import * -import defs +from gfxprim.genutils import * +from gfxprim.pixeltype import * +from gfxprim.genutils import j2render as r +from gfxprim.core.gen_pixeltype import *
h = [] c = [] diff --git a/libs/core/gen/make_GP_Pixel_Scale.py b/pylib/gfxprim/core/make_GP_Pixel_Scale.py similarity index 87% rename from libs/core/gen/make_GP_Pixel_Scale.py rename to pylib/gfxprim/core/make_GP_Pixel_Scale.py index 13a63a2..f864489 100644 --- a/libs/core/gen/make_GP_Pixel_Scale.py +++ b/pylib/gfxprim/core/make_GP_Pixel_Scale.py @@ -1,11 +1,14 @@ - #!/usr/bin/python +# # Script generating GP_Pixel.gen.c and GP_Pixel.gen.h +# # 2011 - Tomas Gavenciak gavento@ucw.cz +#
-from pixeltype import * -from gen_utils import * -import defs +from gfxprim.genutils import * +from gfxprim.pixeltype import * +from gfxprim.genutils import j2render as r +from gfxprim.core.gen_pixeltype import *
h = [] c = [] diff --git a/libs/core/gen/gen_utils.py b/pylib/gfxprim/genutils.py similarity index 75% rename from libs/core/gen/gen_utils.py rename to pylib/gfxprim/genutils.py index 547b06d..281518b 100644 --- a/libs/core/gen/gen_utils.py +++ b/pylib/gfxprim/genutils.py @@ -3,11 +3,8 @@
import sys import jinja2 - -def die(msg): - sys.stderr.write(msg) - sys.exit(1) - +import gfxprim +from gfxprim import die
def hmask(bits): "Helper returning hex mask for that many bits" @@ -15,7 +12,7 @@ def hmask(bits): return hex((1<<bits)-1)
-def r(tmpl, **kw): +def j2render(tmpl, **kw): "Internal helper to render jinja2 templates (with StrictUndefined)" t2 = tmpl.rstrip('n') # Jinja strips the last 'n', so add these later return jinja2.Template(t2, undefined=jinja2.StrictUndefined).render(**kw) + tmpl[len(t2):] @@ -24,7 +21,7 @@ def r(tmpl, **kw): def gen_headers(header, code, descr, authors, generator, hdef): "Generate header- and source-file headers" "TODO - add license" - header.append(r( + header.append(j2render( "/* GENERATED header -- {{ descr }}n" " * DO NOT MODIFY THIS FILE DIRECTLY! *n" " *n" @@ -36,7 +33,7 @@ def gen_headers(header, code, descr, authors, generator, hdef): "#ifndef {{ hdef }}n" "#define {{ hdef }}nn", descr=descr, authors=authors, generator=generator, hdef=hdef)) - code.append(r( + code.append(j2render( "/* GENERATED header -- {{ descr }}n" " * DO NOT MODIFY THIS FILE DIRECTLY! *n" " *n" @@ -53,21 +50,17 @@ def gen_footers(header, code): header.append("#endif /* Header file #include guard */n")
-#import pprint -def main_write(header, code): - "Helper writing header to argv[1] and code to argv[2]" +def main_write(*files): + "Helper writing files to argv[1:], " + "usually header to argv[1] and code to argv[2].n" "Skips writing header resp. code if set to None" "Expects as many argv params as not-None arguments" - - # Some after-midnight functional crazines: - proc = [a for a in [header, code] if a is not None] - if len(sys.argv) != len(proc) + 1: - die("Generator expects %d parameters (output file names).n" % len(proc)) - for i in range(len(proc)): - p = proc[i] + if len(sys.argv) != len(files) + 1: + die("Generator expects %d parameters (output file names).n" % len(files)) + for i in range(len(files)): + p = files[i] fname = sys.argv[i+1] - sys.stderr.write("Writing GP_Pixel generated " + ("header" if p==header else "source") + - " to " + fname + "n") + sys.stderr.write("Writing generated source to " + fname + "n") f = open(fname, "wt") f.write('n'.join(p)) f.close() diff --git a/libs/core/gen/pixeltype.py b/pylib/gfxprim/pixeltype.py similarity index 72% rename from libs/core/gen/pixeltype.py rename to pylib/gfxprim/pixeltype.py index 3e85dfe..7c4248d 100644 --- a/libs/core/gen/pixeltype.py +++ b/pylib/gfxprim/pixeltype.py @@ -10,8 +10,9 @@ # bitwidth # name
-import re - +import re, os, sys +import gfxprim +from gfxprim import die
## *Global* dictionary of all pixeltypes { name : PixelType } pixeltypes = {} @@ -90,5 +91,28 @@ class PixelType(object): def __str__(self): return "<PixelType " + self.name + ">"
-if 0 not in pixeltypes: - PixelType("UNKNOWN", 0, [], bit_endian=bit_endians[0], number=0) +def load_pixeltypes(defs_file = None): + "Initialize pixeltypes by loading the defs file.n" + "Looks for the file by parameter, env['PIXELTYPE_DEFS'] and " + "in dir(__file__)/../../pixeltypes.py, in that order.n" + "PixelType UNKNOWN is not defined here." + if not defs_file: + defs_file = os.environ.get('PIXELTYPE_DEFS', None) + if not defs_file: + path = os.path.dirname(os.path.abspath(__file__)) + defs_file = os.path.join(path, '..', 'pixeltypes.py') + sys.stderr.write("Opening PixelType defs file '" + defs_file + "'n") + l1 = len(pixeltypes) + execfile(defs_file) + l2 = len(pixeltypes) + sys.stderr.write("Read %d PixelTypes, now %d totaln" % (l2 - l1, l2)) + +def __init__(): + "Initialize PixelType UNKNOWN.n" + "Currently also reads PIXELTYPE_DEFS, but that may change!" + if 0 not in pixeltypes: + PixelType("UNKNOWN", 0, [], bit_endian=bit_endians[0], number=0) + load_pixeltypes() + +__init__() + diff --git a/libs/core/gen/defs.py b/pylib/pixeltypes.py similarity index 57% rename from libs/core/gen/defs.py rename to pylib/pixeltypes.py index 8e9bd5c..7f77336 100644 --- a/libs/core/gen/defs.py +++ b/pylib/pixeltypes.py @@ -1,9 +1,18 @@ -# Module defining known PixelTypes -# 2011 - Tomas Gavenciak gavento@ucw.cz - -# NOTE: order defines numbering +# +# pixeltypes.py - module defining known PixelTypes +#
-from pixeltype import PixelType +# +# 2011 - Tomas Gavenciak gavento@ucw.cz +# +# Every call to PixelType defines one new GP_PixelType, order defines +# the numbering. Undefined type is defined automatically. +# No other functionality than PixelType() should be defined here. +# +# This file is sourced by all the generating scripts. +# Moreover, the generated files are sourced by almost all Gfxprim sources, +# a complete recompilation is required after any change. +#
PixelType(name='RGBx8888', size=32, chanslist=[
http://repo.or.cz/w/gfxprim.git/commit/bc3e7e202aaedf55738f151b598ffc1016188...
commit bc3e7e202aaedf55738f151b598ffc10161881c5 Merge: 5e1cf45 af6444d Author: Tomas Gavenciak gavento@ucw.cz Date: Wed May 25 21:40:39 2011 +0200
Merge branch 'master' into generate
http://repo.or.cz/w/gfxprim.git/commit/af6444d674affcc352f05e1616ad2b6fa4a5d...
commit af6444d674affcc352f05e1616ad2b6fa4a5dfe8 Merge: 45b543a 7f6bea0 Author: Tomas Gavenciak gavento@ucw.cz Date: Wed May 25 21:40:18 2011 +0200
Merge branch 'master' of git://repo.or.cz/gfxprim
-----------------------------------------------------------------------
Summary of changes: Makefile | 17 +++- build/Makefile | 40 ++++---- build/get_objs.sh | 12 ++ build/link.sh | 27 ----- config.mk | 6 + gen.mk | 37 +++++++ include.mk | 7 ++ include/GP.h | 3 + include/backends/GP_Backend.h | 2 +- {tests => include}/sdl/GP_SDL.h | 0 {tests => include}/sdl/GP_SDL_Context.h | 3 +- {tests => include}/sdl/GP_SDL_VideoInit.h | 0 include/sdl/README | 2 + libs/Makefile | 2 +- libs/core/Makefile | 19 +++- libs/core/gen/gen_utils.py | 74 ------------- libs/gfx/GP_Circle.c | 10 ++ {tests => libs}/sdl/GP_SDL_Context.c | 3 +- {tests => libs}/sdl/GP_SDL_VideoInit.c | 0 libs/{gfx => sdl}/Makefile | 2 +- pylib/bin/generate_file.py | 22 ++++ {libs/core/gen => pylib/gfxprim}/README | 0 pylib/gfxprim/__init__.py | 12 ++ .../gfxprim/generators/core}/gen_blit.py | 2 +- .../gfxprim/generators/core}/gen_pixeltype.py | 5 +- .../gfxprim/generators/core}/make_GP_Blit.py | 11 ++- .../gfxprim/generators/core}/make_GP_Pixel.py | 11 ++- .../generators/core}/make_GP_Pixel_Scale.py | 11 ++- pylib/gfxprim/generators/generator.py | 112 ++++++++++++++++++++ .../gen => pylib/gfxprim/generators}/pixeltype.py | 32 +++++- pylib/gfxprim/generators/utils.py | 34 ++++++ libs/core/gen/defs.py => pylib/pixeltypes.py | 19 +++- tests/Makefile | 2 +- tests/sdl/Makefile | 18 +++- tests/sdl/{tests => }/fileview.c | 0 tests/sdl/{tests => }/fonttest.c | 0 tests/sdl/{tests => }/linetest.c | 0 tests/sdl/{tests/Makefile => old.dddd} | 0 tests/sdl/{tests => }/pixeltest.c | 0 tests/sdl/{tests => }/randomshapetest.c | 0 tests/sdl/runtest.sh | 10 ++ tests/sdl/{tests => }/shapetest.c | 0 tests/sdl/{tests => }/sierpinsky.c | 0 tests/sdl/{tests => }/symbolstest.c | 0 tests/sdl/tests/runtest.sh | 10 -- tests/sdl/{tests => }/textaligntest.c | 0 tests/sdl/{tests => }/trianglefps.c | 0 47 files changed, 407 insertions(+), 170 deletions(-) create mode 100755 build/get_objs.sh delete mode 100755 build/link.sh create mode 100644 gen.mk rename {tests => include}/sdl/GP_SDL.h (100%) rename {tests => include}/sdl/GP_SDL_Context.h (95%) rename {tests => include}/sdl/GP_SDL_VideoInit.h (100%) create mode 100644 include/sdl/README delete mode 100644 libs/core/gen/gen_utils.py rename {tests => libs}/sdl/GP_SDL_Context.c (98%) rename {tests => libs}/sdl/GP_SDL_VideoInit.c (100%) copy libs/{gfx => sdl}/Makefile (88%) create mode 100644 pylib/bin/generate_file.py rename {libs/core/gen => pylib/gfxprim}/README (100%) create mode 100644 pylib/gfxprim/__init__.py create mode 100644 pylib/gfxprim/generators/__init__.py create mode 100644 pylib/gfxprim/generators/core/__init__.py rename {libs/core/gen => pylib/gfxprim/generators/core}/gen_blit.py (99%) rename {libs/core/gen => pylib/gfxprim/generators/core}/gen_pixeltype.py (98%) rename {libs/core/gen => pylib/gfxprim/generators/core}/make_GP_Blit.py (84%) rename {libs/core/gen => pylib/gfxprim/generators/core}/make_GP_Pixel.py (89%) rename {libs/core/gen => pylib/gfxprim/generators/core}/make_GP_Pixel_Scale.py (87%) create mode 100644 pylib/gfxprim/generators/generator.py rename {libs/core/gen => pylib/gfxprim/generators}/pixeltype.py (72%) create mode 100644 pylib/gfxprim/generators/utils.py rename libs/core/gen/defs.py => pylib/pixeltypes.py (57%) rename tests/sdl/{tests => }/fileview.c (100%) rename tests/sdl/{tests => }/fonttest.c (100%) rename tests/sdl/{tests => }/linetest.c (100%) rename tests/sdl/{tests/Makefile => old.dddd} (100%) rename tests/sdl/{tests => }/pixeltest.c (100%) rename tests/sdl/{tests => }/randomshapetest.c (100%) create mode 100755 tests/sdl/runtest.sh rename tests/sdl/{tests => }/shapetest.c (100%) rename tests/sdl/{tests => }/sierpinsky.c (100%) rename tests/sdl/{tests => }/symbolstest.c (100%) delete mode 100755 tests/sdl/tests/runtest.sh rename tests/sdl/{tests => }/textaligntest.c (100%) rename tests/sdl/{tests => }/trianglefps.c (100%)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos@gmail.com if you want to unsubscribe, or site admin admin@repo.or.cz if you receive no reply.