forked from richard-vd/musl-cross-make
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
212 lines (161 loc) · 6.58 KB
/
Makefile
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
SOURCES = sources
COMPILER = gcc
GNU_SITE = https://ftpmirror.gnu.org/gnu
GCC_SITE = $(GNU_SITE)/gcc
BINUTILS_SITE = $(GNU_SITE)/binutils
GMP_SITE = $(GNU_SITE)/gmp
MPC_SITE = $(GNU_SITE)/mpc
MPFR_SITE = $(GNU_SITE)/mpfr
ISL_SITE = https://downloads.sourceforge.net/project/libisl/
LLVM_SITE = https://github.com/llvm/llvm-project/releases/download
MUSL_SITE = https://musl.libc.org/releases
MUSL_REPO = git://git.musl-libc.org/musl
LINUX_SITE = https://cdn.kernel.org/pub/linux/kernel
LINUX_HEADERS_SITE = http://ftp.barfooze.de/pub/sabotage/tarballs/
DL_CMD = wget -c -O
SHA256_CMD = sha256sum -c
COWPATCH = $(CURDIR)/cowpatch.sh
HOST = $(if $(NATIVE),$(TARGET))
BUILD_DIR = build-$(COMPILER)/$(if $(HOST),$(HOST),local)/$(TARGET)
OUTPUT = $(CURDIR)/output$(if $(HOST),-$(HOST))
REL_TOP = ../..$(if $(TARGET),/..)
-include config.mak
MUSL_VER ?= 1.2.5
LINUX_VER ?= 4.19.308
ifeq ($(COMPILER),gcc)
CONFIG_SUB_REV ?= 948ae97ca570
BINUTILS_VER ?= 2.42
GCC_VER ?= 13.2.0
GMP_VER ?= 6.3.0
MPC_VER ?= 1.3.1
MPFR_VER ?= 4.2.1
endif
ifeq ($(COMPILER),clang)
LLVM_VER ?= 17.0.6
endif
SRC_DIRS = musl-$(MUSL_VER) \
$(if $(GCC_VER),gcc-$(GCC_VER)) \
$(if $(BINUTILS_VER),binutils-$(BINUTILS_VER)) \
$(if $(GMP_VER),gmp-$(GMP_VER)) \
$(if $(MPC_VER),mpc-$(MPC_VER)) \
$(if $(MPFR_VER),mpfr-$(MPFR_VER)) \
$(if $(ISL_VER),isl-$(ISL_VER)) \
$(if $(LINUX_VER),linux-$(LINUX_VER)) \
$(if $(LLVM_VER),llvm-project-$(LLVM_VER).src)
all:
clean:
rm -rf gcc-* binutils-* musl-* gmp-* mpc-* mpfr-* isl-* build build-* linux-* llvm-project-*
distclean: clean
rm -rf sources
# Rules for downloading and verifying sources. Treat an external SOURCES path as
# immutable and do not try to download anything into it.
ifeq ($(SOURCES),sources)
$(patsubst hashes/%.sha256,$(SOURCES)/%,$(wildcard hashes/gmp*)): SITE = $(GMP_SITE)
$(patsubst hashes/%.sha256,$(SOURCES)/%,$(wildcard hashes/mpc*)): SITE = $(MPC_SITE)
$(patsubst hashes/%.sha256,$(SOURCES)/%,$(wildcard hashes/mpfr*)): SITE = $(MPFR_SITE)
$(patsubst hashes/%.sha256,$(SOURCES)/%,$(wildcard hashes/isl*)): SITE = $(ISL_SITE)
$(patsubst hashes/%.sha256,$(SOURCES)/%,$(wildcard hashes/binutils*)): SITE = $(BINUTILS_SITE)
$(patsubst hashes/%.sha256,$(SOURCES)/%,$(wildcard hashes/gcc*)): SITE = $(GCC_SITE)/$(basename $(basename $(notdir $@)))
$(patsubst hashes/%.sha256,$(SOURCES)/%,$(wildcard hashes/musl*)): SITE = $(MUSL_SITE)
$(patsubst hashes/%.sha256,$(SOURCES)/%,$(wildcard hashes/linux-6*)): SITE = $(LINUX_SITE)/v6.x
$(patsubst hashes/%.sha256,$(SOURCES)/%,$(wildcard hashes/linux-5*)): SITE = $(LINUX_SITE)/v5.x
$(patsubst hashes/%.sha256,$(SOURCES)/%,$(wildcard hashes/linux-4*)): SITE = $(LINUX_SITE)/v4.x
$(patsubst hashes/%.sha256,$(SOURCES)/%,$(wildcard hashes/linux-3*)): SITE = $(LINUX_SITE)/v3.x
$(patsubst hashes/%.sha256,$(SOURCES)/%,$(wildcard hashes/linux-2.6*)): SITE = $(LINUX_SITE)/v2.6
$(patsubst hashes/%.sha256,$(SOURCES)/%,$(wildcard hashes/linux-headers-*)): SITE = $(LINUX_HEADERS_SITE)
$(patsubst hashes/%.sha256,$(SOURCES)/%,$(wildcard hashes/llvm-project-*)): SITE = $(LLVM_SITE)/llvmorg-$(patsubst llvm-project-%.src,%,$(basename $(basename $(notdir $@))))
$(SOURCES):
mkdir -p $@
$(SOURCES)/config.sub: | $(SOURCES)
mkdir -p [email protected]
cd [email protected] && $(DL_CMD) $(notdir $@) "http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=$(CONFIG_SUB_REV)"
cd [email protected] && touch $(notdir $@)
cd [email protected] && $(SHA256_CMD) $(CURDIR)/hashes/$(notdir $@).$(CONFIG_SUB_REV).sha256
mv [email protected]/$(notdir $@) $@
rm -rf [email protected]
$(SOURCES)/%: hashes/%.sha256 | $(SOURCES)
mkdir -p [email protected]
cd [email protected] && $(DL_CMD) $(notdir $@) $(SITE)/$(notdir $@)
cd [email protected] && touch $(notdir $@)
cd [email protected] && $(SHA256_CMD) $(CURDIR)/hashes/$(notdir $@).sha256
mv [email protected]/$(notdir $@) $@
rm -rf [email protected]
endif
# Rules for extracting and patching sources, or checking them out from git.
musl-git-%:
rm -rf [email protected]
git clone -b $(patsubst musl-git-%,%,$@) $(MUSL_REPO) [email protected]
cd [email protected] && git fsck
mv [email protected] $@
%.orig: $(SOURCES)/%.tar.gz
case "$@" in */*) exit 1 ;; esac
rm -rf [email protected]
mkdir [email protected]
( cd [email protected] && tar zxf - ) < $<
rm -rf $@
touch [email protected]/$(patsubst %.orig,%,$@)
mv [email protected]/$(patsubst %.orig,%,$@) $@
rm -rf [email protected]
%.orig: $(SOURCES)/%.tar.bz2
case "$@" in */*) exit 1 ;; esac
rm -rf [email protected]
mkdir [email protected]
( cd [email protected] && tar jxf - ) < $<
rm -rf $@
touch [email protected]/$(patsubst %.orig,%,$@)
mv [email protected]/$(patsubst %.orig,%,$@) $@
rm -rf [email protected]
%.orig: $(SOURCES)/%.tar.xz
case "$@" in */*) exit 1 ;; esac
rm -rf [email protected]
mkdir [email protected]
( cd [email protected] && tar Jxf - ) < $<
rm -rf $@
touch [email protected]/$(patsubst %.orig,%,$@)
mv [email protected]/$(patsubst %.orig,%,$@) $@
rm -rf [email protected]
%: %.orig | $(if $(CONFIG_SUB_REV),$(SOURCES)/config.sub)
case "$@" in */*) exit 1 ;; esac
rm -rf [email protected]
mkdir [email protected]
( cd [email protected] && $(COWPATCH) -I ../$< )
test ! -d patches/$@ || cat patches/$@/* | ( cd [email protected] && $(COWPATCH) -p1 )
ifneq ($(CONFIG_SUB_REV),)
if test -f $</configfsf.sub ; then cs=configfsf.sub ; elif test -f $</config.sub ; then cs=config.sub ; else exit 0 ; fi ; rm -f [email protected]/$$cs && cp -f $(SOURCES)/config.sub [email protected]/$$cs && chmod +x [email protected]/$$cs
endif
rm -rf $@
mv [email protected] $@
# Add deps for all patched source dirs on their patchsets
$(foreach dir,$(notdir $(basename $(basename $(basename $(wildcard hashes/*))))),$(eval $(dir): $$(wildcard patches/$(dir) patches/$(dir)/*)))
extract_all: | $(SRC_DIRS)
# Rules for building.
ifeq ($(COMPILER)$(TARGET),gcc)
all:
@echo TARGET must be set for gcc build via config.mak or command line.
@exit 1
else
$(BUILD_DIR):
mkdir -p $@
$(BUILD_DIR)/Makefile: | $(BUILD_DIR)
ln -sf $(REL_TOP)/litecross/Makefile.$(COMPILER) $@
$(BUILD_DIR)/config.mak: | $(BUILD_DIR)
printf >$@ '%s\n' \
$(if $(TARGET),"TARGET = $(TARGET)") \
"HOST = $(HOST)" \
"MUSL_SRCDIR = $(REL_TOP)/musl-$(MUSL_VER)" \
$(if $(GCC_VER),"GCC_SRCDIR = $(REL_TOP)/gcc-$(GCC_VER)") \
$(if $(BINUTILS_VER),"BINUTILS_SRCDIR = $(REL_TOP)/binutils-$(BINUTILS_VER)") \
$(if $(GMP_VER),"GMP_SRCDIR = $(REL_TOP)/gmp-$(GMP_VER)") \
$(if $(MPC_VER),"MPC_SRCDIR = $(REL_TOP)/mpc-$(MPC_VER)") \
$(if $(MPFR_VER),"MPFR_SRCDIR = $(REL_TOP)/mpfr-$(MPFR_VER)") \
$(if $(ISL_VER),"ISL_SRCDIR = $(REL_TOP)/isl-$(ISL_VER)") \
$(if $(LINUX_VER),"LINUX_SRCDIR = $(REL_TOP)/linux-$(LINUX_VER)") \
$(if $(LLVM_VER),"LLVM_SRCDIR = $(REL_TOP)/llvm-project-$(LLVM_VER).src") \
$(if $(LLVM_VER),"LLVM_VER = $(LLVM_VER)") \
"-include $(REL_TOP)/config.mak"
all: | $(SRC_DIRS) $(BUILD_DIR) $(BUILD_DIR)/Makefile $(BUILD_DIR)/config.mak
cd $(BUILD_DIR) && $(MAKE) $@
install: | $(SRC_DIRS) $(BUILD_DIR) $(BUILD_DIR)/Makefile $(BUILD_DIR)/config.mak
cd $(BUILD_DIR) && $(MAKE) OUTPUT=$(OUTPUT) $@
endif
.SECONDARY: