-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.arch
136 lines (124 loc) · 3.14 KB
/
Makefile.arch
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
133
134
135
136
TARGETS=bash-linux-static thumb-linux-static thumb-linux-gnueabi thumb-linux-android \
thumb2-linux-static thumb2-linux-gnueabi thumb2-linux-android \
x86-linux-static x86-linux-gnueabi \
x86_64-linux-static x86_64-linux-gnueabi \
x86-netbsd-static x86-netbsd-dynamic
HOSTS=$(TARGETS)
HOST?=$(MAKE_HOST)
TARGET?=thumb-linux-static
platform_tuple=$($(1)_ARCH)-$($(1)_OS)-$($(1)_ABI)
define platform_vars # (var_prefix)
ifneq (,$$(findstring x86_64,$(2)))
$(1)_ARCH?=x86_64
$(1)_BITS?=64
$(1)_RUNNER?=qemu-x86_64
else ifneq (,$$(findstring x86,$(2)))
$(1)_ARCH?=x86
$(1)_BITS?=32
$(1)_RUNNER?=qemu-i386
else ifneq (,$$(findstring arm,$(2)))
$(1)_ARCH?=arm
$(1)_BITS?=32
$(1)_RUNNER?=qemu-arm
else ifneq (,$$(findstring thumb2,$(2)))
$(1)_ARCH?=thumb2
$(1)_BITS?=32
$(1)_RUNNER?=qemu-arm
else ifneq (,$$(findstring thumb,$(2)))
$(1)_ARCH?=thumb
$(1)_BITS?=32
$(1)_RUNNER?=qemu-arm
else ifneq (,$$(findstring aarch64,$(2)))
$(1)_ARCH?=aarch64
$(1)_BITS?=64
$(1)_RUNNER?=qemu-aarch64
else ifneq (,$$(findstring bash,$(2)))
$(1)_ARCH?=bash
$(1)_BITS?=32
else
$$(error "Bad arch: $(2)")
endif
ifneq (,$$(findstring linux,$(2)))
$(1)_OS?=linux
else ifneq (,$$(findstring windows,$(2)))
$(1)_OS?=windows
else ifneq (,$$(findstring netbsd,$(2)))
$(1)_OS?=netbsd
else ifneq (,$$(findstring dragonfly,$(2)))
$(1)_OS?=netbsd
else ifneq (,$$(findstring freebsd,$(2)))
$(1)_OS?=netbsd
else ifneq (,$$(findstring openbsd,$(2)))
$(1)_OS?=netbsd
else ifneq (,$$(findstring netbsd,$(2)))
$(1)_OS?=netbsd
else
$$(error "Bad OS: $(2)")
endif
ifneq (,$$(findstring gnu,$(2)))
$(1)_ABI?=gnueabi
$(1)_STATIC?=false
else ifneq (,$$(findstring android,$(2)))
$(1)_ABI?=android
$(1)_STATIC?=false
else ifneq (,$$(findstring static,$(2)))
$(1)_ABI?=static
$(1)_STATIC?=true
else ifneq (,$$(findstring dynamic,$(2)))
$(1)_ABI?=dynamic
$(1)_STATIC?=false
else
$$(info "Bad ABI: $(2)")
$(1)_ABI?=static
$(1)_STATIC?=true
endif
endef
$(eval $(call platform_vars,HOST,$(HOST)))
$(eval $(call platform_vars,TARGET,$(TARGET)))
ifeq ($(HOST_ARCH), $(TARGET_ARCH))
TARGET_CC?=$(CC)
TARGET_RUNNER=
else
ifneq (32,$(TARGET_BITS))
TARGET_CFLAGS?=-m32
endif
ifeq ($(TARGET_ARCH), thumb)
TARGET_CC?=arm-$(TARGET_OS)-$(TARGET_ABI)
TARGET_CFLAGS+=-Mthumb
else
ifeq ($(TARGET_ARCH), thumb2)
TARGET_CC?=arm-$(TARGET_OS)-$(TARGET_ABI)
TARGET_CFLAGS+=-Mthumb
else
TARGET_CC?=$(TARGET)-gcc
endif
endif
#TARGET_RUNNER?=qemu-$(TARGET_ARCH)
endif
TARGET_VALID=true
ifneq ($(TARGET),$(filter $(TARGET),$(TARGETS)))
TARGET_VALID=false
endif
.PHONY: env targets hosts
hosts:
@echo $(HOSTS)
targets:
@echo $(TARGETS)
define tuple_printer
@echo " tuple: " $(call platform_tuple,$(1))
@echo " arch: " $($(1)_ARCH)
@echo " OS: " $($(1)_OS)
@echo " bits: " $($(1)_BITS)
@echo " static: " $($(1)_STATIC)
endef
env:
@echo " Host: " $(HOST)
$(call tuple_printer,HOST)
@echo
@echo " Target: " $(TARGET)
$(call tuple_printer,TARGET)
@echo
@echo "Make host: " $(MAKE_HOST)
@echo Target CC: $(TARGET_CC) $(TARGET_CFLAGS)
@echo Valid target: $(TARGET_VALID)
@echo Runner: $(TARGET_RUNNER)