Chris Kay | cc277de | 2023-10-20 09:17:33 +0000 | [diff] [blame] | 1 | # |
Chris Kay | c327370 | 2025-01-13 15:57:32 +0000 | [diff] [blame] | 2 | # Copyright (c) 2023-2025, Arm Limited and Contributors. All rights reserved. |
Chris Kay | cc277de | 2023-10-20 09:17:33 +0000 | [diff] [blame] | 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | |
| 7 | # |
| 8 | # TF-A uses three toolchains: |
| 9 | # |
| 10 | # - The host toolchain (`host`) for building native tools |
Chris Kay | 291e718 | 2024-05-14 13:08:31 +0000 | [diff] [blame] | 11 | # - The AArch32 toolchain (`aarch32`) for building Arm AArch32 images |
Chris Kay | cc277de | 2023-10-20 09:17:33 +0000 | [diff] [blame] | 12 | # - The AArch64 toolchain (`aarch64`) for building Arm AArch64 images |
| 13 | # |
| 14 | # In the main Makefile only one of the two Arm toolchains is enabled in any |
| 15 | # given build, but individual tools and libraries may need access to both. |
| 16 | # |
| 17 | |
Chris Kay | 291e718 | 2024-05-14 13:08:31 +0000 | [diff] [blame] | 18 | ifndef toolchain-mk |
| 19 | toolchain-mk := $(lastword $(MAKEFILE_LIST)) |
Chris Kay | cc277de | 2023-10-20 09:17:33 +0000 | [diff] [blame] | 20 | |
Chris Kay | 3789c3c | 2024-06-03 11:10:11 +0000 | [diff] [blame] | 21 | include $(dir $(toolchain-mk))utilities.mk |
Chris Kay | 4731c00 | 2024-04-09 16:30:52 +0000 | [diff] [blame] | 22 | |
Chris Kay | 3789c3c | 2024-06-03 11:10:11 +0000 | [diff] [blame] | 23 | # |
| 24 | # Make assigns generic default values to `CC`, `CPP`, `AS`, etc. if they |
| 25 | # are not explicitly assigned values by the user. These are usually okay |
| 26 | # for very simple programs when building for the host system, but we |
| 27 | # need greater control over the toolchain flow. |
| 28 | # |
| 29 | # Therefore, we undefine these built-in variables if they have default |
| 30 | # values, so that we can provide our own default values later instead. |
| 31 | # |
Chris Kay | cc277de | 2023-10-20 09:17:33 +0000 | [diff] [blame] | 32 | |
Chris Kay | 3789c3c | 2024-06-03 11:10:11 +0000 | [diff] [blame] | 33 | ifeq ($(origin CC),default) |
| 34 | undefine CC |
| 35 | endif |
| 36 | |
| 37 | ifeq ($(origin CPP),default) |
| 38 | undefine CPP |
| 39 | endif |
| 40 | |
| 41 | ifeq ($(origin AS),default) |
| 42 | undefine AS |
| 43 | endif |
| 44 | |
| 45 | ifeq ($(origin AR),default) |
| 46 | undefine AR |
| 47 | endif |
| 48 | |
| 49 | ifeq ($(origin LD),default) |
| 50 | undefine LD |
| 51 | endif |
| 52 | |
| 53 | # |
| 54 | # The full list of toolchains supported by TF-A. |
| 55 | # |
| 56 | # Each of these toolchains defines a file of the same name in the |
| 57 | # `toolchains` directory, which must configure the following variables: |
| 58 | # |
| 59 | # - <toolchain>-name |
| 60 | # |
| 61 | # A human-readable name for the toolchain, |
| 62 | # |
| 63 | # Additionally, for every tool class, it must also define: |
| 64 | # |
| 65 | # - <toolchain>-<tool-class>-parameter |
| 66 | # |
| 67 | # The command line or environment variable used to set the tool for |
| 68 | # for the given tool class. |
| 69 | # |
Chris Kay | 9cea2c3 | 2024-08-29 15:08:42 +0000 | [diff] [blame] | 70 | # - <toolchain>-<tool-class>-default-id |
Chris Kay | 3789c3c | 2024-06-03 11:10:11 +0000 | [diff] [blame] | 71 | # |
| 72 | # The default tool identifier used if the tool for the given tool |
| 73 | # class cannot be identified. |
| 74 | # |
Chris Kay | 9cea2c3 | 2024-08-29 15:08:42 +0000 | [diff] [blame] | 75 | # - <toolchain>-<tool-class>-default |
| 76 | # |
| 77 | # The default commands to try, in the order defined, for the given |
| 78 | # tool class if the user does not explicitly provide one, and if the |
| 79 | # command could not be derived from the C compiler. |
| 80 | # |
Chris Kay | 3789c3c | 2024-06-03 11:10:11 +0000 | [diff] [blame] | 81 | |
| 82 | toolchains := host # Used for host targets |
| 83 | toolchains += aarch32 # Used for AArch32 targets |
| 84 | toolchains += aarch64 # Used for AArch64 targets |
| 85 | toolchains += rk3399-m0 # Used for RK3399 Cortex-M0 targets |
| 86 | |
| 87 | include $(toolchains:%=$(dir $(toolchain-mk))toolchains/%.mk) |
Chris Kay | cc277de | 2023-10-20 09:17:33 +0000 | [diff] [blame] | 88 | |
Chris Kay | 291e718 | 2024-05-14 13:08:31 +0000 | [diff] [blame] | 89 | # |
| 90 | # Configure tool classes that we recognize. |
| 91 | # |
| 92 | # In the context of this build system, a tool class identifies a |
| 93 | # specific role or type of tool in the toolchain. |
| 94 | # |
Chris Kay | cc277de | 2023-10-20 09:17:33 +0000 | [diff] [blame] | 95 | |
Chris Kay | 14260db | 2024-06-03 02:01:34 +0000 | [diff] [blame] | 96 | toolchain-tool-classes := cc |
| 97 | toolchain-tool-class-name-cc := C compiler |
Chris Kay | cc277de | 2023-10-20 09:17:33 +0000 | [diff] [blame] | 98 | |
Chris Kay | 14260db | 2024-06-03 02:01:34 +0000 | [diff] [blame] | 99 | toolchain-tool-classes += cpp |
| 100 | toolchain-tool-class-name-cpp := C preprocessor |
Chris Kay | cc277de | 2023-10-20 09:17:33 +0000 | [diff] [blame] | 101 | |
Chris Kay | 14260db | 2024-06-03 02:01:34 +0000 | [diff] [blame] | 102 | toolchain-tool-classes += as |
| 103 | toolchain-tool-class-name-as := assembler |
Chris Kay | 3d6c7e5 | 2024-04-16 17:19:20 +0000 | [diff] [blame] | 104 | |
Chris Kay | 14260db | 2024-06-03 02:01:34 +0000 | [diff] [blame] | 105 | toolchain-tool-classes += ld |
| 106 | toolchain-tool-class-name-ld := linker |
Chris Kay | 3d6c7e5 | 2024-04-16 17:19:20 +0000 | [diff] [blame] | 107 | |
Chris Kay | 14260db | 2024-06-03 02:01:34 +0000 | [diff] [blame] | 108 | toolchain-tool-classes += oc |
| 109 | toolchain-tool-class-name-oc := object copier |
Chris Kay | 3d6c7e5 | 2024-04-16 17:19:20 +0000 | [diff] [blame] | 110 | |
Chris Kay | 14260db | 2024-06-03 02:01:34 +0000 | [diff] [blame] | 111 | toolchain-tool-classes += od |
| 112 | toolchain-tool-class-name-od := object dumper |
Chris Kay | 3d6c7e5 | 2024-04-16 17:19:20 +0000 | [diff] [blame] | 113 | |
Chris Kay | 14260db | 2024-06-03 02:01:34 +0000 | [diff] [blame] | 114 | toolchain-tool-classes += ar |
| 115 | toolchain-tool-class-name-ar := archiver |
Chris Kay | cc277de | 2023-10-20 09:17:33 +0000 | [diff] [blame] | 116 | |
Chris Kay | 14260db | 2024-06-03 02:01:34 +0000 | [diff] [blame] | 117 | toolchain-tool-classes += dtc |
| 118 | toolchain-tool-class-name-dtc := device tree compiler |
Chris Kay | cc277de | 2023-10-20 09:17:33 +0000 | [diff] [blame] | 119 | |
Chris Kay | d286739 | 2024-09-26 14:18:04 +0000 | [diff] [blame] | 120 | toolchain-tool-classes += poetry |
| 121 | toolchain-tool-class-name-poetry := Python Poetry package manager |
| 122 | |
Chris Kay | 291e718 | 2024-05-14 13:08:31 +0000 | [diff] [blame] | 123 | # |
| 124 | # Configure tools that we recognize. |
| 125 | # |
| 126 | # Here we declare the list of specific toolchain tools that we know how |
| 127 | # to interact with. We don't organize these into tool classes yet - that |
| 128 | # happens further down. |
| 129 | # |
Chris Kay | 3d6c7e5 | 2024-04-16 17:19:20 +0000 | [diff] [blame] | 130 | |
Chris Kay | 291e718 | 2024-05-14 13:08:31 +0000 | [diff] [blame] | 131 | # Arm® Compiler for Embedded |
Chris Kay | 14260db | 2024-06-03 02:01:34 +0000 | [diff] [blame] | 132 | toolchain-tools := arm-clang |
| 133 | toolchain-tool-name-arm-clang := Arm® Compiler for Embedded `armclang` |
Chris Kay | 3d6c7e5 | 2024-04-16 17:19:20 +0000 | [diff] [blame] | 134 | |
Chris Kay | 14260db | 2024-06-03 02:01:34 +0000 | [diff] [blame] | 135 | toolchain-tools += arm-link |
| 136 | toolchain-tool-name-arm-link := Arm® Compiler for Embedded `armlink` |
Chris Kay | 3d6c7e5 | 2024-04-16 17:19:20 +0000 | [diff] [blame] | 137 | |
Chris Kay | 14260db | 2024-06-03 02:01:34 +0000 | [diff] [blame] | 138 | toolchain-tools += arm-ar |
| 139 | toolchain-tool-name-arm-ar := Arm® Compiler for Embedded `armar` |
Chris Kay | cc277de | 2023-10-20 09:17:33 +0000 | [diff] [blame] | 140 | |
Chris Kay | 14260db | 2024-06-03 02:01:34 +0000 | [diff] [blame] | 141 | toolchain-tools += arm-fromelf |
| 142 | toolchain-tool-name-arm-fromelf := Arm® Compiler for Embedded `fromelf` |
Chris Kay | 3d6c7e5 | 2024-04-16 17:19:20 +0000 | [diff] [blame] | 143 | |
Chris Kay | 291e718 | 2024-05-14 13:08:31 +0000 | [diff] [blame] | 144 | # LLVM Project |
Chris Kay | 14260db | 2024-06-03 02:01:34 +0000 | [diff] [blame] | 145 | toolchain-tools += llvm-clang |
| 146 | toolchain-tool-name-llvm-clang := LLVM Clang (`clang`) |
Chris Kay | 3d6c7e5 | 2024-04-16 17:19:20 +0000 | [diff] [blame] | 147 | |
Chris Kay | 14260db | 2024-06-03 02:01:34 +0000 | [diff] [blame] | 148 | toolchain-tools += llvm-lld |
| 149 | toolchain-tool-name-llvm-lld := LLVM LLD (`lld`) |
Chris Kay | 3d6c7e5 | 2024-04-16 17:19:20 +0000 | [diff] [blame] | 150 | |
Chris Kay | 14260db | 2024-06-03 02:01:34 +0000 | [diff] [blame] | 151 | toolchain-tools += llvm-objcopy |
| 152 | toolchain-tool-name-llvm-objcopy := LLVM `llvm-objcopy` |
Chris Kay | 3d6c7e5 | 2024-04-16 17:19:20 +0000 | [diff] [blame] | 153 | |
Chris Kay | 14260db | 2024-06-03 02:01:34 +0000 | [diff] [blame] | 154 | toolchain-tools += llvm-objdump |
| 155 | toolchain-tool-name-llvm-objdump := LLVM `llvm-objdump` |
Chris Kay | cc277de | 2023-10-20 09:17:33 +0000 | [diff] [blame] | 156 | |
Chris Kay | 14260db | 2024-06-03 02:01:34 +0000 | [diff] [blame] | 157 | toolchain-tools += llvm-ar |
| 158 | toolchain-tool-name-llvm-ar := LLVM `llvm-ar` |
Chris Kay | 3d6c7e5 | 2024-04-16 17:19:20 +0000 | [diff] [blame] | 159 | |
Chris Kay | 291e718 | 2024-05-14 13:08:31 +0000 | [diff] [blame] | 160 | # GNU Compiler Collection & GNU Binary Utilities |
Chris Kay | 14260db | 2024-06-03 02:01:34 +0000 | [diff] [blame] | 161 | toolchain-tools += gnu-gcc |
| 162 | toolchain-tool-name-gnu-gcc := GNU GCC (`gcc`) |
Chris Kay | 3d6c7e5 | 2024-04-16 17:19:20 +0000 | [diff] [blame] | 163 | |
Chris Kay | 14260db | 2024-06-03 02:01:34 +0000 | [diff] [blame] | 164 | toolchain-tools += gnu-ld |
| 165 | toolchain-tool-name-gnu-ld := GNU LD (`ld.bfd`) |
Chris Kay | 3d6c7e5 | 2024-04-16 17:19:20 +0000 | [diff] [blame] | 166 | |
Chris Kay | 14260db | 2024-06-03 02:01:34 +0000 | [diff] [blame] | 167 | toolchain-tools += gnu-objcopy |
| 168 | toolchain-tool-name-gnu-objcopy := GNU `objcopy` |
Chris Kay | 3d6c7e5 | 2024-04-16 17:19:20 +0000 | [diff] [blame] | 169 | |
Chris Kay | 14260db | 2024-06-03 02:01:34 +0000 | [diff] [blame] | 170 | toolchain-tools += gnu-objdump |
| 171 | toolchain-tool-name-gnu-objdump := GNU `objdump` |
Chris Kay | cc277de | 2023-10-20 09:17:33 +0000 | [diff] [blame] | 172 | |
Chris Kay | 14260db | 2024-06-03 02:01:34 +0000 | [diff] [blame] | 173 | toolchain-tools += gnu-ar |
| 174 | toolchain-tool-name-gnu-ar := GNU `ar` |
Chris Kay | cc277de | 2023-10-20 09:17:33 +0000 | [diff] [blame] | 175 | |
Chris Kay | 291e718 | 2024-05-14 13:08:31 +0000 | [diff] [blame] | 176 | # Other tools |
Chris Kay | 14260db | 2024-06-03 02:01:34 +0000 | [diff] [blame] | 177 | toolchain-tools += generic-dtc |
| 178 | toolchain-tool-name-generic-dtc := Device Tree Compiler (`dtc`) |
Chris Kay | cc277de | 2023-10-20 09:17:33 +0000 | [diff] [blame] | 179 | |
Chris Kay | d286739 | 2024-09-26 14:18:04 +0000 | [diff] [blame] | 180 | toolchain-tools += generic-poetry |
| 181 | toolchain-tool-name-generic-poetry := Poetry (`poetry`) |
| 182 | |
Chris Kay | 291e718 | 2024-05-14 13:08:31 +0000 | [diff] [blame] | 183 | # |
| 184 | # Assign tools to tool classes. |
| 185 | # |
| 186 | # Multifunctional tools, i.e. tools which can perform multiple roles in |
| 187 | # a toolchain, may be specified in multiple tool class lists. For |
| 188 | # example, a C compiler which can also perform the role of a linker may |
Chris Kay | 14260db | 2024-06-03 02:01:34 +0000 | [diff] [blame] | 189 | # be placed in both `toolchain-tools-cc` and `toolchain-tools-ld`. |
Chris Kay | 291e718 | 2024-05-14 13:08:31 +0000 | [diff] [blame] | 190 | # |
Chris Kay | cc277de | 2023-10-20 09:17:33 +0000 | [diff] [blame] | 191 | |
Chris Kay | 291e718 | 2024-05-14 13:08:31 +0000 | [diff] [blame] | 192 | # C-related tools |
Chris Kay | 14260db | 2024-06-03 02:01:34 +0000 | [diff] [blame] | 193 | toolchain-tools-cc := arm-clang llvm-clang gnu-gcc # C compilers |
| 194 | toolchain-tools-cpp := arm-clang llvm-clang gnu-gcc # C preprocessors |
Chris Kay | cc277de | 2023-10-20 09:17:33 +0000 | [diff] [blame] | 195 | |
Chris Kay | 291e718 | 2024-05-14 13:08:31 +0000 | [diff] [blame] | 196 | # Assembly-related tools |
Chris Kay | 14260db | 2024-06-03 02:01:34 +0000 | [diff] [blame] | 197 | toolchain-tools-as := arm-clang llvm-clang gnu-gcc # Assemblers |
Chris Kay | cc277de | 2023-10-20 09:17:33 +0000 | [diff] [blame] | 198 | |
Chris Kay | 291e718 | 2024-05-14 13:08:31 +0000 | [diff] [blame] | 199 | # Linking and object-handling tools |
Chris Kay | 14260db | 2024-06-03 02:01:34 +0000 | [diff] [blame] | 200 | toolchain-tools-ld := arm-clang arm-link llvm-clang llvm-lld gnu-gcc gnu-ld # Linkers |
| 201 | toolchain-tools-oc := arm-fromelf llvm-objcopy gnu-objcopy # Object copiers |
| 202 | toolchain-tools-od := arm-fromelf llvm-objdump gnu-objdump # Object dumpers |
| 203 | toolchain-tools-ar := arm-ar llvm-ar gnu-ar # Archivers |
Chris Kay | cc277de | 2023-10-20 09:17:33 +0000 | [diff] [blame] | 204 | |
Chris Kay | 291e718 | 2024-05-14 13:08:31 +0000 | [diff] [blame] | 205 | # Other tools |
Chris Kay | 14260db | 2024-06-03 02:01:34 +0000 | [diff] [blame] | 206 | toolchain-tools-dtc := generic-dtc # Device tree compilers |
Chris Kay | d286739 | 2024-09-26 14:18:04 +0000 | [diff] [blame] | 207 | toolchain-tools-poetry := generic-poetry # Python Poetry package manager |
Chris Kay | cc277de | 2023-10-20 09:17:33 +0000 | [diff] [blame] | 208 | |
Chris Kay | 291e718 | 2024-05-14 13:08:31 +0000 | [diff] [blame] | 209 | # |
Chris Kay | 291e718 | 2024-05-14 13:08:31 +0000 | [diff] [blame] | 210 | # Helper functions to identify toolchain tools. |
| 211 | # |
| 212 | # The functions defined in this section return a tool identifier when |
| 213 | # given a path to a binary. We generally check a help or version string |
| 214 | # to more reliably identify tools than by looking at the path alone |
| 215 | # (e.g. `gcc` on macOS is actually Apple Clang). |
| 216 | # |
Chris Kay | 14260db | 2024-06-03 02:01:34 +0000 | [diff] [blame] | 217 | # Each tool-guessing function (`toolchain-guess-tool-$(tool)`) takes a |
| 218 | # single argument giving the path to the tool to guess, and returns a |
| 219 | # non-empty value if the tool corresponds to the tool identifier |
| 220 | # `$(tool)`: |
Chris Kay | 291e718 | 2024-05-14 13:08:31 +0000 | [diff] [blame] | 221 | # |
Chris Kay | 14260db | 2024-06-03 02:01:34 +0000 | [diff] [blame] | 222 | # $(call toolchain-guess-tool-llvm-clang,aarch64-none-elf-gcc) # <empty> |
| 223 | # $(call toolchain-guess-tool-gnu-gcc,aarch64-none-elf-gcc) # <non-empty> |
Chris Kay | 291e718 | 2024-05-14 13:08:31 +0000 | [diff] [blame] | 224 | # |
Chris Kay | 14260db | 2024-06-03 02:01:34 +0000 | [diff] [blame] | 225 | # The `toolchain-guess-tool` function tries to find the corresponding tool |
Chris Kay | 291e718 | 2024-05-14 13:08:31 +0000 | [diff] [blame] | 226 | # identifier for a tool given its path. It takes two arguments: |
| 227 | # |
| 228 | # - $(1): a list of candidate tool identifiers to check |
| 229 | # - $(2): the path to the tool to identify |
| 230 | # |
| 231 | # If any of the guess functions corresponding to candidate tool |
| 232 | # identifiers return a non-empty value then the tool identifier of the |
| 233 | # first function to do so is returned: |
| 234 | # |
Chris Kay | 14260db | 2024-06-03 02:01:34 +0000 | [diff] [blame] | 235 | # $(call toolchain-guess-tool,gnu-gcc llvm-clang,armclang) # <empty> |
| 236 | # $(call toolchain-guess-tool,gnu-gcc llvm-clang,clang-14) # llvm-clang |
| 237 | # $(call toolchain-guess-tool,gnu-gcc llvm-clang,aarch64-none-elf-gcc-12) # gnu-gcc |
Chris Kay | 291e718 | 2024-05-14 13:08:31 +0000 | [diff] [blame] | 238 | # |
Chris Kay | 14260db | 2024-06-03 02:01:34 +0000 | [diff] [blame] | 239 | # Tools are checked in the order that they are provided, and the first |
| 240 | # match is returned. |
Chris Kay | 291e718 | 2024-05-14 13:08:31 +0000 | [diff] [blame] | 241 | # |
Chris Kay | cc277de | 2023-10-20 09:17:33 +0000 | [diff] [blame] | 242 | |
Chris Kay | 291e718 | 2024-05-14 13:08:31 +0000 | [diff] [blame] | 243 | # Arm Compiler for Embedded |
Chris Kay | c327370 | 2025-01-13 15:57:32 +0000 | [diff] [blame] | 244 | toolchain-guess-tool-arm-clang = $(shell $(1) --version 2>&1 </dev/null | grep -o "Tool: armclang") |
| 245 | toolchain-guess-tool-arm-link = $(shell $(1) --help 2>&1 </dev/null | grep -o "Tool: armlink") |
| 246 | toolchain-guess-tool-arm-fromelf = $(shell $(1) --help 2>&1 </dev/null | grep -o "Tool: fromelf") |
| 247 | toolchain-guess-tool-arm-ar = $(shell $(1) --version 2>&1 </dev/null | grep -o "Tool: armar") |
Chris Kay | cc277de | 2023-10-20 09:17:33 +0000 | [diff] [blame] | 248 | |
Chris Kay | 291e718 | 2024-05-14 13:08:31 +0000 | [diff] [blame] | 249 | # LLVM Project |
Chris Kay | c327370 | 2025-01-13 15:57:32 +0000 | [diff] [blame] | 250 | toolchain-guess-tool-llvm-clang = $(shell $(1) -v 2>&1 </dev/null | grep -o "clang version") |
| 251 | toolchain-guess-tool-llvm-lld = $(shell $(1) --help 2>&1 </dev/null | grep -o "OVERVIEW: lld") |
| 252 | toolchain-guess-tool-llvm-objcopy = $(shell $(1) --help 2>&1 </dev/null | grep -o "llvm-objcopy tool") |
| 253 | toolchain-guess-tool-llvm-objdump = $(shell $(1) --help 2>&1 </dev/null | grep -o "llvm object file dumper") |
| 254 | toolchain-guess-tool-llvm-ar = $(shell $(1) --help 2>&1 </dev/null | grep -o "LLVM Archiver") |
Chris Kay | cc277de | 2023-10-20 09:17:33 +0000 | [diff] [blame] | 255 | |
Chris Kay | 291e718 | 2024-05-14 13:08:31 +0000 | [diff] [blame] | 256 | # GNU Compiler Collection & GNU Binary Utilities |
Chris Kay | c327370 | 2025-01-13 15:57:32 +0000 | [diff] [blame] | 257 | toolchain-guess-tool-gnu-gcc = $(shell $(1) -v 2>&1 </dev/null | grep -o "gcc version") |
| 258 | toolchain-guess-tool-gnu-ld = $(shell $(1) -v 2>&1 </dev/null | grep -o "GNU ld") |
| 259 | toolchain-guess-tool-gnu-objcopy = $(shell $(1) --version 2>&1 </dev/null | grep -o "GNU objcopy") |
| 260 | toolchain-guess-tool-gnu-objdump = $(shell $(1) --version 2>&1 </dev/null | grep -o "GNU objdump") |
| 261 | toolchain-guess-tool-gnu-ar = $(shell $(1) --version 2>&1 </dev/null | grep -o "GNU ar") |
Chris Kay | cc277de | 2023-10-20 09:17:33 +0000 | [diff] [blame] | 262 | |
Chris Kay | 291e718 | 2024-05-14 13:08:31 +0000 | [diff] [blame] | 263 | # Other tools |
Chris Kay | c327370 | 2025-01-13 15:57:32 +0000 | [diff] [blame] | 264 | toolchain-guess-tool-generic-dtc = $(shell $(1) --version 2>&1 </dev/null | grep -o "Version: DTC") |
| 265 | toolchain-guess-tool-generic-poetry = $(shell $(1) --version 2>&1 </dev/null) |
Chris Kay | cc277de | 2023-10-20 09:17:33 +0000 | [diff] [blame] | 266 | |
Chris Kay | d286739 | 2024-09-26 14:18:04 +0000 | [diff] [blame] | 267 | toolchain-guess-tool = $(if $(2),$(firstword $(foreach candidate,$(1),$\ |
| 268 | $(if $(call toolchain-guess-tool-$(candidate),$(2)),$(candidate))))) |
Chris Kay | 3d6c7e5 | 2024-04-16 17:19:20 +0000 | [diff] [blame] | 269 | |
Chris Kay | 291e718 | 2024-05-14 13:08:31 +0000 | [diff] [blame] | 270 | # |
Chris Kay | 3789c3c | 2024-06-03 11:10:11 +0000 | [diff] [blame] | 271 | # Warn the user that a tool could not be identified. |
| 272 | # |
| 273 | # Parameters: |
| 274 | # |
| 275 | # - $1: The toolchain that the tool belongs to. |
| 276 | # - $2: The tool class that the tool belongs to. |
| 277 | # |
| 278 | |
| 279 | define toolchain-warn-unrecognized |
| 280 | $(warning ) |
Chris Kay | 9cea2c3 | 2024-08-29 15:08:42 +0000 | [diff] [blame] | 281 | $(warning The configured $($(1)-name) $(toolchain-tool-class-name-$(2)) could not be identified:) |
Chris Kay | 3789c3c | 2024-06-03 11:10:11 +0000 | [diff] [blame] | 282 | $(warning ) |
| 283 | $(warning $(space) $($(1)-$(2))$(if $($(1)-$(2)-parameter), (via `$($(1)-$(2)-parameter)`))) |
| 284 | $(warning ) |
Chris Kay | 9cea2c3 | 2024-08-29 15:08:42 +0000 | [diff] [blame] | 285 | $(warning The following tools were tried, but either did not exist or could not be identified:) |
Chris Kay | 3789c3c | 2024-06-03 11:10:11 +0000 | [diff] [blame] | 286 | $(warning ) |
Chris Kay | 9cea2c3 | 2024-08-29 15:08:42 +0000 | [diff] [blame] | 287 | |
| 288 | $(foreach default,$($(1)-$(2)-default), \ |
| 289 | $(warning $(space) - $(default))) |
| 290 | |
Chris Kay | 3789c3c | 2024-06-03 11:10:11 +0000 | [diff] [blame] | 291 | $(warning ) |
| 292 | $(warning The following tools are supported:) |
| 293 | $(warning ) |
| 294 | |
| 295 | $(foreach tool,$(toolchain-tools-$(2)), \ |
| 296 | $(warning $(space) - $(toolchain-tool-name-$(tool)))) |
| 297 | |
| 298 | $(warning ) |
Chris Kay | 9cea2c3 | 2024-08-29 15:08:42 +0000 | [diff] [blame] | 299 | $(warning The build system will treat this $(toolchain-tool-class-name-$(2)) as $(toolchain-tool-name-$($(1)-$(2)-default-id)).) |
Chris Kay | 3789c3c | 2024-06-03 11:10:11 +0000 | [diff] [blame] | 300 | $(warning ) |
| 301 | endef |
| 302 | |
| 303 | # |
Chris Kay | 291e718 | 2024-05-14 13:08:31 +0000 | [diff] [blame] | 304 | # Locate and identify tools belonging to each toolchain. |
| 305 | # |
| 306 | # Each tool class in each toolchain receives a variable of the form |
| 307 | # `$(toolchain)-$(tool)` giving the associated path to the program. For |
| 308 | # example: |
| 309 | # |
| 310 | # - `aarch64-ld` gives the linker for the AArch64 toolchain, |
| 311 | # - `aarch32-oc` gives the object copier for the AArch32 toolchain, and |
| 312 | # - `host-cc` gives the C compiler for the host toolchain. |
| 313 | # |
| 314 | # For each of these variables, if no program path is explicitly provided |
| 315 | # by the parent Makefile then the C compiler is queried (if supported) |
Chris Kay | 14260db | 2024-06-03 02:01:34 +0000 | [diff] [blame] | 316 | # for its location. |
Chris Kay | 291e718 | 2024-05-14 13:08:31 +0000 | [diff] [blame] | 317 | # |
Chris Kay | 14260db | 2024-06-03 02:01:34 +0000 | [diff] [blame] | 318 | # If the C compiler cannot provide the location (or the tool class *is* |
| 319 | # the C compiler), then it is assigned a default value specific for that |
| 320 | # toolchain. |
Chris Kay | 291e718 | 2024-05-14 13:08:31 +0000 | [diff] [blame] | 321 | # |
Chris Kay | 3d6c7e5 | 2024-04-16 17:19:20 +0000 | [diff] [blame] | 322 | |
Chris Kay | d286739 | 2024-09-26 14:18:04 +0000 | [diff] [blame] | 323 | toolchain-derive-arm-clang-cpp = $(1) |
| 324 | toolchain-derive-arm-clang-as = $(1) |
| 325 | toolchain-derive-arm-clang-ld = # Fall back to `$(toolchain)-ld-default` |
| 326 | toolchain-derive-arm-clang-oc = # Fall back to `$(toolchain)-oc-default` |
| 327 | toolchain-derive-arm-clang-od = # Fall back to `$(toolchain)-od-default` |
| 328 | toolchain-derive-arm-clang-ar = # Fall back to `$(toolchain)-ar-default` |
Chris Kay | 3d6c7e5 | 2024-04-16 17:19:20 +0000 | [diff] [blame] | 329 | |
Chris Kay | d286739 | 2024-09-26 14:18:04 +0000 | [diff] [blame] | 330 | toolchain-derive-llvm-clang-cpp = $(1) |
| 331 | toolchain-derive-llvm-clang-as = $(1) |
Chris Kay | c327370 | 2025-01-13 15:57:32 +0000 | [diff] [blame] | 332 | toolchain-derive-llvm-clang-ld = $(shell $(1) --print-prog-name ld.lld 2>/dev/null) |
| 333 | toolchain-derive-llvm-clang-oc = $(shell $(1) --print-prog-name llvm-objcopy 2>/dev/null) |
| 334 | toolchain-derive-llvm-clang-od = $(shell $(1) --print-prog-name llvm-objdump 2>/dev/null) |
| 335 | toolchain-derive-llvm-clang-ar = $(shell $(1) --print-prog-name llvm-ar 2>/dev/null) |
Chris Kay | 3d6c7e5 | 2024-04-16 17:19:20 +0000 | [diff] [blame] | 336 | |
Chris Kay | d286739 | 2024-09-26 14:18:04 +0000 | [diff] [blame] | 337 | toolchain-derive-gnu-gcc-cpp = $(1) |
| 338 | toolchain-derive-gnu-gcc-as = $(1) |
| 339 | toolchain-derive-gnu-gcc-ld = $(1) |
Chris Kay | c327370 | 2025-01-13 15:57:32 +0000 | [diff] [blame] | 340 | toolchain-derive-gnu-gcc-oc = $(shell $(1) --print-prog-name objcopy 2>/dev/null) |
| 341 | toolchain-derive-gnu-gcc-od = $(shell $(1) --print-prog-name objdump 2>/dev/null) |
| 342 | toolchain-derive-gnu-gcc-ar = $(shell $(1) --print-prog-name ar 2>/dev/null) |
Chris Kay | d286739 | 2024-09-26 14:18:04 +0000 | [diff] [blame] | 343 | |
| 344 | toolchain-derive = $(if $3,$(call toolchain-derive-$1-$2,$3)) |
Chris Kay | cc277de | 2023-10-20 09:17:33 +0000 | [diff] [blame] | 345 | |
Chris Kay | 3789c3c | 2024-06-03 11:10:11 +0000 | [diff] [blame] | 346 | # |
| 347 | # Configure a toolchain. |
| 348 | # |
| 349 | # Parameters: |
| 350 | # |
| 351 | # - $1: The toolchain to configure. |
| 352 | # |
| 353 | # This function iterates over all tool classes and configures them for |
| 354 | # the provided toolchain. Toolchain tools are initialized lazily and |
| 355 | # on-demand based on the first read of the tool path or identifier |
| 356 | # variables. |
| 357 | # |
Chris Kay | 3d6c7e5 | 2024-04-16 17:19:20 +0000 | [diff] [blame] | 358 | |
Chris Kay | 3789c3c | 2024-06-03 11:10:11 +0000 | [diff] [blame] | 359 | define toolchain-configure |
| 360 | $$(foreach tool-class,$$(toolchain-tool-classes), \ |
| 361 | $$(eval $$(call toolchain-configure-tool,$1,$$(tool-class)))) |
Chris Kay | 291e718 | 2024-05-14 13:08:31 +0000 | [diff] [blame] | 362 | endef |
Chris Kay | cc277de | 2023-10-20 09:17:33 +0000 | [diff] [blame] | 363 | |
Chris Kay | 3789c3c | 2024-06-03 11:10:11 +0000 | [diff] [blame] | 364 | # |
| 365 | # Configure a specific tool within a toolchain. |
| 366 | # |
| 367 | # Parameters: |
| 368 | # |
| 369 | # - $1: The toolchain to configure. |
| 370 | # - $2: The tool class to configure. |
| 371 | # |
| 372 | |
| 373 | define toolchain-configure-tool |
| 374 | $1-$2-configure = $\ |
| 375 | $$(eval $$(call toolchain-determine-tool,$1,$2)) |
| 376 | |
| 377 | # |
| 378 | # When either of the following variables are read for the first |
| 379 | # time, the appropriate tool is determined and *both* variables |
| 380 | # are overwritten with their final values. |
| 381 | # |
| 382 | |
| 383 | $1-$2 = $$($1-$2-configure)$$($1-$2) |
| 384 | $1-$2-id = $$($1-$2-configure)$$($1-$2-id) |
| 385 | endef |
| 386 | |
| 387 | # |
| 388 | # Determines and identifies a tool. |
| 389 | # |
| 390 | # Parameters: |
| 391 | # |
| 392 | # - $1: The toolchain identifier. |
| 393 | # - $2: The tool class. |
| 394 | # |
| 395 | # Tool identification happens by reading the designated tool parameter |
| 396 | # to get the user-specified command for the tool (e.g. `CC` or `LD`). If |
| 397 | # no tool parameter is defined then try to derive the tool from the C |
| 398 | # compiler. |
| 399 | # |
| 400 | # If all else fails, fall back to the default command defined by the |
| 401 | # toolchain makefile. |
| 402 | # |
| 403 | |
Chris Kay | e01c712 | 2024-05-15 11:19:17 +0000 | [diff] [blame] | 404 | define toolchain-determine-tool |
Chris Kay | d286739 | 2024-09-26 14:18:04 +0000 | [diff] [blame] | 405 | toolchain-$1-$2-derive-from-cc = $$(if $$(filter-out cc,$2),$\ |
| 406 | $$(call toolchain-derive,$$($1-cc-id),$2,$$($1-cc))) |
Chris Kay | cc277de | 2023-10-20 09:17:33 +0000 | [diff] [blame] | 407 | |
Chris Kay | d286739 | 2024-09-26 14:18:04 +0000 | [diff] [blame] | 408 | toolchain-$1-$2-shell = $\ |
| 409 | $$(if $$(call defined,$$($1-$2-parameter)),$\ |
| 410 | $$($$($1-$2-parameter)),$\ |
| 411 | $$(or $$(toolchain-$1-$2-derive-from-cc),$\ |
| 412 | $$(toolchain-$1-$2-default))) |
Chris Kay | 9cea2c3 | 2024-08-29 15:08:42 +0000 | [diff] [blame] | 413 | |
| 414 | toolchain-$1-$2-default = $$(firstword $\ |
| 415 | $$(foreach default,$$($1-$2-default),$\ |
| 416 | $$(if $$(call which,$$(default)),$$(default))) $\ |
| 417 | $$($1-$2-default)) |
Chris Kay | 291e718 | 2024-05-14 13:08:31 +0000 | [diff] [blame] | 418 | |
Chris Kay | d286739 | 2024-09-26 14:18:04 +0000 | [diff] [blame] | 419 | $1-$2 := $$(if $$(call which,$$(toolchain-$1-$2-shell)),$\ |
Chris Kay | 3789c3c | 2024-06-03 11:10:11 +0000 | [diff] [blame] | 420 | $$(call escape-shell,$$(toolchain-$1-$2-shell)),$\ |
| 421 | $$(toolchain-$1-$2-shell)) |
Chris Kay | 291e718 | 2024-05-14 13:08:31 +0000 | [diff] [blame] | 422 | |
Chris Kay | d286739 | 2024-09-26 14:18:04 +0000 | [diff] [blame] | 423 | $1-$2-id := $$(if $$($1-$2),$$(or $\ |
| 424 | $$(call toolchain-guess-tool,$$\ |
| 425 | $$(toolchain-tools-$2),$$($1-$2)),$\ |
| 426 | $$($1-$2-default-id))) |
| 427 | |
| 428 | ifeq ($$(or $$($1-$2-id),$$(call bool,$$($1-$2-optional))),) |
| 429 | $$(call toolchain-warn-unrecognized,$1,$2) |
| 430 | endif |
Chris Kay | 291e718 | 2024-05-14 13:08:31 +0000 | [diff] [blame] | 431 | endef |
Chris Kay | cc277de | 2023-10-20 09:17:33 +0000 | [diff] [blame] | 432 | |
Chris Kay | 291e718 | 2024-05-14 13:08:31 +0000 | [diff] [blame] | 433 | $(foreach toolchain,$(toolchains), \ |
Chris Kay | 3789c3c | 2024-06-03 11:10:11 +0000 | [diff] [blame] | 434 | $(eval $(call toolchain-configure,$(toolchain)))) |
Chris Kay | 291e718 | 2024-05-14 13:08:31 +0000 | [diff] [blame] | 435 | endif |