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

crossmingw.py 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. """SCons.Tool.gcc
  2. Tool-specific initialization for MinGW (http://www.mingw.org/)
  3. There normally shouldn't be any need to import this module directly.
  4. It will usually be imported through the generic SCons.Tool.Tool()
  5. selection method.
  6. See also http://www.scons.org/wiki/CrossCompilingMingw
  7. """
  8. #
  9. # Copyright (c) 2001, 2002, 2003, 2004 The SCons Foundation
  10. #
  11. # Permission is hereby granted, free of charge, to any person obtaining
  12. # a copy of this software and associated documentation files (the
  13. # "Software"), to deal in the Software without restriction, including
  14. # without limitation the rights to use, copy, modify, merge, publish,
  15. # distribute, sublicense, and/or sell copies of the Software, and to
  16. # permit persons to whom the Software is furnished to do so, subject to
  17. # the following conditions:
  18. #
  19. # The above copyright notice and this permission notice shall be included
  20. # in all copies or substantial portions of the Software.
  21. #
  22. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
  23. # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  24. # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. #
  30. import os
  31. import os.path
  32. import string
  33. import SCons.Action
  34. import SCons.Builder
  35. import SCons.Tool
  36. import SCons.Util
  37. # This is what we search for to find mingw:
  38. prefixes = SCons.Util.Split("""
  39. mingw32-
  40. mingw32msvc-
  41. i386-mingw32-
  42. i486-mingw32-
  43. i586-mingw32-
  44. i686-mingw32-
  45. i386-mingw32msvc-
  46. i486-mingw32msvc-
  47. i586-mingw32msvc-
  48. i686-mingw32msvc-
  49. i686-pc-mingw32-
  50. """)
  51. def find(env):
  52. for prefix in prefixes:
  53. # First search in the SCons path and then the OS path:
  54. if env.WhereIs(prefix + 'gcc') or SCons.Util.WhereIs(prefix + 'gcc'):
  55. return prefix
  56. return ''
  57. def shlib_generator(target, source, env, for_signature):
  58. cmd = SCons.Util.CLVar(['$SHLINK', '$SHLINKFLAGS'])
  59. dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX')
  60. if dll: cmd.extend(['-o', dll])
  61. cmd.extend(['$SOURCES', '$_LIBDIRFLAGS', '$_LIBFLAGS'])
  62. implib = env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX')
  63. if implib: cmd.append('-Wl,--out-implib,'+implib.get_string(for_signature))
  64. def_target = env.FindIxes(target, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX')
  65. if def_target: cmd.append('-Wl,--output-def,'+def_target.get_string(for_signature))
  66. return [cmd]
  67. def shlib_emitter(target, source, env):
  68. dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX')
  69. no_import_lib = env.get('no_import_lib', 0)
  70. if not dll:
  71. raise SCons.Errors.UserError, "A shared library should have exactly one target with the suffix: %s" % env.subst("$SHLIBSUFFIX")
  72. if not no_import_lib and \
  73. not env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX'):
  74. # Append an import library to the list of targets.
  75. target.append(env.ReplaceIxes(dll,
  76. 'SHLIBPREFIX', 'SHLIBSUFFIX',
  77. 'LIBPREFIX', 'LIBSUFFIX'))
  78. # Append a def file target if there isn't already a def file target
  79. # or a def file source. There is no option to disable def file
  80. # target emitting, because I can't figure out why someone would ever
  81. # want to turn it off.
  82. def_source = env.FindIxes(source, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX')
  83. def_target = env.FindIxes(target, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX')
  84. if not def_source and not def_target:
  85. target.append(env.ReplaceIxes(dll,
  86. 'SHLIBPREFIX', 'SHLIBSUFFIX',
  87. 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX'))
  88. return (target, source)
  89. shlib_action = SCons.Action.Action(shlib_generator, '$SHLINKCOMSTR', generator=1)
  90. res_action = SCons.Action.Action('$RCCOM', '$RCCOMSTR')
  91. res_builder = SCons.Builder.Builder(action=res_action, suffix='.o',
  92. source_scanner=SCons.Tool.SourceFileScanner)
  93. SCons.Tool.SourceFileScanner.add_scanner('.rc', SCons.Defaults.CScan)
  94. def generate(env):
  95. mingw_prefix = find(env)
  96. if mingw_prefix:
  97. dir = os.path.dirname(env.WhereIs(mingw_prefix + 'gcc') or SCons.Util.WhereIs(mingw_prefix + 'gcc'))
  98. # The mingw bin directory must be added to the path:
  99. path = env['ENV'].get('PATH', [])
  100. if not path:
  101. path = []
  102. if SCons.Util.is_String(path):
  103. path = string.split(path, os.pathsep)
  104. env['ENV']['PATH'] = string.join([dir] + path, os.pathsep)
  105. # Most of mingw is the same as gcc and friends...
  106. gnu_tools = ['gcc', 'g++', 'gnulink', 'ar', 'gas']
  107. for tool in gnu_tools:
  108. SCons.Tool.Tool(tool)(env)
  109. #... but a few things differ:
  110. env['CC'] = mingw_prefix + 'gcc'
  111. env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS')
  112. env['CXX'] = mingw_prefix + 'g++'
  113. env['SHCXXFLAGS'] = SCons.Util.CLVar('$CXXFLAGS')
  114. env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS -shared')
  115. env['SHLINKCOM'] = shlib_action
  116. env.Append(SHLIBEMITTER = [shlib_emitter])
  117. env['LINK'] = mingw_prefix + 'g++'
  118. env['AR'] = mingw_prefix + 'ar'
  119. env['RANLIB'] = mingw_prefix + 'ranlib'
  120. env['LINK'] = mingw_prefix + 'g++'
  121. env['AS'] = mingw_prefix + 'as'
  122. env['WIN32DEFPREFIX'] = ''
  123. env['WIN32DEFSUFFIX'] = '.def'
  124. env['SHOBJSUFFIX'] = '.o'
  125. env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1
  126. env['RC'] = mingw_prefix + 'windres'
  127. env['RCFLAGS'] = SCons.Util.CLVar('')
  128. env['RCCOM'] = '$RC $_CPPDEFFLAGS $_CPPINCFLAGS ${INCPREFIX}${SOURCE.dir} $RCFLAGS -i $SOURCE -o $TARGET'
  129. env['BUILDERS']['RES'] = res_builder
  130. # Some setting from the platform also have to be overridden:
  131. env['OBJPREFIX'] = ''
  132. env['OBJSUFFIX'] = '.o'
  133. env['SHOBJPREFIX'] = '$OBJPREFIX'
  134. env['SHOBJSUFFIX'] = '$OBJSUFFIX'
  135. env['PROGPREFIX'] = ''
  136. env['PROGSUFFIX'] = '.exe'
  137. env['LIBPREFIX'] = 'lib'
  138. env['LIBSUFFIX'] = '.a'
  139. env['SHLIBPREFIX'] = ''
  140. env['SHLIBSUFFIX'] = '.dll'
  141. env['LIBPREFIXES'] = [ 'lib', '' ]
  142. env['LIBSUFFIXES'] = [ '.a', '.lib' ]
  143. # MinGW port of gdb does not handle well dwarf debug info which is the
  144. # default in recent gcc versions
  145. env.AppendUnique(CFLAGS = ['-gstabs'])
  146. env.AppendUnique(CPPDEFINES = [('__MSVCRT_VERSION__', '0x0700')])
  147. #env.AppendUnique(LIBS = ['iberty'])
  148. env.AppendUnique(SHLINKFLAGS = ['-Wl,--enable-stdcall-fixup'])
  149. #env.AppendUnique(SHLINKFLAGS = ['-Wl,--kill-at'])
  150. def exists(env):
  151. return find(env)