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