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