blob: 66abf5e3879e6e76b0ccfed4e53e5b69e36b2cfd [file] [log] [blame]
Joakim Bech427dd632015-05-04 15:52:33 +02001################################################################################
2# Toolchains
3################################################################################
Yunli Liu904f1482021-01-22 11:08:08 +08004SHELL = /bin/bash
Joakim Bechc9606632017-01-27 11:50:49 +01005ROOT ?= $(CURDIR)/..
Joakim Bech427dd632015-05-04 15:52:33 +02006TOOLCHAIN_ROOT ?= $(ROOT)/toolchains
Sean Gilligan4d33afe2024-05-19 18:20:11 -07007RUST_TOOLCHAIN_PATH ?= $(TOOLCHAIN_ROOT)/rust
Jens Wiklander68f7f8d2021-06-07 16:02:24 +00008UNAME_M := $(shell uname -m)
Alvin Chang344f7712023-07-25 23:28:32 +08009ARCH ?= arm
Joakim Bech427dd632015-05-04 15:52:33 +020010
Joakim Bechc9606632017-01-27 11:50:49 +010011# Download toolchain macro for saving some repetition
12# $(1) is $AARCH.._PATH : i.e., path to the destination
13# $(2) is $SRC_AARCH.._GCC : is the downloaded tar.gz file
14# $(3) is $.._GCC_VERSION : the name of the file to download
15define dltc
16 @if [ ! -d "$(1)" ]; then \
Joakim Bechc9606632017-01-27 11:50:49 +010017 echo "Downloading $(3) ..."; \
Aleksey Kazantsevc551e2a2021-07-15 11:08:47 +030018 mkdir -p $(1); \
Jerome Forissier3408c892023-05-04 13:58:35 +020019 curl --retry 5 -k -s -S -L $(2) -o $(TOOLCHAIN_ROOT)/$(3).tar.xz || \
Aleksey Kazantsevc551e2a2021-07-15 11:08:47 +030020 { rm -f $(TOOLCHAIN_ROOT)/$(3).tar.xz; cd $(TOOLCHAIN_ROOT) && rmdir $(1); echo Download failed; exit 1; }; \
21 tar xf $(TOOLCHAIN_ROOT)/$(3).tar.xz -C $(1) --strip-components=1 || \
22 { rm $(TOOLCHAIN_ROOT)/$(3).tar.xz; echo Downloaded file is damaged; \
23 cd $(TOOLCHAIN_ROOT) && rm -rf $(1); exit 1; }; \
Alvin Chang4a1fef82023-05-17 00:18:01 +080024 (cd $(1)/bin && shopt -s nullglob && for f in *-none-linux*; do ln -s $$f $${f//-none} ; done;) \
Joakim Bechc9606632017-01-27 11:50:49 +010025 fi
26endef
27
Sumit Garg495dc6a2021-12-23 14:45:36 +053028# Build buildroot toolchain macro for saving some repetition
29# $(1) is $ARCH : target architecture
30# $(2) is $AARCH.._PATH : i.e., path to the destination
31# $(3) & $(4) : parts of toolchain target triplet
32define build_toolchain
33 @echo Building $1 toolchain
34 @mkdir -p ../out-$1-sdk $2
Imre Kisdc34f492023-04-11 16:53:06 +020035 @(cd .. && $(PYTHON3) build/br-ext/scripts/make_def_config.py \
Sumit Garg495dc6a2021-12-23 14:45:36 +053036 --br buildroot --out out-$1-sdk --br-ext build/br-ext \
37 --top-dir "$(ROOT)" \
38 --br-defconfig build/br-ext/configs/sdk-$1 \
39 --br-defconfig build/br-ext/configs/sdk-common \
40 --make-cmd $(MAKE))
Jerome Forissier80164982022-08-03 14:59:39 +000041 +@$(MAKE) -C ../out-$1-sdk clean
42 +@$(MAKE) -C ../out-$1-sdk sdk
Sumit Garg495dc6a2021-12-23 14:45:36 +053043 @tar xf ../out-$1-sdk/images/$3-buildroot-linux-$4_sdk-buildroot.tar.gz \
44 -C $2 --strip-components=1
45 @touch $2/.done
46endef
47
Sean Gilligan4d33afe2024-05-19 18:20:11 -070048# Download the Rust toolchain
49define dl-rust-toolchain
50 @if [ ! -d "$(1)" ]; then \
51 mkdir -p $(1) && \
52 export RUSTUP_HOME=$(1)/.rustup && \
53 export CARGO_HOME=$(1)/.cargo && \
54 curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path; \
55 fi
56endef
57
Sumit Garg495dc6a2021-12-23 14:45:36 +053058ifeq ($(UNAME_M),x86_64)
Alvin Chang344f7712023-07-25 23:28:32 +080059ifeq ($(ARCH),arm)
Jens Wiklander5f64ee72024-07-04 10:07:09 +000060# Please keep in sync with br-ext/configs/toolchain-aarch32
61# and below for aarch64 host
Sumit Garg495dc6a2021-12-23 14:45:36 +053062AARCH32_PATH ?= $(TOOLCHAIN_ROOT)/aarch32
63AARCH32_CROSS_COMPILE ?= $(AARCH32_PATH)/bin/arm-linux-gnueabihf-
Jerome Forissier19b7b072023-02-09 16:10:13 +010064AARCH32_GCC_VERSION ?= arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-linux-gnueabihf
65SRC_AARCH32_GCC ?= https://developer.arm.com/-/media/Files/downloads/gnu/11.3.rel1/binrel/$(AARCH32_GCC_VERSION).tar.xz
Sumit Garg495dc6a2021-12-23 14:45:36 +053066
Jens Wiklander5f64ee72024-07-04 10:07:09 +000067# Please keep in sync with br-ext/configs/toolchain-aarch64
Sumit Garg495dc6a2021-12-23 14:45:36 +053068AARCH64_PATH ?= $(TOOLCHAIN_ROOT)/aarch64
69AARCH64_CROSS_COMPILE ?= $(AARCH64_PATH)/bin/aarch64-linux-gnu-
Jerome Forissier19b7b072023-02-09 16:10:13 +010070AARCH64_GCC_VERSION ?= arm-gnu-toolchain-11.3.rel1-x86_64-aarch64-none-linux-gnu
71SRC_AARCH64_GCC ?= https://developer.arm.com/-/media/Files/downloads/gnu/11.3.rel1/binrel/$(AARCH64_GCC_VERSION).tar.xz
Sumit Garg495dc6a2021-12-23 14:45:36 +053072
Joakim Bechc9606632017-01-27 11:50:49 +010073.PHONY: toolchains
Sumit Garg857eaa02024-01-25 11:43:29 +053074toolchains: aarch32-toolchain aarch64-toolchain rust-toolchain
Joakim Bech427dd632015-05-04 15:52:33 +020075
Sumit Garg50458912024-01-25 11:37:50 +053076.PHONY: aarch32-toolchain
77aarch32-toolchain:
Joakim Bechc9606632017-01-27 11:50:49 +010078 $(call dltc,$(AARCH32_PATH),$(SRC_AARCH32_GCC),$(AARCH32_GCC_VERSION))
Joakim Bech427dd632015-05-04 15:52:33 +020079
Sumit Garg50458912024-01-25 11:37:50 +053080.PHONY: aarch64-toolchain
81aarch64-toolchain:
Joakim Bechc9606632017-01-27 11:50:49 +010082 $(call dltc,$(AARCH64_PATH),$(SRC_AARCH64_GCC),$(AARCH64_GCC_VERSION))
Jerome Forissierc3cd9f52020-05-25 18:47:00 +020083
Sumit Garg857eaa02024-01-25 11:43:29 +053084.PHONY: rust-toolchain
85rust-toolchain:
86 $(call dl-rust-toolchain,$(RUST_TOOLCHAIN_PATH))
87
Jerome Forissierc09d34c2021-04-15 17:09:44 +020088CLANG_VER ?= 12.0.0
Jerome Forissier0ae3f0a2021-04-15 17:09:44 +020089CLANG_PATH ?= $(ROOT)/clang-$(CLANG_VER)
Jerome Forissierc3cd9f52020-05-25 18:47:00 +020090
91# Download the Clang compiler with LLVM tools and compiler-rt libraries
92define dl-clang
Jerome Forissier0ae3f0a2021-04-15 17:09:44 +020093 @if [ ! -d "$(2)" ]; then \
94 ./get_clang.sh $(1) $(2); \
Jerome Forissierc3cd9f52020-05-25 18:47:00 +020095 else \
Jerome Forissier0ae3f0a2021-04-15 17:09:44 +020096 echo "$(2) already exists"; \
Jerome Forissierc3cd9f52020-05-25 18:47:00 +020097 fi
98endef
99
Alvin Chang344f7712023-07-25 23:28:32 +0800100else ifeq ($(ARCH),riscv)
Alvin Chang6902e462023-07-19 14:37:25 +0800101RISCV64_PATH ?= $(TOOLCHAIN_ROOT)/riscv64
102RISCV64_CROSS_COMPILE ?= $(RISCV64_PATH)/bin/riscv64-unknown-linux-gnu-
103RISCV64_GCC_RELEASE_DATE ?= 2023.07.07
104RISCV64_GCC_VERSION ?= riscv64-glibc-ubuntu-22.04-gcc-nightly-$(RISCV64_GCC_RELEASE_DATE)-nightly
105SRC_RISCV64_GCC ?= https://github.com/riscv-collab/riscv-gnu-toolchain/releases/download/$(RISCV64_GCC_RELEASE_DATE)/$(RISCV64_GCC_VERSION).tar.gz
106
107.PHONY: toolchains
Sumit Garg50458912024-01-25 11:37:50 +0530108toolchains: riscv64-toolchain
Alvin Chang6902e462023-07-19 14:37:25 +0800109
Sumit Garg50458912024-01-25 11:37:50 +0530110.PHONY: riscv64-toolchain
111riscv64-toolchain:
Alvin Chang6902e462023-07-19 14:37:25 +0800112 $(call dltc,$(RISCV64_PATH),$(SRC_RISCV64_GCC),$(RISCV64_GCC_VERSION))
113
114endif
115
Sumit Garg495dc6a2021-12-23 14:45:36 +0530116else ifeq ($(UNAME_M),aarch64)
117
Jens Wiklander5f64ee72024-07-04 10:07:09 +0000118# Please keep in sync with br-ext/configs/toolchain-aarch32
119# and above for x86_64 host
Sumit Garg495dc6a2021-12-23 14:45:36 +0530120AARCH32_PATH ?= $(TOOLCHAIN_ROOT)/aarch32
121AARCH32_CROSS_COMPILE ?= $(AARCH32_PATH)/bin/arm-linux-gnueabihf-
Jens Wiklander9edc5be2024-07-04 07:47:48 +0000122AARCH32_GCC_VERSION ?= arm-gnu-toolchain-11.3.rel1-aarch64-arm-none-linux-gnueabihf
123SRC_AARCH32_GCC ?= https://developer.arm.com/-/media/Files/downloads/gnu/11.3.rel1/binrel/$(AARCH32_GCC_VERSION).tar.xz
Sumit Garg495dc6a2021-12-23 14:45:36 +0530124
125# There isn't any native aarch64 toolchain released from Arm and buildroot
126# doesn't support distribution toolchain [1]. So we are left with no choice
127# but to build buildroot toolchain from source and use it.
128#
129# [1] https://buildroot.org/downloads/manual/manual.html#_cross_compilation_toolchain
130AARCH64_PATH ?= $(TOOLCHAIN_ROOT)/aarch64
131AARCH64_CROSS_COMPILE ?= $(AARCH64_PATH)/bin/aarch64-linux-
132
133.PHONY: toolchains
Sean Gilligan4d33afe2024-05-19 18:20:11 -0700134toolchains: aarch32-toolchain $(AARCH64_PATH)/.done rust-toolchain
Sumit Garg495dc6a2021-12-23 14:45:36 +0530135
Sumit Garg50458912024-01-25 11:37:50 +0530136.PHONY: aarch32-toolchain
137aarch32-toolchain:
Sumit Garg495dc6a2021-12-23 14:45:36 +0530138 $(call dltc,$(AARCH32_PATH),$(SRC_AARCH32_GCC),$(AARCH32_GCC_VERSION))
139
140$(AARCH64_PATH)/.done:
141 $(call build_toolchain,aarch64,$(AARCH64_PATH),aarch64,gnu)
142
Sean Gilligan4d33afe2024-05-19 18:20:11 -0700143.PHONY: rust-toolchain
144rust-toolchain:
145 $(call dl-rust-toolchain,$(RUST_TOOLCHAIN_PATH))
146
Sumit Garg495dc6a2021-12-23 14:45:36 +0530147else # $(UNAME_M) != x86_64 or $(UNAME_M) != aarch64
Jens Wiklander68f7f8d2021-06-07 16:02:24 +0000148AARCH32_PATH := $(TOOLCHAIN_ROOT)/aarch32
149AARCH32_CROSS_COMPILE := $(AARCH32_PATH)/bin/arm-linux-
150AARCH64_PATH := $(TOOLCHAIN_ROOT)/aarch64
151AARCH64_CROSS_COMPILE := $(AARCH64_PATH)/bin/aarch64-linux-
152
153.PHONY: toolchains
154toolchains: $(AARCH64_PATH)/.done $(AARCH32_PATH)/.done
155
Jens Wiklander68f7f8d2021-06-07 16:02:24 +0000156$(AARCH64_PATH)/.done:
157 $(call build_toolchain,aarch64,$(AARCH64_PATH),aarch64,gnu)
158
159$(AARCH32_PATH)/.done:
160 $(call build_toolchain,aarch32,$(AARCH32_PATH),arm,gnueabihf)
161endif