-
Notifications
You must be signed in to change notification settings - Fork 17
/
toolchain.mk
53 lines (42 loc) · 1.8 KB
/
toolchain.mk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
include functions.mk
# Default toolchain URL and version
__toolchain__/DEFAULT_VERSION := 2024.02-1
toolchain_url := https://toolchains.bootlin.com/downloads/releases/toolchains/$(arch)/tarballs/$(arch)--musl--stable-$(__toolchain__/DEFAULT_VERSION).tar.bz2
# Determine the desired toolchain version to use.
define __toolchain__/determine_latest
$(eval override __toolchain__/VERSION := $(call shell_checked,. ./version.sh; list_bootlin_versions $(arch) | sort_versions | tail -n 1))
endef
$(call determine_version,__toolchain__,$(__toolchain__/DEFAULT_VERSION))
# Update URL with the discovered version
toolchain_url := https://toolchains.bootlin.com/downloads/releases/toolchains/$(arch)/tarballs/$(arch)--musl--stable-$(__toolchain__/VERSION).tar.bz2
# Update paths to be more confortable
dl_dir := $(dl_dir)/__toolchain__/$(__toolchain__/VERSION)
build_dir := $(build_dir)/__toolchain__/$(__toolchain__/VERSION)
state_dir := $(state_dir)/__toolchain__/$(__toolchain__/VERSION)
toolchain_file := __toolchain__-$(arch)-$(__toolchain__/VERSION).tar.bz2
.PHONY: all config
.SHELLFLAGS = -e -c
.ONESHELL:
define download =
mkdir -p '$(dl_dir)'
cd '$(dl_dir)'
curl -L '$(toolchain_url)' -o '$(dl_dir)/$(toolchain_file)'
endef
define prepare =
mkdir -p '$(build_dir)'
cd '$(build_dir)'
tar -xf '$(dl_dir)/$(toolchain_file)'
$(call depfile,toolchain,prepare)
endef
#############################################
# Targets
#############################################
all: $(call depends,toolchain,prepare)
$(call depends,toolchain,prepare): $(dl_dir)/$(toolchain_file)
$(prepare)
$(dl_dir)/$(toolchain_file):
$(download)
config:
[ -z '$(__toolchain__/VERSION)' ] && { echo "__toolchain__/VERSION is empty" >&2; exit 1; }
printf 'export %s := %s\n' '__toolchain__/VERSION' \
'$(__toolchain__/VERSION)' >> '$(config_file)'