fbfacccd32f068f8efb8b759ac8ea05152e60823
[mesa.git] / src / mesa / SConscript
1 #######################################################################
2 # SConscript for Mesa
3
4
5 Import('*')
6 import filecmp
7 import os
8 import subprocess
9 from sys import executable as python_cmd
10
11 env = env.Clone()
12
13 env.Append(CPPPATH = [
14 '#/src/mapi',
15 '#/src/glsl',
16 '#/src/mesa',
17 Dir('../mapi'), # src/mapi build path
18 Dir('.'), # src/mesa build path
19 ])
20
21 if env['platform'] == 'windows':
22 env.Append(CPPDEFINES = [
23 '_GDI32_', # prevent gl* being declared __declspec(dllimport) in MS headers
24 'BUILD_GL32', # declare gl* as __declspec(dllexport) in Mesa headers
25 ])
26 if not env['gles']:
27 # prevent _glapi_* from being declared __declspec(dllimport)
28 env.Append(CPPDEFINES = ['_GLAPI_NO_EXPORTS'])
29 else:
30 env.Append(CPPDEFINES = [
31 ('HAVE_DLOPEN', '1'),
32 ])
33
34 # parse Makefile.sources
35 source_lists = env.ParseSourceList('Makefile.sources')
36
37 env.Append(YACCFLAGS = '-d -p "_mesa_program_"')
38 program_lex = env.CFile('program/lex.yy.c', 'program/program_lexer.l')
39 program_parse = env.CFile('program/program_parse.tab.c',
40 'program/program_parse.y')
41 program_sources = source_lists['PROGRAM_FILES'] + [
42 program_lex,
43 program_parse[0],
44 ]
45
46 mesa_sources = (
47 source_lists['MESA_FILES'] +
48 program_sources +
49 source_lists['STATETRACKER_FILES']
50 )
51
52 GLAPI = '#src/mapi/glapi/'
53
54 get_hash_header = env.CodeGenerate(
55 target = 'main/get_hash.h',
56 script = 'main/get_hash_generator.py',
57 source = GLAPI + 'gen/gl_and_es_API.xml',
58 command = python_cmd + ' $SCRIPT ' + ' -f $SOURCE > $TARGET'
59 )
60
61 #
62 # Assembly sources
63 #
64 if (env['gcc'] or env['clang']) and \
65 env['platform'] not in ('cygwin', 'darwin', 'windows', 'haiku'):
66 if env['machine'] == 'x86':
67 env.Append(CPPDEFINES = [
68 'USE_X86_ASM',
69 'USE_MMX_ASM',
70 'USE_3DNOW_ASM',
71 'USE_SSE_ASM',
72 ])
73 mesa_sources += source_lists['X86_FILES']
74 elif env['machine'] == 'x86_64':
75 env.Append(CPPDEFINES = [
76 'USE_X86_64_ASM',
77 ])
78 mesa_sources += source_lists['X86_64_FILES']
79 elif env['machine'] == 'sparc':
80 mesa_sources += source_lists['SPARC_FILES']
81 else:
82 pass
83
84 # Generate matypes.h
85 if env['machine'] in ('x86', 'x86_64'):
86 # See http://www.scons.org/wiki/UsingCodeGenerators
87 gen_matypes = env.Program(
88 target = 'gen_matypes',
89 source = 'x86/gen_matypes.c',
90 )
91 matypes = env.Command(
92 'matypes.h',
93 gen_matypes,
94 gen_matypes[0].abspath + ' > $TARGET',
95 )
96 # Add the dir containing the generated header (somewhere inside the
97 # build dir) to the include path
98 env.Append(CPPPATH = [matypes[0].dir])
99
100
101 def write_git_sha1_h_file(filename):
102 """Mesa looks for a git_sha1.h file at compile time in order to display
103 the current git hash id in the GL_VERSION string. This function tries
104 to retrieve the git hashid and write the header file. An empty file
105 will be created if anything goes wrong."""
106
107 args = [ 'git', 'log', '-n', '1', '--oneline' ]
108 try:
109 (commit, foo) = subprocess.Popen(args, stdout=subprocess.PIPE).communicate()
110 except:
111 # git log command didn't work
112 if not os.path.exists(filename):
113 # create an empty file if none already exists
114 f = open(filename, "w")
115 f.close()
116 return
117
118 commit = '#define MESA_GIT_SHA1 "git-%s"\n' % commit[0:7]
119 tempfile = "git_sha1.h.tmp"
120 f = open(tempfile, "w")
121 f.write(commit)
122 f.close()
123 if not os.path.exists(filename) or not filecmp.cmp(tempfile, filename):
124 # The filename does not exist or it's different from the new file,
125 # so replace old file with new.
126 if os.path.exists(filename):
127 os.remove(filename)
128 os.rename(tempfile, filename)
129 return
130
131
132 # Create the git_sha1.h header file
133 write_git_sha1_h_file("main/git_sha1.h")
134 # and update CPPPATH so the git_sha1.h header can be found
135 env.Append(CPPPATH = ["#" + env['build_dir'] + "/mesa/main"])
136
137
138 #
139 # Libraries
140 #
141
142 mesa = env.ConvenienceLibrary(
143 target = 'mesa',
144 source = mesa_sources,
145 )
146
147 env.Alias('mesa', mesa)
148
149 Export('mesa')
150
151 SConscript('drivers/SConscript')