-
Notifications
You must be signed in to change notification settings - Fork 3
/
rustc_targets.mk
132 lines (113 loc) · 4.12 KB
/
rustc_targets.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# Pull target info so we can type the CPU/CPU_SUBTYPE
target_conf=$(subst .,_,$(subst -,_,$(subst /,_,$(1))))
PLATFORM_DIR:=$(TOPDIR)/target/linux/$(BOARD)
SUBTARGET:=$(strip $(foreach subdir,$(patsubst $(PLATFORM_DIR)/%/target.mk,%,$(wildcard $(PLATFORM_DIR)/*/target.mk)),$(if $(CONFIG_TARGET_$(call target_conf,$(BOARD)_$(subdir))),$(subdir))))
PLATFORM_SUBDIR:=$(PLATFORM_DIR)$(if $(SUBTARGET),/$(SUBTARGET))
include $(PLATFORM_DIR)/Makefile
ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
-include $(PLATFORM_SUBDIR)/target.mk
endif
# Rust Environmental Vars
CONFIG_HOST_SUFFIX:=$(shell cut -d"-" -f4 <<<"$(GNU_HOST_NAME)")
RUSTC_HOST_ARCH:=$(HOST_ARCH)-unknown-linux-$(CONFIG_HOST_SUFFIX)
RUSTC_TARGET_ARCH:=$(REAL_GNU_TARGET_NAME)
RUSTC_TARGET_ARCH:=$(subst openwrt,unknown,$(RUSTC_TARGET_ARCH))
CARGO_HOME:=$(STAGING_DIR_HOST)/.cargo
LLVM_DIR:=$(STAGING_DIR_HOST)/llvm-rust
RUSTC_CPU_TYPE=$(CPU_TYPE)
RUSTFLAGS=
$(warning CPU_TYPE is $(RUSTC_CPU_TYPE))
# ARM Logic
ifeq ($(ARCH),arm)
$(warning Entering ARM)
# Split out ARMv7
ifeq ($(CONFIG_arm_v7),y)
$(warning Target is ARMv7)
RUSTC_TARGET_ARCH:=$(subst arm,armv7,$(RUSTC_TARGET_ARCH))
# Set ARMv7 Soft-Float vs Hard-Float Instruction Sets
ifeq ($(CONFIG_HAS_FPU),y)
RUST_FEATURES += +v7 -d32 +thumb2
else
RUST_FEATURES += +v7 +thumb2 +soft-float
endif
endif
# ARMv5
ifeq ($(RUSTC_CPU_TYPE),arm926ej-s)
RUSTC_TARGET_ARCH:=$(subst arm,armv5tej,$(RUSTC_TARGET_ARCH))
RUST_FEATURES += +soft-float +strict-align
endif
# ARMv6 uses arm-openwrt-linux
ifeq ($(RUSTC_CPU_TYPE),arm1176jzf-s)
$(warning Target is ARMv6)
RUST_FEATURES += +v6 +vfp2 -d32
endif
ifeq ($(RUSTC_CPU_TYPE),mpcore)
$(warning Target is mpcore)
RUSTC_TARGET_ARCH:=$(subst arm,armv6k,$(RUSTC_TARGET_ARCH))
RUST_FEATURES += +v6 +soft-float +strict-align
endif
# Set Hard-Float ABI if TARGET has FPU
ifeq ($(CONFIG_HAS_FPU),y)
RUSTC_TARGET_ARCH:=$(RUSTC_TARGET_ARCH:muslgnueabi=muslgnueabihf)
endif
# CPU_SUBTYPE carries instruction flags in OpenWrt
ifneq ($(CPU_SUBTYPE),)
# NEON Support
ifneq ($(findstring neon,$(CPU_SUBTYPE)),)
RUST_FEATURES += +neon
else
RUST_FEATURES += -neon
endif
###
# vfpv prefix is not recognized by LLVM - convert to vfp and remove the
# hyphen. This is important for CPU_SUBTYPE that use hyphenated CPU_SUBTYPE
# like neon-vfpv4 and vfpv3-d16
RUST_FEATURES += +$(lastword $(subst neon,,$(subst vfpv,vfp,$(subst -,,$(CPU_SUBTYPE)))))
endif
###
# If the RUST_FEATURES is empty or a single word, use as is, otherwise
# split it into a Comma-delimited format for use with target-features
ifneq ($(words $(RUST_FEATURES)),1)
RUST_TARGET_FEATURES = $(subst $(space),$(comma),$(RUST_FEATURES))
else
RUST_TARGET_FEATURES = $(RUST_FEATURES)
endif
ifeq ($(RUSTC_CPU_TYPE),fa526)
RUSTC_TARGET_ARCH:=$(subst arm,armv7,$(RUSTC_TARGET_ARCH))
RUSTC_CPU_TYPE := generic
endif
endif
ifneq (,$(findstring muslgnueabihf,$(RUSTC_TARGET_ARCH)))
RUSTC_TARGET_ARCH:=$(subst muslgnueabihf,musleabihf,$(RUSTC_TARGET_ARCH))
endif
ifeq ($(RUSTC_TARGET_ARCH),mips64-unknown-linux-musl)
RUSTC_TARGET_ARCH:=mips64-unknown-linux-muslabi64
endif
ifeq ($(RUSTC_TARGET_ARCH),mips64el-unknown-linux-musl)
RUSTC_TARGET_ARCH:=mips64el-unknown-linux-muslabi64
endif
ifeq ($(RUSTC_TARGET_ARCH),riscv64-unknown-linux-musl)
RUSTC_TARGET_ARCH:=riscv64gc-unknown-linux-musl
endif
$(warning RUSTC_TARGET_ARCH is $(RUSTC_TARGET_ARCH))
# ARM Logic
ifeq ($(ARCH),mips64)
RUSTC_CPU_TYPE := octeon+
endif
# AArch64 Flags
ifeq ($(ARCH),aarch64)
RUSTFLAGS += -C link-arg=-lgcc
endif
NEED_BUILD_STD:=
ifeq ($(RUSTC_TARGET_ARCH),mipsel-unknown-linux-musl)
NEED_BUILD_STD:=-Zbuild-std
else ifeq ($(RUSTC_TARGET_ARCH),riscv64gc-unknown-linux-musl)
NEED_BUILD_STD:=-Zbuild-std
else ifeq ($(RUSTC_TARGET_ARCH),mips-unknown-linux-musl)
NEED_BUILD_STD:=-Zbuild-std
else ifeq ($(RUSTC_TARGET_ARCH),mips64-unknown-linux-muslabi64)
NEED_BUILD_STD:=-Zbuild-std
else ifeq ($(RUSTC_TARGET_ARCH),mips64el-unknown-linux-musl)
NEED_BUILD_STD:=-Zbuild-std
endif
$(warning RUST_TARGET_FEATURES is $(RUST_TARGET_FEATURES))