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