linkers.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. # Copyright 2012-2017 The Meson development team
  2. # Licensed under the Apache License, Version 2.0 (the "License");
  3. # you may not use this file except in compliance with the License.
  4. # You may obtain a copy of the License at
  5. # http://www.apache.org/licenses/LICENSE-2.0
  6. # Unless required by applicable law or agreed to in writing, software
  7. # distributed under the License is distributed on an "AS IS" BASIS,
  8. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. # See the License for the specific language governing permissions and
  10. # limitations under the License.
  11. from .mesonlib import Popen_safe
  12. from . import mesonlib
  13. class StaticLinker:
  14. def can_linker_accept_rsp(self):
  15. """
  16. Determines whether the linker can accept arguments using the @rsp syntax.
  17. """
  18. return mesonlib.is_windows()
  19. class VisualStudioLinker(StaticLinker):
  20. always_args = ['/NOLOGO']
  21. def __init__(self, exelist):
  22. self.exelist = exelist
  23. def get_exelist(self):
  24. return self.exelist[:]
  25. def get_std_link_args(self):
  26. return []
  27. def get_buildtype_linker_args(self, buildtype):
  28. return []
  29. def get_output_args(self, target):
  30. return ['/OUT:' + target]
  31. def get_coverage_link_args(self):
  32. return []
  33. def get_always_args(self):
  34. return VisualStudioLinker.always_args[:]
  35. def get_linker_always_args(self):
  36. return VisualStudioLinker.always_args[:]
  37. def build_rpath_args(self, build_dir, from_dir, rpath_paths, build_rpath, install_rpath):
  38. return []
  39. def thread_link_flags(self, env):
  40. return []
  41. def openmp_flags(self):
  42. return []
  43. def get_option_link_args(self, options):
  44. return []
  45. @classmethod
  46. def unix_args_to_native(cls, args):
  47. from .compilers import VisualStudioCCompiler
  48. return VisualStudioCCompiler.unix_args_to_native(args)
  49. def get_link_debugfile_args(self, targetfile):
  50. # Static libraries do not have PDB files
  51. return []
  52. class ArLinker(StaticLinker):
  53. def __init__(self, exelist):
  54. self.exelist = exelist
  55. self.id = 'ar'
  56. pc, stdo = Popen_safe(self.exelist + ['-h'])[0:2]
  57. # Enable deterministic builds if they are available.
  58. if '[D]' in stdo:
  59. self.std_args = ['csrD']
  60. else:
  61. self.std_args = ['csr']
  62. # For 'armar' the options should be prefixed with '-'.
  63. if 'armar' in stdo:
  64. self.std_args = ['-csr']
  65. def can_linker_accept_rsp(self):
  66. return mesonlib.is_windows()
  67. def build_rpath_args(self, build_dir, from_dir, rpath_paths, build_rpath, install_rpath):
  68. return []
  69. def get_exelist(self):
  70. return self.exelist[:]
  71. def get_std_link_args(self):
  72. return self.std_args
  73. def get_output_args(self, target):
  74. return [target]
  75. def get_buildtype_linker_args(self, buildtype):
  76. return []
  77. def get_linker_always_args(self):
  78. return []
  79. def get_coverage_link_args(self):
  80. return []
  81. def get_always_args(self):
  82. return []
  83. def thread_link_flags(self, env):
  84. return []
  85. def openmp_flags(self):
  86. return []
  87. def get_option_link_args(self, options):
  88. return []
  89. @classmethod
  90. def unix_args_to_native(cls, args):
  91. return args[:]
  92. def get_link_debugfile_args(self, targetfile):
  93. return []