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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. """)
  51. prefixes64 = SCons.Util.Split("""
  52. amd64-mingw32-
  53. amd64-mingw32msvc-
  54. amd64-pc-mingw32-
  55. """)
  56. def find(env):
  57. if env['machine'] == 'x86_64':
  58. prefixes = prefixes64
  59. else:
  60. prefixes = prefixes32
  61. for prefix in prefixes:
  62. # First search in the SCons path and then the OS path:
  63. if env.WhereIs(prefix + 'gcc') or SCons.Util.WhereIs(prefix + 'gcc'):
  64. return prefix
  65. return ''
  66. def shlib_generator(target, source, env, for_signature):
  67. cmd = SCons.Util.CLVar(['$SHLINK', '$SHLINKFLAGS'])
  68. dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX')
  69. if dll: cmd.extend(['-o', dll])
  70. cmd.extend(['$SOURCES', '$_LIBDIRFLAGS', '$_LIBFLAGS'])
  71. implib = env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX')
  72. if implib: cmd.append('-Wl,--out-implib,'+implib.get_string(for_signature))
  73. def_target = env.FindIxes(target, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX')
  74. if def_target: cmd.append('-Wl,--output-def,'+def_target.get_string(for_signature))
  75. return [cmd]
  76. def shlib_emitter(target, source, env):
  77. dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX')
  78. no_import_lib = env.get('no_import_lib', 0)
  79. if not dll:
  80. raise SCons.Errors.UserError, "A shared library should have exactly one target with the suffix: %s" % env.subst("$SHLIBSUFFIX")
  81. if not no_import_lib and \
  82. not env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX'):
  83. # Append an import library to the list of targets.
  84. target.append(env.ReplaceIxes(dll,
  85. 'SHLIBPREFIX', 'SHLIBSUFFIX',
  86. 'LIBPREFIX', 'LIBSUFFIX'))
  87. # Append a def file target if there isn't already a def file target
  88. # or a def file source. There is no option to disable def file
  89. # target emitting, because I can't figure out why someone would ever
  90. # want to turn it off.
  91. def_source = env.FindIxes(source, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX')
  92. def_target = env.FindIxes(target, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX')
  93. if not def_source and not def_target:
  94. target.append(env.ReplaceIxes(dll,
  95. 'SHLIBPREFIX', 'SHLIBSUFFIX',
  96. 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX'))
  97. return (target, source)
  98. shlib_action = SCons.Action.Action(shlib_generator, '$SHLINKCOMSTR', generator=1)
  99. res_action = SCons.Action.Action('$RCCOM', '$RCCOMSTR')
  100. res_builder = SCons.Builder.Builder(action=res_action, suffix='.o',
  101. source_scanner=SCons.Tool.SourceFileScanner)
  102. SCons.Tool.SourceFileScanner.add_scanner('.rc', SCons.Defaults.CScan)
  103. def generate(env):
  104. mingw_prefix = find(env)
  105. if mingw_prefix:
  106. dir = os.path.dirname(env.WhereIs(mingw_prefix + 'gcc') or SCons.Util.WhereIs(mingw_prefix + 'gcc'))
  107. # The mingw bin directory must be added to the path:
  108. path = env['ENV'].get('PATH', [])
  109. if not path:
  110. path = []
  111. if SCons.Util.is_String(path):
  112. path = string.split(path, os.pathsep)
  113. env['ENV']['PATH'] = string.join([dir] + path, os.pathsep)
  114. # Most of mingw is the same as gcc and friends...
  115. gnu_tools = ['gcc', 'g++', 'gnulink', 'ar', 'gas']
  116. for tool in gnu_tools:
  117. SCons.Tool.Tool(tool)(env)
  118. #... but a few things differ:
  119. env['CC'] = mingw_prefix + 'gcc'
  120. env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS')
  121. env['CXX'] = mingw_prefix + 'g++'
  122. env['SHCXXFLAGS'] = SCons.Util.CLVar('$CXXFLAGS')
  123. env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS -shared')
  124. env['SHLINKCOM'] = shlib_action
  125. env.Append(SHLIBEMITTER = [shlib_emitter])
  126. env['LINK'] = mingw_prefix + 'g++'
  127. env['AR'] = mingw_prefix + 'ar'
  128. env['RANLIB'] = mingw_prefix + 'ranlib'
  129. env['LINK'] = mingw_prefix + 'g++'
  130. env['AS'] = mingw_prefix + 'as'
  131. env['WIN32DEFPREFIX'] = ''
  132. env['WIN32DEFSUFFIX'] = '.def'
  133. env['SHOBJSUFFIX'] = '.o'
  134. env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1
  135. env['RC'] = mingw_prefix + 'windres'
  136. env['RCFLAGS'] = SCons.Util.CLVar('')
  137. env['RCCOM'] = '$RC $_CPPDEFFLAGS $_CPPINCFLAGS ${INCPREFIX}${SOURCE.dir} $RCFLAGS -i $SOURCE -o $TARGET'
  138. env['BUILDERS']['RES'] = res_builder
  139. # Some setting from the platform also have to be overridden:
  140. env['OBJPREFIX'] = ''
  141. env['OBJSUFFIX'] = '.o'
  142. env['SHOBJPREFIX'] = '$OBJPREFIX'
  143. env['SHOBJSUFFIX'] = '$OBJSUFFIX'
  144. env['PROGPREFIX'] = ''
  145. env['PROGSUFFIX'] = '.exe'
  146. env['LIBPREFIX'] = 'lib'
  147. env['LIBSUFFIX'] = '.a'
  148. env['SHLIBPREFIX'] = ''
  149. env['SHLIBSUFFIX'] = '.dll'
  150. env['LIBPREFIXES'] = [ 'lib', '' ]
  151. env['LIBSUFFIXES'] = [ '.a', '.lib' ]
  152. # MinGW port of gdb does not handle well dwarf debug info which is the
  153. # default in recent gcc versions
  154. env.AppendUnique(CCFLAGS = ['-gstabs'])
  155. env.AppendUnique(CPPDEFINES = [('__MSVCRT_VERSION__', '0x0700')])
  156. #env.AppendUnique(LIBS = ['iberty'])
  157. env.AppendUnique(SHLINKFLAGS = ['-Wl,--enable-stdcall-fixup'])
  158. #env.AppendUnique(SHLINKFLAGS = ['-Wl,--kill-at'])
  159. def exists(env):
  160. return find(env)