목차

임시 시스템 제작

젠투로 치면 Stage 1에 해당하는 과정. 꽤 복잡하기 때문에 일일이 문서로 작업 과정을 기록하여, 혹여 작업이 중간에 중단된 후 재개되더라도 손쉽게 재추적할 수 있도록 한다. 또한 이전 과정을 반복해야 할 경우를 대비하여 미리 작업 내용은 쉘 스크립트하여 보관한다.

모든 스크립트의 실행 디렉토리는 $LFS/sources 로 간주한다.

64비트 설치라면 /tools/lib에 /tools/lib64 symlink를 걸어둔다.

# mkdir /tools/lib
# ln -s /tools/lib /tools/lib64

lfs 과정중 $LFS 에 생기는 모든 디렉토리에 대해 사용자 'lfs'가 권한을 가지는지에 대해 확인하라.

Binutils Pass 1

binutils.sh
tar xjf binutils-2.23.1.tar.bz2
cd binutils-2.23.1
patch -p1 < ../binutils-2.23.1-testsuite_fix-1.patch 
mkdir ../binutils-build
cd ../binutils-build
../binutils-2.23.1/configure   \
    --prefix=/tools            \
    --with-sysroot=$LFS        \
    --with-lib-path=/tools/lib \
    --target=$LFS_TGT          \
    --disable-nls              \
    --disable-werror
make
make install
cd ..
rm -fr binutils-build
rm -fr binutils-2.23.1

GCC-4.7.2 - Pass 1

gcc-4.7.2-pass1.sh
tar xjf gcc-4.7.2.tar.bz2 
cd gcc-4.7.2
tar -Jxf ../mpfr-3.1.1.tar.xz
tar -Jxf ../gmp-5.1.1.tar.xz   
tar -zxf ../mpc-1.0.1.tar.gz
mv -v mpfr-3.1.1 mpfr
mv -v gmp-5.1.1 gmp
mv -v mpc-1.0.1 mpc
 
for file in \
 $(find gcc/config -name linux64.h -o -name linux.h -o -name sysv4.h)
do
  cp -uv $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
 
mkdir -v ../gcc-build
cd ../gcc-build
 
../gcc-4.7.2/configure         \
    --target=$LFS_TGT          \
    --prefix=/tools            \
    --with-sysroot=$LFS        \
    --with-newlib              \
    --without-headers          \
    --with-local-prefix=/tools \
    --with-native-system-header-dir=/tools/include \
    --disable-nls              \
    --disable-shared           \
    --disable-multilib         \
    --disable-decimal-float    \
    --disable-threads          \
    --disable-libmudflap       \
    --disable-libssp           \
    --disable-libgomp          \
    --disable-libquadmath      \
    --enable-languages=c       \
    --with-mpfr-include=$(pwd)/../gcc-4.7.2/mpfr/src \
    --with-mpfr-lib=$(pwd)/mpfr/src/.libs
make
make install
pushd $(dirname $(find $LFS/tools -type f -name 'libgcc.a'))
ln -sv libgcc.a `$LFS_TGT-gcc -print-libgcc-file-name | sed 's/libgcc/&_eh/'`
popd
cd ..
rm -fr gcc-4.7.2 gcc-build

Linux-3.8.1 API Headers

