BUILD.gn 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. # Copyright 2021 The Chromium Authors. All rights reserved.
  2. # Use of this source code is governed by a BSD-style license that can be
  3. # found in the LICENSE file.
  4. # This file is based on gcc_toolchain.gni and customized for z/OS.
  5. import("//build/toolchain/gcc_toolchain.gni")
  6. toolchain("s390x") {
  7. cc = "xlclang"
  8. cxx = "xlclang++"
  9. asm = "xlclang"
  10. ar = "ar"
  11. ld = cxx
  12. toolchain_args = {
  13. current_cpu = "s390x"
  14. current_os = "zos"
  15. }
  16. rebuild_string = ""
  17. default_shlib_extension = ".so"
  18. default_shlib_subdir = ""
  19. extra_cflags = ""
  20. extra_cppflags = ""
  21. extra_cxxflags = ""
  22. extra_asmflags = ""
  23. extra_ldflags = ""
  24. # These library switches can apply to all tools below.
  25. lib_switch = "-l"
  26. lib_dir_switch = "-L"
  27. # Object files go in this directory.
  28. object_subdir = "{{target_out_dir}}/{{label_name}}"
  29. tool("cc") {
  30. depfile = "{{output}}.d"
  31. command = "$cc -MF $depfile ${rebuild_string}{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}${extra_cflags} -c {{source}} -o {{output}}"
  32. depsformat = "gcc"
  33. description = "CC {{output}}"
  34. outputs = [ "$object_subdir/{{source_name_part}}.o" ]
  35. }
  36. tool("cxx") {
  37. depfile = "{{output}}.d"
  38. command = "$cxx -MF $depfile ${rebuild_string}{{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}${extra_cppflags}${extra_cxxflags} -c {{source}} -o {{output}}"
  39. depsformat = "gcc"
  40. description = "CXX {{output}}"
  41. outputs = [ "$object_subdir/{{source_name_part}}.o" ]
  42. }
  43. tool("asm") {
  44. # Just use the C compiler to compile assembly.
  45. depfile = "{{output}}.d"
  46. command = "$asm -MF $depfile ${rebuild_string}{{defines}} {{include_dirs}} {{asmflags}}${extra_asmflags} -c {{source}} -o {{output}}"
  47. depsformat = "gcc"
  48. description = "ASM {{output}}"
  49. outputs = [ "$object_subdir/{{source_name_part}}.o" ]
  50. }
  51. tool("alink") {
  52. command = "$ar {{arflags}} -r -c -s {{output}} {{inputs}}"
  53. # Remove the output file first so that ar doesn't try to modify the
  54. # existing file.
  55. command = "rm -f {{output}} && $command"
  56. # Almost all targets build with //build/config/compiler:thin_archive which
  57. # adds -T to arflags.
  58. description = "AR {{output}}"
  59. outputs = [ "{{output_dir}}/{{target_output_name}}{{output_extension}}" ]
  60. # Shared libraries go in the target out directory by default so we can
  61. # generate different targets with the same name and not have them collide.
  62. default_output_dir = "{{target_out_dir}}"
  63. default_output_extension = ".a"
  64. output_prefix = "lib"
  65. }
  66. tool("solink") {
  67. soname = "{{target_output_name}}{{output_extension}}" # e.g. "libfoo.so".
  68. sofile = "{{output_dir}}/$soname" # Possibly including toolchain dir.
  69. xfile = "{{output_dir}}/{{target_output_name}}.x"
  70. rspfile = sofile + ".rsp"
  71. # These variables are not built into GN but are helpers that
  72. # implement (1) linking to produce a .so, (2) extracting the symbols
  73. # from that file (3) if the extracted list differs from the existing
  74. # .TOC file, overwrite it, otherwise, don't change it.
  75. link_command = "$ld -Wl,DLL {{ldflags}}${extra_ldflags} -o \"$sofile\" `cat $rspfile`"
  76. solink_wrapper =
  77. rebase_path("//build/toolchain/gcc_link_wrapper.py", root_build_dir)
  78. command = "$python_path \"$solink_wrapper\" --output=\"$sofile\" -- $link_command"
  79. rspfile_content = "{{inputs}} {{solibs}} {{libs}}"
  80. description = "SOLINK $sofile"
  81. # Use this for {{output_extension}} expansions unless a target manually
  82. # overrides it (in which case {{output_extension}} will be what the target
  83. # specifies).
  84. default_output_extension = default_shlib_extension
  85. default_output_dir = "{{root_out_dir}}${default_shlib_subdir}"
  86. output_prefix = "lib"
  87. # Since the above commands only updates the .TOC file when it changes, ask
  88. # Ninja to check if the timestamp actually changed to know if downstream
  89. # dependencies should be recompiled.
  90. restat = true
  91. # Tell GN about the output files. It will link to the sofile but use the
  92. # tocfile for dependency management.
  93. outputs = [ xfile ]
  94. outputs += [ sofile ]
  95. link_output = xfile
  96. depend_output = xfile
  97. }
  98. tool("solink_module") {
  99. soname = "{{target_output_name}}{{output_extension}}" # e.g. "libfoo.so".
  100. sofile = "{{output_dir}}/$soname"
  101. xfile = "{{output_dir}}/{{target_output_name}}.x"
  102. rspfile = sofile + ".rsp"
  103. command = "$ld {{ldflags}}${extra_ldflags} -o \"$sofile\" `cat $rspfile`"
  104. rspfile_content = "{{inputs}} {{solibs}} {{libs}}"
  105. description = "SOLINK_MODULE $sofile"
  106. default_output_dir = "{{root_out_dir}}${default_shlib_subdir}"
  107. output_prefix = "lib"
  108. outputs = [ xfile ]
  109. outputs += [ sofile ]
  110. }
  111. tool("link") {
  112. exename = "{{target_output_name}}{{output_extension}}"
  113. outfile = "{{output_dir}}/$exename"
  114. rspfile = "$outfile.rsp"
  115. default_output_dir = "{{root_out_dir}}"
  116. link_command = "$ld {{ldflags}}${extra_ldflags} -o \"$outfile\" `cat $rspfile` {{solibs}} {{libs}}"
  117. link_wrapper =
  118. rebase_path("//build/toolchain/gcc_link_wrapper.py", root_build_dir)
  119. command = "$python_path \"$link_wrapper\" --output=\"$outfile\" -- $link_command"
  120. description = "LINK $outfile"
  121. rspfile_content = "{{inputs}}"
  122. outputs = [ outfile ]
  123. }
  124. # These two are really entirely generic, but have to be repeated in
  125. # each toolchain because GN doesn't allow a template to be used here.
  126. # See //build/toolchain/toolchain.gni for details.
  127. tool("stamp") {
  128. command = stamp_command
  129. description = stamp_description
  130. }
  131. tool("copy") {
  132. command = copy_command
  133. description = copy_description
  134. }
  135. }