SCons: make OSL linking work on windows, and fix OSL compiler path issue to
[blender.git] / intern / cycles / kernel / shaders / SConscript
1 #!/usr/bin/python
2 import sys
3 import os
4 import Blender as B
5
6 def normpath(path):
7     return os.path.abspath(os.path.normpath(path))
8
9 Import ('env')
10
11 oso_files = []
12
13 if env['WITH_BF_CYCLES_OSL']:
14     shaders = env.Clone()
15
16     # osl compiler
17     osl_compiler = env._canonicalize(env.subst(env['BF_OSL_COMPILER']))
18
19     # build directory
20     root_build_dir = normpath(env['BF_BUILDDIR'])
21     build_dir = os.path.join(root_build_dir, 'intern/cycles/kernel/shaders')
22
23     # source directories and files
24     source_dir = Dir('.').srcnode().path
25
26     # dependencies
27     dependencies = shaders.Glob('*.h')
28
29     for f in os.listdir(source_dir):
30         if f.endswith('.osl'):
31             osl_file = os.path.join(source_dir, f)
32             oso_file = os.path.join(build_dir, f.replace('.osl', '.oso'))
33
34             command = "%s -O2 -I%s -o %s %s" % (osl_compiler, source_dir, oso_file, osl_file)
35
36             shaders.Command(oso_file, f, command)
37             shaders.Depends(oso_file, [f] + dependencies)
38
39             oso_files.append(oso_file)
40
41
42 Return('oso_files')