summaryrefslogtreecommitdiff
path: root/elements/gnu-toolchain/stage2-glibc.bst
blob: e64af939d57850d940e9bc900c937a6b2c7b5e6f (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
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
kind: manual

sources:
- kind: git
  url: upstream:glibc
  track: release/2.25/master
  ref: db0242e3023436757bbc7c488a779e6e3343db04

depends:
- filename: gnu-toolchain/stage1.bst
  type: build
- filename: gnu-toolchain/stage2-fhs-dirs.bst
  type: runtime
- gnu-toolchain/stage2-linux-api-headers.bst

variables:
  prefix: /tools

  glibc-arch-flags: ''
  glibc-ld-so-name: 'autodetect'
  glibc-ld-so-libdir: 'lib'

  (?):
    - arch.startswith("armv7"):
        glibc-arch-flags: --without-fp

    - arch in ["armv8b", "armv8l"]:
        glibc-ld-so-name: ld-linux-aarch64.so.1

    - arch == "ppc64":
        glibc-ld-so-name: ld64.so.1
        glibc-ld-so-libdir: lib64

    - arch == "ppc64le":
        glibc-ld-so-name: ld64.so.2
        glibc-ld-so-libdir: lib64

    - arch == "x86_64":
        glibc-ld-so-name: ld-linux-x86-64.so.2
        glibc-ld-so-libdir: lib64

environment:
  PATH: /tools/bin:/usr/bin:/bin:/usr/sbin:/sbin

config:

  configure-commands:
  - mkdir o

  # Configure flag notes:
  #   1. Avoid installing to PREFIX/lib64 on x86_64.
  #   2. We install ld.so.conf to /etc, not /tools/etc, and we need to ensure
  #      ldconfig looks for it in the right place.
  #   3. Location of linux-api-headers.
  #   4. Normal flags. See glibc.morph.
  #   5. Force configuration values of certain things that can't be detected
  #      in a cross-compile.
  - |
    export CFLAGS="-O2 $CFLAGS"; export CXX=false; \
    cd o && ../configure %{glibc-arch-flags} \
      --build=$(../scripts/config.guess) --host=%{target-stage1} \
      --prefix="%{prefix}" \
      `# [1]` --libdir="%{prefix}/lib" \
      `# [2]` --sysconfdir="/etc" \
      `# [3]` --with-headers="%{prefix}/include" \
      `# [4]` --disable-profile  --enable-kernel=2.6.25 \
      `# [5]` libc_cv_c_cleanup=yes libc_cv_ctors_header=yes \
              libc_cv_forced_unwind=yes libc_cv_ssp=no

  build-commands:
  - cd o && make localtime=UTC

  install-commands:
  - cd o && make install_root="%{install-root}" localtime=UTC install
  - mkdir -p "%{install-root}/etc"
  - mkdir -p "%{install-root}/etc/ld.so.conf.d"
  - |
    cat <<EOF > ld.so.conf
    /lib
    /lib64
    /usr/lib
    /usr/lib64
    /usr/local/lib
    /usr/local/lib64
    include /etc/ld.so.conf.d/*.conf
    EOF
  - install -m 644 -o root -g root ld.so.conf "%{install-root}/etc/ld.so.conf"
  - |
    # Fix up GCC to handle the sysroot containing glibc 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.

    sysroot="$(dirname $(dirname $(pwd)))"
    specs_dir="$(dirname $(%{target-stage1}-gcc --print-libgcc-file-name))"
    target_specs_dir="%{install-root}/${specs_dir#$sysroot}"
    mkdir -p "$target_specs_dir"

    %{target-stage1}-gcc -dumpspecs |
        sed -e "s@[gMS]\?crt[1in].o%s@%:getenv(STAGE2_SYSROOT %{libdir}/&)@g" \
            -e "s@/lib\(64\)\?/ld@%{libdir}/ld@g" \
        > "$target_specs_dir/specs-for-sysroot"

    # NASTY HACK #
    # We create a symlink to the actual specs here, so that later the
    # symlink can be replaced with a dangling link.
    #
    # This is necessary as we need to have gcc use its internal specs,
    # which can differ to the specs generated by `gcc -dumpspecs`.
    #
    # The dangling symlink will not make it onto the final system, just
    # like all other bootstrap only components.
    ln -s specs-for-sysroot "$target_specs_dir/specs"

  - |
    # Install a symlink for the program interpreter (ld.so) so that binaries
    # built in stage 3 before the stage 3 glibc is built can use it.
    #
    # The name of the dynamic loader is hardcoded in GCC during its 'configure'
    # stage, but the file is actually provided by the libc (usually GLIBC). It
    # would be better if we could ask GCC or GLIBC what the expected name of the
    # ld.so is for the given platform rather than hardcoding it again here.
    loader="%{glibc-ld-so-name}"

    if [ "$loader" == "autodetect" ]; then
      loader=$(basename $(ls "%{install-root}%{prefix}"/lib/ld-linux*))
      [ -z $loader ] && loader=$(basename $(ls "%{install-root}%{prefix}"/lib/ld.so*))
      [ -z $loader ] && ( echo "Bug in stage2-glibc ld.so symlinks" ; exit 1 )
    fi

    install -d "%{install-root}/usr/%{glibc-ld-so-libdir}"
    ln -s "/usr/%{glibc-ld-so-libdir}" "%{install-root}/%{glibc-ld-so-libdir}"
    ln -s "%{prefix}/lib/$loader" "%{install-root}/usr/%{glibc-ld-so-libdir}/$loader"

  strip-commands:
  - |
    %{stage2-strip-binaries}