blob: 517b91331cb1f097b5f3a0f29c027508031c230e [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
Jens Wiklander68f7f8d2021-06-07 16:02:24 +00007UNAME_M := $(shell uname -m)
Alvin Chang344f7712023-07-25 23:28:32 +08008ARCH ?= arm
Joakim Bech427dd632015-05-04 15:52:33 +02009
Joakim Bechc9606632017-01-27 11:50:49 +010010# Download toolchain macro for saving some repetition
11# $(1) is $AARCH.._PATH : i.e., path to the destination
12# $(2) is $SRC_AARCH.._GCC : is the downloaded tar.gz file
13# $(3) is $.._GCC_VERSION : the name of the file to download
14define dltc
15 @if [ ! -d "$(1)" ]; then \
Joakim Bechc9606632017-01-27 11:50:49 +010016 echo "Downloading $(3) ..."; \
Aleksey Kazantsevc551e2a2021-07-15 11:08:47 +030017 mkdir -p $(1); \
Jerome Forissier3408c892023-05-04 13:58:35 +020018 curl --retry 5 -k -s -S -L $(2) -o $(TOOLCHAIN_ROOT)/$(3).tar.xz || \
Aleksey Kazantsevc551e2a2021-07-15 11:08:47 +030019 { rm -f $(TOOLCHAIN_ROOT)/$(3).tar.xz; cd $(TOOLCHAIN_ROOT) && rmdir $(1); echo Download failed; exit 1; }; \
20 tar xf $(TOOLCHAIN_ROOT)/$(3).tar.xz -C $(1) --strip-components=1 || \
21 { rm $(TOOLCHAIN_ROOT)/$(3).tar.xz; echo Downloaded file is damaged; \
22 cd $(TOOLCHAIN_ROOT) && rm -rf $(1); exit 1; }; \
Alvin Chang4a1fef82023-05-17 00:18:01 +080023 (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 +010024 fi
25endef
26
Sumit Garg495dc6a2021-12-23 14:45:36 +053027# Build buildroot toolchain macro for saving some repetition
28# $(1) is $ARCH : target architecture
29# $(2) is $AARCH.._PATH : i.e., path to the destination
30# $(3) & $(4) : parts of toolchain target triplet
31define build_toolchain
32 @echo Building $1 toolchain
33 @mkdir -p ../out-$1-sdk $2
Imre Kisdc34f492023-04-11 16:53:06 +020034 @(cd .. && $(PYTHON3) build/br-ext/scripts/make_def_config.py \
Sumit Garg495dc6a2021-12-23 14:45:36 +053035 --br buildroot --out out-$1-sdk --br-ext build/br-ext \
36 --top-dir "$(ROOT)" \
37 --br-defconfig build/br-ext/configs/sdk-$1 \
38 --br-defconfig build/br-ext/configs/sdk-common \
39 --make-cmd $(MAKE))
Jerome Forissier80164982022-08-03 14:59:39 +000040 +@$(MAKE) -C ../out-$1-sdk clean
41 +@$(MAKE) -C ../out-$1-sdk sdk
Sumit Garg495dc6a2021-12-23 14:45:36 +053042 @tar xf ../out-$1-sdk/images/$3-buildroot-linux-$4_sdk-buildroot.tar.gz \
43 -C $2 --strip-components=1
44 @touch $2/.done
45endef
46
47ifeq ($(UNAME_M),x86_64)
Alvin Chang344f7712023-07-25 23:28:32 +080048ifeq ($(ARCH),arm)
Sumit Garg495dc6a2021-12-23 14:45:36 +053049AARCH32_PATH ?= $(TOOLCHAIN_ROOT)/aarch32
50AARCH32_CROSS_COMPILE ?= $(AARCH32_PATH)/bin/arm-linux-gnueabihf-
Jerome Forissier19b7b072023-02-09 16:10:13 +010051AARCH32_GCC_VERSION ?= arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-linux-gnueabihf
52SRC_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 +053053
54AARCH64_PATH ?= $(TOOLCHAIN_ROOT)/aarch64
55AARCH64_CROSS_COMPILE ?= $(AARCH64_PATH)/bin/aarch64-linux-gnu-
Jerome Forissier19b7b072023-02-09 16:10:13 +010056AARCH64_GCC_VERSION ?= arm-gnu-toolchain-11.3.rel1-x86_64-aarch64-none-linux-gnu
57SRC_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 +053058
Joakim Bechc9606632017-01-27 11:50:49 +010059.PHONY: toolchains
Joakim Bech6a0fc2b2018-05-23 08:38:47 +020060toolchains: aarch32 aarch64
Joakim Bech427dd632015-05-04 15:52:33 +020061
Joakim Bechc9606632017-01-27 11:50:49 +010062.PHONY: aarch32
Joakim Bech42807a72017-01-27 10:43:28 +010063aarch32:
Joakim Bechc9606632017-01-27 11:50:49 +010064 $(call dltc,$(AARCH32_PATH),$(SRC_AARCH32_GCC),$(AARCH32_GCC_VERSION))
Joakim Bech427dd632015-05-04 15:52:33 +020065
Joakim Bechc9606632017-01-27 11:50:49 +010066.PHONY: aarch64
Joakim Bech42807a72017-01-27 10:43:28 +010067aarch64:
Joakim Bechc9606632017-01-27 11:50:49 +010068 $(call dltc,$(AARCH64_PATH),$(SRC_AARCH64_GCC),$(AARCH64_GCC_VERSION))
Jerome Forissierc3cd9f52020-05-25 18:47:00 +020069
Jerome Forissierc09d34c2021-04-15 17:09:44 +020070CLANG_VER ?= 12.0.0
Jerome Forissier0ae3f0a2021-04-15 17:09:44 +020071CLANG_PATH ?= $(ROOT)/clang-$(CLANG_VER)
Jerome Forissierc3cd9f52020-05-25 18:47:00 +020072
73# Download the Clang compiler with LLVM tools and compiler-rt libraries
74define dl-clang
Jerome Forissier0ae3f0a2021-04-15 17:09:44 +020075 @if [ ! -d "$(2)" ]; then \
76 ./get_clang.sh $(1) $(2); \
Jerome Forissierc3cd9f52020-05-25 18:47:00 +020077 else \
Jerome Forissier0ae3f0a2021-04-15 17:09:44 +020078 echo "$(2) already exists"; \
Jerome Forissierc3cd9f52020-05-25 18:47:00 +020079 fi
80endef
81
82.PHONY: clang-toolchains
83clang-toolchains:
Jerome Forissier0ae3f0a2021-04-15 17:09:44 +020084 $(call dl-clang,$(CLANG_VER),$(CLANG_PATH))
Jens Wiklander68f7f8d2021-06-07 16:02:24 +000085
Alvin Chang344f7712023-07-25 23:28:32 +080086else ifeq ($(ARCH),riscv)
Alvin Chang6902e462023-07-19 14:37:25 +080087RISCV64_PATH ?= $(TOOLCHAIN_ROOT)/riscv64
88RISCV64_CROSS_COMPILE ?= $(RISCV64_PATH)/bin/riscv64-unknown-linux-gnu-
89RISCV64_GCC_RELEASE_DATE ?= 2023.07.07
90RISCV64_GCC_VERSION ?= riscv64-glibc-ubuntu-22.04-gcc-nightly-$(RISCV64_GCC_RELEASE_DATE)-nightly
91SRC_RISCV64_GCC ?= https://github.com/riscv-collab/riscv-gnu-toolchain/releases/download/$(RISCV64_GCC_RELEASE_DATE)/$(RISCV64_GCC_VERSION).tar.gz
92
93.PHONY: toolchains
94toolchains: riscv64
95
96.PHONY: riscv64
97riscv64:
98 $(call dltc,$(RISCV64_PATH),$(SRC_RISCV64_GCC),$(RISCV64_GCC_VERSION))
99
100endif
101
Sumit Garg495dc6a2021-12-23 14:45:36 +0530102else ifeq ($(UNAME_M),aarch64)
103
104AARCH32_PATH ?= $(TOOLCHAIN_ROOT)/aarch32
105AARCH32_CROSS_COMPILE ?= $(AARCH32_PATH)/bin/arm-linux-gnueabihf-
106AARCH32_GCC_VERSION ?= gcc-arm-10.2-2020.11-aarch64-arm-none-linux-gnueabihf
107SRC_AARCH32_GCC ?= https://developer.arm.com/-/media/Files/downloads/gnu-a/10.2-2020.11/binrel/$(AARCH32_GCC_VERSION).tar.xz
108
109# There isn't any native aarch64 toolchain released from Arm and buildroot
110# doesn't support distribution toolchain [1]. So we are left with no choice
111# but to build buildroot toolchain from source and use it.
112#
113# [1] https://buildroot.org/downloads/manual/manual.html#_cross_compilation_toolchain
114AARCH64_PATH ?= $(TOOLCHAIN_ROOT)/aarch64
115AARCH64_CROSS_COMPILE ?= $(AARCH64_PATH)/bin/aarch64-linux-
116
117.PHONY: toolchains
118toolchains: aarch32 $(AARCH64_PATH)/.done
119
120.PHONY: aarch32
121aarch32:
122 $(call dltc,$(AARCH32_PATH),$(SRC_AARCH32_GCC),$(AARCH32_GCC_VERSION))
123
124$(AARCH64_PATH)/.done:
125 $(call build_toolchain,aarch64,$(AARCH64_PATH),aarch64,gnu)
126
127else # $(UNAME_M) != x86_64 or $(UNAME_M) != aarch64
Jens Wiklander68f7f8d2021-06-07 16:02:24 +0000128AARCH32_PATH := $(TOOLCHAIN_ROOT)/aarch32
129AARCH32_CROSS_COMPILE := $(AARCH32_PATH)/bin/arm-linux-
130AARCH64_PATH := $(TOOLCHAIN_ROOT)/aarch64
131AARCH64_CROSS_COMPILE := $(AARCH64_PATH)/bin/aarch64-linux-
132
133.PHONY: toolchains
134toolchains: $(AARCH64_PATH)/.done $(AARCH32_PATH)/.done
135
Jens Wiklander68f7f8d2021-06-07 16:02:24 +0000136$(AARCH64_PATH)/.done:
137 $(call build_toolchain,aarch64,$(AARCH64_PATH),aarch64,gnu)
138
139$(AARCH32_PATH)/.done:
140 $(call build_toolchain,aarch32,$(AARCH32_PATH),arm,gnueabihf)
141endif