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.

crossmingw.py 6.5KB

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