blob: ec0f5122291f4b07094513a0bc885ebe5069f07f [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
Joakim Bechc9606632017-01-27 11:50:49 +01009# Download toolchain macro for saving some repetition
10# $(1) is $AARCH.._PATH : i.e., path to the destination
11# $(2) is $SRC_AARCH.._GCC : is the downloaded tar.gz file
12# $(3) is $.._GCC_VERSION : the name of the file to download
13define dltc
14 @if [ ! -d "$(1)" ]; then \
Joakim Bechc9606632017-01-27 11:50:49 +010015 echo "Downloading $(3) ..."; \
Aleksey Kazantsevc551e2a2021-07-15 11:08:47 +030016 mkdir -p $(1); \
Jerome Forissier3408c892023-05-04 13:58:35 +020017 curl --retry 5 -k -s -S -L $(2) -o $(TOOLCHAIN_ROOT)/$(3).tar.xz || \
Aleksey Kazantsevc551e2a2021-07-15 11:08:47 +030018 { rm -f $(TOOLCHAIN_ROOT)/$(3).tar.xz; cd $(TOOLCHAIN_ROOT) && rmdir $(1); echo Download failed; exit 1; }; \
19 tar xf $(TOOLCHAIN_ROOT)/$(3).tar.xz -C $(1) --strip-components=1 || \
20 { rm $(TOOLCHAIN_ROOT)/$(3).tar.xz; echo Downloaded file is damaged; \
21 cd $(TOOLCHAIN_ROOT) && rm -rf $(1); exit 1; }; \
Alvin Chang4a1fef82023-05-17 00:18:01 +080022 (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 +010023 fi
24endef
25
Sumit Garg495dc6a2021-12-23 14:45:36 +053026# Build buildroot toolchain macro for saving some repetition
27# $(1) is $ARCH : target architecture
28# $(2) is $AARCH.._PATH : i.e., path to the destination
29# $(3) & $(4) : parts of toolchain target triplet
30define build_toolchain
31 @echo Building $1 toolchain
32 @mkdir -p ../out-$1-sdk $2
Imre Kisdc34f492023-04-11 16:53:06 +020033 @(cd .. && $(PYTHON3) build/br-ext/scripts/make_def_config.py \
Sumit Garg495dc6a2021-12-23 14:45:36 +053034 --br buildroot --out out-$1-sdk --br-ext build/br-ext \
35 --top-dir "$(ROOT)" \
36 --br-defconfig build/br-ext/configs/sdk-$1 \
37 --br-defconfig build/br-ext/configs/sdk-common \
38 --make-cmd $(MAKE))
Jerome Forissier80164982022-08-03 14:59:39 +000039 +@$(MAKE) -C ../out-$1-sdk clean
40 +@$(MAKE) -C ../out-$1-sdk sdk
Sumit Garg495dc6a2021-12-23 14:45:36 +053041 @tar xf ../out-$1-sdk/images/$3-buildroot-linux-$4_sdk-buildroot.tar.gz \
42 -C $2 --strip-components=1
43 @touch $2/.done
44endef
45
46ifeq ($(UNAME_M),x86_64)
47AARCH32_PATH ?= $(TOOLCHAIN_ROOT)/aarch32
48AARCH32_CROSS_COMPILE ?= $(AARCH32_PATH)/bin/arm-linux-gnueabihf-
Jerome Forissier19b7b072023-02-09 16:10:13 +010049AARCH32_GCC_VERSION ?= arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-linux-gnueabihf
50SRC_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 +053051
52AARCH64_PATH ?= $(TOOLCHAIN_ROOT)/aarch64
53AARCH64_CROSS_COMPILE ?= $(AARCH64_PATH)/bin/aarch64-linux-gnu-
Jerome Forissier19b7b072023-02-09 16:10:13 +010054AARCH64_GCC_VERSION ?= arm-gnu-toolchain-11.3.rel1-x86_64-aarch64-none-linux-gnu
55SRC_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 +053056
Joakim Bechc9606632017-01-27 11:50:49 +010057.PHONY: toolchains
Joakim Bech6a0fc2b2018-05-23 08:38:47 +020058toolchains: aarch32 aarch64
Joakim Bech427dd632015-05-04 15:52:33 +020059
Joakim Bechc9606632017-01-27 11:50:49 +010060.PHONY: aarch32
Joakim Bech42807a72017-01-27 10:43:28 +010061aarch32:
Joakim Bechc9606632017-01-27 11:50:49 +010062 $(call dltc,$(AARCH32_PATH),$(SRC_AARCH32_GCC),$(AARCH32_GCC_VERSION))
Joakim Bech427dd632015-05-04 15:52:33 +020063
Joakim Bechc9606632017-01-27 11:50:49 +010064.PHONY: aarch64
Joakim Bech42807a72017-01-27 10:43:28 +010065aarch64:
Joakim Bechc9606632017-01-27 11:50:49 +010066 $(call dltc,$(AARCH64_PATH),$(SRC_AARCH64_GCC),$(AARCH64_GCC_VERSION))
Jerome Forissierc3cd9f52020-05-25 18:47:00 +020067
Jerome Forissierc09d34c2021-04-15 17:09:44 +020068CLANG_VER ?= 12.0.0
Jerome Forissier0ae3f0a2021-04-15 17:09:44 +020069CLANG_PATH ?= $(ROOT)/clang-$(CLANG_VER)
Jerome Forissierc3cd9f52020-05-25 18:47:00 +020070
71# Download the Clang compiler with LLVM tools and compiler-rt libraries
72define dl-clang
Jerome Forissier0ae3f0a2021-04-15 17:09:44 +020073 @if [ ! -d "$(2)" ]; then \
74 ./get_clang.sh $(1) $(2); \
Jerome Forissierc3cd9f52020-05-25 18:47:00 +020075 else \
Jerome Forissier0ae3f0a2021-04-15 17:09:44 +020076 echo "$(2) already exists"; \
Jerome Forissierc3cd9f52020-05-25 18:47:00 +020077 fi
78endef
79
80.PHONY: clang-toolchains
81clang-toolchains:
Jerome Forissier0ae3f0a2021-04-15 17:09:44 +020082 $(call dl-clang,$(CLANG_VER),$(CLANG_PATH))
Jens Wiklander68f7f8d2021-06-07 16:02:24 +000083
Sumit Garg495dc6a2021-12-23 14:45:36 +053084else ifeq ($(UNAME_M),aarch64)
85
86AARCH32_PATH ?= $(TOOLCHAIN_ROOT)/aarch32
87AARCH32_CROSS_COMPILE ?= $(AARCH32_PATH)/bin/arm-linux-gnueabihf-
88AARCH32_GCC_VERSION ?= gcc-arm-10.2-2020.11-aarch64-arm-none-linux-gnueabihf
89SRC_AARCH32_GCC ?= https://developer.arm.com/-/media/Files/downloads/gnu-a/10.2-2020.11/binrel/$(AARCH32_GCC_VERSION).tar.xz
90
91# There isn't any native aarch64 toolchain released from Arm and buildroot
92# doesn't support distribution toolchain [1]. So we are left with no choice
93# but to build buildroot toolchain from source and use it.
94#
95# [1] https://buildroot.org/downloads/manual/manual.html#_cross_compilation_toolchain
96AARCH64_PATH ?= $(TOOLCHAIN_ROOT)/aarch64
97AARCH64_CROSS_COMPILE ?= $(AARCH64_PATH)/bin/aarch64-linux-
98
99.PHONY: toolchains
100toolchains: aarch32 $(AARCH64_PATH)/.done
101
102.PHONY: aarch32
103aarch32:
104 $(call dltc,$(AARCH32_PATH),$(SRC_AARCH32_GCC),$(AARCH32_GCC_VERSION))
105
106$(AARCH64_PATH)/.done:
107 $(call build_toolchain,aarch64,$(AARCH64_PATH),aarch64,gnu)
108
109else # $(UNAME_M) != x86_64 or $(UNAME_M) != aarch64
Jens Wiklander68f7f8d2021-06-07 16:02:24 +0000110AARCH32_PATH := $(TOOLCHAIN_ROOT)/aarch32
111AARCH32_CROSS_COMPILE := $(AARCH32_PATH)/bin/arm-linux-
112AARCH64_PATH := $(TOOLCHAIN_ROOT)/aarch64
113AARCH64_CROSS_COMPILE := $(AARCH64_PATH)/bin/aarch64-linux-
114
115.PHONY: toolchains
116toolchains: $(AARCH64_PATH)/.done $(AARCH32_PATH)/.done
117
Jens Wiklander68f7f8d2021-06-07 16:02:24 +0000118$(AARCH64_PATH)/.done:
119 $(call build_toolchain,aarch64,$(AARCH64_PATH),aarch64,gnu)
120
121$(AARCH32_PATH)/.done:
122 $(call build_toolchain,aarch32,$(AARCH32_PATH),arm,gnueabihf)
123endif