linux-3.8.1.sh
tar -Jxf linux-3.8.1.tar.xz 
cd linux-3.8.1
make mrproper
make headers_check
make INSTALL_HDR_PATH=dest headers_install
cp -rv dest/include/* /tools/include
cd ..
rm -fr linux-3.8.1

Glibc-2.17

glibc-2.17.sh
tar -Jxf glibc-2.17.tar.xz
cd glibc-2.17
if [ ! -r /usr/include/rpc/types.h ]; then
  su -c 'mkdir -p /usr/include/rpc'
  su -c 'cp -v sunrpc/rpc/*.h /usr/include/rpc'
fi
mkdir ../glibc-build
cd ../glibc-build
../glibc-2.17/configure                             \
      --prefix=/tools                                 \
      --host=$LFS_TGT                                 \
      --build=$(../glibc-2.17/scripts/config.guess) \
      --disable-profile                               \
      --enable-kernel=2.6.25                          \
      --with-headers=/tools/include                   \
      libc_cv_forced_unwind=yes                       \
      libc_cv_ctors_header=yes                        \
      libc_cv_c_cleanup=yes
make
make install
echo 'main(){}' > dummy.c
$LFS_TGT-gcc dummy.c
readelf -l a.out | grep ': /tools' # carefully check the output of this command! /tools/lib, or /tools/lib64 for 64-bit machines appears as the prefix of the dynamic linker
rm -v dummy.c a.out
cd ..
rm -fr glibc-2.17 glibc-build

Binutils-2.23.1 - Pass 2

binutils-2.23.1-pass2.sh
tar -xjf binutils-2.23.1.tar.bz2
mkdir binutils-build
cd binutils-build
CC=$LFS_TGT-gcc            \
AR=$LFS_TGT-ar             \
RANLIB=$LFS_TGT-ranlib     \
../binutils-2.23.1/configure \
    --prefix=/tools        \
    --disable-nls          \
    --with-lib-path=/tools/lib
make
make install
make -C ld clean
make -C ld LIB_PATH=/usr/lib:/lib
cp -v ld/ld-new /tools/bin
cd ..
rm -fr binutils-build binutils-2.23.1

GCC-4.7.2 - Pass 2

gcc-4.7.2-pass2.sh
tar xjf gcc-4.7.2.tar.bz2 
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
cp -v gcc/Makefile.in{,.tmp}
sed 's/^T_CFLAGS =$/& -fomit-frame-pointer/' gcc/Makefile.in.tmp \
  > gcc/Makefile.in
for file in \
 $(find gcc/config -name linux64.h -o -name linux.h -o -name sysv4.h)
do
  cp -uv $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
tar -Jxf ../mpfr-3.1.1.tar.xz
mv -v mpfr-3.1.1 mpfr
tar -Jxf ../gmp-5.1.1.tar.xz
mv -v gmp-5.1.1 gmp
tar -zxf ../mpc-1.0.1.tar.gz
mv -v mpc-1.0.1 mpc
sed -i 's/BUILD_INFO=info/BUILD_INFO=/' gcc/configure
mkdir -v ../gcc-build
cd ../gcc-build
CC=$LFS_TGT-gcc \
AR=$LFS_TGT-ar                  \
RANLIB=$LFS_TGT-ranlib          \
../gcc-4.7.2/configure          \
    --prefix=/tools             \
    --with-local-prefix=/tools  \
    --with-native-system-header-dir=/tools/include \
    --enable-clocale=gnu        \
    --enable-shared             \
    --enable-threads=posix      \
    --enable-__cxa_atexit       \
    --enable-languages=c,c++    \
    --disable-libstdcxx-pch     \
    --disable-multilib          \
    --disable-bootstrap         \
    --disable-libgomp           \
    --with-mpfr-include=$(pwd)/../gcc-4.7.2/mpfr/src \
    --with-mpfr-lib=$(pwd)/mpfr/src/.libs
make
make install
ln -sv gcc /tools/bin/cc
echo 'main(){}' > dummy.c
cc dummy.c
readelf -l a.out | grep ': /tools' # [Requesting program interpreter: /tools/lib/ld-linux.so.2]
rm -v dummy.c a.out
cd ..
rm -fr gcc-4.7.2 gcc-build

Tcl-8.6.0

tcl-8.6.0.sh
tar -xzf tcl8.6.0-src.tar.gz 
cd tcl8.6.0/unix
./configure --prefix=/tools
make
TZ=UTC make test
make install
chmod -v u+w /tools/lib/libtcl8.6.so
make install-private-headers
ln -sv tclsh8.6 /tools/bin/tclsh
cd ../../
rm -fr tcl8.6.0

Expect-5.45

expect-5.45.sh
tar -xzf expect5.45.tar.gz
cd expect5.45
cp -v configure{,.orig}
sed 's:/usr/local/bin:/bin:' configure.orig > configure
./configure --prefix=/tools --with-tcl=/tools/lib \
  --with-tclinclude=/tools/include
make
make test
make SCRIPTS="" install
cd ..
rm -fr expect5.45

DejaGNU-1.5

dejagnu-1.5.sh
tar -xzf dejagnu-1.5.tar.gz
cd dejagnu-1.5
./configure --prefix=/tools
make
make check
make install
cd ..
rm -fr dejagnu-1.5

Check-0.9.9

check-0.9.9.sh
tar -xzf check-0.9.9.tar.gz
cd check-0.9.9
CFLAGS="-L/tools/lib -lpthread" ./configure --prefix=/tools3
CFLAGS="-L/tools/lib -lpthread" make
make check
make install
cd ..
rm -fr check-0.9.9

Ncurses-5.9

ncurses-5.9.sh
tar -xzf ncurses-5.9.tar.gz
cd ncurses-5.9
./configure --prefix=/tools --with-shared \
    --without-debug --without-ada --enable-overwrite
make
make install
cd ..
rm -fr ncurses-5.9

Bash-4.2

bash-4.2.sh
tar -xzf bash-4.2.tar.gz
cd bash-4.2
patch -Np1 -i ../bash-4.2-fixes-11.patch
./configure --prefix=/tools --without-bash-malloc
make
make tests
make install
ln -sv bash /tools/bin/sh
cd ..
rm -fr bash-4.2

Bzip2-1.0.6

bzip2-1.0.6.sh
tar -xzf bzip2-1.0.6.tar.gz
cd bzip2-1.0.6
make
make PREFIX=/tools install
cd ..
rm -fr bzip2-1.0.6

Coreutils-8.21

coreutils-8.21.sh
tar -xJf coreutils-8.21.tar.xz
cd coreutils-8.21
./configure --prefix=/tools --enable-install-program=hostname
make
make RUN_EXPENSIVE_TESTS=yes check
make install
cd ..
rm -fr coreutils-8.21

Diffutils-3.2

diffutils-3.2.sh
tar -xzf diffutils-3.2.tar.gz
cd diffutils-3.2
sed -i -e '/gets is a/d' lib/stdio.in.h
./configure --prefix=/tools
make
make check
make install
cd ..
rm -fr diffutils-3.2

File-5.13

file-5.13.sh
tar -xzf file-5.13.tar.gz
cd file-5.13
./configure --prefix=/tools
make && make check && make install
cd ..
rm -fr file-5.13

Findutils-4.4.2

findutils-4.4.2.sh
tar -xzf findutils-4.4.2.tar.gz
cd findutils-4.4.2
./configure --prefix=/tools
make && make check && make install
cd ..
rm -fr findutils-4.4.2

Gawk-4.0.2

gawk-4.0.2.sh
tar -xJf gawk-4.0.2.tar.xz
cd gawk-4.0.2
./configure --prefix=/tools
make && make check && make install
cd ..
rm -fr gawk-4.0.2

Gettext-0.18.2

gettext-0.18.2.sh
tar -xzf gettext-0.18.2.tar.gz
cd gettext-0.18.2
cd gettext-tools
EMACS="no" ./configure --prefix=/tools --disable-shared
make -C gnulib-lib
make -C src msgfmt
cp -v src/msgfmt /tools/bin
cd ../../
rm -fr gettext-0.18.2

Grep-2.14

grep-2.14.sh
tar -xJf grep-2.14.tar.xz
cd grep-2.14
./configure --prefix=/tools
make && make check && make install
cd ..
rm -fr grep-2.14

Gzip-1.5

gzip-1.5.sh
tar -xJf gzip-1.5.tar.xz
cd gzip-1.5
./configure --prefix=/tools
make && make check && make install
cd ..
rm -fr gzip-1.5

M4-1.4.16

m4-1.4.16.sh
tar -xjf m4-1.4.16.tar.bz2
cd m4-1.4.16
sed -i -e '/gets is a/d' lib/stdio.in.h
./configure --prefix=/tools
make && make check && make install
cd ..
rm -fr m4-1.4.16

Make-3.82

make-3.82.sh
tar -xjf make-3.82.tar.bz2
cd make-3.82
./configure --prefix=/tools
make && make check && make install
cd ..
rm -fr make-3.82

Patch-2.7.1

patch-2.7.1.sh
tar -xJf patch-2.7.1.tar.xz
cd patch-2.7.1
./configure --prefix=/tools
make && make check && make install
cd ..
rm -fr patch-2.7.1

Perl-5.16.2

perl-5.16.2.sh
tar -xjf perl-5.16.2.tar.bz2
cd perl-5.16.2
patch -Np1 -i ../perl-5.16.2-libc-1.patch
sh Configure -des -Dprefix=/tools
make
cp -v perl cpan/podlators/pod2man /tools/bin
mkdir -pv /tools/lib/perl5/5.16.2
cp -Rv lib/* /tools/lib/perl5/5.16.2
cd ..
rm -fr perl-5.16.2

Sed-4.2.2

sed-4.2.2.sh
tar -xjf sed-4.2.2.tar.bz2
cd sed-4.2.2
./configure --prefix=/tools
make && make check && make install
cd ..
rm -fr sed-4.2.2

Tar-1.26

tar-1.26.sh
tar -xjf tar-1.26.tar.bz2
cd tar-1.26
sed -i -e '/gets is a/d' gnu/stdio.in.h
./configure --prefix=/tools
make && make check && make install
cd ..
rm -fr tar-1.26

Texinfo-5.0

texinfo-5.0.sh
tar -xJf texinfo-5.0.tar.xz
cd texinfo-5.0
./configure --prefix=/tools
make && make check && make install
cd ..
rm -fr texinfo-5.0

Xz-5.0.4

xz-5.0.4.sh
tar -xJf xz-5.0.4.tar.xz
cd xz-5.0.4
./configure --prefix=/tools
make && make check && make install
cd ..
rm -fr xz-5.0.4

스트리핑

설치된 패키지 중 불필요한 부분을 찾아 삭제하는 부가적인 과정

strip --strip-debug /tools/lib/*
strip --strip-unneeded /tools/{,s}bin/*
rm -fr /tools/{,share}/{info,man,doc}

소유권 변경

$FLS/tools 디렉토리에 모든 파일들은 현재 lfs 소유이지만 이것은 부자연스럽다.

# chown -R root:root $LFS/tools