uname_hack kernel module required for i486

export CLFS=/mnt/clfs ***

sudo mkdir -p ${CLFS} ***
sudo mount /dev/sdb1 ${CLFS} ***

sudo install -d ${CLFS}/tools
sudo ln -s ${CLFS}/tools / ***

sudo install -d ${CLFS}/cross-tools
sudo ln -s ${CLFS}/cross-tools / ***

sudo install -d ${CLFS}/sources

sudo chown tc:staff ${CLFS}/tools
sudo chown tc:staff ${CLFS}/cross-tools
sudo chown tc:staff ${CLFS}/sources

tce-load -i compiletc bash

cat > ~/.bash_profile << "EOF"
exec env -i HOME=${HOME} TERM=${TERM} PS1='\u:\w\$ ' /usr/local/bin/bash
EOF

cat > ~/.bashrc << "EOF"
set +h
umask 022
CLFS=/mnt/clfs
LC_ALL=POSIX
PATH=/cross-tools/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
export CLFS LC_ALL PATH
EOF

source ~/.bash_profile

unset CFLAGS
unset CXXFLAGS

echo unset CFLAGS >> ~/.bashrc
echo unset CXXFLAGS >> ~/.bashrc

sudo insmod /tmp/uname_hack.ko ***

export CLFS_HOST=$(echo ${MACHTYPE} | sed -e 's/-[^-]*/-cross/')
[echo $CLFS_HOST -> i686-cross-linux-gnu]

export CLFS_TARGET="i486-pc-linux-gnu"

cat >> ~/.bashrc << EOF
export CLFS_HOST="${CLFS_HOST}"
export CLFS_TARGET="${CLFS_TARGET}"
EOF

----------

tce-load -i perl5

cd linux-3.8.3

