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 = "ibm-clang" 11 cxx = "ibm-clang++" 12 asm = "ibm-clang" 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 -MMD -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 -MMD -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 ${rebuild_string} {{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,-x${xfile} {{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 = 96 "$python_path \"$solink_wrapper\" --output=\"$sofile\" -- $link_command" 97 98 rspfile_content = "{{inputs}} {{solibs}} {{libs}}" 99 100 description = "SOLINK $sofile" 101 102 # Use this for {{output_extension}} expansions unless a target manually 103 # overrides it (in which case {{output_extension}} will be what the target 104 # specifies). 105 default_output_extension = default_shlib_extension 106 107 default_output_dir = "{{root_out_dir}}${default_shlib_subdir}" 108 109 output_prefix = "lib" 110 111 # Since the above commands only updates the .TOC file when it changes, ask 112 # Ninja to check if the timestamp actually changed to know if downstream 113 # dependencies should be recompiled. 114 restat = true 115 116 # Tell GN about the output files. It will link to the sofile but use the 117 # tocfile for dependency management. 118 outputs = [ xfile ] 119 outputs += [ sofile ] 120 121 link_output = xfile 122 depend_output = xfile 123 } 124 125 tool("solink_module") { 126 soname = "{{target_output_name}}{{output_extension}}" # e.g. "libfoo.so". 127 sofile = "{{output_dir}}/$soname" 128 xfile = "{{output_dir}}/{{target_output_name}}.x" 129 130 rspfile = sofile + ".rsp" 131 132 command = "$ld {{ldflags}}${extra_ldflags} -o \"$sofile\" `cat $rspfile`" 133 134 rspfile_content = "{{inputs}} {{solibs}} {{libs}}" 135 136 description = "SOLINK_MODULE $sofile" 137 138 default_output_dir = "{{root_out_dir}}${default_shlib_subdir}" 139 140 output_prefix = "lib" 141 outputs = [ xfile ] 142 outputs += [ sofile ] 143 } 144 145 tool("link") { 146 exename = "{{target_output_name}}{{output_extension}}" 147 outfile = "{{output_dir}}/$exename" 148 rspfile = "$outfile.rsp" 149 150 default_output_dir = "{{root_out_dir}}" 151 152 link_command = "$ld {{ldflags}}${extra_ldflags} -o \"$outfile\" `cat $rspfile` {{solibs}} {{libs}}" 153 154 link_wrapper = 155 rebase_path("//build/toolchain/gcc_link_wrapper.py", root_build_dir) 156 157 command = 158 "$python_path \"$link_wrapper\" --output=\"$outfile\" -- $link_command" 159 160 description = "LINK $outfile" 161 rspfile_content = "{{inputs}}" 162 outputs = [ outfile ] 163 } 164 165 # These two are really entirely generic, but have to be repeated in 166 # each toolchain because GN doesn't allow a template to be used here. 167 # See //build/toolchain/toolchain.gni for details. 168 tool("stamp") { 169 command = stamp_command 170 description = stamp_description 171 } 172 tool("copy") { 173 command = copy_command 174 description = copy_description 175 } 176} 177