|
| 1 | +# Copyright 2019 The Fuchsia 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 | + |
| 5 | +if (target_os == "") { |
| 6 | + target_os = host_os |
| 7 | +} |
| 8 | + |
| 9 | +if (target_cpu == "") { |
| 10 | + target_cpu = host_cpu |
| 11 | +} |
| 12 | + |
| 13 | +if (current_cpu == "") { |
| 14 | + current_cpu = target_cpu |
| 15 | +} |
| 16 | +if (current_os == "") { |
| 17 | + current_os = target_os |
| 18 | +} |
| 19 | + |
| 20 | +is_fuchsia = current_os == "fuchsia" |
| 21 | +is_linux = current_os == "linux" |
| 22 | + |
| 23 | +declare_args() { |
| 24 | + is_debug = true |
| 25 | +} |
| 26 | + |
| 27 | +# Set the host_toolchain |
| 28 | +declare_args() { |
| 29 | + host_toolchain = "" |
| 30 | +} |
| 31 | + |
| 32 | +# ============================================================================== |
| 33 | +# TOOLCHAIN SETUP |
| 34 | +# ============================================================================== |
| 35 | +# |
| 36 | +# Here we set the default toolchain, as well as the variable host_toolchain |
| 37 | +# which will identify the toolchain corresponding to the local system when |
| 38 | +# doing cross-compiles. When not cross-compiling, this will be the same as the |
| 39 | +# default toolchain. |
| 40 | +# |
| 41 | +# We do this before anything else to make sure we complain about any |
| 42 | +# unsupported os/cpu combinations as early as possible. |
| 43 | + |
| 44 | +if (host_toolchain == "") { |
| 45 | + # This should only happen in the top-level context. |
| 46 | + # In a specific toolchain context, the toolchain_args() |
| 47 | + # block should have propagated a value down. |
| 48 | + |
| 49 | + if (host_os == "linux") { |
| 50 | + host_toolchain = "//build/fuchsia/toolchain/linux:clang_$host_cpu" |
| 51 | + } else if (host_os == "mac") { |
| 52 | + host_toolchain = "//build/fuchsia/toolchain/mac:$host_cpu" |
| 53 | + } else { |
| 54 | + assert(false, "Unsupported host_os: $host_os") |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +# Set toolchain based on target_os and target_cpu |
| 59 | +_default_toolchain = "" |
| 60 | + |
| 61 | +if (target_os == "linux") { |
| 62 | + _default_toolchain = "//build/fuchsia/toolchain/linux:clang_$target_cpu" |
| 63 | +} else if (target_os == "fuchsia") { |
| 64 | + _default_toolchain = "//build/fuchsia/toolchain/fuchsia:$target_cpu" |
| 65 | +} else { |
| 66 | + assert(false, "Unsupported target_os: $target_os") |
| 67 | +} |
| 68 | + |
| 69 | +set_default_toolchain(_default_toolchain) |
| 70 | + |
| 71 | +# Set compiler defaults |
| 72 | + |
| 73 | +# Holds all configs used for running the compiler. |
| 74 | +default_compiler_configs = [ |
| 75 | + "//build/fuchsia:compiler_defaults", |
| 76 | + "//build/fuchsia/config/compiler:assembler_debug_dir", |
| 77 | + "//build/fuchsia/config/compiler:compiler", |
| 78 | + "//build/fuchsia/config/compiler:compiler_arm_fpu", |
| 79 | + "//build/fuchsia/config/compiler:c++", |
| 80 | + "//build/fuchsia/config/compiler:default_include_dirs", |
| 81 | + "//build/fuchsia/config/compiler:default_optimization", |
| 82 | + "//build/fuchsia/config/compiler:default_symbols", |
| 83 | + "//build/fuchsia/config/compiler:no_exceptions", |
| 84 | + "//build/fuchsia/config/compiler:no_rtti", |
| 85 | + "//build/fuchsia/config/compiler:runtime_library", |
| 86 | + "//build/fuchsia/config/compiler:extra_warnings", |
| 87 | + "//build/fuchsia/config/compiler:symbol_visibility_hidden", |
| 88 | +] |
| 89 | + |
| 90 | +if (is_fuchsia) { |
| 91 | + default_compiler_configs += [ |
| 92 | + "//third_party/fuchsia-sdk/build/config:compiler", |
| 93 | + "//third_party/fuchsia-sdk/build/config:runtime_library", |
| 94 | + ] |
| 95 | + |
| 96 | + # these are additional flags recommended |
| 97 | + default_compiler_configs += [ "//build/fuchsia/config/compiler:default_stack_frames" ] |
| 98 | +} |
| 99 | + |
| 100 | +# Debug/release-related defines. |
| 101 | +if (is_debug) { |
| 102 | + default_compiler_configs += [ "//build/fuchsia/config:debug" ] |
| 103 | +} else { |
| 104 | + default_compiler_configs += [ "//build/fuchsia/config:release" ] |
| 105 | +} |
| 106 | + |
| 107 | +# Static libraries and source sets use only the compiler ones. |
| 108 | +set_defaults("static_library") { |
| 109 | + configs = default_compiler_configs |
| 110 | +} |
| 111 | +set_defaults("source_set") { |
| 112 | + configs = default_compiler_configs |
| 113 | +} |
| 114 | + |
| 115 | +# Executable defaults. |
| 116 | +default_executable_configs = default_compiler_configs + [ |
| 117 | + "//build/fuchsia:executable_ldconfig", |
| 118 | + "//build/fuchsia/config:default_libs", |
| 119 | + ] |
| 120 | +set_defaults("executable") { |
| 121 | + configs = default_executable_configs |
| 122 | +} |
| 123 | + |
| 124 | +# Shared library and loadable module defaults (also for components in component |
| 125 | +# mode). |
| 126 | +default_shared_library_configs = |
| 127 | + default_compiler_configs + [ "//build/fuchsia/config:default_libs" ] |
| 128 | + |
| 129 | +set_defaults("shared_library") { |
| 130 | + configs = default_shared_library_configs |
| 131 | +} |
| 132 | +set_defaults("loadable_module") { |
| 133 | + configs = default_shared_library_configs |
| 134 | +} |
| 135 | + |
| 136 | +if (is_fuchsia) { |
| 137 | + # Sets default dependencies for executable and shared_library targets. |
| 138 | + # |
| 139 | + # Variables |
| 140 | + # no_default_deps: If true, no standard dependencies will be added. |
| 141 | + foreach(_target_type, |
| 142 | + [ |
| 143 | + "executable", |
| 144 | + "shared_library", |
| 145 | + ]) { |
| 146 | + template(_target_type) { |
| 147 | + target(_target_type, target_name) { |
| 148 | + forward_variables_from(invoker, "*", [ "no_default_deps" ]) |
| 149 | + if (!defined(deps)) { |
| 150 | + deps = [] |
| 151 | + } |
| 152 | + if (!defined(data_deps)) { |
| 153 | + data_deps = [] |
| 154 | + } |
| 155 | + if (!defined(invoker.no_default_deps) || !invoker.no_default_deps) { |
| 156 | + data_deps += [ "//build/fuchsia/config/clang:c++-runtime-deps" ] |
| 157 | + deps += [ "//third_party/fuchsia-sdk/build/config:runtime_library_group" ] |
| 158 | + } |
| 159 | + } |
| 160 | + } |
| 161 | + } |
| 162 | +} |
0 commit comments