summaryrefslogtreecommitdiff
path: root/stage2-eglibc-fix-specs
blob: 82e292036de32c34582ab04dfe84fcd8fbaddaff (plain)
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
#!/bin/sh

# Fix up GCC to handle the sysroot containing eglibc being in a different
# location for each chunk build.
#
# For headers, it's enough to pass -B in the CPPFLAGS. This would work for
# the startup files (crt*.o) as well, except where libtool is involved (in
# which case it strips -B out of your LDFLAGS before calling GCC). We get
# around this by making GCC locate them relative to the environment variable
# STAGE2_SYSROOT, which we can then set along with CPPFLAGS in each stage 2
# chunk build.
#
# We also force the use of the program loader at PREFIX/lib/ld.so instead
# of its usual home in /lib or /lib64, which is necessary for the output of
# stage 2 to work as a chroot when building stage 3.

set -eu

specs_dir="$(dirname $($TARGET_STAGE1-gcc --print-libgcc-file-name))"
mkdir -p "$specs_dir"

$TARGET_STAGE1-gcc -dumpspecs | \
    sed -e "s@[gMS]\?crt[1in].o%s@%:getenv(STAGE2_SYSROOT $PREFIX/lib/&)@g" \
        -e "s@/lib\(64\)\?/ld@$PREFIX/lib/ld@g" \
    > "$specs_dir/specs"