<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
  "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
  <!ENTITY % general-entities SYSTEM "../general.ent">
  %general-entities;
]>

<sect1 arch="ml_32,ml_x32,ml_all" id="ch-system-glibc-32" role="wrap">
  <?dbhtml filename="glibc-32.html"?>

  <sect1info condition="script">
    <productname>glibc-32</productname>
    <productnumber>&glibc-version;</productnumber>
    <address>&glibc-url;</address>
  </sect1info>

  <title>Glibc-&glibc-version; - 32-bit</title>

  <indexterm zone="ch-system-glibc-32">
    <primary sortas="a-Glibc-32">Glibc-32</primary>
  </indexterm>

  <sect2 role="installation">
    <title>Preparation to install of ML-Glibc</title>

<screen><userinput remap="pre">patch -Np1 -i ../&glibc-fhs-patch;</userinput></screen>

    <para>Remove a file that may be left over from a previous build attempt:</para>

<screen><userinput remap="pre">mv /usr/include/limits.h{,.backup} </userinput></screen>

  </sect2>

  <!-- ~~~~~~~~~~~~~~~~~~~~ ABI 32 ~~~~~~~~~~~~~~~~~~~~ -->
  
  <sect2 arch="ml_32,ml_all" role="installation">
    <title>Installation of Glibc - 32-bit</title>

    <para>The Glibc documentation recommends building Glibc 
    in a dedicated build directory:</para>

<screen><userinput remap="pre">mkdir -v build
cd       build</userinput></screen>

    <para>Prepare Glibc for compilation:</para>

<screen><userinput remap="configure">CC="gcc -m32 -ffile-prefix-map=/tools=/usr" \
CXX="g++ -m32 -ffile-prefix-map=/tools=/usr" \
../configure --prefix=/usr                          \
             --disable-werror                       \
             --enable-kernel=&min-kernel;                    \
             --enable-stack-protector=strong        \
             --enable-multi-arch                    \
             --libdir=/usr/lib32                    \
             --libexecdir=/usr/lib32                \
             --with-headers=/usr/include            \
             libc_cv_slibdir=/usr/lib32             \
             i686-pc-linux-gnu</userinput></screen>

    <para>Compile the package:</para>

<screen><userinput remap="make">make</userinput></screen>

    <para>Install the package:</para>

<screen><userinput remap="install">sed '/test-installation/s@$(PERL)@echo not running@' -i ../Makefile
make install_root=$PWD/DESTDIR install
mv -v DESTDIR/usr/lib32/* /usr/lib32/
install -vm644 DESTDIR/usr/include/gnu/{lib-names,stubs}-32.h \
               /usr/include/gnu/
ln -svf ../usr/lib32/ld-linux.so.2 /lib/ld-linux.so.2
ln -svf ../usr/lib32/ld-linux.so.2 /lib/ld-lsb.so.3
ln -svf ../lib/locale /usr/lib32/locale</userinput></screen>

    <para>Configure the linker cache configuration:</para>

<screen><userinput>echo "/usr/lib32" > /etc/ld.so.conf.d/lib32.conf
ldconfig</userinput></screen>

    <para>Do cleanup:</para>

<screen><userinput>cd ..
rm -rf build</userinput></screen>

  </sect2>

  <!-- ~~~~~~~~~~~~~~~~~~~~ ABI x32 ~~~~~~~~~~~~~~~~~~~~ -->

<!--
In case the compilation ends with

...
if test -r /autolfs/sources/glibc-2.29/build/DESTDIR/usr/include/gnu/stubs-x32.h && cmp -s /autolfs/sources/glibc-2.29/build/stubs.h /autolfs/sources/glibc-2.29/build/DESTDIR/usr/include/gnu/stubs-x32.h; \
then echo 'stubs.h unchanged'; \
else /usr/bin/install -c -m 644 /autolfs/sources/glibc-2.29/build/stubs.h /autolfs/sources/glibc-2.29/build/DESTDIR/usr/include/gnu/stubs-x32.h; fi
rm -f /autolfs/sources/glibc-2.29/build/stubs.h
/autolfs/sources/glibc-2.29/build/elf/sln /autolfs/sources/glibc-2.29/build/elf/symlink.list
/autolfs/sources/glibc-2.29/build/elf/sln: /autolfs/sources/glibc-2.29/build/elf/sln: cannot execute binary file
make[1]: *** [Makefile:106: install-symbolic-link] Error 126
make[1]: Leaving directory '/autolfs/sources/glibc-2.29'
make: *** [Makefile:12: install] Error 2

it is a good sign that the actually running kernel isn't ML-enabled.
ArchLinux's kernels are configured like

CONFIG_IA32_EMULATION=y
# CONFIG_IA32_AOUT is not set
# CONFIG_X86_X32 is not set

It isn't x32-enabled ==> Error when building x32 stuff
-->
  
  <sect2 arch="ml_x32,ml_all" role="installation">
    <title>Glibc - x32-bit</title>

    <para>The Glibc documentation recommends building Glibc 
    in a dedicated build directory:</para>

<screen><userinput remap="pre">mkdir -v build
cd       build</userinput></screen>

      <para>Prepare Glibc for compilation:</para>

<screen><userinput remap="configure">CC="gcc -mx32 -ffile-prefix-map=/tools=/usr" \
CXX="g++ -mx32 -ffile-prefix-map=/tools=/usr" \
../configure --prefix=/usr                          \
             --disable-werror                       \
             --enable-kernel=&min-kernel;                    \
             --enable-stack-protector=strong        \
             --enable-multi-arch                    \
             --libdir=/usr/libx32                   \
             --with-headers=/usr/include            \
             libc_cv_slibdir=/usr/libx32            \
             x86_64-pc-linux-gnux32</userinput></screen>

    <para>Compile the package:</para>

<screen><userinput remap="make">make</userinput></screen>

    <para>Install the package:</para>

<screen><userinput remap="install">sed '/test-installation/s@$(PERL)@echo not running@' -i ../Makefile
make install_root=$PWD/DESTDIR install
mv -v DESTDIR/usr/libx32/* /usr/libx32/
install -vm644 DESTDIR/usr/include/gnu/lib-names-x32.h /usr/include/gnu/
[ -e DESTDIR/usr/include/gnu/stubs-x32.h ] \
  &amp;&amp; install -vm644 DESTDIR/usr/include/gnu/stubs-x32.h /usr/include/gnu/ \
  || ln -v /usr/include/gnu/stubs-64.h /usr/include/gnu/stubs-x32.h
ln -svf ../usr/libx32/ld-linux-x32.so.2 /lib/ld-linux-x32.so.2
ln -svf ../lib/locale /usr/libx32/locale</userinput></screen>
<!-- For whatever reason the stubs-x32.h doesn't get created. The 'ln' above is
just a "brute force" workaraound by copying the stubs-64.h file. -->

    <para>Configure the linker cache configuration:</para>

<screen><userinput>echo "/usr/libx32" > /etc/ld.so.conf.d/libx32.conf
ldconfig</userinput></screen>

    <para>Do cleanup:</para>

<screen><userinput>cd ..
rm -rf build</userinput></screen>

  </sect2>

  <!-- ~~~~~~~~~~~~~~~~~~~~ Cleanup ~~~~~~~~~~~~~~~~~~~~ -->

  <sect2 role="installation">
    <title>Cleanup</title>

    <para>Restore the file we moved temporarily away:</para>

<screen><userinput remap="pre">mv /usr/include/limits.h{.backup,} </userinput></screen>

  </sect2>
  
</sect1>
