-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
212 lines (166 loc) · 6.1 KB
/
Copy pathMakefile
File metadata and controls
212 lines (166 loc) · 6.1 KB
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
# http://preshing.com/20141119/how-to-build-a-gcc-cross-compiler/
ARCH ?= mipsel-linux
PREFIX ?= $(PWD)/$(ARCH)
SYSROOT := $(PREFIX)/$(ARCH)
KERNEL ?= $(PWD)/../linux-new
KERNEL_ARCH ?= mips
GCC_DOWNLOAD ?= https://ftp.gnu.org/gnu/gcc/gcc-11.2.0/gcc-11.2.0.tar.xz
GMP_DOWNLOAD ?= https://gmplib.org/download/gmp/gmp-6.2.1.tar.xz
MPFR_DOWNLOAD ?= https://www.mpfr.org/mpfr-current/mpfr-4.1.0.tar.xz
MPC_DOWNLOAD ?= https://ftp.gnu.org/gnu/mpc/mpc-1.2.1.tar.gz
ISL_DOWNLOAD ?= https://libisl.sourceforge.io/isl-0.24.tar.xz
CLOOG_DOWNLOAD ?= http://www.bastoul.net/cloog/pages/download/cloog-0.18.4.tar.gz
GDB_DOWNLOAD ?= https://ftp.gnu.org/gnu/gdb/gdb-11.2.tar.xz
GLIBC_DOWNLOAD ?= https://ftp.gnu.org/gnu/glibc/glibc-2.35.tar.xz
BINUTILS_DOWNLOAD ?= https://ftp.gnu.org/gnu/binutils/binutils-2.38.tar.xz
GCC_ARCHIVE := $(notdir $(GCC_DOWNLOAD))
GMP_ARCHIVE := $(notdir $(GMP_DOWNLOAD))
MPFR_ARCHIVE := $(notdir $(MPFR_DOWNLOAD))
MPC_ARCHIVE := $(notdir $(MPC_DOWNLOAD))
ISL_ARCHIVE := $(notdir $(ISL_DOWNLOAD))
CLOOG_ARCHIVE := $(notdir $(CLOOG_DOWNLOAD))
GDB_ARCHIVE := $(notdir $(GDB_DOWNLOAD))
GLIBC_ARCHIVE := $(notdir $(GLIBC_DOWNLOAD))
BINUTILS_ARCHIVE := $(notdir $(BINUTILS_DOWNLOAD))
GCC_DIR ?= $(GCC_ARCHIVE:%.tar.xz=%)
GMP_DIR ?= $(GMP_ARCHIVE:%.tar.xz=%)
MPFR_DIR ?= $(MPFR_ARCHIVE:%.tar.xz=%)
MPC_DIR ?= $(MPC_ARCHIVE:%.tar.gz=%)
ISL_DIR ?= $(ISL_ARCHIVE:%.tar.xz=%)
CLOOG_DIR ?= $(CLOOG_ARCHIVE:%.tar.gz=%)
GDB_DIR ?= $(GDB_ARCHIVE:%.tar.xz=%)
GLIBC_DIR ?= $(GLIBC_ARCHIVE:%.tar.xz=%)
BINUTILS_DIR ?= $(BINUTILS_ARCHIVE:%.tar.xz=%)
TARGETS := gcc gdb binutils glibc
TARGETS_ALL := $(ARCH) $(TARGETS) gcc-first glibc-first gmp mpc mpfr isl cloog
.SECONDARY:
.DELETE_ON_ERROR:
.PHONY: all
all: $(TARGETS:%=install-%)
.PHONY: clean
clean: $(TARGETS_ALL:%=clean-%)
# Directories
$(TARGETS_ALL):
mkdir -p $@
%/build:
mkdir -p $@
# Common rules
.PHONY: $(TARGETS:%=build-%)
$(TARGETS:%=build-%): build-%: %/.compile
.PHONY: $(TARGETS:%=install-%)
$(TARGETS:%=install-%): install-%: %/.install
%/.extract:
tar axf "$<" -C $*
@touch $@
%/.configure: %/.extract
%/.compile: %/.configure
cd $*/build; $(MAKE)
@touch $@
%/.install: %/.compile
cd $*/build; $(MAKE) install
@touch $@
clean-%:
rm -rf $*
# Target specific rules
gcc-first/.configure: gcc/.link binutils/.install | gcc-first/build
cd $|; ../../gcc/$(GCC_DIR)/configure --target=$(ARCH) \
--prefix=$(PREFIX) --with-sysroot=$(SYSROOT) \
--enable-languages=c,c++ --disable-threads --disable-multilib \
--with-native-system-header-dir=/include \
--without-headers
@touch $@
gcc-first/.compile: %/.compile: %/.configure
cd $*/build; $(MAKE) all-gcc
@touch $@
gcc-first/.libgcc: %/.libgcc: glibc-first/.install %/.configure
cd $*/build; $(MAKE) all-target-libgcc
@touch $@
gcc-first/.install: %/.install: %/.compile
cd $*/build; $(MAKE) install-gcc
@touch $@
gcc-first/.libgcc-install: %/.libgcc-install: %/.libgcc
cd $*/build; $(MAKE) install-target-libgcc
@touch $@
gcc/.configure: glibc/.install gcc/.link binutils/.install | gcc/build
cd $|; ../$(GCC_DIR)/configure --target=$(ARCH) \
--prefix=$(PREFIX) --with-sysroot=$(SYSROOT) \
--with-build-sysroot=$(SYSROOT) \
--enable-languages=c,c++ --enable-threads --disable-multilib \
--with-native-system-header-dir=/include \
--with-headers
@touch $@
gcc/.link: gcc/.extract gmp/.extract mpfr/.extract mpc/.extract isl/.extract cloog/.extract
ln -sfr gmp/$(GMP_DIR) gcc/$(GCC_DIR)/gmp
ln -sfr mpfr/$(MPFR_DIR) gcc/$(GCC_DIR)/mpfr
ln -sfr mpc/$(MPC_DIR) gcc/$(GCC_DIR)/mpc
ln -sfr isl/$(ISL_DIR) gcc/$(GCC_DIR)/isl
ln -sfr cloog/$(CLOOG_DIR) gcc/$(GCC_DIR)/cloog
@touch $@
gdb/.configure: gdb/.extract gcc/.install | gdb/build
cd $|; ../$(GDB_DIR)/configure --target=$(ARCH) \
--prefix=$(PREFIX) --with-sysroot=$(SYSROOT) --with-python=yes
@touch $@
glibc-first/.configure: glibc/.extract glibc/.headers gcc-first/.install | glibc-first/build
cd $|; PATH="$$PATH:$(PREFIX)/bin" ../../glibc/$(GLIBC_DIR)/configure \
--host=$(ARCH) \
--prefix= \
--with-headers=$(SYSROOT)/include \
--enable-strip --disable-multilib
@touch $@
glibc-first/.compile: %/.compile: %/.configure
cd $*/build; PATH="$$PATH:$(PREFIX)/bin" $(MAKE) csu/subdir_lib
@touch $@
glibc-first/.install: %/.install: %/.compile
cd $*/build; $(MAKE) install-bootstrap-headers=yes install-headers DESTDIR=$(SYSROOT)
cd $*/build; install csu/crt1.o csu/crti.o csu/crtn.o $(SYSROOT)/lib
$(PREFIX)/bin/mipsel-linux-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o $(SYSROOT)/lib/libc.so
touch $(SYSROOT)/include/gnu/stubs.h
@touch $@
glibc/.configure: glibc/.extract glibc/.headers gcc-first/.libgcc-install | glibc/build
cd $|; PATH="$$PATH:$(PREFIX)/bin" ../../glibc/$(GLIBC_DIR)/configure \
--host=$(ARCH) \
--prefix= \
--with-headers=$(SYSROOT)/include \
--enable-strip --disable-multilib
@touch $@
glibc/.compile: %/.compile: %/.configure
cd $*/build; PATH="$$PATH:$(PREFIX)/bin" $(MAKE)
@touch $@
glibc/.install: %/.install: %/.compile
cd $*/build; $(MAKE) install DESTDIR=$(SYSROOT)
@touch $@
glibc/.headers:
cd $(KERNEL); ARCH=$(KERNEL_ARCH) $(MAKE) INSTALL_HDR_PATH=$(SYSROOT) headers_install
@touch $@
binutils/.configure: binutils/.extract | binutils/build
cd $|; ../$(BINUTILS_DIR)/configure --target=$(ARCH) \
--prefix=$(PREFIX) --with-sysroot=$(SYSROOT)
@touch $@
# Archives
gcc/.extract: gcc/$(GCC_ARCHIVE)
%/$(GCC_ARCHIVE): | %
wget -O "$@" "$(GCC_DOWNLOAD)"
gmp/.extract: gmp/$(GMP_ARCHIVE)
%/$(GMP_ARCHIVE): | %
wget -O "$@" "$(GMP_DOWNLOAD)"
mpfr/.extract: mpfr/$(MPFR_ARCHIVE)
%/$(MPFR_ARCHIVE): | %
wget -O "$@" "$(MPFR_DOWNLOAD)" --no-check-certificate
mpc/.extract: mpc/$(MPC_ARCHIVE)
%/$(MPC_ARCHIVE): | %
wget -O "$@" "$(MPC_DOWNLOAD)"
isl/.extract: isl/$(ISL_ARCHIVE)
%/$(ISL_ARCHIVE): | %
wget -O "$@" "$(ISL_DOWNLOAD)"
cloog/.extract: cloog/$(CLOOG_ARCHIVE)
%/$(CLOOG_ARCHIVE): | %
wget -O "$@" "$(CLOOG_DOWNLOAD)"
gdb/.extract: gdb/$(GDB_ARCHIVE)
%/$(GDB_ARCHIVE): | %
wget -O "$@" "$(GDB_DOWNLOAD)"
glibc/.extract: glibc/$(GLIBC_ARCHIVE)
%/$(GLIBC_ARCHIVE): | %
wget -O "$@" "$(GLIBC_DOWNLOAD)"
binutils/.extract: binutils/$(BINUTILS_ARCHIVE)
%/$(BINUTILS_ARCHIVE): | %
wget -O "$@" "$(BINUTILS_DOWNLOAD)"