blob: fbfacccd32f068f8efb8b759ac8ea05152e60823 [file] [log] [blame]
José Fonsecac42e6252008-01-31 13:14:35 +09001#######################################################################
José Fonseca33ceb672008-02-18 10:52:44 +00002# SConscript for Mesa
José Fonsecac42e6252008-01-31 13:14:35 +09003
4
5Import('*')
Brian Paulf83af362011-09-28 08:15:22 -06006import filecmp
7import os
8import subprocess
Brian Pauldff36e92012-05-30 10:08:11 -06009from sys import executable as python_cmd
José Fonsecac42e6252008-01-31 13:14:35 +090010
José Fonseca601498a2010-11-01 13:30:22 +000011env = env.Clone()
José Fonsecab9da3792008-02-19 15:07:53 +090012
José Fonseca601498a2010-11-01 13:30:22 +000013env.Append(CPPPATH = [
14 '#/src/mapi',
15 '#/src/glsl',
16 '#/src/mesa',
José Fonseca71c87e42013-01-21 17:47:51 +000017 Dir('../mapi'), # src/mapi build path
18 Dir('.'), # src/mesa build path
José Fonseca601498a2010-11-01 13:30:22 +000019])
José Fonseca2105b612009-01-06 16:20:12 +000020
José Fonseca601498a2010-11-01 13:30:22 +000021if 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
José Fonseca601498a2010-11-01 13:30:22 +000025 ])
Chia-I Wubb770af2011-01-14 17:50:29 +080026 if not env['gles']:
27 # prevent _glapi_* from being declared __declspec(dllimport)
28 env.Append(CPPDEFINES = ['_GLAPI_NO_EXPORTS'])
Chia-I Wubb045d32010-11-20 17:47:11 -080029else:
30 env.Append(CPPDEFINES = [
Tapani Pälli91214602012-08-28 14:01:51 +030031 ('HAVE_DLOPEN', '1'),
Chia-I Wubb045d32010-11-20 17:47:11 -080032 ])
José Fonseca5c9c6b02008-06-04 23:56:57 +090033
Jason Ekstranddcc29c12014-07-23 17:20:12 -070034# parse Makefile.sources
35source_lists = env.ParseSourceList('Makefile.sources')
José Fonseca601498a2010-11-01 13:30:22 +000036
Brian Paule78ebbc2012-09-15 09:01:02 -060037env.Append(YACCFLAGS = '-d -p "_mesa_program_"')
Kenneth Graunke8be58df2011-03-01 15:04:04 -080038program_lex = env.CFile('program/lex.yy.c', 'program/program_lexer.l')
39program_parse = env.CFile('program/program_parse.tab.c',
40 'program/program_parse.y')
Jason Ekstranddcc29c12014-07-23 17:20:12 -070041program_sources = source_lists['PROGRAM_FILES'] + [
Kenneth Graunke8be58df2011-03-01 15:04:04 -080042 program_lex,
43 program_parse[0],
José Fonseca601498a2010-11-01 13:30:22 +000044]
45
46mesa_sources = (
Jason Ekstranddcc29c12014-07-23 17:20:12 -070047 source_lists['MESA_FILES'] +
José Fonseca601498a2010-11-01 13:30:22 +000048 program_sources +
Jason Ekstranddcc29c12014-07-23 17:20:12 -070049 source_lists['STATETRACKER_FILES']
José Fonseca601498a2010-11-01 13:30:22 +000050)
51
Brian Pauldff36e92012-05-30 10:08:11 -060052GLAPI = '#src/mapi/glapi/'
53
Imre Deak98f880e2012-09-10 08:46:13 +030054get_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',
Brian Paul815ca0b2013-04-17 09:49:39 -060058 command = python_cmd + ' $SCRIPT ' + ' -f $SOURCE > $TARGET'
Imre Deak98f880e2012-09-10 08:46:13 +030059)
60
José Fonseca601498a2010-11-01 13:30:22 +000061#
62# Assembly sources
63#
José Fonseca16879322013-04-24 22:02:18 +010064if (env['gcc'] or env['clang']) and \
65 env['platform'] not in ('cygwin', 'darwin', 'windows', 'haiku'):
José Fonsecaf9156eb2010-11-01 13:56:16 +000066 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 ])
Jason Ekstranddcc29c12014-07-23 17:20:12 -070073 mesa_sources += source_lists['X86_FILES']
José Fonsecaf9156eb2010-11-01 13:56:16 +000074 elif env['machine'] == 'x86_64':
75 env.Append(CPPDEFINES = [
76 'USE_X86_64_ASM',
77 ])
Jason Ekstranddcc29c12014-07-23 17:20:12 -070078 mesa_sources += source_lists['X86_64_FILES']
José Fonsecaf9156eb2010-11-01 13:56:16 +000079 elif env['machine'] == 'sparc':
Jason Ekstranddcc29c12014-07-23 17:20:12 -070080 mesa_sources += source_lists['SPARC_FILES']
José Fonsecaf9156eb2010-11-01 13:56:16 +000081 else:
82 pass
José Fonseca601498a2010-11-01 13:30:22 +000083
José Fonsecaf9156eb2010-11-01 13:56:16 +000084 # 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])
José Fonseca601498a2010-11-01 13:30:22 +000099
Brian Paul0c245502011-04-05 14:07:41 -0600100
Brian Paulf83af362011-09-28 08:15:22 -0600101def 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
Brian Pauld487cc22011-09-28 09:51:36 -0600118 commit = '#define MESA_GIT_SHA1 "git-%s"\n' % commit[0:7]
Brian Paulf83af362011-09-28 08:15:22 -0600119 tempfile = "git_sha1.h.tmp"
120 f = open(tempfile, "w")
121 f.write(commit)
Vinson Lee622ee082011-04-05 15:32:39 -0700122 f.close()
Brian Paulf83af362011-09-28 08:15:22 -0600123 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.
Brian Paule1122872011-09-28 09:04:03 -0600126 if os.path.exists(filename):
127 os.remove(filename)
Brian Paulf83af362011-09-28 08:15:22 -0600128 os.rename(tempfile, filename)
129 return
130
131
132# Create the git_sha1.h header file
133write_git_sha1_h_file("main/git_sha1.h")
Vinson Lee622ee082011-04-05 15:32:39 -0700134# and update CPPPATH so the git_sha1.h header can be found
135env.Append(CPPPATH = ["#" + env['build_dir'] + "/mesa/main"])
Brian Paul0c245502011-04-05 14:07:41 -0600136
137
José Fonseca601498a2010-11-01 13:30:22 +0000138#
139# Libraries
140#
141
142mesa = env.ConvenienceLibrary(
143 target = 'mesa',
144 source = mesa_sources,
145)
146
147env.Alias('mesa', mesa)
148
149Export('mesa')
José Fonseca8e8a56e2011-04-23 12:22:59 +0100150
151SConscript('drivers/SConscript')