blob: 65ffddf4929227e788f12965cba8907d019bb58e [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)
Joakim Bech427dd632015-05-04 15:52:33 +02008
Jens Wiklander68f7f8d2021-06-07 16:02:24 +00009ifeq ($(UNAME_M),x86_64)
Joakim Bech427dd632015-05-04 15:52:33 +020010AARCH32_PATH ?= $(TOOLCHAIN_ROOT)/aarch32
11AARCH32_CROSS_COMPILE ?= $(AARCH32_PATH)/bin/arm-linux-gnueabihf-
Joakim Bech19ea7132021-06-14 11:32:46 +020012AARCH32_GCC_VERSION ?= gcc-arm-10.2-2020.11-x86_64-arm-none-linux-gnueabihf
13SRC_AARCH32_GCC ?= https://developer.arm.com/-/media/Files/downloads/gnu-a/10.2-2020.11/binrel/$(AARCH32_GCC_VERSION).tar.xz
Joakim Bech427dd632015-05-04 15:52:33 +020014
15AARCH64_PATH ?= $(TOOLCHAIN_ROOT)/aarch64
16AARCH64_CROSS_COMPILE ?= $(AARCH64_PATH)/bin/aarch64-linux-gnu-
Joakim Bech19ea7132021-06-14 11:32:46 +020017AARCH64_GCC_VERSION ?= gcc-arm-10.2-2020.11-x86_64-aarch64-none-linux-gnu
18SRC_AARCH64_GCC ?= https://developer.arm.com/-/media/Files/downloads/gnu-a/10.2-2020.11/binrel/$(AARCH64_GCC_VERSION).tar.xz
Joakim Bech427dd632015-05-04 15:52:33 +020019
Joakim Bechc9606632017-01-27 11:50:49 +010020# Download toolchain macro for saving some repetition
21# $(1) is $AARCH.._PATH : i.e., path to the destination
22# $(2) is $SRC_AARCH.._GCC : is the downloaded tar.gz file
23# $(3) is $.._GCC_VERSION : the name of the file to download
24define dltc
25 @if [ ! -d "$(1)" ]; then \
Joakim Bechc9606632017-01-27 11:50:49 +010026 echo "Downloading $(3) ..."; \
Aleksey Kazantsevc551e2a2021-07-15 11:08:47 +030027 mkdir -p $(1); \
28 curl --retry 5 -s -S -L $(2) -o $(TOOLCHAIN_ROOT)/$(3).tar.xz || \
29 { rm -f $(TOOLCHAIN_ROOT)/$(3).tar.xz; cd $(TOOLCHAIN_ROOT) && rmdir $(1); echo Download failed; exit 1; }; \
30 tar xf $(TOOLCHAIN_ROOT)/$(3).tar.xz -C $(1) --strip-components=1 || \
31 { rm $(TOOLCHAIN_ROOT)/$(3).tar.xz; echo Downloaded file is damaged; \
32 cd $(TOOLCHAIN_ROOT) && rm -rf $(1); exit 1; }; \
Jerome Forissier38cc5a82020-09-21 17:42:09 +020033 (cd $(1)/bin && for f in *-none-linux*; do ln -s $$f $${f//-none} ; done;) \
Joakim Bechc9606632017-01-27 11:50:49 +010034 fi
35endef
36
37.PHONY: toolchains
Joakim Bech6a0fc2b2018-05-23 08:38:47 +020038toolchains: aarch32 aarch64
Joakim Bech427dd632015-05-04 15:52:33 +020039
Joakim Bechc9606632017-01-27 11:50:49 +010040.PHONY: aarch32
Joakim Bech42807a72017-01-27 10:43:28 +010041aarch32:
Joakim Bechc9606632017-01-27 11:50:49 +010042 $(call dltc,$(AARCH32_PATH),$(SRC_AARCH32_GCC),$(AARCH32_GCC_VERSION))
Joakim Bech427dd632015-05-04 15:52:33 +020043
Joakim Bechc9606632017-01-27 11:50:49 +010044.PHONY: aarch64
Joakim Bech42807a72017-01-27 10:43:28 +010045aarch64:
Joakim Bechc9606632017-01-27 11:50:49 +010046 $(call dltc,$(AARCH64_PATH),$(SRC_AARCH64_GCC),$(AARCH64_GCC_VERSION))
Jerome Forissierc3cd9f52020-05-25 18:47:00 +020047
Jerome Forissierc09d34c2021-04-15 17:09:44 +020048CLANG_VER ?= 12.0.0
Jerome Forissier0ae3f0a2021-04-15 17:09:44 +020049CLANG_PATH ?= $(ROOT)/clang-$(CLANG_VER)
Jerome Forissierc3cd9f52020-05-25 18:47:00 +020050
51# Download the Clang compiler with LLVM tools and compiler-rt libraries
52define dl-clang
Jerome Forissier0ae3f0a2021-04-15 17:09:44 +020053 @if [ ! -d "$(2)" ]; then \
54 ./get_clang.sh $(1) $(2); \
Jerome Forissierc3cd9f52020-05-25 18:47:00 +020055 else \
Jerome Forissier0ae3f0a2021-04-15 17:09:44 +020056 echo "$(2) already exists"; \
Jerome Forissierc3cd9f52020-05-25 18:47:00 +020057 fi
58endef
59
60.PHONY: clang-toolchains
61clang-toolchains:
Jerome Forissier0ae3f0a2021-04-15 17:09:44 +020062 $(call dl-clang,$(CLANG_VER),$(CLANG_PATH))
Jens Wiklander68f7f8d2021-06-07 16:02:24 +000063
64else # $(UNAME_M) != x86_64
65AARCH32_PATH := $(TOOLCHAIN_ROOT)/aarch32
66AARCH32_CROSS_COMPILE := $(AARCH32_PATH)/bin/arm-linux-
67AARCH64_PATH := $(TOOLCHAIN_ROOT)/aarch64
68AARCH64_CROSS_COMPILE := $(AARCH64_PATH)/bin/aarch64-linux-
69
70.PHONY: toolchains
71toolchains: $(AARCH64_PATH)/.done $(AARCH32_PATH)/.done
72
73define build_toolchain
74 @echo Building $1 toolchain
75 @mkdir -p ../out-$1-sdk $2
76 @(cd .. && python build/br-ext/scripts/make_def_config.py \
77 --br buildroot --out out-$1-sdk --br-ext build/br-ext \
78 --top-dir "$(ROOT)" \
79 --br-defconfig build/br-ext/configs/sdk-$1 \
80 --br-defconfig build/br-ext/configs/sdk-common \
81 --make-cmd $(MAKE))
82 @$(MAKE) -C ../out-$1-sdk clean
83 @$(MAKE) -C ../out-$1-sdk sdk
84 @tar xf ../out-$1-sdk/images/$3-buildroot-linux-$4_sdk-buildroot.tar.gz \
85 -C $2 --strip-components=1
86 @touch $2/.done
87endef
88
89$(AARCH64_PATH)/.done:
90 $(call build_toolchain,aarch64,$(AARCH64_PATH),aarch64,gnu)
91
92$(AARCH32_PATH)/.done:
93 $(call build_toolchain,aarch32,$(AARCH32_PATH),arm,gnueabihf)
94endif