Clone of mesa.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

common.py 8.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. #######################################################################
  2. # Common SCons code
  3. import os
  4. import os.path
  5. import sys
  6. import platform as _platform
  7. #######################################################################
  8. # Defaults
  9. _platform_map = {
  10. 'linux2': 'linux',
  11. 'win32': 'winddk',
  12. }
  13. default_platform = sys.platform
  14. default_platform = _platform_map.get(default_platform, default_platform)
  15. _machine_map = {
  16. 'x86': 'x86',
  17. 'i386': 'x86',
  18. 'i486': 'x86',
  19. 'i586': 'x86',
  20. 'i686': 'x86',
  21. 'x86_64': 'x86_64',
  22. }
  23. if 'PROCESSOR_ARCHITECTURE' in os.environ:
  24. default_machine = os.environ['PROCESSOR_ARCHITECTURE']
  25. else:
  26. default_machine = _platform.machine()
  27. default_machine = _machine_map.get(default_machine, 'generic')
  28. if default_platform in ('linux', 'freebsd', 'darwin'):
  29. default_dri = 'yes'
  30. elif default_platform in ('winddk', 'windows'):
  31. default_dri = 'no'
  32. else:
  33. default_dri = 'no'
  34. #######################################################################
  35. # Common options
  36. def AddOptions(opts):
  37. try:
  38. from SCons.Options.BoolOption import BoolOption
  39. except ImportError:
  40. from SCons.Variables.BoolVariable import BoolVariable as BoolOption
  41. try:
  42. from SCons.Options.EnumOption import EnumOption
  43. except ImportError:
  44. from SCons.Variables.EnumVariable import EnumVariable as EnumOption
  45. opts.Add(BoolOption('debug', 'debug build', 'no'))
  46. opts.Add(BoolOption('profile', 'profile build', 'no'))
  47. #opts.Add(BoolOption('quiet', 'quiet command lines', 'no'))
  48. opts.Add(EnumOption('machine', 'use machine-specific assembly code', default_machine,
  49. allowed_values=('generic', 'x86', 'x86_64')))
  50. opts.Add(EnumOption('platform', 'target platform', default_platform,
  51. allowed_values=('linux', 'cell', 'windows', 'winddk')))
  52. opts.Add(BoolOption('llvm', 'use LLVM', 'no'))
  53. opts.Add(BoolOption('dri', 'build DRI drivers', default_dri))
  54. #######################################################################
  55. # Quiet command lines
  56. #
  57. # See also http://www.scons.org/wiki/HidingCommandLinesInOutput
  58. def quietCommandLines(env):
  59. env['CCCOMSTR'] = "Compiling $SOURCE ..."
  60. env['CXXCOMSTR'] = "Compiling $SOURCE ..."
  61. env['ARCOMSTR'] = "Archiving $TARGET ..."
  62. env['RANLIBCOMSTR'] = ""
  63. env['LINKCOMSTR'] = "Linking $TARGET ..."
  64. #######################################################################
  65. # Convenience Library Builder
  66. # based on the stock StaticLibrary and SharedLibrary builders
  67. import SCons.Action
  68. import SCons.Builder
  69. def createConvenienceLibBuilder(env):
  70. """This is a utility function that creates the ConvenienceLibrary
  71. Builder in an Environment if it is not there already.
  72. If it is already there, we return the existing one.
  73. """
  74. try:
  75. convenience_lib = env['BUILDERS']['ConvenienceLibrary']
  76. except KeyError:
  77. action_list = [ SCons.Action.Action("$ARCOM", "$ARCOMSTR") ]
  78. if env.Detect('ranlib'):
  79. ranlib_action = SCons.Action.Action("$RANLIBCOM", "$RANLIBCOMSTR")
  80. action_list.append(ranlib_action)
  81. convenience_lib = SCons.Builder.Builder(action = action_list,
  82. emitter = '$LIBEMITTER',
  83. prefix = '$LIBPREFIX',
  84. suffix = '$LIBSUFFIX',
  85. src_suffix = '$SHOBJSUFFIX',
  86. src_builder = 'SharedObject')
  87. env['BUILDERS']['ConvenienceLibrary'] = convenience_lib
  88. env['BUILDERS']['Library'] = convenience_lib
  89. return convenience_lib
  90. #######################################################################
  91. # Build
  92. def make_build_dir(env):
  93. # Put build output in a separate dir, which depends on the current configuration
  94. # See also http://www.scons.org/wiki/AdvancedBuildExample
  95. build_topdir = 'build'
  96. build_subdir = env['platform']
  97. if env['dri']:
  98. build_subdir += "-dri"
  99. if env['llvm']:
  100. build_subdir += "-llvm"
  101. if env['machine'] != 'generic':
  102. build_subdir += '-' + env['machine']
  103. if env['debug']:
  104. build_subdir += "-debug"
  105. if env['profile']:
  106. build_subdir += "-profile"
  107. build_dir = os.path.join(build_topdir, build_subdir)
  108. # Place the .sconsign file on the builddir too, to avoid issues with different scons
  109. # versions building the same source file
  110. env.SConsignFile(os.path.join(build_dir, '.sconsign'))
  111. return build_dir
  112. #######################################################################
  113. # Common environment generation code
  114. def generate(env):
  115. # FIXME: this is already too late
  116. #if env.get('quiet', False):
  117. # quietCommandLines(env)
  118. # shortcuts
  119. debug = env['debug']
  120. machine = env['machine']
  121. platform = env['platform']
  122. x86 = env['machine'] == 'x86'
  123. gcc = env['platform'] in ('linux', 'freebsd', 'darwin')
  124. msvc = env['platform'] in ('windows', 'winddk')
  125. # C preprocessor options
  126. cppdefines = []
  127. if debug:
  128. cppdefines += ['DEBUG']
  129. else:
  130. cppdefines += ['NDEBUG']
  131. if env['profile']:
  132. cppdefines += ['PROFILE']
  133. if platform == 'windows':
  134. cppdefines += [
  135. 'WIN32',
  136. '_WINDOWS',
  137. '_UNICODE',
  138. 'UNICODE',
  139. # http://msdn2.microsoft.com/en-us/library/6dwk3a1z.aspx,
  140. 'WIN32_LEAN_AND_MEAN',
  141. 'VC_EXTRALEAN',
  142. '_CRT_SECURE_NO_DEPRECATE',
  143. ]
  144. if debug:
  145. cppdefines += ['_DEBUG']
  146. if platform == 'winddk':
  147. # Mimic WINDDK's builtin flags. See also:
  148. # - WINDDK's bin/makefile.new i386mk.inc for more info.
  149. # - buildchk_wxp_x86.log files, generated by the WINDDK's build
  150. # - http://alter.org.ua/docs/nt_kernel/vc8_proj/
  151. cppdefines += [
  152. ('_X86_', '1'),
  153. ('i386', '1'),
  154. 'STD_CALL',
  155. ('CONDITION_HANDLING', '1'),
  156. ('NT_INST', '0'),
  157. ('WIN32', '100'),
  158. ('_NT1X_', '100'),
  159. ('WINNT', '1'),
  160. ('_WIN32_WINNT', '0x0501'), # minimum required OS version
  161. ('WINVER', '0x0501'),
  162. ('_WIN32_IE', '0x0603'),
  163. ('WIN32_LEAN_AND_MEAN', '1'),
  164. ('DEVL', '1'),
  165. ('__BUILDMACHINE__', 'WinDDK'),
  166. ('FPO', '0'),
  167. ]
  168. if debug:
  169. cppdefines += [('DBG', 1)]
  170. if platform == 'windows':
  171. cppdefines += ['PIPE_SUBSYSTEM_USER']
  172. if platform == 'winddk':
  173. cppdefines += ['PIPE_SUBSYSTEM_KERNEL']
  174. env.Append(CPPDEFINES = cppdefines)
  175. # C compiler options
  176. cflags = []
  177. if gcc:
  178. if debug:
  179. cflags += ['-O0', '-g3']
  180. else:
  181. cflags += ['-O3', '-g3']
  182. if env['profile']:
  183. cflags += ['-pg']
  184. cflags += [
  185. '-Wall',
  186. '-Wmissing-prototypes',
  187. '-Wno-long-long',
  188. '-ffast-math',
  189. '-pedantic',
  190. '-fmessage-length=0', # be nice to Eclipse
  191. ]
  192. if msvc:
  193. # See also:
  194. # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
  195. # - cl /?
  196. if debug:
  197. cflags += [
  198. '/Od', # disable optimizations
  199. '/Oi', # enable intrinsic functions
  200. '/Oy-', # disable frame pointer omission
  201. ]
  202. else:
  203. cflags += [
  204. '/Ox', # maximum optimizations
  205. '/Oi', # enable intrinsic functions
  206. '/Os', # favor code space
  207. ]
  208. if env['profile']:
  209. cflags += [
  210. '/Gh', # enable _penter hook function
  211. '/GH', # enable _pexit hook function
  212. ]
  213. if platform == 'windows':
  214. cflags += [
  215. # TODO
  216. #'/Wp64', # enable 64 bit porting warnings
  217. ]
  218. if platform == 'winddk':
  219. cflags += [
  220. '/Zl', # omit default library name in .OBJ
  221. '/Zp8', # 8bytes struct member alignment
  222. '/Gy', # separate functions for linker
  223. '/Gm-', # disable minimal rebuild
  224. '/W3', # warning level
  225. '/WX', # treat warnings as errors
  226. '/Gz', # __stdcall Calling convention
  227. '/GX-', # disable C++ EH
  228. '/GR-', # disable C++ RTTI
  229. '/GF', # enable read-only string pooling
  230. '/G6', # optimize for PPro, P-II, P-III
  231. '/Ze', # enable extensions
  232. '/Gi-', # disable incremental compilation
  233. '/QIfdiv-', # disable Pentium FDIV fix
  234. '/hotpatch', # prepares an image for hotpatching.
  235. #'/Z7', #enable old-style debug info
  236. ]
  237. # Put debugging information in a separate .pdb file for each object file as
  238. # descrived in the scons manpage
  239. env['CCPDBFLAGS'] = '/Zi /Fd${TARGET}.pdb'
  240. env.Append(CFLAGS = cflags)
  241. env.Append(CXXFLAGS = cflags)
  242. # Linker options
  243. if platform == 'winddk':
  244. # See also:
  245. # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
  246. env.Append(LINKFLAGS = [
  247. '/merge:_PAGE=PAGE',
  248. '/merge:_TEXT=.text',
  249. '/section:INIT,d',
  250. '/opt:ref',
  251. '/opt:icf',
  252. '/ignore:4198,4010,4037,4039,4065,4070,4078,4087,4089,4221',
  253. '/incremental:no',
  254. '/fullbuild',
  255. '/release',
  256. '/nodefaultlib',
  257. '/wx',
  258. '/debug',
  259. '/debugtype:cv',
  260. '/version:5.1',
  261. '/osversion:5.1',
  262. '/functionpadmin:5',
  263. '/safeseh',
  264. '/pdbcompress',
  265. '/stack:0x40000,0x1000',
  266. '/driver',
  267. '/align:0x80',
  268. '/subsystem:native,5.01',
  269. '/base:0x10000',
  270. '/entry:DrvEnableDriver',
  271. ])
  272. createConvenienceLibBuilder(env)
  273. # for debugging
  274. #print env.Dump()