1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136
  137
  138
  139
  140
  141
  142
  143
  144
  145
  146
  147
  148
  149
  150
  151
  152
  153
  154
  155
  156
  157
  158
  159
  160
  161
  162
  163
  164
  165
  166
  167
  168
  169
  170
  171
  172
  173
  174
  175
  176

build / toolchain / zos / BUILD.gn [blame]

# Copyright 2021 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# This file is based on gcc_toolchain.gni and customized for z/OS.

import("//build/toolchain/gcc_toolchain.gni")

toolchain("s390x") {
  cc = "ibm-clang"
  cxx = "ibm-clang++"
  asm = "ibm-clang"
  ar = "ar"
  ld = cxx

  toolchain_args = {
    current_cpu = "s390x"
    current_os = "zos"
  }

  rebuild_string = ""
  default_shlib_extension = ".so"
  default_shlib_subdir = ""
  extra_cflags = ""
  extra_cppflags = ""
  extra_cxxflags = ""
  extra_asmflags = ""
  extra_ldflags = ""

  # These library switches can apply to all tools below.
  lib_switch = "-l"
  lib_dir_switch = "-L"

  # Object files go in this directory.
  object_subdir = "{{target_out_dir}}/{{label_name}}"

  tool("cc") {
    depfile = "{{output}}.d"
    command = "$cc -MMD -MF $depfile ${rebuild_string}{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}${extra_cflags} -c {{source}} -o {{output}}"
    depsformat = "gcc"
    description = "CC {{output}}"
    outputs = [ "$object_subdir/{{source_name_part}}.o" ]
  }

  tool("cxx") {
    depfile = "{{output}}.d"
    command = "$cxx -MMD -MF $depfile ${rebuild_string}{{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}${extra_cppflags}${extra_cxxflags} -c {{source}} -o {{output}}"
    depsformat = "gcc"
    description = "CXX {{output}}"
    outputs = [ "$object_subdir/{{source_name_part}}.o" ]
  }

  tool("asm") {
    # Just use the C compiler to compile assembly.
    depfile = "{{output}}.d"
    command = "$asm ${rebuild_string} {{asmflags}}${extra_asmflags} -c {{source}} -o {{output}}"
    depsformat = "gcc"
    description = "ASM {{output}}"
    outputs = [ "$object_subdir/{{source_name_part}}.o" ]
  }

  tool("alink") {
    command = "$ar {{arflags}} -r -c -s {{output}} {{inputs}}"

    # Remove the output file first so that ar doesn't try to modify the
    # existing file.
    command = "rm -f {{output}} && $command"

    # Almost all targets build with //build/config/compiler:thin_archive which
    # adds -T to arflags.
    description = "AR {{output}}"
    outputs = [ "{{output_dir}}/{{target_output_name}}{{output_extension}}" ]

    # Shared libraries go in the target out directory by default so we can
    # generate different targets with the same name and not have them collide.
    default_output_dir = "{{target_out_dir}}"
    default_output_extension = ".a"
    output_prefix = "lib"
  }

  tool("solink") {
    soname = "{{target_output_name}}{{output_extension}}"  # e.g. "libfoo.so".
    sofile = "{{output_dir}}/$soname"  # Possibly including toolchain dir.
    xfile = "{{output_dir}}/{{target_output_name}}.x"
    rspfile = sofile + ".rsp"

    # These variables are not built into GN but are helpers that
    # implement (1) linking to produce a .so, (2) extracting the symbols
    # from that file (3) if the extracted list differs from the existing
    # .TOC file, overwrite it, otherwise, don't change it.
    link_command = "$ld -Wl,-x${xfile} {{ldflags}}${extra_ldflags} -o \"$sofile\" `cat $rspfile`"

    solink_wrapper =
        rebase_path("//build/toolchain/gcc_link_wrapper.py", root_build_dir)
    command =
        "$python_path \"$solink_wrapper\" --output=\"$sofile\" -- $link_command"

    rspfile_content = "{{inputs}} {{solibs}} {{libs}}"

    description = "SOLINK $sofile"

    # Use this for {{output_extension}} expansions unless a target manually
    # overrides it (in which case {{output_extension}} will be what the target
    # specifies).
    default_output_extension = default_shlib_extension

    default_output_dir = "{{root_out_dir}}${default_shlib_subdir}"

    output_prefix = "lib"

    # Since the above commands only updates the .TOC file when it changes, ask
    # Ninja to check if the timestamp actually changed to know if downstream
    # dependencies should be recompiled.
    restat = true

    # Tell GN about the output files. It will link to the sofile but use the
    # tocfile for dependency management.
    outputs = [ xfile ]
    outputs += [ sofile ]

    link_output = xfile
    depend_output = xfile
  }

  tool("solink_module") {
    soname = "{{target_output_name}}{{output_extension}}"  # e.g. "libfoo.so".
    sofile = "{{output_dir}}/$soname"
    xfile = "{{output_dir}}/{{target_output_name}}.x"

    rspfile = sofile + ".rsp"

    command = "$ld {{ldflags}}${extra_ldflags} -o \"$sofile\" `cat $rspfile`"

    rspfile_content = "{{inputs}} {{solibs}} {{libs}}"

    description = "SOLINK_MODULE $sofile"

    default_output_dir = "{{root_out_dir}}${default_shlib_subdir}"

    output_prefix = "lib"
    outputs = [ xfile ]
    outputs += [ sofile ]
  }

  tool("link") {
    exename = "{{target_output_name}}{{output_extension}}"
    outfile = "{{output_dir}}/$exename"
    rspfile = "$outfile.rsp"

    default_output_dir = "{{root_out_dir}}"

    link_command = "$ld {{ldflags}}${extra_ldflags} -o \"$outfile\" `cat $rspfile` {{solibs}} {{libs}}"

    link_wrapper =
        rebase_path("//build/toolchain/gcc_link_wrapper.py", root_build_dir)

    command =
        "$python_path \"$link_wrapper\" --output=\"$outfile\" -- $link_command"

    description = "LINK $outfile"
    rspfile_content = "{{inputs}}"
    outputs = [ outfile ]
  }

  # These two are really entirely generic, but have to be repeated in
  # each toolchain because GN doesn't allow a template to be used here.
  # See //build/toolchain/toolchain.gni for details.
  tool("stamp") {
    command = stamp_command
    description = stamp_description
  }
  tool("copy") {
    command = copy_command
    description = copy_description
  }
}