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