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.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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', 'wince'):
  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', 'wince')))
  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', 'wince')
  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 == 'wince':
  171. cppdefines += [
  172. ('_WIN32_WCE', '500'),
  173. 'WCE_PLATFORM_STANDARDSDK_500',
  174. '_i386_',
  175. ('UNDER_CE', '500'),
  176. 'UNICODE',
  177. '_UNICODE',
  178. '_X86_',
  179. 'x86',
  180. '_USRDLL',
  181. 'TEST_EXPORTS' ,
  182. ]
  183. if platform == 'windows':
  184. cppdefines += ['PIPE_SUBSYSTEM_USER']
  185. if platform == 'winddk':
  186. cppdefines += ['PIPE_SUBSYSTEM_KERNEL']
  187. env.Append(CPPDEFINES = cppdefines)
  188. # C compiler options
  189. cflags = []
  190. if gcc:
  191. if debug:
  192. cflags += ['-O0', '-g3']
  193. else:
  194. cflags += ['-O3', '-g3']
  195. if env['profile']:
  196. cflags += ['-pg']
  197. cflags += [
  198. '-Wall',
  199. '-Wmissing-prototypes',
  200. '-Wno-long-long',
  201. '-ffast-math',
  202. '-pedantic',
  203. '-fmessage-length=0', # be nice to Eclipse
  204. ]
  205. if msvc:
  206. # See also:
  207. # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
  208. # - cl /?
  209. if debug:
  210. cflags += [
  211. '/Od', # disable optimizations
  212. '/Oi', # enable intrinsic functions
  213. '/Oy-', # disable frame pointer omission
  214. ]
  215. else:
  216. cflags += [
  217. '/Ox', # maximum optimizations
  218. '/Oi', # enable intrinsic functions
  219. '/Os', # favor code space
  220. ]
  221. if env['profile']:
  222. cflags += [
  223. '/Gh', # enable _penter hook function
  224. '/GH', # enable _pexit hook function
  225. ]
  226. if platform == 'windows':
  227. cflags += [
  228. # TODO
  229. #'/Wp64', # enable 64 bit porting warnings
  230. ]
  231. if platform == 'winddk':
  232. cflags += [
  233. '/Zl', # omit default library name in .OBJ
  234. '/Zp8', # 8bytes struct member alignment
  235. '/Gy', # separate functions for linker
  236. '/Gm-', # disable minimal rebuild
  237. '/W3', # warning level
  238. '/WX', # treat warnings as errors
  239. '/Gz', # __stdcall Calling convention
  240. '/GX-', # disable C++ EH
  241. '/GR-', # disable C++ RTTI
  242. '/GF', # enable read-only string pooling
  243. '/G6', # optimize for PPro, P-II, P-III
  244. '/Ze', # enable extensions
  245. '/Gi-', # disable incremental compilation
  246. '/QIfdiv-', # disable Pentium FDIV fix
  247. '/hotpatch', # prepares an image for hotpatching.
  248. #'/Z7', #enable old-style debug info
  249. ]
  250. if platform == 'wince':
  251. cflags += [
  252. '/Gs8192',
  253. '/GF', # enable read-only string pooling
  254. ]
  255. # Put debugging information in a separate .pdb file for each object file as
  256. # descrived in the scons manpage
  257. env['CCPDBFLAGS'] = '/Zi /Fd${TARGET}.pdb'
  258. env.Append(CFLAGS = cflags)
  259. env.Append(CXXFLAGS = cflags)
  260. # Linker options
  261. if platform == 'winddk':
  262. # See also:
  263. # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
  264. env.Append(LINKFLAGS = [
  265. '/merge:_PAGE=PAGE',
  266. '/merge:_TEXT=.text',
  267. '/section:INIT,d',
  268. '/opt:ref',
  269. '/opt:icf',
  270. '/ignore:4198,4010,4037,4039,4065,4070,4078,4087,4089,4221',
  271. '/incremental:no',
  272. '/fullbuild',
  273. '/release',
  274. '/nodefaultlib',
  275. '/wx',
  276. '/debug',
  277. '/debugtype:cv',
  278. '/version:5.1',
  279. '/osversion:5.1',
  280. '/functionpadmin:5',
  281. '/safeseh',
  282. '/pdbcompress',
  283. '/stack:0x40000,0x1000',
  284. '/driver',
  285. '/align:0x80',
  286. '/subsystem:native,5.01',
  287. '/base:0x10000',
  288. '/entry:DrvEnableDriver',
  289. ])
  290. createConvenienceLibBuilder(env)
  291. # for debugging
  292. #print env.Dump()