-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
126 lines (99 loc) · 4.16 KB
/
Copy pathMakefile
File metadata and controls
126 lines (99 loc) · 4.16 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
# Installation path, also used when configuring the components.
PREFIX=/usr/local/cross
# Target architecture.
TARGET=i686-elf
# Component versions.
BINUTILS_VER=2.39
GCC_VER=12.2.0
GDB_VER=15.2
# Directories that will contain the extracted contents of each component.
ARCHIVEDIR=archives
BINUTILS_ARCHIVEDIR=$(ARCHIVEDIR)/binutils-$(BINUTILS_VER)
GCC_ARCHIVEDIR=$(ARCHIVEDIR)/gcc-$(GCC_VER)
GDB_ARCHIVEDIR=$(ARCHIVEDIR)/gdb-$(GDB_VER)
# Directories used when building each component.
#
# NOTE: We need to build in a different path because building in the source tree
# is unsupported by GNU.
BUILDDIR=build
BINUTILS_BUILDDIR=$(BUILDDIR)/binutils-$(BINUTILS_VER)
GCC_BUILDDIR=$(BUILDDIR)/gcc-$(GCC_VER)
GDB_BUILDDIR=$(BUILDDIR)/gdb-$(GDB_VER)
# ------------------------------------------------------------------------------
.PHONY: all clean clean-archives clean-builds
all: build
clean: clean-archives clean-builds
clean-archives:
rm -rf $(ARCHIVEDIR)/*
clean-builds:
rm -rf $(BUILDDIR)/*
# ------------------------------------------------------------------------------
.PHONY: dependencies
dependencies: $(ARCHIVEDIR)/binutils-$(BINUTILS_VER) $(ARCHIVEDIR)/gcc-$(GCC_VER) $(ARCHIVEDIR)/gdb-$(GDB_VER)
$(ARCHIVEDIR)/binutils-$(BINUTILS_VER).tar.gz:
@mkdir -p "$(dir $@)"
curl -o $@ "https://ftp.gnu.org/gnu/binutils/binutils-$(BINUTILS_VER).tar.gz"
$(ARCHIVEDIR)/gcc-$(GCC_VER).tar.gz:
@mkdir -p "$(dir $@)"
curl -o $@ "https://ftp.gnu.org/gnu/gcc/gcc-$(GCC_VER)/gcc-$(GCC_VER).tar.gz"
$(ARCHIVEDIR)/gdb-$(GDB_VER).tar.gz:
@mkdir -p "$(dir $@)"
curl -o $@ "https://ftp.gnu.org/gnu/gdb/gdb-$(GDB_VER).tar.gz"
# NOTE: We need to touch the extracted directory so it's timestamp is updated
# and future calls to 'make' can detect that the directory is newer than the
# archive.
$(ARCHIVEDIR)/%: $(ARCHIVEDIR)/%.tar.gz
tar --directory="$(dir $@)" -xf $<
@touch "$@"
# ----------------------------------------------------------------------------------
.PHONY: build build-binutils build-gcc build-gdb
build: build-binutils build-gcc
build-binutils: $(BINUTILS_BUILDDIR)
build-gcc: $(GCC_BUILDDIR)
build-gdb: $(GDB_BUILDDIR)
# TODO: Don't use annoying "&& \", which are needed because we are changing
# directory across multiple commands. We could perhaps use '.ONESHELL'.
$(BINUTILS_BUILDDIR): $(BINUTILS_ARCHIVEDIR)
@mkdir -p "$@"
cd "$@" && \
"$(abspath $<)/configure" --target="$(TARGET)" --prefix="$(PREFIX)" --disable-nls --with-sysroot --disable-werror && \
make
# We modify the $PATH to include binaries from the 'build-binutils' target.
#
# FIXME: The 'build-gcc' target depends on the 'install-binutils' target,
# because we need to add its binaries to the $PATH. We can't specify
# the binutils build directory (BINUTILS_BUILDDIR), since those binaries don't
# have the right names, and they problably wouldn't work with the right name.
$(GCC_BUILDDIR): $(GCC_ARCHIVEDIR)
@mkdir -p "$@"
export PATH="$(PREFIX)/bin:$$PATH" && \
cd "$@" && \
"$(abspath $<)/configure" --target="$(TARGET)" --prefix="$(PREFIX)" --disable-nls --enable-languages=c --without-headers && \
make all-gcc && \
make all-target-libgcc
# NOTE: The GDB 15.2 build has been tested with GCC 15.2 and failed. It seems to
# compile with clang 20.1.8.
$(GDB_BUILDDIR): $(GDB_ARCHIVEDIR)
@mkdir -p "$@"
cd "$<" && \
patch --forward -p1 < "$(CURDIR)/remote-packet-patch.diff" # End of source patching
cd "$@" && \
"$(abspath $<)/configure" --target="$(TARGET)" --prefix="$(PREFIX)" --disable-nls && \
make CC=clang all-gdb
# ----------------------------------------------------------------------------------
# Remember to run as root when needed.
.PHONY: install install-binutils install-gcc install-gdb
install: install-binutils install-gcc
install-binutils: $(BINUTILS_BUILDDIR)
@[ "$$(id -u)" -eq 0 ] || (echo "This target ($@) needs to be run as root." 1>&2 && exit 1)
cd "$<" && \
make install
install-gcc: $(GCC_BUILDDIR)
@[ "$$(id -u)" -eq 0 ] || (echo "This target ($@) needs to be run as root." 1>&2 && exit 1)
cd "$<" && \
make install-gcc && \
make install-target-libgcc
install-gdb: $(GDB_BUILDDIR)
@[ "$$(id -u)" -eq 0 ] || (echo "This target ($@) needs to be run as root." 1>&2 && exit 1)
cd "$<" && \
make install-gdb