SConscript revision 848b8605
1848b8605Smrg#######################################################################
2848b8605Smrg# SConscript for Mesa
3848b8605Smrg
4848b8605Smrg
5848b8605SmrgImport('*')
6848b8605Smrgimport filecmp
7848b8605Smrgimport os
8848b8605Smrgimport subprocess
9848b8605Smrgfrom sys import executable as python_cmd
10848b8605Smrg
11848b8605Smrgenv = env.Clone()
12848b8605Smrg
13848b8605Smrgenv.Append(CPPPATH = [
14848b8605Smrg    '#/src',
15848b8605Smrg    '#/src/mapi',
16848b8605Smrg    '#/src/glsl',
17848b8605Smrg    '#/src/mesa',
18848b8605Smrg    Dir('../mapi'), # src/mapi build path
19848b8605Smrg    Dir('.'), # src/mesa build path
20848b8605Smrg])
21848b8605Smrg
22848b8605Smrgif env['platform'] == 'windows':
23848b8605Smrg    env.Append(CPPDEFINES = [
24848b8605Smrg        '_GDI32_', # prevent gl* being declared __declspec(dllimport) in MS headers
25848b8605Smrg        'BUILD_GL32', # declare gl* as __declspec(dllexport) in Mesa headers
26848b8605Smrg    ])
27848b8605Smrg    if not env['gles']:
28848b8605Smrg        # prevent _glapi_* from being declared __declspec(dllimport)
29848b8605Smrg        env.Append(CPPDEFINES = ['_GLAPI_NO_EXPORTS'])
30848b8605Smrgelse:
31848b8605Smrg    env.Append(CPPDEFINES = [
32848b8605Smrg        ('HAVE_DLOPEN', '1'),
33848b8605Smrg    ])
34848b8605Smrg
35848b8605Smrg# parse Makefile.sources
36848b8605Smrgsource_lists = env.ParseSourceList('Makefile.sources')
37848b8605Smrg
38848b8605Smrgenv.Append(YACCFLAGS = '-d -p "_mesa_program_"')
39848b8605Smrgprogram_lex = env.CFile('program/lex.yy.c', 'program/program_lexer.l')
40848b8605Smrgprogram_parse = env.CFile('program/program_parse.tab.c',
41848b8605Smrg                          'program/program_parse.y')
42848b8605Smrgprogram_sources = source_lists['PROGRAM_FILES'] + [
43848b8605Smrg    program_lex,
44848b8605Smrg    program_parse[0],
45848b8605Smrg]
46848b8605Smrg
47848b8605Smrgmesa_sources = (
48848b8605Smrg    source_lists['MESA_FILES'] +
49848b8605Smrg    program_sources +
50848b8605Smrg    source_lists['STATETRACKER_FILES']
51848b8605Smrg)
52848b8605Smrg
53848b8605SmrgGLAPI = '#src/mapi/glapi/'
54848b8605Smrg
55848b8605Smrgget_hash_header = env.CodeGenerate(
56848b8605Smrg      target = 'main/get_hash.h',
57848b8605Smrg      script = 'main/get_hash_generator.py',
58848b8605Smrg      source = GLAPI + 'gen/gl_and_es_API.xml',
59848b8605Smrg      command = python_cmd + ' $SCRIPT ' + ' -f $SOURCE > $TARGET'
60848b8605Smrg)
61848b8605Smrg
62848b8605Smrgformat_info = env.CodeGenerate(
63848b8605Smrg      target = 'main/format_info.c',
64848b8605Smrg      script = 'main/format_info.py',
65848b8605Smrg      source = 'main/formats.csv',
66848b8605Smrg      command = python_cmd + ' $SCRIPT ' + ' $SOURCE > $TARGET'
67848b8605Smrg)
68848b8605Smrg
69848b8605Smrg#
70848b8605Smrg# Assembly sources
71848b8605Smrg#
72848b8605Smrgif (env['gcc'] or env['clang']) and \
73848b8605Smrg   env['platform'] not in ('cygwin', 'darwin', 'windows', 'haiku'):
74848b8605Smrg    if env['machine'] == 'x86':
75848b8605Smrg        env.Append(CPPDEFINES = [
76848b8605Smrg            'USE_X86_ASM',
77848b8605Smrg            'USE_MMX_ASM',
78848b8605Smrg            'USE_3DNOW_ASM',
79848b8605Smrg            'USE_SSE_ASM',
80848b8605Smrg        ])
81848b8605Smrg        mesa_sources += source_lists['X86_FILES']
82848b8605Smrg    elif env['machine'] == 'x86_64':
83848b8605Smrg        env.Append(CPPDEFINES = [
84848b8605Smrg            'USE_X86_64_ASM',
85848b8605Smrg        ])
86848b8605Smrg        mesa_sources += source_lists['X86_64_FILES']
87848b8605Smrg    elif env['machine'] == 'sparc':
88848b8605Smrg        mesa_sources += source_lists['SPARC_FILES']
89848b8605Smrg    else:
90848b8605Smrg        pass
91848b8605Smrg
92848b8605Smrg    # Generate matypes.h
93848b8605Smrg    if env['machine'] in ('x86', 'x86_64'):
94848b8605Smrg        # See http://www.scons.org/wiki/UsingCodeGenerators
95848b8605Smrg        gen_matypes = env.Program(
96848b8605Smrg            target = 'gen_matypes',
97848b8605Smrg            source = 'x86/gen_matypes.c',
98848b8605Smrg        )
99848b8605Smrg        matypes = env.Command(
100848b8605Smrg            'matypes.h',
101848b8605Smrg            gen_matypes,
102848b8605Smrg            gen_matypes[0].abspath + ' > $TARGET',
103848b8605Smrg        )
104848b8605Smrg        # Add the dir containing the generated header (somewhere inside  the
105848b8605Smrg        # build dir) to the include path
106848b8605Smrg        env.Append(CPPPATH = [matypes[0].dir])
107848b8605Smrg
108848b8605Smrg
109848b8605Smrgdef write_git_sha1_h_file(filename):
110848b8605Smrg    """Mesa looks for a git_sha1.h file at compile time in order to display
111848b8605Smrg    the current git hash id in the GL_VERSION string.  This function tries
112848b8605Smrg    to retrieve the git hashid and write the header file.  An empty file
113848b8605Smrg    will be created if anything goes wrong."""
114848b8605Smrg
115848b8605Smrg    args = [ 'git', 'log', '-n', '1', '--oneline' ]
116848b8605Smrg    try:
117848b8605Smrg        (commit, foo) = subprocess.Popen(args, stdout=subprocess.PIPE).communicate()
118848b8605Smrg    except:
119848b8605Smrg        # git log command didn't work
120848b8605Smrg        if not os.path.exists(filename):
121848b8605Smrg            # create an empty file if none already exists
122848b8605Smrg            f = open(filename, "w")
123848b8605Smrg            f.close()
124848b8605Smrg        return
125848b8605Smrg
126848b8605Smrg    commit = '#define MESA_GIT_SHA1 "git-%s"\n' % commit[0:7]
127848b8605Smrg    tempfile = "git_sha1.h.tmp"
128848b8605Smrg    f = open(tempfile, "w")
129848b8605Smrg    f.write(commit)
130848b8605Smrg    f.close()
131848b8605Smrg    if not os.path.exists(filename) or not filecmp.cmp(tempfile, filename):
132848b8605Smrg        # The filename does not exist or it's different from the new file,
133848b8605Smrg        # so replace old file with new.
134848b8605Smrg        if os.path.exists(filename):
135848b8605Smrg            os.remove(filename)
136848b8605Smrg        os.rename(tempfile, filename)
137848b8605Smrg    return
138848b8605Smrg
139848b8605Smrg
140848b8605Smrg# Create the git_sha1.h header file
141848b8605Smrgwrite_git_sha1_h_file("main/git_sha1.h")
142848b8605Smrg# and update CPPPATH so the git_sha1.h header can be found
143848b8605Smrgenv.Append(CPPPATH = ["#" + env['build_dir'] + "/mesa/main"])
144848b8605Smrg
145848b8605Smrg
146848b8605Smrg#
147848b8605Smrg# Libraries
148848b8605Smrg#
149848b8605Smrg
150848b8605Smrgmesa = env.ConvenienceLibrary(
151848b8605Smrg    target = 'mesa',
152848b8605Smrg    source = mesa_sources,
153848b8605Smrg)
154848b8605Smrg
155848b8605Smrgenv.Alias('mesa', mesa)
156848b8605Smrg
157848b8605SmrgExport('mesa')
158848b8605Smrg
159848b8605SmrgSConscript('drivers/SConscript')
160