Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

common.py 8.0KB

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