[Mesa-dev] [PATCH] glsl: Autogenerate builtin_functions.cpp as part of the build process.
Kenneth Graunke
kenneth at whitecape.org
Sat Jan 8 21:53:29 PST 2011
Now that this works with both make and SCons, builtin_function.cpp no
longer needs to live in the repository.
---
src/glsl/.gitignore | 1 +
src/glsl/Makefile | 16 +-
src/glsl/SConscript | 24 +-
src/glsl/builtin_function.cpp |13637 --------------------------
src/glsl/builtins/tools/generate_builtins.py | 11 +-
7 files changed, 78 insertions(+), 13687 deletions(-)
glsl/builtin_function.cpp -> deleted
glsl/builtins/tools/builtin_function.cpp -> renamed as glsl/builtin_stubs.cpp
diff --git a/src/glsl/.gitignore b/src/glsl/.gitignore
index 4c21231..162ed42 100644
--- a/src/glsl/.gitignore
+++ b/src/glsl/.gitignore
@@ -1,2 +1,3 @@
glsl_compiler
glsl_parser.output
+builtin_function.cpp
diff --git a/src/glsl/Makefile b/src/glsl/Makefile
index 86a577e..93b3bc3 100644
--- a/src/glsl/Makefile
+++ b/src/glsl/Makefile
@@ -133,10 +133,11 @@ default: depend lib$(LIBNAME).a $(APPS)
lib$(LIBNAME).a: $(OBJECTS) Makefile $(TOP)/src/glsl/Makefile.template
$(MKLIB) -cplusplus -o $(LIBNAME) -static $(OBJECTS)
-depend: $(ALL_SOURCES) Makefile
+DEPEND_SOURCES=$(subst builtin_function.cpp,,$(ALL_SOURCES))
+depend: $(DEPEND_SOURCES) Makefile
rm -f depend
touch depend
- $(MKDEP) $(MKDEP_OPTIONS) $(INCLUDES) $(ALL_SOURCES) 2> /dev/null
+ $(MKDEP) $(MKDEP_OPTIONS) $(INCLUDES) $(DEPEND_SOURCES) 2> /dev/null
# Remove .o and backup files
clean:
@@ -174,13 +175,12 @@ glcpp/glcpp-lex.c: glcpp/glcpp-lex.l
glcpp/glcpp-parse.c: glcpp/glcpp-parse.y
bison -v -o "$@" --defines=glcpp/glcpp-parse.h $<
-builtins: builtin_function.cpp builtins/profiles/* builtins/ir/* builtins/tools/generate_builtins.py
builtins/tools/texture_builtins.py
+BUILTIN_OBJECTS = $(subst builtin_function,builtin_stubs,$(OBJECTS)) $(GLSL2_OBJECTS)
+builtin_function.cpp: builtins/profiles/* builtins/ir/* builtins/tools/generate_builtins.py
builtins/tools/texture_builtins.py $(BUILTIN_OBJECTS)
@echo Bootstrapping the compiler...
- cp builtins/tools/builtin_function.cpp .
- make glsl_compiler
+ $(APP_CXX) $(INCLUDES) $(CFLAGS) $(LDFLAGS) $(BUILTIN_OBJECTS) $(TALLOC_LIBS) -o
builtin_compiler
@echo Regenerating builtin_function.cpp...
- $(PYTHON2) $(PYTHON_FLAGS) builtins/tools/generate_builtins.py > builtin_function.cpp
- @echo Rebuilding the real compiler...
- make glsl_compiler
+ $(PYTHON2) $(PYTHON_FLAGS) builtins/tools/generate_builtins.py $(PWD)/builtin_compiler >
builtin_function.cpp
+ rm builtin_compiler builtin_stubs.o
-include depend
diff --git a/src/glsl/SConscript b/src/glsl/SConscript
index f179721..5a0d396 100644
--- a/src/glsl/SConscript
+++ b/src/glsl/SConscript
@@ -2,6 +2,8 @@ import common
Import('*')
+from sys import executable as python_cmd
+
env = env.Clone()
env.Prepend(CPPPATH = [
@@ -20,7 +22,6 @@ sources = [
'ast_function.cpp',
'ast_to_hir.cpp',
'ast_type.cpp',
- 'builtin_function.cpp',
'glsl_lexer.cpp',
'glsl_parser.cpp',
'glsl_parser_extras.cpp',
@@ -79,9 +80,28 @@ sources = [
'strtod.c',
]
+env.Prepend(LIBS = ['talloc'])
+env.Append(CPPPATH = ['#/src/glsl'])
+
+builtin_compiler = env.Program(
+ target = 'builtin_compiler',
+ source = sources + ['main.cpp', 'builtin_stubs.cpp',
+ '../mesa/program/hash_table.c',
+ '../mesa/program/symbol_table.c'],
+)
+
+env.CodeGenerate(
+ target = 'builtin_function.cpp',
+ script = 'builtins/tools/generate_builtins.py',
+ source = builtin_compiler,
+ command = python_cmd + ' $SCRIPT $SOURCE > $TARGET'
+)
+
+env.Depends('builtin_function.cpp', ['builtins/tools/generate_builtins.py',
'builtins/tools/texture_builtins.py'] + Glob('builtins/ir/*'))
+
glsl = env.ConvenienceLibrary(
target = 'glsl',
- source = sources,
+ source = sources + [ 'builtin_function.cpp' ],
)
Export('glsl')
diff --git a/src/glsl/builtins/tools/generate_builtins.py b/src/glsl/builtins/tools/generate_builtins.py
index e2de9db..8b11338 100755
--- a/src/glsl/builtins/tools/generate_builtins.py
+++ b/src/glsl/builtins/tools/generate_builtins.py
@@ -5,12 +5,20 @@ import re
from glob import glob
from os import path
from subprocess import Popen, PIPE
+from sys import argv
# Local module: generator for texture lookup builtins
from texture_builtins import generate_texture_functions
builtins_dir = path.join(path.dirname(path.abspath(__file__)), "..")
+# Get the path to the standalone GLSL compiler
+if len(argv) != 2:
+ print "Usage:", argv[0], "<path to compiler>"
+ sys.exit(1)
+
+compiler = argv[1]
+
# Read the files in builtins/ir/*...add them to the supplied dictionary.
def read_ir_files(fs):
for filename in glob(path.join(path.join(builtins_dir, 'ir'), '*')):
@@ -47,8 +55,7 @@ def write_function_definitions():
print stringify(v), ';'
def run_compiler(args):
- compiler_path = path.join(path.join(builtins_dir, '..'), 'glsl_compiler')
- command = [compiler_path, '--dump-lir'] + args
+ command = [compiler, '--dump-lir'] + args
p = Popen(command, 1, stdout=PIPE, shell=False)
output = p.communicate()[0]
--
1.7.3.4
More information about the mesa-dev
mailing list