-
Notifications
You must be signed in to change notification settings - Fork 57
/
binutils.sh
executable file
·59 lines (48 loc) · 1.39 KB
/
binutils.sh
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
#!/bin/sh
BINUTILS_DL="https://ftp.gnu.org/gnu/binutils"
BINUTILS_XZ="binutils-2.38.tar.xz"
BINUTILS_DIR="$(basename $BINUTILS_XZ .tar.xz)"
BINUTILS_URL="$BINUTILS_DL/$BINUTILS_XZ"
ORIG_DIR="$(pwd)"
# Dont continue on error.
set -e
# Help text.
if [ "$1" = '-h' ]; then
echo >&2 "Usage: $0 [clean]"
echo >&2
echo >&2 'Specify "clean" to remove binutils, otherwise it will be downloaded and built.'
exit 1
fi
# Optional cleanup if requested.
if [ "$1" = 'clean' ]; then
rm -fv objcopy objdump ld "$BINUTILS_XZ"
rm -rfv "$BINUTILS_DIR"
exit
fi
# Extract binutils.
if [ ! -d "$BINUTILS_DIR" ]; then
# Download binutils.
if [ ! -f "$BINUTILS_XZ" ]; then
wget "$BINUTILS_URL"
fi
tar xf "$BINUTILS_XZ"
fi
# Compile binutils.
if [ ! -x "$BINUTILS_DIR/binutils/objcopy" ]; then
cd "$BINUTILS_DIR"
./configure --enable-targets=i386-pc-elf32 \
--disable-gas \
--disable-libctf \
--disable-plugins \
--disable-gprof \
--enable-compressed-debug-sections=none
make all-ld -j$(nproc) MAKEINFO=true
fi
# Copy compiled binaries to working directory.
copy() {
test ! -x "$2" && cp -v "$1" "$2"
}
cd "$ORIG_DIR"
copy "$BINUTILS_DIR/binutils/objcopy" objcopy
copy "$BINUTILS_DIR/binutils/objdump" objdump
copy "$BINUTILS_DIR/ld/ld-new" ld