Clone of mesa.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

crossmingw.py 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. prefixes32 = 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. i686-w64-mingw32-
  51. """)
  52. prefixes64 = SCons.Util.Split("""
  53. x86_64-w64-mingw32-
  54. amd64-mingw32-
  55. amd64-mingw32msvc-
  56. amd64-pc-mingw32-
  57. """)
  58. def find(env):
  59. if env['machine'] == 'x86_64':
  60. prefixes = prefixes64
  61. else:
  62. prefixes = prefixes32
  63. for prefix in prefixes:
  64. # First search in the SCons path and then the OS path:
  65. if env.WhereIs(prefix + 'gcc') or SCons.Util.WhereIs(prefix + 'gcc'):
  66. return prefix
  67. return ''
  68. def shlib_generator(target, source, env, for_signature):
  69. cmd = SCons.Util.CLVar(['$SHLINK', '$SHLINKFLAGS'])
  70. dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX')
  71. if dll: cmd.extend(['-o', dll])
  72. cmd.extend(['$SOURCES', '$_LIBDIRFLAGS', '$_LIBFLAGS'])
  73. implib = env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX')
  74. if implib: cmd.append('-Wl,--out-implib,'+implib.get_string(for_signature))
  75. def_target = env.FindIxes(target, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX')
  76. if def_target: cmd.append('-Wl,--output-def,'+def_target.get_string(for_signature))
  77. return [cmd]
  78. def shlib_emitter(target, source, env):
  79. dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX')
  80. no_import_lib = env.get('no_import_lib', 0)
  81. if not dll:
  82. raise SCons.Errors.UserError, "A shared library should have exactly one target with the suffix: %s" % env.subst("$SHLIBSUFFIX")
  83. if not no_import_lib and \
  84. not env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX'):
  85. # Append an import library to the list of targets.
  86. target.append(env.ReplaceIxes(dll,
  87. 'SHLIBPREFIX', 'SHLIBSUFFIX',
  88. 'LIBPREFIX', 'LIBSUFFIX'))
  89. # Append a def file target if there isn't already a def file target
  90. # or a def file source. There is no option to disable def file
  91. # target emitting, because I can't figure out why someone would ever
  92. # want to turn it off.
  93. def_source = env.FindIxes(source, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX')
  94. def_target = env.FindIxes(target, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX')
  95. if not def_source and not def_target:
  96. target.append(env.ReplaceIxes(dll,
  97. 'SHLIBPREFIX', 'SHLIBSUFFIX',
  98. 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX'))
  99. return (target, source)
  100. shlib_action = SCons.Action.Action(shlib_generator, '$SHLINKCOMSTR', generator=1)
  101. res_action = SCons.Action.Action('$RCCOM', '$RCCOMSTR')
  102. res_builder = SCons.Builder.Builder(action=res_action, suffix='.o',
  103. source_scanner=SCons.Tool.SourceFileScanner)
  104. SCons.Tool.SourceFileScanner.add_scanner('.rc', SCons.Defaults.CScan)
  105. def compile_without_gstabs(env, sources, c_file):
  106. '''This is a hack used to compile some source files without the
  107. -gstabs option.
  108. It seems that some versions of mingw32's gcc (4.4.2 at least) die
  109. when compiling large files with the -gstabs option. -gstabs is
  110. related to debug symbols and can be omitted from the effected
  111. files.
  112. This function compiles the given c_file without -gstabs, removes
  113. the c_file from the sources list, then appends the new .o file to
  114. sources. Then return the new sources list.
  115. '''
  116. # Modify CCFLAGS to not have -gstabs option:
  117. env2 = env.Clone()
  118. flags = str(env2['CCFLAGS'])
  119. flags = flags.replace("-gstabs", "")
  120. env2['CCFLAGS'] = SCons.Util.CLVar(flags)
  121. # Build the special-case files:
  122. obj_file = env2.SharedObject(c_file)
  123. # Replace ".cpp" or ".c" with ".o"
  124. o_file = c_file.replace(".cpp", ".o")
  125. o_file = o_file.replace(".c", ".o")
  126. # Replace the .c files with the specially-compiled .o file
  127. sources.remove(c_file)
  128. sources.append(o_file)
  129. return sources
  130. def generate(env):
  131. mingw_prefix = find(env)
  132. if mingw_prefix:
  133. dir = os.path.dirname(env.WhereIs(mingw_prefix + 'gcc') or SCons.Util.WhereIs(mingw_prefix + 'gcc'))
  134. # The mingw bin directory must be added to the path:
  135. path = env['ENV'].get('PATH', [])
  136. if not path:
  137. path = []
  138. if SCons.Util.is_String(path):
  139. path = string.split(path, os.pathsep)
  140. env['ENV']['PATH'] = string.join([dir] + path, os.pathsep)
  141. # Most of mingw is the same as gcc and friends...
  142. gnu_tools = ['gcc', 'g++', 'gnulink', 'ar', 'gas']
  143. for tool in gnu_tools:
  144. SCons.Tool.Tool(tool)(env)
  145. #... but a few things differ:
  146. env['CC'] = mingw_prefix + 'gcc'
  147. env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS')
  148. env['CXX'] = mingw_prefix + 'g++'
  149. env['SHCXXFLAGS'] = SCons.Util.CLVar('$CXXFLAGS')
  150. env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS -shared')
  151. env['SHLINKCOM'] = shlib_action
  152. env.Append(SHLIBEMITTER = [shlib_emitter])
  153. env['LINK'] = mingw_prefix + 'g++'
  154. env['AR'] = mingw_prefix + 'ar'
  155. env['RANLIB'] = mingw_prefix + 'ranlib'
  156. env['LINK'] = mingw_prefix + 'g++'
  157. env['AS'] = mingw_prefix + 'as'
  158. env['WIN32DEFPREFIX'] = ''
  159. env['WIN32DEFSUFFIX'] = '.def'
  160. env['SHOBJSUFFIX'] = '.o'
  161. env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1
  162. env['RC'] = mingw_prefix + 'windres'
  163. env['RCFLAGS'] = SCons.Util.CLVar('')
  164. env['RCCOM'] = '$RC $_CPPDEFFLAGS $_CPPINCFLAGS ${INCPREFIX}${SOURCE.dir} $RCFLAGS -i $SOURCE -o $TARGET'
  165. env['BUILDERS']['RES'] = res_builder
  166. # Some setting from the platform also have to be overridden:
  167. env['OBJPREFIX'] = ''
  168. env['OBJSUFFIX'] = '.o'
  169. env['SHOBJPREFIX'] = '$OBJPREFIX'
  170. env['SHOBJSUFFIX'] = '$OBJSUFFIX'
  171. env['PROGPREFIX'] = ''
  172. env['PROGSUFFIX'] = '.exe'
  173. env['LIBPREFIX'] = 'lib'
  174. env['LIBSUFFIX'] = '.a'
  175. env['SHLIBPREFIX'] = ''
  176. env['SHLIBSUFFIX'] = '.dll'
  177. env['LIBPREFIXES'] = [ 'lib', '' ]
  178. env['LIBSUFFIXES'] = [ '.a', '.lib' ]
  179. # MinGW x86 port of gdb does not handle well dwarf debug info which is the
  180. # default in recent gcc versions. The x64 port gdb from mingw-w64 seems to
  181. # handle it fine though, so stick with the default there.
  182. if env['machine'] != 'x86_64':
  183. env.AppendUnique(CCFLAGS = ['-gstabs'])
  184. env.AddMethod(compile_without_gstabs, 'compile_without_gstabs')
  185. def exists(env):
  186. return find(env)