build: Convert git_sha1_gen script to Python.
[mesa.git] / src / SConscript
1 import filecmp
2 import os
3 import subprocess
4 from sys import executable as python_cmd
5
6 Import('*')
7
8 if env['platform'] == 'windows':
9 SConscript('getopt/SConscript')
10
11 SConscript('util/xmlpool/SConscript')
12 SConscript('util/SConscript')
13 SConscript('compiler/SConscript')
14
15 if env['hostonly']:
16 # We are just compiling the things necessary on the host for cross
17 # compilation
18 Return()
19
20
21 def write_git_sha1_h_file(filename):
22 """Mesa looks for a git_sha1.h file at compile time in order to display
23 the current git hash id in the GL_VERSION string. This function tries
24 to retrieve the git hashid and write the header file. An empty file
25 will be created if anything goes wrong."""
26
27 tempfile = "git_sha1.h.tmp"
28 with open(tempfile, "w") as f:
29 args = [ python_cmd, Dir('#').abspath + '/bin/git_sha1_gen.py' ]
30 try:
31 subprocess.Popen(args, stdout=f).wait()
32 except:
33 print "Warning: exception in write_git_sha1_h_file()"
34 return
35
36 if not os.path.exists(filename) or not filecmp.cmp(tempfile, filename):
37 # The filename does not exist or it's different from the new file,
38 # so replace old file with new.
39 if os.path.exists(filename):
40 os.remove(filename)
41 os.rename(tempfile, filename)
42 return
43
44
45 # Create the git_sha1.h header file
46 write_git_sha1_h_file("git_sha1.h")
47 # and update CPPPATH so the git_sha1.h header can be found
48 env.Append(CPPPATH = ["#" + env['build_dir']])
49
50
51
52 if env['platform'] != 'windows':
53 SConscript('loader/SConscript')
54
55 # When env['gles'] is set, the targets defined in mapi/glapi/SConscript are not
56 # used. libgl-xlib and libgl-gdi adapt themselves to use the targets defined
57 # in mapi/glapi-shared/SConscript. mesa/SConscript also adapts itself to
58 # enable OpenGL ES support.
59 SConscript('mapi/glapi/gen/SConscript')
60 SConscript('mapi/glapi/SConscript')
61
62 # Haiku C++ libGL dispatch (renderers depend on libgl)
63 if env['platform'] in ['haiku']:
64 SConscript('hgl/SConscript')
65
66 SConscript('mesa/SConscript')
67
68 if not env['embedded']:
69 if env['platform'] not in ('cygwin', 'darwin', 'freebsd', 'haiku', 'windows'):
70 SConscript('glx/SConscript')
71 if env['platform'] == 'haiku':
72 SConscript('egl/SConscript')
73
74 if env['gles']:
75 SConscript('mapi/shared-glapi/SConscript')
76
77 SConscript('gallium/SConscript')
78