| # Copyright 2019 The Pigweed Authors |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| # use this file except in compliance with the License. You may obtain a copy of |
| # the License at |
| # |
| # https://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| # License for the specific language governing permissions and limitations under |
| # the License. |
| |
| import("arm_gcc.gni") |
| import("host_clang.gni") |
| import("host_gcc.gni") |
| |
| # Creates a series of toolchain targets with common compiler options. |
| # |
| # Args: |
| # toolchain_template: The target template to use to create the toolchains. |
| # common_toolchain_cflags: cflags to be shared by all toolchains. |
| # common_toolchain_ldflags: ldflags to be shared by all toolchains. |
| # toolchains: List of scopes defining each of the desired toolchains. |
| # Each scope contains up to three variables: |
| # toolchain_name: The full target name of the toolchain. |
| # additional_cflags: Optional list of extra cflags for the toolchain. |
| # additional_ldflags: Optional list of extra ldflags for the toolchain. |
| template("generate_toolchains") { |
| not_needed([ "target_name" ]) |
| |
| assert(defined(invoker.toolchain_template), |
| "generate_toolchains requires a toolchain template") |
| assert(defined(invoker.toolchains), |
| "generate_toolchains must be called with a list of toolchains") |
| |
| if (defined(invoker.common_toolchain_cflags)) { |
| _common_cflags = invoker.common_toolchain_cflags |
| } else { |
| _common_cflags = [] |
| } |
| |
| if (defined(invoker.common_toolchain_ldflags)) { |
| _common_ldflags = invoker.common_toolchain_ldflags |
| } else { |
| _common_ldflags = [] |
| } |
| |
| # Create a target for each of the desired toolchains, appending its own cflags |
| # and ldflags to the common ones. |
| foreach(toolchain_config, invoker.toolchains) { |
| # GN does not allow assigning a non-empty array to a non-empty array. |
| # This must be done as two assignments, first clearing the original value. |
| _toolchain_cflags = [] |
| _toolchain_cflags = _common_cflags |
| if (defined(toolchain_config.additional_cflags)) { |
| _toolchain_cflags += toolchain_config.additional_cflags |
| } |
| |
| _toolchain_ldflags = [] |
| _toolchain_ldflags = _common_ldflags |
| if (defined(toolchain_config.additional_ldflags)) { |
| _toolchain_ldflags += toolchain_config.additional_ldflags |
| } |
| |
| target(invoker.toolchain_template, toolchain_config.toolchain_name) { |
| toolchain_cflags = _toolchain_cflags |
| toolchain_ldflags = _toolchain_ldflags |
| } |
| } |
| } |
| |
| generate_toolchains("cortex_m4") { |
| toolchain_template = "arm_gcc_toolchain" |
| |
| software_fpu_cflags = [ "-mfloat-abi=soft" ] |
| |
| hardware_fpu_cflags = [ |
| # When hardware FPU is enabled, PW_ARMV7M_ENABLE_FPU is set to 1. |
| # TODO(pwbug/17): Replace when there's a more sophisticated configuration |
| # system. |
| "-DPW_ARMV7M_ENABLE_FPU=1", |
| "-mfloat-abi=hard", |
| "-mfpu=fpv4-sp-d16", |
| ] |
| |
| common_toolchain_cflags = [ |
| "-mabi=aapcs", |
| "-mcpu=cortex-m4", |
| "-mthumb", |
| "-specs=nano.specs", |
| "-specs=nosys.specs", |
| ] |
| |
| common_toolchain_ldflags = [ |
| "-lnosys", |
| "-lc", |
| ] |
| |
| toolchains = [ |
| # Cortex-M4 toolchains that use software-emulated floating point. |
| { |
| toolchain_name = "arm_gcc_cortex_m4_og" |
| additional_cflags = [ "-Og" ] |
| additional_cflags += software_fpu_cflags |
| }, |
| { |
| toolchain_name = "arm_gcc_cortex_m4_o1" |
| additional_cflags = [ "-O1" ] |
| additional_cflags += software_fpu_cflags |
| }, |
| { |
| toolchain_name = "arm_gcc_cortex_m4_o2" |
| additional_cflags = [ "-O2" ] |
| additional_cflags += software_fpu_cflags |
| }, |
| { |
| toolchain_name = "arm_gcc_cortex_m4_os" |
| additional_cflags = [ "-Os" ] |
| additional_cflags += software_fpu_cflags |
| }, |
| |
| # Cortex-M4 toolchains that use hardware FPU instructions. |
| { |
| toolchain_name = "arm_gcc_cortex_m4f_og" |
| additional_cflags = [ "-Og" ] |
| additional_cflags += hardware_fpu_cflags |
| }, |
| { |
| toolchain_name = "arm_gcc_cortex_m4f_o1" |
| additional_cflags = [ "-O1" ] |
| additional_cflags += hardware_fpu_cflags |
| }, |
| { |
| toolchain_name = "arm_gcc_cortex_m4f_o2" |
| additional_cflags = [ "-O2" ] |
| additional_cflags += hardware_fpu_cflags |
| }, |
| { |
| toolchain_name = "arm_gcc_cortex_m4f_os" |
| additional_cflags = [ "-Os" ] |
| additional_cflags += hardware_fpu_cflags |
| }, |
| ] |
| } |
| |
| generate_toolchains("host_gcc_suite") { |
| toolchain_template = "host_gcc" |
| |
| toolchains = [ |
| { |
| toolchain_name = "host_gcc_og" |
| additional_cflags = [ "-Og" ] |
| }, |
| { |
| toolchain_name = "host_gcc_o2" |
| additional_cflags = [ "-O2" ] |
| }, |
| { |
| toolchain_name = "host_gcc_os" |
| additional_cflags = [ "-Os" ] |
| }, |
| ] |
| } |
| |
| generate_toolchains("host_clang_suite") { |
| toolchain_template = "host_clang" |
| common_toolchain_cflags = [ "-g3" ] |
| |
| toolchains = [ |
| { |
| toolchain_name = "host_clang_og" |
| additional_cflags = [ "-Og" ] |
| }, |
| { |
| toolchain_name = "host_clang_o2" |
| additional_cflags = [ "-O2" ] |
| }, |
| { |
| toolchain_name = "host_clang_os" |
| additional_cflags = [ "-Os" ] |
| }, |
| ] |
| } |