install -d /tools/include
make mrproper
make ARCH=i386 headers_check
make ARCH=i386 INSTALL_HDR_PATH=dest headers_install
cp -r dest/include/* /tools/include

cd file-5.13

./configure --prefix=/cross-tools --disable-static
make
make install

cd m4-1.4.16

./configure --prefix=/cross-tools
make
make install

cd ncurses-5.9

patch -Np1 -i ../ncurses-5.9-bash_fix-1.patch

./configure --prefix=/cross-tools --without-debug --without-shared
make -C include
make -C progs tic
install -m755 progs/tic /cross-tools/bin

cd gmp-5.1.1

CPPFLAGS=-fexceptions ./configure --prefix=/cross-tools --enable-cxx --disable-static
make
make install

cd mpfr-3.1.1

LDFLAGS="-Wl,-rpath,/cross-tools/lib" ./configure --prefix=/cross-tools --enable-shared --disable-static --with-gmp=/cross-tools
make
make install

cd mpc-1.0.1

LDFLAGS="-Wl,-rpath,/cross-tools/lib" ./configure --prefix=/cross-tools --disable-static --with-gmp=/cross-tools --with-mpfr=/cross-tools
make
make install

cd ppl-1.1pre7

CPPFLAGS="-I/cross-tools/include" LDFLAGS="-Wl,-rpath,/cross-tools/lib" ./configure --prefix=/cross-tools --enable-shared --disable-static --enable-interfaces="c,cxx" --disable-optimization --with-gmp=/cross-tools
make
make install

cd cloog-0.18.0

cp configure configure.orig
sed -e "/LD_LIBRARY_PATH=/d" configure.orig > configure

LDFLAGS="-Wl,-rpath,/cross-tools/lib" ./configure --prefix=/cross-tools --enable-shared --disable-static --with-gmp-prefix=/cross-tools
make
make install

cd binutils-2.23.1

mkdir ../binutils-build
cd ../binutils-build

AR=ar AS=as ../binutils-2.23.1/configure --prefix=/cross-tools --host=${CLFS_HOST} --target=${CLFS_TARGET} --with-sysroot=${CLFS} --with-lib-path=/tools/lib --disable-nls --enable-shared --disable-static --disable-multilib

make configure-host
make
make install
 
cp ../binutils-2.23.1/include/libiberty.h /tools/include

cd gcc-4.7.2

for file in $(find gcc/config -name linux64.h -o -name linux.h -o -name sysv4.h)
do
  cp -u $file $file.orig
  sed -e 's@/lib\(64\)\?\(32\)\?/ld@/tools&@g' -e 's@/usr@/tools@g' $file.orig > $file
  echo '
#undef STANDARD_STARTFILE_PREFIX_1
#undef STANDARD_STARTFILE_PREFIX_2
#define STANDARD_STARTFILE_PREFIX_1 "/tools/lib/"
#define STANDARD_STARTFILE_PREFIX_2 ""' >> $file
  touch $file.orig
done

sed -i '/k prot/agcc_cv_libc_provides_ssp=yes' gcc/configure

sed -i 's/BUILD_INFO=info/BUILD_INFO=/' gcc/configure
 
cp gcc/Makefile.in gcc/Makefile.in.orig
sed -e "s@\(^CROSS_SYSTEM_HEADER_DIR =\).*@\1 /tools/include@g" gcc/Makefile.in.orig > gcc/Makefile.in

touch /tools/include/limits.h

mkdir ../gcc-build
cd ../gcc-build

AR=ar LDFLAGS="-Wl,-rpath,/cross-tools/lib" ../gcc-4.7.2/configure --prefix=/cross-tools --build=${CLFS_HOST} --host=${CLFS_HOST} --target=${CLFS_TARGET} --with-sysroot=${CLFS} --with-local-prefix=/tools --disable-nls --disable-shared --disable-static --with-mpfr=/cross-tools --with-gmp=/cross-tools --with-ppl=/cross-tools --with-cloog=/cross-tools --without-headers --with-newlib --disable-decimal-float --disable-libgomp --disable-libmudflap --disable-libssp --disable-threads --enable-languages=c --disable-multilib --enable-cloog-backend=isl --with-native-system-header-dir=/tools --disable-cloog-version-check --disable-ppl-version-check

make all-gcc all-target-libgcc
make install-gcc install-target-libgcc

cd glibc-2.17

tce-load -i coreutils

cp Makeconfig Makeconfig.orig
sed -e 's/-lgcc_eh//g' Makeconfig.orig > Makeconfig

mkdir ../glibc-build
cd ../glibc-build

cat > config.cache << "EOF"
libc_cv_forced_unwind=yes
libc_cv_c_cleanup=yes
libc_cv_ctors_header=yes
EOF

BUILD_CC="gcc" CC="${CLFS_TARGET}-gcc" AR="${CLFS_TARGET}-ar" RANLIB="${CLFS_TARGET}-ranlib" CFLAGS="-march=$(cut -d- -f1 <<< $CLFS_TARGET) -mtune=generic -g -O2" ../glibc-2.17/configure --prefix=/tools --host=${CLFS_TARGET} --build=${CLFS_HOST} --disable-profile --enable-add-ons --with-tls --enable-kernel=3.0.21 --with-__thread --with-binutils=/cross-tools/bin --with-headers=/tools/include --cache-file=config.cache

make
make install inst_vardbdir=/tools/var/db
 
cp ../glibc-2.17/sunrpc/rpc/*.h /tools/include/rpc
cp ../glibc-2.17/sunrpc/rpcsvc/*.h /tools/include/rpcsvc
cp ../glibc-2.17/nis/rpcsvc/*.h /tools/include/rpcsvc

cd gcc-4.7.2

cat gcc/limitx.h gcc/glimits.h gcc/limity.h > `dirname $($LFS_TGT-gcc -print-libgcc-file-name)`/include-fixed/limits.h

cat gcc/limitx.h gcc/glimits.h gcc/limity.h > /mnt/clfs/cross-tools/bin/../lib/gcc/i486-pc-linux-gnu/4.7.2/include-fixed/limits.h

for file in $(find gcc/config -name linux64.h -o -name linux.h -o -name sysv4.h)
do
  cp -u $file $file.orig
  sed -e 's@/lib\(64\)\?\(32\)\?/ld@/tools&@g' -e 's@/usr@/tools@g' $file.orig > $file
  echo '
#undef STANDARD_STARTFILE_PREFIX_1
#undef STANDARD_STARTFILE_PREFIX_2
#define STANDARD_STARTFILE_PREFIX_1 "/tools/lib/"
#define STANDARD_STARTFILE_PREFIX_2 ""' >> $file
  touch $file.orig
done

cp gcc/Makefile.in gcc/Makefile.in.orig
sed -e "s@\(^CROSS_SYSTEM_HEADER_DIR =\).*@\1 /tools/include@g" gcc/Makefile.in.orig > gcc/Makefile.in

sed -i 's/BUILD_INFO=info/BUILD_INFO=/' gcc/configure

mkdir ../gcc-build
cd ../gcc-build

AR=ar LDFLAGS="-Wl,-rpath,/cross-tools/lib" ../gcc-4.7.2/configure --prefix=/cross-tools --build=${CLFS_HOST} --target=${CLFS_TARGET} --host=${CLFS_HOST} --with-sysroot=${CLFS} --with-local-prefix=/tools --disable-nls --enable-shared --disable-static --enable-languages=c,c++ --enable-__cxa_atexit --with-mpfr=/cross-tools --with-gmp=/cross-tools --enable-c99 --with-ppl=/cross-tools --with-cloog=/cross-tools --enable-cloog-backend=isl --enable-long-long --enable-threads=posix --disable-multilib  --with-native-system-header-dir=/tools --disable-cloog-version-check --disable-ppl-version-check

make AS_FOR_TARGET="${CLFS_TARGET}-as" LD_FOR_TARGET="${CLFS_TARGET}-ld"
make install

----------

export CC="${CLFS_TARGET}-gcc"
export CXX="${CLFS_TARGET}-g++"
export AR="${CLFS_TARGET}-ar"
export AS="${CLFS_TARGET}-as"
export RANLIB="${CLFS_TARGET}-ranlib"
export LD="${CLFS_TARGET}-ld"
export STRIP="${CLFS_TARGET}-strip"

echo export CC=\""${CC}\"" >> ~/.bashrc
echo export CXX=\""${CXX}\"" >> ~/.bashrc
echo export AR=\""${AR}\"" >> ~/.bashrc
echo export AS=\""${AS}\"" >> ~/.bashrc
echo export RANLIB=\""${RANLIB}\"" >> ~/.bashrc
echo export LD=\""${LD}\"" >> ~/.bashrc
echo export STRIP=\""${STRIP}\"" >> ~/.bashrc

cd gmp-5.1.1

HOST_CC=gcc CPPFLAGS=-fexceptions ./configure --prefix=/tools --build=${CLFS_HOST} --host=${CLFS_TARGET} --enable-cxx
make
make install

cd mpfr-3.1.1

./configure --prefix=/tools --build=${CLFS_HOST} --host=${CLFS_TARGET} --enable-shared --with-gmp=/tools
make
make install

cd mpc-1.0.1

EGREP="grep -E" ./configure --prefix=/tools --build=${CLFS_HOST} --host=${CLFS_TARGET}
make
make install

cd ppl-0.12.1

patch -Np1 -i ../ppl-gmp-5.1.0.patch

./configure --prefix=/tools --build=${CLFS_HOST} --host=${CLFS_TARGET} --enable-interfaces="c,cxx" --enable-shared --disable-optimization --with-gmp-include=/tools/include --with-gmp-lib=/tools/lib
make
make install

cd cloog-0.18.0

cp configure configure.orig
sed -e "/LD_LIBRARY_PATH=/d" configure.orig > configure

./configure --prefix=/tools --build=${CLFS_HOST} --host=${CLFS_TARGET} --with-gmp-prefix=/tools
make

cp /mnt/clfs/sources/cloog-0.18.0/isl/.libs/libisl.so.10.1.1 /mnt/clfs/tools/lib
cd /mnt/clfs/tools/lib
ln -s libisl.so.10.1.1 libisl.so.10
ln -s libisl.so.10.1.1 libisl.so

make install

cd zlib-1.2.7

./configure --prefix=/tools
make
make install

cd binutils-2.23.1

mkdir ../binutils-build
cd ../binutils-build

../binutils-2.23.1/configure --prefix=/tools --build=${CLFS_HOST} --host=${CLFS_TARGET} --target=${CLFS_TARGET} --with-lib-path=/tools/lib --disable-nls --enable-shared --disable-multilib

make configure-host
make
make install

cd gcc-4.7.2

for file in $(find gcc/config -name linux64.h -o -name linux.h -o -name sysv4.h)
do
  cp -u $file $file.orig
  sed -e 's@/lib\(64\)\?\(32\)\?/ld@/tools&@g' -e 's@/usr@/tools@g' $file.orig > $file
  echo '
#undef STANDARD_STARTFILE_PREFIX_1
#undef STANDARD_STARTFILE_PREFIX_2
#define STANDARD_STARTFILE_PREFIX_1 "/tools/lib/"
#define STANDARD_STARTFILE_PREFIX_2 ""' >> $file
  touch $file.orig
done

sed -i '/k prot/agcc_cv_libc_provides_ssp=yes' gcc/configure

cp gcc/Makefile.in gcc/Makefile.in.orig
sed -e 's@\(^NATIVE_SYSTEM_HEADER_DIR =\).*@\1 /tools/include@g' gcc/Makefile.in.orig > gcc/Makefile.in

sed -i 's/BUILD_INFO=info/BUILD_INFO=/' gcc/configure

mkdir ../gcc-build
cd ../gcc-build

../gcc-4.7.2/configure --prefix=/tools --build=${CLFS_HOST} --host=${CLFS_TARGET} --target=${CLFS_TARGET} --with-local-prefix=/tools --enable-long-long --enable-c99 --enable-shared --enable-threads=posix --enable-__cxa_atexit --disable-nls --enable-languages=c,c++ --disable-libstdcxx-pch --disable-multilib --enable-cloog-backend=isl --with-native-system-header-dir=/tools --disable-cloog-version-check

cp Makefile Makefile.orig
sed "/^HOST_\(GMP\|PPL\|CLOOG\)\(LIBS\|INC\)/s:-[IL]/\(lib\|include\)::" Makefile.orig > Makefile

make AS_FOR_TARGET="${AS}" LD_FOR_TARGET="${LD}"
make install

cd ncurses-5.9

patch -Np1 -i ../ncurses-5.9-bash_fix-1.patch

./configure --prefix=/tools --with-shared --build=${CLFS_HOST} --host=${CLFS_TARGET} --without-debug --without-ada --enable-overwrite --with-build-cc=gcc
make
make install

cd bash-4.2

patch -Np1 -i ../bash-4.2-branch_update-6.patch

cat > config.cache << "EOF"
ac_cv_func_mmap_fixed_mapped=yes
ac_cv_func_strcoll_works=yes
ac_cv_func_working_mktime=yes
bash_cv_func_sigsetjmp=present
bash_cv_getcwd_malloc=yes
bash_cv_job_control_missing=present
bash_cv_printf_a_format=yes
bash_cv_sys_named_pipes=present
bash_cv_ulimit_maxfds=yes
bash_cv_under_sys_siglist=yes
bash_cv_unusable_rtsigs=no
gt_cv_int_divbyzero_sigfpe=yes
EOF

./configure --prefix=/tools --build=${CLFS_HOST} --host=${CLFS_TARGET} --without-bash-malloc --cache-file=config.cache
make
make install

ln -s bash /tools/bin/sh

cd bison-2.7

./configure --prefix=/tools --build=${CLFS_HOST} --host=${CLFS_TARGET}
make
make install

cd bzip2-1.0.6

cp Makefile Makefile.orig
sed -e 's@^\(all:.*\) test@\1@g' Makefile.orig > Makefile

make CC="${CC}" AR="${AR}" RANLIB="${RANLIB}"
make PREFIX=/tools install

cd coreutils-8.20

touch man/uname.1 man/hostname.1

cat > config.cache << EOF
fu_cv_sys_stat_statfs2_bsize=yes
gl_cv_func_working_mkstemp=yes
EOF

./configure --prefix=/tools --build=${CLFS_HOST} --host=${CLFS_TARGET} --enable-install-program=hostname --cache-file=config.cache

cp Makefile Makefile.orig
sed '/src_make_prime_list/d' Makefile.orig > Makefile
depbase=`echo src/make-prime-list.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;gcc -std=gnu99  -I. -I./lib  -Ilib -I./lib -Isrc -I./src -fdiagnostics-show-option -funit-at-a-time -g -O2 -MT src/make-prime-list.o -MD -MP -MF $depbase.Tpo -c -o src/make-prime-list.o src/make-prime-list.c
mv -f $depbase.Tpo $depbase.Po
gcc -std=gnu99 -fdiagnostics-show-option -funit-at-a-time -g -O2 -Wl,--as-needed  -o src/make-prime-list src/make-prime-list.o

cp Makefile Makefile.bak
sed -e '/hostname.1/d' Makefile.bak > Makefile

make
make install

cd diffutils-3.2

sed -i -e '/gets is a/d' lib/stdio.in.h

./configure --prefix=/tools --build=${CLFS_HOST} --host=${CLFS_TARGET}
make
make install

cd findutils-4.4.2

echo "gl_cv_func_wcwidth_works=yes" > config.cache
echo "ac_cv_func_fnmatch_gnu=yes" >> config.cache

./configure --prefix=/tools --build=${CLFS_HOST} --host=${CLFS_TARGET} --cache-file=config.cache
make
make install

cd file-5.13

./configure --prefix=/tools --build=${CLFS_HOST} --host=${CLFS_TARGET}
make
make install

cd flex-2.5.37

cat > config.cache << EOF
ac_cv_func_malloc_0_nonnull=yes
ac_cv_func_realloc_0_nonnull=yes
EOF

./configure --prefix=/tools --build=${CLFS_HOST} --host=${CLFS_TARGET} --cache-file=config.cache
make
make install

cd gawk-4.0.2

./configure --prefix=/tools --build=${CLFS_HOST} --host=${CLFS_TARGET}
make
make install

cd gettext-0.18.2.1

cd gettext-tools

echo "gl_cv_func_wcwidth_works=yes" > config.cache

./configure --prefix=/tools --build=${CLFS_HOST} --host=${CLFS_TARGET} --disable-shared --cache-file=config.cache

make -C gnulib-lib
make -C src msgfmt

cp src/msgfmt /tools/bin

cd grep-2.14

cat > config.cache << EOF
ac_cv_func_malloc_0_nonnull=yes
ac_cv_func_realloc_0_nonnull=yes
EOF

./configure --prefix=/tools --build=${CLFS_HOST} --host=${CLFS_TARGET} --disable-perl-regexp --without-included-regex --cache-file=config.cache
make
make install

cd gzip-1.5

./configure --prefix=/tools --build=${CLFS_HOST} --host=${CLFS_TARGET}
make
make install

cd m4-1.4.16

sed -i -e '/gets is a/d' lib/stdio.in.h

cat > config.cache << EOF
gl_cv_func_btowc_eof=yes
gl_cv_func_mbrtowc_incomplete_state=yes
gl_cv_func_mbrtowc_sanitycheck=yes
gl_cv_func_mbrtowc_null_arg=yes
gl_cv_func_mbrtowc_retval=yes
gl_cv_func_mbrtowc_nul_retval=yes
gl_cv_func_wcrtomb_retval=yes
gl_cv_func_wctob_works=yes
EOF

./configure --prefix=/tools --build=${CLFS_HOST} --host=${CLFS_TARGET} --cache-file=config.cache
make
make install

cd make-3.82

./configure --prefix=/tools --build=${CLFS_HOST} --host=${CLFS_TARGET}
make
make install

cd patch-2.7.1

echo "ac_cv_func_strnlen_working=yes" > config.cache

./configure --prefix=/tools --build=${CLFS_HOST} --host=${CLFS_TARGET} --cache-file=config.cache
make
make install

cd sed-4.2.2

./configure --prefix=/tools --build=${CLFS_HOST} --host=${CLFS_TARGET}
make
make install

cd tar-1.26

sed -i -e '/gets is a/d' gnu/stdio.in.h

cat > config.cache << EOF
gl_cv_func_wcwidth_works=yes
gl_cv_func_btowc_eof=yes
ac_cv_func_malloc_0_nonnull=yes
ac_cv_func_realloc_0_nonnull=yes
gl_cv_func_mbrtowc_incomplete_state=yes
gl_cv_func_mbrtowc_nul_retval=yes
gl_cv_func_mbrtowc_null_arg=yes
gl_cv_func_mbrtowc_retval=yes
gl_cv_func_wcrtomb_retval=yes
EOF

./configure --prefix=/tools --build=${CLFS_HOST} --host=${CLFS_TARGET} --cache-file=config.cache
make
make install

cd texinfo-5.0

./configure --prefix=/tools --build=${CLFS_HOST} --host=${CLFS_TARGET}

make -C tools/gnulib/lib
make -C tools
make
make install

cd vim73

patch -Np1 -i ../vim-7.3-branch_update-6.patch

cp src/auto/configure src/auto/configure.orig
sed -i "/using uint32_t/s/as_fn_error/#&/" src/auto/configure

cat > src/auto/config.cache << "EOF"
vim_cv_getcwd_broken=no
vim_cv_memmove_handles_overlap=yes
vim_cv_stat_ignores_slash=no
vim_cv_terminfo=yes
vim_cv_tgent=zero
vim_cv_toupper_broken=no
vim_cv_tty_group=world
ac_cv_sizeof_int=4
ac_cv_sizeof_long=4
ac_cv_sizeof_time_t=4
ac_cv_sizeof_off_t=4
EOF

echo '#define SYS_VIMRC_FILE "/tools/etc/vimrc"' >> src/feature.h

./configure --build=${CLFS_HOST} --host=${CLFS_TARGET} --prefix=/tools --enable-multibyte --enable-gui=no --disable-gtktest --disable-xim --with-features=normal --disable-gpm --without-x --disable-netbeans --with-tlib=ncurses
make
make install

ln -s vim /tools/bin/vi

cat > /tools/etc/vimrc << "EOF"
" Begin /etc/vimrc

set nocompatible
set backspace=2
set ruler
syntax on

" End /etc/vimrc
EOF

cd xz-5.0.4

./configure --prefix=/tools --build=${CLFS_HOST} --host=${CLFS_TARGET}
make
make install

/tools/lib/libc.so.6
GNU C Library (GNU libc) stable release version 2.17, by Roland McGrath et al.
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 4.7.2.
Compiled on a Linux 3.8.2 system on 2013-03-08.
Available extensions:
        crypt add-on version 2.1 by Michael Glad and others
        GNU Libidn by Simon Josefsson
        Native POSIX Threads Library by Ulrich Drepper et al
        BIND-8.2.3-T5B
libc ABIs: UNIQUE IFUNC
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>.

/tools/bin/gcc -v
Using built-in specs.
COLLECT_GCC=/tools/bin/gcc
COLLECT_LTO_WRAPPER=/mnt/clfs/tools/bin/../libexec/gcc/i486-pc-linux-gnu/4.7.2/lto-wrapper
Target: i486-pc-linux-gnu
Configured with: ../gcc-4.7.2/configure --prefix=/tools --build=i686-cross-linux-gnu --host=i486-pc-linux-gnu --target=i486-pc-linux-gnu --with-local-prefix=/tools --enable-long-long --enable-c99 --enable-shared --enable-threads=posix --enable-__cxa_atexit --disable-nls --enable-languages=c,c++ --disable-libstdcxx-pch --disable-multilib --enable-cloog-backend=isl --with-native-system-header-dir=/tools --disable-cloog-version-check
Thread model: posix
gcc version 4.7.2 (GCC)

----------

cd util-linux-2.22.2

echo "scanf_cv_type_modifier=as" > config.cache

./configure --prefix=/tools --build=${CLFS_HOST} --host=${CLFS_TARGET} --disable-makeinstall-chown --config-cache --disable-login --disable-su
make
make install

----------

sudo su
export CLFS=/mnt/clfs

mkdir -p ${CLFS}/dev
mkdir -p ${CLFS}/proc
mkdir -p ${CLFS}/sys

mount -t proc proc ${CLFS}/proc
mount -t sysfs sysfs ${CLFS}/sys

mknod -m 600 ${CLFS}/dev/console c 5 1
mknod -m 666 ${CLFS}/dev/null c 1 3

mount -o bind /dev ${CLFS}/dev

mount -f -t tmpfs tmpfs ${CLFS}/dev/shm
mount -f -t devpts -o gid=4,mode=620 devpts ${CLFS}/dev/pts

cd automake-1.12.3

lib/config.guess -> x86_64-unknown-linux-gnu [so we need uname_hack]

[export CLFS_TARGET="i486-pc-linux-gnu"]

setarch linux32 lib/config.guess -> i686-pc-linux-gnu

[need to do on core64 corepure64]
cd uname_hack
make uname_hack_fake_machine=i486
insmod uname_hack.ko

cd automake-1.12.3
lib/config.guess -> i486-pc-linux-gnu

chroot "${CLFS}" /tools/bin/env -i HOME=/root TERM="${TERM}" PS1='\u:\w\$ ' PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin /tools/bin/bash --login +h

mkdir -p /{bin,boot,dev,{etc/,}opt,home,lib,mnt}
mkdir -p /{proc,media/{floppy,cdrom},run/{,shm},sbin,srv,sys}
mkdir -p /var/{lock,log,mail,spool}
mkdir -p /var/{opt,cache,lib/{misc,locate},local}
install -d -m 0750 /root
install -d -m 1777 {/var,}/tmp
mkdir -p /usr/{,local/}{bin,include,lib,sbin,src}
mkdir -p /usr/{,local/}share/{doc,info,locale,man}
mkdir -p /usr/{,local/}share/{misc,terminfo,zoneinfo}
mkdir -p /usr/{,local/}share/man/man{1..8}
for dir in /usr{,/local}; do
  ln -s share/{man,doc,info} $dir
done

ln -s /tools/bin/{bash,cat,echo,grep,pwd,stty} /bin
ln -s /tools/bin/file /usr/bin
ln -s /tools/lib/libgcc_s.so{,.1} /usr/lib
ln -s /tools/lib/libstd* /usr/lib
ln -s bash /bin/sh
ln -s /run /var/run

cat > /etc/passwd << "EOF"
root:x:0:0:root:/root:/bin/bash
EOF

cat > /etc/group << "EOF"
root:x:0:
tty:x:4:
lp:x:7:lp
nogroup:x:65534:
staff:x:50:
EOF

exec /tools/bin/bash --login +h

touch /var/run/utmp /var/log/{btmp,lastlog,wtmp}
chmod 664 /var/run/utmp /var/log/lastlog
chmod 600 /var/log/btmp

mount -t devpts -o gid=4,mode=620 none /dev/pts
mount -t tmpfs none /dev/shm

----------

cd perl-5.16.2

patch -Np1 -i ../perl-5.16.2-libc-1.patch

sed -i 's@/usr/include@/tools/include@g' ext/Errno/Errno_pm.PL

./configure.gnu --prefix=/tools -Dcc="gcc"
make
make install

ln -sf /tools/bin/perl /usr/bin

cd linux-3.8.3

make mrproper
make headers_check
make INSTALL_HDR_PATH=dest headers_install
find dest/include \( -name .install -o -name ..install.cmd \) -delete
cp -r dest/include/* /usr/include

cd glibc-2.17

sed -i 's/\(&& $name ne\) "db1"/ & \1 "nss_test1"/' scripts/test-installation.pl

LINKER=$(readelf -l /tools/bin/bash | sed -n 's@.*interpret.*/tools\(.*\)]$@\1@p')
sed -i "s|libs -o|libs -L/usr/lib -Wl,-dynamic-linker=${LINKER} -o|" scripts/test-installation.pl
unset LINKER

