blob: ecf5068ee65a2caf095db627810c54c24fa67d4c [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 \
26 mkdir -p $(1); \
27 echo "Downloading $(3) ..."; \
28 curl -s -L $(2) -o $(TOOLCHAIN_ROOT)/$(3).tar.xz; \
29 tar xf $(TOOLCHAIN_ROOT)/$(3).tar.xz -C $(1) --strip-components=1; \
Jerome Forissier38cc5a82020-09-21 17:42:09 +020030 (cd $(1)/bin && for f in *-none-linux*; do ln -s $$f $${f//-none} ; done;) \
Joakim Bechc9606632017-01-27 11:50:49 +010031 fi
32endef
33
34.PHONY: toolchains
Joakim Bech6a0fc2b2018-05-23 08:38:47 +020035toolchains: aarch32 aarch64
Joakim Bech427dd632015-05-04 15:52:33 +020036
Joakim Bechc9606632017-01-27 11:50:49 +010037.PHONY: aarch32
Joakim Bech42807a72017-01-27 10:43:28 +010038aarch32:
Joakim Bechc9606632017-01-27 11:50:49 +010039 $(call dltc,$(AARCH32_PATH),$(SRC_AARCH32_GCC),$(AARCH32_GCC_VERSION))
Joakim Bech427dd632015-05-04 15:52:33 +020040
Joakim Bechc9606632017-01-27 11:50:49 +010041.PHONY: aarch64
Joakim Bech42807a72017-01-27 10:43:28 +010042aarch64:
Joakim Bechc9606632017-01-27 11:50:49 +010043 $(call dltc,$(AARCH64_PATH),$(SRC_AARCH64_GCC),$(AARCH64_GCC_VERSION))
Jerome Forissierc3cd9f52020-05-25 18:47:00 +020044
Jerome Forissierc09d34c2021-04-15 17:09:44 +020045CLANG_VER ?= 12.0.0
Jerome Forissier0ae3f0a2021-04-15 17:09:44 +020046CLANG_PATH ?= $(ROOT)/clang-$(CLANG_VER)
Jerome Forissierc3cd9f52020-05-25 18:47:00 +020047
48# Download the Clang compiler with LLVM tools and compiler-rt libraries
49define dl-clang
Jerome Forissier0ae3f0a2021-04-15 17:09:44 +020050 @if [ ! -d "$(2)" ]; then \
51 ./get_clang.sh $(1) $(2); \
Jerome Forissierc3cd9f52020-05-25 18:47:00 +020052 else \
Jerome Forissier0ae3f0a2021-04-15 17:09:44 +020053 echo "$(2) already exists"; \
Jerome Forissierc3cd9f52020-05-25 18:47:00 +020054 fi
55endef
56
57.PHONY: clang-toolchains
58clang-toolchains:
Jerome Forissier0ae3f0a2021-04-15 17:09:44 +020059 $(call dl-clang,$(CLANG_VER),$(CLANG_PATH))
Jens Wiklander68f7f8d2021-06-07 16:02:24 +000060
61else # $(UNAME_M) != x86_64
62AARCH32_PATH := $(TOOLCHAIN_ROOT)/aarch32
63AARCH32_CROSS_COMPILE := $(AARCH32_PATH)/bin/arm-linux-
64AARCH64_PATH := $(TOOLCHAIN_ROOT)/aarch64
65AARCH64_CROSS_COMPILE := $(AARCH64_PATH)/bin/aarch64-linux-
66
67.PHONY: toolchains
68toolchains: $(AARCH64_PATH)/.done $(AARCH32_PATH)/.done
69
70define build_toolchain
71 @echo Building $1 toolchain
72 @mkdir -p ../out-$1-sdk $2
73 @(cd .. && python build/br-ext/scripts/make_def_config.py \
74 --br buildroot --out out-$1-sdk --br-ext build/br-ext \
75 --top-dir "$(ROOT)" \
76 --br-defconfig build/br-ext/configs/sdk-$1 \
77 --br-defconfig build/br-ext/configs/sdk-common \
78 --make-cmd $(MAKE))
79 @$(MAKE) -C ../out-$1-sdk clean
80 @$(MAKE) -C ../out-$1-sdk sdk
81 @tar xf ../out-$1-sdk/images/$3-buildroot-linux-$4_sdk-buildroot.tar.gz \
82 -C $2 --strip-components=1
83 @touch $2/.done
84endef
85
86$(AARCH64_PATH)/.done:
87 $(call build_toolchain,aarch64,$(AARCH64_PATH),aarch64,gnu)
88
89$(AARCH32_PATH)/.done:
90 $(call build_toolchain,aarch32,$(AARCH32_PATH),arm,gnueabihf)
91endif