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 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #######################################################################
  2. # Common SCons code
  3. import os
  4. import os.path
  5. import re
  6. import subprocess
  7. import sys
  8. import platform as _platform
  9. import SCons.Script.SConscript
  10. #######################################################################
  11. # Defaults
  12. host_platform = _platform.system().lower()
  13. if host_platform.startswith('cygwin'):
  14. host_platform = 'cygwin'
  15. # MSYS2 default platform selection.
  16. if host_platform.startswith('mingw'):
  17. host_platform = 'windows'
  18. # Search sys.argv[] for a "platform=foo" argument since we don't have
  19. # an 'env' variable at this point.
  20. if 'platform' in SCons.Script.ARGUMENTS:
  21. target_platform = SCons.Script.ARGUMENTS['platform']
  22. else:
  23. target_platform = host_platform
  24. _machine_map = {
  25. 'x86': 'x86',
  26. 'i386': 'x86',
  27. 'i486': 'x86',
  28. 'i586': 'x86',
  29. 'i686': 'x86',
  30. 'BePC': 'x86',
  31. 'Intel': 'x86',
  32. 'ppc': 'ppc',
  33. 'BeBox': 'ppc',
  34. 'BeMac': 'ppc',
  35. 'AMD64': 'x86_64',
  36. 'x86_64': 'x86_64',
  37. 'sparc': 'sparc',
  38. 'sun4u': 'sparc',
  39. }
  40. # find host_machine value
  41. if 'PROCESSOR_ARCHITECTURE' in os.environ:
  42. host_machine = os.environ['PROCESSOR_ARCHITECTURE']
  43. else:
  44. host_machine = _platform.machine()
  45. host_machine = _machine_map.get(host_machine, 'generic')
  46. # MSYS2 default machine selection.
  47. if _platform.system().lower().startswith('mingw') and 'MSYSTEM' in os.environ:
  48. if os.environ['MSYSTEM'] == 'MINGW32':
  49. host_machine = 'x86'
  50. if os.environ['MSYSTEM'] == 'MINGW64':
  51. host_machine = 'x86_64'
  52. default_machine = host_machine
  53. default_toolchain = 'default'
  54. # MSYS2 default toolchain selection.
  55. if _platform.system().lower().startswith('mingw'):
  56. default_toolchain = 'mingw'
  57. if target_platform == 'windows' and host_platform != 'windows':
  58. default_machine = 'x86'
  59. default_toolchain = 'crossmingw'
  60. # find default_llvm value
  61. if 'LLVM' in os.environ or 'LLVM_CONFIG' in os.environ:
  62. default_llvm = 'yes'
  63. else:
  64. default_llvm = 'no'
  65. try:
  66. if target_platform != 'windows' and \
  67. subprocess.call(['llvm-config', '--version'],
  68. stdout=subprocess.PIPE) == 0:
  69. default_llvm = 'yes'
  70. except:
  71. pass
  72. #######################################################################
  73. # Common options
  74. def AddOptions(opts):
  75. try:
  76. from SCons.Variables.BoolVariable import BoolVariable as BoolOption
  77. except ImportError:
  78. from SCons.Options.BoolOption import BoolOption
  79. try:
  80. from SCons.Variables.EnumVariable import EnumVariable as EnumOption
  81. except ImportError:
  82. from SCons.Options.EnumOption import EnumOption
  83. opts.Add(EnumOption('build', 'build type', 'debug',
  84. allowed_values=('debug', 'checked', 'profile',
  85. 'release')))
  86. opts.Add(BoolOption('verbose', 'verbose output', 'no'))
  87. opts.Add(EnumOption('machine', 'use machine-specific assembly code',
  88. default_machine,
  89. allowed_values=('generic', 'ppc', 'x86', 'x86_64')))
  90. opts.Add(EnumOption('platform', 'target platform', host_platform,
  91. allowed_values=('cygwin', 'darwin', 'freebsd', 'haiku',
  92. 'linux', 'sunos', 'windows')))
  93. opts.Add(BoolOption('embedded', 'embedded build', 'no'))
  94. opts.Add(BoolOption('analyze',
  95. 'enable static code analysis where available', 'no'))
  96. opts.Add(BoolOption('asan', 'enable Address Sanitizer', 'no'))
  97. opts.Add('toolchain', 'compiler toolchain', default_toolchain)
  98. opts.Add(BoolOption('llvm', 'use LLVM', default_llvm))
  99. opts.Add(BoolOption('force_scons', 'Force enable scons on deprecated platforms', 'false'))
  100. opts.Add(BoolOption('openmp', 'EXPERIMENTAL: compile with openmp (swrast)',
  101. 'no'))
  102. opts.Add(BoolOption('debug', 'DEPRECATED: debug build', 'yes'))
  103. opts.Add(BoolOption('profile', 'DEPRECATED: profile build', 'no'))
  104. opts.Add(BoolOption('quiet', 'DEPRECATED: profile build', 'yes'))
  105. opts.Add(BoolOption('swr', 'Build OpenSWR', 'no'))
  106. if host_platform == 'windows':
  107. opts.Add('MSVC_VERSION', 'Microsoft Visual C/C++ version')
  108. opts.Add('MSVC_USE_SCRIPT', 'Microsoft Visual C/C++ vcvarsall script', True)