edit Makeconfig configure -O2 -> -Os

mkdir ../glibc-build
cd ../glibc-build

echo "CFLAGS += -march=i486 -mtune=native -Os -pipe" > configparms

cat > config.cache << "EOF"
libc_cv_ssp=no
EOF

../glibc-2.17/configure --prefix=/usr --disable-profile --enable-kernel=3.0.21 --libexecdir=/usr/lib/glibc --cache-file=config.cache

make

touch /etc/ld.so.conf

make install

cp ../glibc-2.17/sunrpc/rpc/*.h /usr/include/rpc
cp ../glibc-2.17/sunrpc/rpcsvc/*.h /usr/include/rpcsvc
cp ../glibc-2.17/nis/rpcsvc/*.h /usr/include/rpcsvc

make localedata/install-locales

cat > /etc/nsswitch.conf << "EOF"
# Begin /etc/nsswitch.conf

passwd: files
group: files
shadow: files

hosts: files dns
networks: files

protocols: files
services: files
ethers: files
rpc: files

# End /etc/nsswitch.conf
EOF

cat > /etc/ld.so.conf << "EOF"
/usr/local/lib
EOF

gcc -dumpspecs | perl -p -e 's@/tools/lib/ld@/lib/ld@g;' -e 's@\*startfile_prefix_spec:\n@$_/usr/lib/ @g;' > $(dirname $(gcc --print-libgcc-file-name))/specs

[gcc --print-libgcc-file-name -> /tools/lib/gcc/i486-pc-linux-gnu/4.7.2/libgcc.a]

echo 'main(){}' > dummy.c
gcc dummy.c
readelf -l a.out | grep ': /lib' ->       [Requesting program interpreter: /lib/ld-linux.so.2]

rm dummy.c a.out

----------

cd gmp-5.1.1

mv config{fsf,}.guess
mv config{fsf,}.sub

CFLAGS="-march=i486 -mtune=i686 -Os -pipe" CXXFLAGS="-march=i486 -mtune=i686 -Os -pipe" CPPFLAGS=-fexceptions CC="gcc -isystem /usr/include" CXX="g++ -isystem /usr/include" LDFLAGS="-Wl,-rpath-link,/usr/lib:/lib" ./configure --prefix=/usr --enable-cxx
make
make install

cd mpfr-3.1.1

CFLAGS="-march=i486 -mtune=i686 -Os -pipe" CXXFLAGS="-march=i486 -mtune=i686 -Os -pipe" CC="gcc -isystem /usr/include" LDFLAGS="-Wl,-rpath-link,/usr/lib:/lib" ./configure --prefix=/usr --enable-shared --with-gmp=/usr
make
make install

cd mpc-1.0.1

CFLAGS="-march=i486 -mtune=i686 -Os -pipe" CXXFLAGS="-march=i486 -mtune=i686 -Os -pipe" CC="gcc -isystem /usr/include" LDFLAGS="-Wl,-rpath-link,/usr/lib:/lib" EGREP="grep -E" ./configure --prefix=/usr
make
make install

cd ppl-0.12.1

patch -Np1 -i ../ppl-gmp-5.1.0.patch

CFLAGS="-march=i486 -mtune=i686 -Os -pipe" CXXFLAGS="-march=i486 -mtune=i686 -Os -pipe" CPPFLAGS=-fexceptions CC="gcc -isystem /usr/include" CXX="g++ -isystem /usr/include" LDFLAGS="-Wl,-rpath-link,/usr/lib:/lib" ./configure --prefix=/usr --enable-shared --disable-optimization
make
make install

cd cloog-0.18.0

CFLAGS="-march=i486 -mtune=i686 -Os -pipe" CXXFLAGS="-march=i486 -mtune=i686 -Os -pipe" CC="gcc -isystem /usr/include" LDFLAGS="-Wl,-rpath-link,/usr/lib:/lib" ./configure --prefix=/usr --enable-shared
make
make install

cd zlib-1.2.7

CFLAGS="-march=i486 -mtune=i686 -Os -pipe" CXXFLAGS="-march=i486 -mtune=i686 -Os -pipe" CC="gcc -isystem /usr/include" CXX="g++ -isystem /usr/include" LDFLAGS="-Wl,-rpath-link,/usr/lib:/lib" ./configure --prefix=/usr
make
make install

cd binutils-2.23.1

mkdir ../binutils-build
cd ../binutils-build

CFLAGS="-march=i486 -mtune=i686 -Os -pipe" CXXFLAGS="-march=i486 -mtune=i686 -Os -pipe" CC="gcc -Wno-error=maybe-uninitialized -isystem /usr/include" LDFLAGS="-Wl,-rpath-link,/usr/lib:/lib" ../binutils-2.23.1/configure --prefix=/usr --enable-shared

make configure-host
make tooldir=/usr
make tooldir=/usr install

cp ../binutils-2.23.1/include/libiberty.h /usr/include

cd gcc-4.7.2

sed -i 's/install_to_$(INSTALL_DEST) //' libiberty/Makefile.in

sed -i -e /autogen/d -e /check.sh/d fixincludes/Makefile.in

sed -i 's/BUILD_INFO=info/BUILD_INFO=/' gcc/configure

mkdir ../gcc-build
cd ../gcc-build

CFLAGS="-march=i486 -mtune=i686 -Os -pipe" CXXFLAGS="-march=i486 -mtune=i686 -Os -pipe" CC="gcc -isystem /usr/include" CXX="g++ -isystem /usr/include" LDFLAGS="-Wl,-rpath-link,/usr/lib:/lib" ../gcc-4.7.2/configure --prefix=/usr --libexecdir=/usr/lib --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-c99 --enable-long-long --enable-clocale=gnu --enable-languages=c,c++ --disable-multilib --disable-libstdcxx-pch --enable-cloog-backend=isl --with-system-zlib --enable-frame-pointer --disable-bootstrap --disable-cloog-version-check

make
make install

ln -s ../usr/bin/cpp /lib
ln -s gcc /usr/bin/cc

----------

[echo $PATH -> /bin:/usr/bin:/sbin:/usr/sbin:/tools/bin]

export PATH=/usr/local/sbin:/usr/local/bin:$PATH

cd gmp-5.1.1

mv config{fsf,}.guess
mv config{fsf,}.sub

CFLAGS="-march=i486 -mtune=i686 -Os -pipe" CXXFLAGS="-march=i486 -mtune=i686 -Os -pipe" CPPFLAGS=-fexceptions CC="gcc -isystem /usr/include" CXX="g++ -isystem /usr/include" LDFLAGS="-Wl,-rpath-link,/usr/lib:/lib" ./configure --prefix=/usr/local --enable-cxx

[-flto -fuse-linker-plugin .so no different in size]

make
make install

cd mpfr-3.1.1

CFLAGS="-march=i486 -mtune=i686 -Os -pipe" CXXFLAGS="-march=i486 -mtune=i686 -Os -pipe" CC="gcc -isystem /usr/include -flto -fuse-linker-plugin" LDFLAGS="-Wl,-rpath-link,/usr/lib:/lib" ./configure --prefix=/usr/local --enable-shared --with-gmp=/usr/local
make
make install

[-flto -fuse-linker-plugin .so smaller .a larger]

cd mpc-1.0.1

CFLAGS="-march=i486 -mtune=i686 -Os -pipe" CXXFLAGS="-march=i486 -mtune=i686 -Os -pipe" CC="gcc -isystem /usr/include -flto -fuse-linker-plugin" LDFLAGS="-Wl,-rpath-link,/usr/lib:/lib" EGREP="grep -E" ./configure --prefix=/usr/local
make
make install

[-flto -fuse-linker-plugin .so smaller .a larger]

cd ppl-0.12.1

patch -Np1 -i ../ppl-gmp-5.1.0.patch

CFLAGS="-march=i486 -mtune=i686 -Os -pipe" CXXFLAGS="-march=i486 -mtune=i686 -Os -pipe" CPPFLAGS=-fexceptions CC="gcc -isystem /usr/include -flto -fuse-linker-plugin" CXX="g++ -isystem /usr/include -flto -fuse-linker-plugin" LDFLAGS="-Wl,-rpath-link,/usr/lib:/lib" ./configure --prefix=/usr/local --enable-shared --disable-optimization
make
make install

[-flto -fuse-linker-plugin .so smaller .a larger]

cd cloog-0.18.0

CFLAGS="-march=i486 -mtune=i686 -Os -pipe" CXXFLAGS="-march=i486 -mtune=i686 -Os -pipe" CC="gcc -isystem /usr/include -flto -fuse-linker-plugin" LDFLAGS="-Wl,-rpath-link,/usr/lib:/lib" ./configure --prefix=/usr/local --enable-shared
make
make install

[-flto -fuse-linker-plugin .so smaller .a larger]

cd zlib-1.2.7

CFLAGS="-march=i486 -mtune=i686 -Os -pipe" CXXFLAGS="-march=i486 -mtune=i686 -Os -pipe" CC="gcc -isystem /usr/include -flto -fuse-linker-plugin" CXX="g++ -isystem /usr/include -flto -fuse-linker-plugin" LDFLAGS="-Wl,-rpath-link,/usr/lib:/lib" ./configure --prefix=/usr
make
make install

[-flto -fuse-linker-plugin .so smaller .a larger]

cd binutils-2.23.1

mkdir ../binutils-build
cd ../binutils-build

CFLAGS="-march=i486 -mtune=i686 -Os -pipe" CXXFLAGS="-march=i486 -mtune=i686 -Os -pipe" CC="gcc -Wno-error=maybe-uninitialized -isystem /usr/include -flto -fuse-linker-plugin" LDFLAGS="-Wl,-rpath-link,/usr/lib:/lib" ../binutils-2.23.1/configure --prefix=/usr/local --enable-shared

make configure-host
make tooldir=/usr/local
make tooldir=/usr/local install

cp ../binutils-2.23.1/include/libiberty.h /usr/local/include

[-flto -fuse-linker-plugin strip is smaller]

cd gcc-4.7.2

sed -i 's/install_to_$(INSTALL_DEST) //' libiberty/Makefile.in

sed -i -e /autogen/d -e /check.sh/d fixincludes/Makefile.in

sed -i 's/BUILD_INFO=info/BUILD_INFO=/' gcc/configure

sed -i 's/^T_CFLAGS =$/& -fno-omit-frame-pointer/' gcc/Makefile.in

mkdir ../gcc-build
cd ../gcc-build

CFLAGS="-march=i486 -mtune=i686 -Os -pipe" CXXFLAGS="-march=i486 -mtune=i686 -Os -pipe" CC="gcc -isystem /usr/include -flto -fuse-linker-plugin -msse2" CXX="g++ -isystem /usr/include -flto -fuse-linker-plugin -msse2" LDFLAGS="-Wl,-rpath-link,/usr/lib:/lib" ../gcc-4.7.2/configure --prefix=/usr/local --libexecdir=/usr/local/lib --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-c99 --enable-long-long --enable-clocale=gnu --enable-languages=c,c++ --disable-multilib --disable-libstdcxx-pch --enable-cloog-backend=isl --with-system-zlib --enable-frame-pointer --disable-bootstrap --disable-cloog-version-check

make
make install

[-flto -fuse-linker-plugin .so same cc1, etc smaller]

ln -s /usr/local/bin/cpp /usr/local/lib/cpp
ln -s gcc /usr/local/bin/cc

----------

for F in `cat /tc/binutils_usr.tce.list`; do rm "$F"; done
for F in `cat /tc/cloog_usr.tce.list`; do rm "$F"; done
for F in `cat /tc/gmp_usr.tce.list`; do rm "$F"; done
for F in `cat /tc/mpc_usr.tce.list`; do rm "$F"; done
for F in `cat /tc/mpfr_usr.tce.list`; do rm "$F"; done
for F in `cat /tc/ppl_usr.tce.list`; do rm "$F"; done
for F in `cat /tc/gcc_usr_nobaselib.tce.list`; do rm "$F"; done

----------

cd sed-4.2.2

CC="gcc -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe" CXX="g++ -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local

find . -name Makefile -type f -exec sed -i 's/-O2/ /g' {} \;

make
make install

cd ncurses-5.9

patch -Np1 -i ../ncurses-5.9-bash_fix-1.patch

find . -name configure -type f -exec sed -i 's/-O2/ /g' {} \;

CC="gcc -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe" CXX="g++ -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe -fno-exceptions -fno-rtti" ./configure --prefix=/usr --with-shared --without-debug --with-manpage-format=normal --with-default-terminfo-dir=/usr/share/terminfo

make
make install

ln -sf /usr/share/terminfo /usr/local/lib/terminfo

cd pkg-config-0.28

CC="gcc -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe" CXX="g++ -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local --with-pc-path="/usr/local/lib/pkgconfig:/usr/lib/pkgconfig:/usr/local/share/pkgconfig:/usr/share/pkgconfig" --with-internal-glib --disable-host-tool --docdir=/usr/share/doc/pkg-config-0.28

find . -name Makefile -type f -exec sed -i 's/-O2/ /g' {} \;

make
make install

cd util-linux-2.22.2

sed -i -e 's@etc/adjtime@var/lib/hwclock/adjtime@g' $(grep -rl '/etc/adjtime' .)

mkdir -p /var/lib/hwclock

CC="gcc -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe" CXX="g++ -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local --enable-arch --enable-write --without-ncurses --disable-login --disable-su --disable-sulogin

find . -name Makefile -type f -exec sed -i 's/-O2/ /g' {} \;

make
make install

cd e2fsprogs-1.42.7

mkdir build
cd build

CC="gcc -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe" CXX="g++ -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe -fno-exceptions -fno-rtti" ../configure --prefix=/usr/local --enable-elf-shlibs --disable-libblkid --disable-libuuid --disable-fsck --disable-uuidd

find . -name Makefile -type f -exec sed -i 's/-O2/ /g' {} \;

make
make install
make install-libs

cd coreutils-8.21

patch -Np1 -i ../coreutils-8.21-i18n-1.patch

FORCE_UNSAFE_CONFIGURE=1 CC="gcc -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe" CXX="g++ -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local --enable-no-install-program=kill,uptime --enable-install-program=hostname

find . -name Makefile -type f -exec sed -i 's/-O2/ /g' {} \;

make
make install

[delete symlinks after perl in /bin to /tools for coreutils - cat echo pwd stty]

cd m4-1.4.16

sed -i -e '/gets is a/d' lib/stdio.in.h

CC="gcc -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe" CXX="g++ -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local

find . -name Makefile -type f -exec sed -i 's/-O2/ /g' {} \;

make
make install

cd bison-2.7

echo '#define YYENABLE_NLS 1' >> lib/config.h

echo "ac_cv_prog_lex_is_flex=yes" > config.cache

CC="gcc -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe" CXX="g++ -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local --cache-file=config.cache

find . -name Makefile -type f -exec sed -i 's/-O2/ /g' {} \;

make
make install

cd flex-2.5.37

CC="gcc -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe" CXX="g++ -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local

find . -name Makefile -type f -exec sed -i 's/-O2/ /g' {} \;

make
make install

cat > /usr/local/bin/lex << "EOF"
#!/bin/sh
# Begin /usr/local/bin/lex

exec /usr/local/bin/flex -l "$@"

# End /usr/local/bin/lex
EOF
chmod 755 /usr/local/bin/lex

cd perl-5.16.3

sed -i -e '/^BUILD_ZLIB/s/True/False/' -e '/^INCLUDE/s,\./zlib-src,/usr/include,' -e '/^LIB/s,\./zlib-src,/usr/lib,' cpan/Compress-Raw-Zlib/config.in

echo "127.0.0.1 localhost $(hostname)" > /etc/hosts

CFLAGS="-march=i486 -mtune=i686 -Os -pipe" CXXFLAGS="-march=i486 -mtune=i686 -Os -pipe -fno-exceptions -fno-rtti" ./configure.gnu --prefix=/usr/local -Dvendorprefix=/usr/local -Dman1dir=/usr/local/share/man/man1 -Dman3dir=/usr/local/share/man/man3 -Dpager="/usr/local/bin/less -isR" -Dusethreads -Duseshrplib

find . -name Makefile -type f -exec sed -i 's/-O2/-Os/g' {} \;

make
make install

[-flto -fuse-linker-plugin fails]

[delete /usr/bin/perl]
[delete symlinks after perl in /bin to /tools for coreutils - cat echo pwd stty]

cd bash-4.2

patch -Np1 -i ../bash-4.2-fixes-12.patch

CC="gcc -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe" CXX="g++ -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local --without-bash-malloc

find . -name Makefile -type f -exec sed -i 's/-O2/ /g' {} \;

make
make install

rm /bin/bash
ln -s /usr/local/bin/bash /bin/bash
exec /bin/bash --login +h

cd bzip2-1.0.6

sed -i -e 's:ln -s -f $(PREFIX)/bin/:ln -s :' Makefile

edit Makefile
CFLAGS=-Wall -Winline -march=i486 -mtune=i686 -Os -pipe -g $(BIGFILES)
edit Makefile-libbz2_so
CFLAGS=-fpic -fPIC -Wall -Winline -march=i486 -mtune=i686 -Os -pipe -g $(BIGFILES)

make CC="gcc -flto -fuse-linker-plugin" -f Makefile-libbz2_so
make clean
make CC="gcc -flto -fuse-linker-plugin"
make PREFIX=/usr/local install

cp bzip2-shared /usr/local/bin/bzip2
cp -a libbz2.so* /usr/local/lib
ln -s /usr/local/lib/libbz2.so.1.0 /usr/local/lib/libbz2.so

cd diffutils-3.2

sed -i -e '/gets is a/d' lib/stdio.in.h

CC="gcc -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe" CXX="g++ -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local

find . -name Makefile -type f -exec sed -i 's/-O2/ /g' {} \;

sed -i 's@\(^#define DEFAULT_EDITOR_PROGRAM \).*@\1"vi"@' lib/config.h

make
make install

cd file-5.13

CC="gcc -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe" CXX="g++ -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local

make
make install

rm /usr/bin/file
ln -s /usr/local/bin/file /usr/bin/file

cd gawk-4.0.2

CC="gcc -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe" CXX="g++ -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local --libexecdir=/usr/local/lib

find . -name Makefile -type f -exec sed -i 's/-O2/ /g' {} \;

make
make install

cd findutils-4.4.2

CC="gcc -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe" CXX="g++ -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local --libexecdir=/usr/local/lib/locate --localstatedir=/var/lib/locate

find . -name Makefile -type f -exec sed -i 's/-O2/ /g' {} \;

make
make install

cd gettext-0.18.2.1

CC="gcc -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe" CXX="g++ -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local

find . -name Makefile -type f -exec sed -i 's/-O2/ /g' {} \;

make
make install

cd grep-2.14

CC="gcc -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe" CXX="g++ -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local

find . -name Makefile -type f -exec sed -i 's/-O2/ /g' {} \;

make
make install

[delete /bin/grep]

cd gzip-1.5

CC="gcc -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe" CXX="g++ -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local

find . -name Makefile -type f -exec sed -i 's/-O2/ /g' {} \;

make
make install

cd make-3.82

patch -Np1 -i ../make-3.82-upstream_fixes-3.patch

CC="gcc -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe" CXX="g++ -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local

find . -name Makefile -type f -exec sed -i 's/-O2/ /g' {} \;

make
make install

cd xz-5.0.4

CC="gcc -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe" CXX="g++ -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local

find . -name Makefile -type f -exec sed -i 's/-O2/ /g' {} \;

make
make pkgconfigdir=/usr/local/lib/pkgconfig install

cd patch-2.7.1

CC="gcc -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe" CXX="g++ -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local

find . -name Makefile -type f -exec sed -i 's/-O2/ /g' {} \;

make
make install

cd tar-1.26

sed -i -e '/gets is a/d' gnu/stdio.in.h

FORCE_UNSAFE_CONFIGURE=1 CC="gcc -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe" CXX="g++ -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local

find . -name Makefile -type f -exec sed -i 's/-O2/ /g' {} \;

make
make install

texinfo-5.1

CC="gcc -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe" CXX="g++ -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local

find . -name Makefile -type f -exec sed -i 's/-O2/ /g' {} \;

make
make install

cd vim73

patch -Np1 -i ../vim-7.3-branch_update-6.patch

echo '#define SYS_VIMRC_FILE "/usr/local/etc/vimrc"' >> src/feature.h

find . -name configure -type f -exec sed -i 's/-O2/ /g' {} \;

CC="gcc -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe" CXX="g++ -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local --enable-multibyte

make
make install

ln -s vim /usr/local/bin/vi

cat > /usr/local/etc/vimrc << "EOF"
" Begin /usr/local/etc/vimrc

set nocompatible
set backspace=2
set ruler
syntax on
if (&term == "iterm") || (&term == "putty")
  set background=dark
endif

" End /usr/local/etc/vimrc
EOF

----------

cd gcc-4.7.2 [base libs]

sed -i 's/install_to_$(INSTALL_DEST) //' libiberty/Makefile.in

sed -i -e /autogen/d -e /check.sh/d fixincludes/Makefile.in

sed -i 's/BUILD_INFO=info/BUILD_INFO=/' gcc/configure

sed -i 's/^T_CFLAGS =$/& -fno-omit-frame-pointer/' gcc/Makefile.in

mkdir ../gcc-build
cd ../gcc-build

CFLAGS="-march=i486 -mtune=i686 -Os -pipe" CXXFLAGS="-march=i486 -mtune=i686 -Os -pipe" CC="gcc -flto -fuse-linker-plugin -msse2" CXX="g++ -flto -fuse-linker-plugin -msse2" ../gcc-4.7.2/configure --prefix=/usr  --libdir=/usr/lib --libexecdir=/usr/lib --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-c99 --enable-long-long --enable-clocale=gnu --enable-languages=c,c++ --disable-multilib --disable-libstdcxx-pch --enable-cloog-backend=isl --with-system-zlib --enable-frame-pointer --disable-bootstrap

make
make install


for F in `cat gcc_usr_non_base`; do echo "$F"; done
for F in `cat gcc_usr_non_base`; do rm "$F"; done
delete base files in /usr/local
ldconfig

cd e2fsprogs-1.42.7

mkdir build
cd build

CC="gcc -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe" CXX="g++ -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe -fno-exceptions -fno-rtti" ../configure --prefix=/usr --with-root-prefix="" --enable-elf-shlibs --disable-libblkid --disable-libuuid --disable-fsck --disable-uuidd

find . -name Makefile -type f -exec sed -i 's/-O2/ /g' {} \;

make
make install
make install-libs

for F in `cat /tc/e2fsprogs_usr_non_base.tce.list`; do rm "$F"; done
for F in `cat /tc/e2fsprogs_usr_local_remove.tce.list`; do rm "$F"; done
ldconfig

cd util-linux-2.22.2

sed -i 's@etc/adjtime@var/lib/hwclock/adjtime@g' sys-utils/hwclock.c
mkdir -p /var/lib/hwclock

CC="gcc -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe" CXX="g++ -flto -fuse-linker-plugin -march=i486 -mtune=i686 -Os -pipe -fno-exceptions -fno-rtti" ./configure --bindir=/bin --sbindir=/sbin --libdir=/lib --enable-arch --enable-partx --enable-write --disable-wall --without-ncurses --disable-login --disable-su

find . -name Makefile -type f -exec sed -i 's/-O2/ /g' {} \;

make
make install

for F in `cat /tc/util-linux_usr_non_base.tce.list`; do rm "$F"; done
for F in `cat /tc/util-linux_usr_local_remove.tce.list`; do rm "$F"; done
ldconfig

----------

strip

# export CLFS=/mnt/clfs
# chroot ${CLFS} /tools/bin/env -i HOME=/root TERM=${TERM} PS1='\u:\w\$ ' PATH=/bin:/usr/bin:/sbin:/usr/sbin /tools/bin/bash --login

# /tools/bin/strip --strip-

re-enter

# export CLFS=/mnt/clfs
# chroot "${CLFS}" /usr/local/bin/env -i HOME=/root TERM="${TERM}" PS1='\u:\w\$ ' PATH=/usr/local/bin:/usr/local/sbin:/bin:/usr/bin:/sbin:/usr/sbin /usr/local/bin/bash --login +h

