|
|
在论坛上,Harold Lee写了个第五章、第六章的辅助编译脚本,但那个脚本是for LFS 6.0,在编译6.1的使用过程中发现了一些不太方便的地方,于是我尝试进行修改,于是有了下面的这些脚本。本文脚本在宿主机环境为LFS 6.1 的VMware 5.0中测试通过。
###################### 引用自原文,但同样适用于本文的内容 ## 引用开始 ################
本脚本的目地是为了帮助对于已经熟悉LFS的编译过程的人,在要编译多个LFS的过程中,能够减少劳动量!因为本脚本是辅助性质的,对于想要全自动编译的人,本脚本并不适合你。nAlfs可能更适合些。
注意:
1. 本脚本只是个辅助工具,应该以LFS书为主,脚本为辅。
2. 你需要至少手动编译过一遍LFS,并且掌握了shell编程知识,以便能够读懂本脚本。
在读懂脚本的基础上,需要适当的作一些修改。
在第6章中有关测试的部分,因为在我的机子上都可以通过,所以为了省时间,我把测试都略过了。如果你需要,可以自行增加。
申明:对于使用本脚本不当,给你的系统带来的任何破坏,后果自负。
###################### 引用自原文,但同样适用于本文的内容 ## 引用结束 ################
使用方法和一些改进的地方:把下面的几个脚本文件拷贝到源程序包目录,也就是 $LFS/sources 下面,执行完环境准备工作后变更目录到sources下,然后运行辅助编译脚本主程序 ./build.sh
对主程序我在原文的基础上增加了些互动式的选择项,可以选择编译的章[5/6] 还可以选择开始的节和结束的节,第5章可以从5.3. Binutils-2.15.94.0.2.2 - Pass 1开始,第6章从6.9. Linux-Libc-Headers-2.6.11.2开始,根据选择执行脚本 source chap5.sh 或者 source chap6 这样就保证了不用修改程序就同时能在5、6章使用。
和原文一样,文件$LFS/sources/log-LFS-6.1是运行过程的LOG文件,可以检查是因为什么原因造成编译错误;同时,对第6章的GLIBC和GCC的make check同时生成error-glibc-make-check-log和error-gcc-make-check-log两个文件,因为按照官方的解释,这两个测试是不可能完全通过的。
在第5章使用主程序build需要先执行第4章的环境准备工作也就是从执行完 #su - lfs 后开始;在第6章使用时需要执行完第6章的创建根目录、创建驱动程序的过程。本文同时提供这些脚本。
辅助编译脚本主程序,脚本 build.sh
#!/bin/sh
#
# By Harold Lee
#
# Aided build script for Chapter 5,6 in LFS 6.0 BOOK
#
# overwrite by Datahome
# overwrite 2005-09-22
# overwrite build script for Chapter 5,6 in LFS 6.1 BOOK
# offset=(3 9) #for chapter 5 offset is 3 and chapter 6 is 9
# There are 30 stages in Chapter 5 and 51 stages in chapter 6
#STAGES5=30
#STAGES6=51
echo " lases choice the build Chapter [5/6] "
read chap
case $chap in
5)
LFS=/mnt/lfs
offset=3 # start section
STAGES=32 # end section
source chap$((chap)).sh
LFS_CHAP=(BINUTILSPASS1 GCCPASS1 LINUX_LIBC GLIBC TOOLCHAIN TCL EXPECT
DEJAGNU GCCPASS2 BINUTILSPASS2 GAWK COREUTILS BZIP2 GZIP DIFFUTILS
FINDUTILS MAKE GREP SED GETTEXT NCURSES PATCH TAR TEXINFO BASH M4 BISON
FLEX UTIL_LINUX PERL)
;;
6)
LFS=''
offset=9 # start section
STAGES=59 # end section
source chap$((chap)).sh
LFS_CHAP=(LINUX_LIBC MAN_PAGES GLIBC RETOOLCHAIN BINUTILS GCC COREUTILS
ZLIB MKTEMP IANA_ETC FINDUTILS GAWK NCURSES READLINE VIM M4 BISON
LESS GROFF SED FLEX GETTEXT INETUTILS IPROUTE2 PERL TEXINFO AUTOCONF
AUTOMAKE BASH FILE LIBTOOL BZIP2 DIFFUTILS KBD E2FSPROGS GREP GRUB
GZIP HOTPLUG MAN MAKE MODULE_INIT_TOOLS PATCH PROCPS PSMISC SHADOW
SYSKLOGD SYSVINIT TAR UDEV UTIL_LINUX)
;;
*)
echo "You must chico [5/6] "
exit 1
esac
SOURCE=$LFS/sources
LOG=$SOURCE/log-lfs-6.1
## select start section and end section ###
echo " lases choice the start Section [${offset}--${STAGES}]"
read START
if (($START<$offset)) || (($START>$STAGES)) ;then
echo "The Chapter 5, start Section MUST [${offset}--${STAGES}]"
exit 1
else
echo " lases choice the end Section [${START}--${STAGES}]"
read END
if (($END<$START)) || (($END>${STAGES})) ;then
echo "The Chapter ${chap}, end Section MUST [${START}--${STAGES}]"
exit 1
fi
fi
start=$START-$offset
end=$END-$offset+1
STEP_START=${LFS_CHAP[start]}
STEP_END=${LFS_CHAP[end-1]}
## Press y to continue ###
echo "You chose is Chapter ${chap}.${START} ==> ${chap}.${END}"
echo "Build for start [${STEP_START}] end [${STEP_END}] "
echo " ress [y/Y] to continue"
read yn
if [ "$yn" != "y" ] && [ "$yn" != "Y" ];then
exit
fi
echo
# main loop
for ((s=start;s<end;s++));do
STEP=${LFS_CHAP}
if [[ ${STEP (-5)):5} == PASS1 ]];then
POSTFIX=Pass1
elif [[ ${STEP (-5)):5} == PASS2 ]];then
POSTFIX=Pass2
else
POSTFIX=""
fi
# now cast the upper case into lower case and merge the real filename
step=$(echo $STEP|tr [A-Z] [a-z]|sed -e 's/_/-/'g -e 's/pass.*//')
if [ $STEP == TOOLCHAIN ];then
buildname="Adjusting the Toolchain"
elif [ $STEP == RETOOLCHAIN ];then
buildname="Re-adjusting the Toolchain"
elif [ $step == gcc ];then
buildname="GCC-3.4.3"
else
buildname=$(echo $step*.bz2|sed 's/\(.*\).tar.*/\1/')
fi
# log the procedure
echo $(date +%c) "Build Start: $chap.$((s+${offset})) $buildname $POSTFIX" >> $LOG
if [[ $STEP != TOOLCHAIN && $STEP != RETOOLCHAIN ]];then
for k in ${step}*;do
if [ -d $k ];then
if rm -fr $k;then
echo $(date +%c) "Delete the $k directory." >> $LOG
else
echo $(date +%c) "Build Interrupt: Delete error." >> $LOG
echo >> $LOG
exit
fi
fi
done
# now we can unpack the tarball safely
for tarball in $(echo ${step}*.bz2);do
if tar xvfj $tarball;then
echo $(date +%c) "Unpack the $tarball." >> $LOG
else
echo $(date +%c) "Build Interrupt: Unpack error." >> $LOG
echo >> $LOG
exit
fi
done
# cd the directory
for j in ${step}*;do
if [ -d $j ];then
if cd $j;then
echo $(date +%c) "Cd the $j directory." >> $LOG
break
else
echo $(date +%c) "Build Interrupt: Change Directory error" >> $LOG
echo >> $LOG
exit
fi
fi
done
fi
# build
# before build disable filename expansion
set -f
echo $(date +%c) "Build command: ${!STEP}" >> $LOG
if ! eval ${!STEP};then
echo $(date +%c) "Build Interrupt: build error" >> $LOG
echo >> $LOG
exit
fi
# after enable filename expansion
set +f
echo $(date +%c) "Build Completed!" >> $LOG
echo >> $LOG
done
第5章的辅助编译内容 脚本 chap5.sh
#!/bin/sh
#
# By Harold Lee
#
#
# overwrite by Datahome
# overwrite 2005-09-22
# overwrite the comands of Chapter5 in LFS 6.1 BOOK
common="./configure --prefix=/tools && make && make install && cd .."
BINUTILSPASS1="mkdir ../binutils-build && cd ../binutils-build && ../binutils-2.15.94.0.2.2/configure --prefix=/tools --disable-nls && make && make install && make -C ld clean && make -C ld LIB_PATH=/tools/lib && cd .."
GCCPASS1="mkdir ../gcc-build && cd ../gcc-build && ../gcc-3.4.3/configure --prefix=/tools --libexecdir=/tools/lib --with-local-prefix=/tools --disable-nls --enable-shared --enable-languages=c && make bootstrap && make install && ln -s gcc /tools/bin/cc && cd .. && rm -fr gcc-build"
LINUX_LIBC="cp -R include/asm-i386 /tools/include/asm && cp -R include/linux /tools/include && cd .."
GLIBC="patch -Np1 -i ../glibc-2.3.4-fix_test-1.patch && mkdir ../glibc-build && cd ../glibc-build && ../glibc-2.3.4/configure --prefix=/tools --disable-profile --enable-add-ons --enable-kernel=2.6.0 --with-binutils=/tools/bin --without-gd --with-headers=/tools/include --without-selinux && make && mkdir /tools/etc && touch /tools/etc/ld.so.conf && make install && mkdir -p /tools/lib/locale && localedef -i de_DE -f ISO-8859-1 de_DE && localedef -i de_DE@euro -f ISO-8859-15 de_DE@euro && localedef -i en_HK -f ISO-8859-1 en_HK && localedef -i en_PH -f ISO-8859-1 en_PH && localedef -i en_US -f ISO-8859-1 en_US && localedef -i es_MX -f ISO-8859-1 es_MX && localedef -i fa_IR -f UTF-8 fa_IR && localedef -i fr_FR -f ISO-8859-1 fr_FR && localedef -i fr_FR@euro -f ISO-8859-15 fr_FR@euro && localedef -i it_IT -f ISO-8859-1 it_IT && localedef -i ja_JP -f EUC-JP ja_JP && cd .."
TOOLCHAIN="cd binutils-build && make -C ld install && cd .. && set +f && SPECFILE=\`gcc --print-file specs\` && sed 's@ /lib/ld-linux.so.2@ /tools/lib/ld-linux.so.2@g' \$SPECFILE > tempspecfile && mv -f tempspecfile \$SPECFILE && unset SPECFILE && rm -f /tools/lib/gcc/*/*/include/{pthread.h,bits/sigthread.h} && echo \"main(){}\" > dummy.c && cc dummy.c && readelf -l a.out | grep \": /tools\" && echo \"the output is [Requesting program interpreter: /lib/ld-linux.so.2]?? [y/n]\" && while read i;do if [ \$i == y ];then break;else exit;fi;done && rm dummy.c a.out"
TCL="cd unix && ${common} && export TCLPATH=\`pwd\` && ln -s tclsh8.4 /tools/bin/tclsh"
EXPECT="patch -Np1 -i ../expect-5.43.0-spawn-1.patch && ./configure --prefix=/tools --with-tcl=/tools/lib --with-tclinclude=\$TCLPATH --with-x=no && make && make SCRIPTS=\"\" install && unset TCLPATH && cd .."
DEJAGNU="./configure --prefix=/tools && make install && cd .."
GCCPASS2="expect -c \"spawn ls\" && patch -Np1 -i ../gcc-3.4.3-no_fixincludes-1.patch && patch -Np1 -i ../gcc-3.4.3-specs-2.patch && mkdir ../gcc-build && cd ../gcc-build && ../gcc-3.4.3/configure --prefix=/tools --libexecdir=/tools/lib --with-local-prefix=/tools --enable-clocale=gnu --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-languages=c,c++ --disable-libstdcxx-pch && make && make install && cd .. && rm -fr gcc-build"
BINUTILSPASS2="mkdir ../binutils-build && cd ../binutils-build && ../binutils-2.15.94.0.2.2/configure --prefix=/tools --disable-nls --enable-shared --with-lib-path=/tools/lib && make && make install && make -C ld clean && make -C ld LIB_PATH=/usr/lib:/lib && cd .."
GAWK=${common}
COREUTILS="DEFAULT_POSIX2_VERSION=199209 ${common}"
BZIP2="make && make PREFIX=/tools install && cd .."
GZIP=${common}
DIFFUTILS=${common}
FINDUTILS=${common}
MAKE=${common}
GREP="./configure --prefix=/tools --disable-perl-regexp && make && make install && cd .."
SED=${common}
GETTEXT="./configure --prefix=/tools --disable-libasprintf --disable-csharp && make && make install && cd .."
NCURSES="./configure --prefix=/tools --with-shared --without-debug --without-ada --enable-overwrite && make && make install && cd .."
PATCH="CPPFLAGS=-D_GNU_SOURCE ./configure --prefix=/tools && make && make install && cd .."
TAR=${common}
TEXINFO=${common}
BASH="patch -Np1 -i ../bash-3.0-avoid_WCONTINUED-1.patch && ./configure --prefix=/tools --without-bash-malloc && make && make install && ln -s bash /tools/bin/sh && cd .."
M4=${common}
BISON=${common}
FLEX="patch -Np1 -i ../flex-2.5.31-debian_fixes-3.patch && touch doc/flex.1 && ${common}"
UTIL_LINUX="sed -i 's@/usr/include@/tools/include@g' configure && ./configure && make -C lib && make -C mount mount umount && make -C text-utils more && cp mount/{,u}mount text-utils/more /tools/bin && cd .."
PERL="patch -Np1 -i ../perl-5.8.6-libc-1.patch && ./configure.gnu --prefix=/tools -Dstatic_ext='IO Fcntl POSIX' && make perl utilities && cp perl pod/pod2man /tools/bin && mkdir -p /tools/lib/perl5/5.8.6 && set +f && cp -R lib/* /tools/lib/perl5/5.8.6 && cd .."
第6章的辅助编译内容 脚本 chap6.sh
#!/bin/sh
#
# By Harold Lee
#
#
# overwrite by Datahome
# overwrite 2005-10-01
# overwrite the comands of Chapter6 in LFS 6.1 BOOK
common="./configure --prefix=/usr && make && make install && cd .."
LINUX_LIBC="cp -R include/asm-i386 /usr/include/asm && cp -R include/linux /usr/include && chown -R root:root /usr/include/{asm,linux} && find /usr/include/{asm,linux} -type d -exec chmod 755 {} \; && find /usr/include/{asm,linux} -type f -exec chmod 644 {} \; && cd .."
MAN_PAGES="make install && cd .."
GLIBC="tar -xjvf /sources/glibc-linuxthreads-2.3.4.tar.bz2 && patch -Np1 -i ../glibc-2.3.4-fix_test-1.patch && mkdir ../glibc-build && cd ../glibc-build && ../glibc-2.3.4/configure --prefix=/usr --disable-profile --enable-add-ons --enable-kernel=2.6.0 --libexecdir=/usr/lib/glibc && make && make -k check 2>> ../error-glibc-make-check-log ; touch /etc/ld.so.conf && make install && make localedata/install-locales && make -C ../glibc-2.3.4/linuxthreads/man && make -C ../glibc-2.3.4/linuxthreads/man install && cd .. && echo \"# Begin /etc/nsswitch.conf\" > /etc/nsswitch.conf && echo \"\" >> /etc/nsswitch.conf && echo \"passwd: files\" >> /etc/nsswitch.conf && echo \"group: files\" >> /etc/nsswitch.conf && echo \"shadow: files\" >> /etc/nsswitch.conf && echo \"\" >> /etc/nsswitch.conf && echo \"hosts: files dns\" >> /etc/nsswitch.conf && echo \"networks: files\" >> /etc/nsswitch.conf && echo \"\" >> /etc/nsswitch.conf && echo \"protocols: files\" >> /etc/nsswitch.conf && echo \"services: files\" >> /etc/nsswitch.conf && echo \"ethers: files\" >> /etc/nsswitch.conf && echo \"rpc: files\" >> /etc/nsswitch.conf && echo \"\" >> /etc/nsswitch.conf && echo \"# End /etc/nsswitch.conf\" >> /etc/nsswitch.conf && cp --remove-destination /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo \"# Begin /etc/ld.so.conf\" > /etc/ld.so.conf && echo \"\" >> /etc/ld.so.conf && echo \"/usr/local/lib\" >> /etc/ld.so.conf && echo \"/opt/lib\" >> /etc/ld.so.conf && echo \"\" >> /etc/ld.so.conf && echo \"# End /etc/ld.so.conf\" >> /etc/ld.so.conf "
RETOOLCHAIN="if [ -d binutils-build ]; then cd binutils-build ; make -C ld INSTALL=/tools/bin/install install ; cd .. ; rm -fr binutils-build ;fi && set +f && perl -pi -e 's@ /tools/lib/ld-linux.so.2@ /lib/ld-linux.so.2@g;' -e 's@\*startfile_prefix_spec:\\n@\$_/usr/lib/ @g;' \`gcc --print-file specs\` && echo \"main(){}\" > dummy.c && cc dummy.c && readelf -l a.out | grep \": /lib\" && echo \"the output is [Requesting program interpreter: /lib/ld-linux.so.2]?? [y/n]\" && while read i;do if [ \$i == y ];then break;else exit;fi;done && rm dummy.c a.out"
# RETOOLCHAIN="if [ -d binutils-build ]; then cd binutils-build ; make -C ld INSTALL=/tools/bin/install install ; cd .. ; rm -fr binutils-build ;fi && set +f && perl -pi -e 's@ /tools/lib/ld-linux.so.2@ /lib/ld-linux.so.2@g;' -e 's@\*startfile_prefix_spec:\\n@\$_/usr/lib/ @g;' \`gcc --print-file specs\` "
BINUTILS="expect -c \"spawn ls\" && mkdir ../binutils-build && cd ../binutils-build && ../binutils-2.15.94.0.2.2/configure --prefix=/usr --enable-shared && make tooldir=/usr && make check && make tooldir=/usr install && cp ../binutils-2.15.94.0.2.2/include/libiberty.h /usr/include && cd .."
GCC="patch -Np1 -i ../gcc-3.4.3-no_fixincludes-1.patch && patch -Np1 -i ../gcc-3.4.3-linkonce-1.patch && sed -i 's/install_to_\$(INSTALL_DEST) //' libiberty/Makefile.in && mkdir ../gcc-build && cd ../gcc-build && ../gcc-3.4.3/configure --prefix=/usr --libexecdir=/usr/lib --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-languages=c,c++ && make && make -k check 2> ../error-gcc-make-check-log ; make install && ln -s ../usr/bin/cpp /lib && ln -s gcc /usr/bin/cc && cd .."
COREUTILS="patch -Np1 -i ../coreutils-5.2.1-uname-2.patch && patch -Np1 -i ../coreutils-5.2.1-suppress_uptime_kill_su-1.patch && DEFAULT_POSIX2_VERSION=199209 ./configure --prefix=/usr && make && make install && mv /usr/bin/{[,basename,cat,chgrp,chmod,chown,cp,dd,df} /bin && mv /usr/bin/{date,echo,false,head,hostname,install,ln} /bin && mv /usr/bin/{ls,mkdir,mknod,mv,pwd,rm,rmdir,sync} /bin && mv /usr/bin/{sleep,stty,test,touch,true,uname} /bin && mv /usr/bin/chroot /usr/sbin && ln -s ../../bin/install /usr/bin && cd .."
ZLIB="patch -Np1 -i ../zlib-1.2.2-security_fix-1.patch && ./configure --prefix=/usr --shared --libdir=/lib && make && make install && rm /lib/libz.so && ln -sf ../../lib/libz.so.1.2.2 /usr/lib/libz.so && make clean && ./configure --prefix=/usr && make && make install && chmod 644 /usr/lib/libz.a && cd .."
MKTEMP="patch -Np1 -i ../mktemp-1.5-add_tempfile-2.patch && ./configure --prefix=/usr --with-libc && make && make install && make install-tempfile && cd .."
IANA_ETC="make && make install && cd .."
FINDUTILS="./configure --prefix=/usr --libexecdir=/usr/lib/locate --localstatedir=/var/lib/locate && make && make install && cd .."
GAWK="./configure --prefix=/usr --with-shared --without-debug && make && make install && cd .."
NCURSES="./configure --prefix=/usr --with-shared --without-debug && make && make install && set +f && chmod 755 /usr/lib/*.5.4 && chmod 644 /usr/lib/libncurses++.a && mv /usr/lib/libncurses.so.5* /lib && ln -sf ../../lib/libncurses.so.5 /usr/lib/libncurses.so && ln -sf libncurses.so /usr/lib/libcurses.so && cd .."
READLINE="patch -Np1 -i ../readline-5.0-fixes-1.patch && ./configure --prefix=/usr --libdir=/lib && make SHLIB_XLDFLAGS=-lncurses && make install && set +f && chmod 755 /lib/lib{readline,history}.so* && mv /lib/lib{readline,history}.a /usr/lib && rm /lib/lib{readline,history}.so && ln -sf ../../lib/libhistory.so.5 /usr/lib/libhistory.so && ln -sf ../../lib/libreadline.so.5 /usr/lib/libreadline.so && cd .."
VIM="echo '#define SYS_VIMRC_FILE \"/etc/vimrc\"' >> src/feature.h && echo '#define SYS_GVIMRC_FILE \"/etc/gvimrc\"' >> src/feature.h && patch -Np1 -i ../vim-6.3-security_fix-1.patch && ./configure --prefix=/usr --enable-multibyte && make && make install && ln -sf vim /usr/bin/vi && cd .. && echo \"\" >> /etc/vimrc && echo \"set nocompatible\" >> /etc/vimrc && echo \"set backspace=2\" >> /etc/vimrc && echo \"syntax on\" >> /etc/vimrc && echo 'if (&term == \"iterm\") || (&term == \"putty\")' >> /etc/vimrc && echo \" set background=dark\" >> /etc/vimrc && echo \"endif\" >> /etc/vimrc && echo \"\" >> /etc/vimrc "
M4=${common}
BISON=${common}
LESS="./configure --prefix=/usr --bindir=/bin --sysconfdir=/etc && make && make install && cd .."
GROFF=" AGE=A4 ./configure --prefix=/usr && make && make install && ln -s soelim /usr/bin/zsoelim && ln -s eqn /usr/bin/geqn && ln -s tbl /usr/bin/gtbl && cd .."
SED="./configure --prefix=/usr --bindir=/bin && make && make install && cd .."
FLEX="patch -Np1 -i ../flex-2.5.31-debian_fixes-3.patch && touch doc/flex.1 && ./configure --prefix=/usr && make && make install && ln -s libfl.a /usr/lib/libl.a && cd .. && echo \"#! /bin/sh\" > /usr/bin/lex && echo \"# Begin /usr/bin/lex\" >> /usr/bin/lex && echo \"\" >> /usr/bin/lex && echo \"exec /usr/bin/flex -l \"\$@\"\" >> /usr/bin/lex && echo \"\" >> /usr/bin/lex && echo \"# End /usr/bin/lex\" >> /usr/bin/lex && chmod 755 /usr/bin/lex"
GETTEXT=${common}
INETUTILS="patch -Np1 -i ../inetutils-1.4.2-kernel_headers-1.patch && patch -Np1 -i ../inetutils-1.4.2-no_server_man_pages-1.patch && ./configure --prefix=/usr --libexecdir=/usr/sbin --sysconfdir=/etc --localstatedir=/var --disable-logger --disable-syslogd --disable-whois --disable-servers && make && make install && mv /usr/bin/ping /bin && cd .."
IPROUTE2="patch -Np1 -i ../iproute2-2.6.11_050330-remove_db-1.patch && ./configure && make SBINDIR=/sbin && make SBINDIR=/sbin install && cd .."
PERL="./configure.gnu --prefix=/usr -Dpager=\"/bin/less -isR\" && make && make install && cd .."
TEXINFO="./configure --prefix=/usr && make && make install && make TEXMF=/usr/share/texmf install-tex && cd .."
AUTOCONF=${common}
AUTOMAKE=${common}
BASH="patch -Np1 -i ../bash-3.0-fixes-3.patch && patch -Np1 -i ../bash-3.0-avoid_WCONTINUED-1.patch && ./configure --prefix=/usr --bindir=/bin --without-bash-malloc --with-installed-readline && make && make install && cd .."
FILE=${common}
LIBTOOL=${common}
BZIP2="make -f Makefile-libbz2_so && make clean && make && make install && cp bzip2-shared /bin/bzip2 && set +f && cp -a libbz2.so* /lib && ln -s ../../lib/libbz2.so.1.0 /usr/lib/libbz2.so && rm /usr/bin/{bunzip2,bzcat,bzip2} && ln -s bzip2 /bin/bunzip2 && ln -s bzip2 /bin/bzcat && cd .."
DIFFUTILS=${common}
KBD="./configure && make && make install && cd .."
E2FSPROGS="sed -i -e 's/-DTEST/\$(ALL_CFLAGS) &/' lib/e2p/Makefile.in && mkdir build && cd build && ../configure --prefix=/usr --with-root-prefix=\"\" --enable-elf-shlibs --disable-evms && make && make install && make install-libs && cd ../../"
GREP="./configure --prefix=/usr --bindir=/bin && make && make install && cd .."
GRUB="${common} && set +f && mkdir -p /boot/grub && cp /usr/lib/grub/i386-pc/stage{1,2} /boot/grub && cp /usr/lib/grub/i386-pc/e2fs_stage1_5 /boot/grub "
GZIP="patch -Np1 -i ../gzip-1.3.5-security_fixes-1.patch && ./configure --prefix=/usr && sed -i 's@\"BINDIR\"@/bin@g' gzexe.in && make && make install && mv /usr/bin/gzip /bin && rm /usr/bin/{gunzip,zcat} && ln -s gzip /bin/gunzip && ln -s gzip /bin/zcat && ln -s gunzip /bin/uncompress && cd .."
HOTPLUG="make install && cp etc/hotplug/pnp.distmap /etc/hotplug && rm -rf /etc/init.d && rm -f /etc/hotplug/net.agent && mkdir /lib/firmware && cd .."
MAN="sed -i 's@-is@&R@g' configure && sed -i 's@MANPATH./usr/man@#&@g' src/man.conf.in && ./configure -confdir=/etc && make && make install && cd .."
MAKE=${common}
MODULE_INIT_TOOLS="touch modprobe.conf.5 && ./configure --prefix=\"\" --enable-zlib && make && make install && cd .."
PATCH="CPPFLAGS=-D_GNU_SOURCE ./configure --prefix=/usr && make && make install && cd .."
PROCPS="make && make install && cd .."
PSMISC="./configure --prefix=/usr --exec-prefix=\"\" && make && make install && set +f && mv /bin/pstree* /usr/bin && ln -sf pstree /usr/bin/pstree.x11 && ln -s killall /bin/pidof && cd .."
SHADOW="./configure --libdir=/lib --enable-shared && sed -i 's/groups\$(EXEEXT) //' src/Makefile && sed -i '/groups/d' man/Makefile && make && make install && cp etc/{limits,login.access} /etc && sed -e's@#MD5_CRYPT_ENAB.no@MD5_CRYPT_ENAB yes@' -e 's@/var/spool/mail@/var/mail@' etc/login.defs.linux > /etc/login.defs && mv /usr/bin/passwd /bin && set +f && mv /lib/libshadow.*a /usr/lib && rm /lib/libshadow.so && ln -sf ../../lib/libshadow.so.0 /usr/lib/libshadow.so && mkdir /etc/default && pwconv && grpconv && cd .."
SYSKLOGD="patch -Np1 -i ../sysklogd-1.4.1-fixes-1.patch && make && make install && cd .. && echo \"# Begin /etc/syslog.conf\" > /etc/syslog.conf && echo \"\" >> /etc/syslog.conf && echo \"auth,authpriv.* -/var/log/auth.log\" >> /etc/syslog.conf && echo \"*.*;auth,authpriv.none -/var/log/sys.log\" >> /etc/syslog.conf && echo \"daemon.* -/var/log/daemon.log\" >> /etc/syslog.conf && echo \"kern.* -/var/log/kern.log\" >> /etc/syslog.conf && echo \"mail.* -/var/log/mail.log\" >> /etc/syslog.conf && echo \"user.* -/var/log/user.log\" >> /etc/syslog.conf && echo \"*.emerg *\" >> /etc/syslog.conf && echo \"\" >> /etc/syslog.conf && echo \"# log the bootscript output:\" >> /etc/syslog.conf && echo \"local2.* -/var/log/boot.log\" >> /etc/syslog.conf && echo \"\" >> /etc/syslog.conf && echo \"# End /etc/syslog.conf\" >> /etc/syslog.conf "
SYSVINIT="sed -i 's@Sending processes@& started by init@g' src/init.c && make -C src && make -C src install && cd .. && echo \"# Begin /etc/inittab\" > /etc/inittab && echo \"\" >> /etc/inittab && echo \"id:3:initdefault:\" >> /etc/inittab && echo \"\" >> /etc/inittab && echo \"si::sysinit:/etc/rc.d/init.d/rc sysinit\" >> /etc/inittab && echo \"\" >> /etc/inittab && echo \"l0:0:wait:/etc/rc.d/init.d/rc 0\" >> /etc/inittab && echo \"l1:S1:wait:/etc/rc.d/init.d/rc 1\" >> /etc/inittab && echo \"l2:2:wait:/etc/rc.d/init.d/rc 2\" >> /etc/inittab && echo \"l3:3:wait:/etc/rc.d/init.d/rc 3\" >> /etc/inittab && echo \"l4:4:wait:/etc/rc.d/init.d/rc 4\" >> /etc/inittab && echo \"l5:5:wait:/etc/rc.d/init.d/rc 5\" >> /etc/inittab && echo \"l6:6:wait:/etc/rc.d/init.d/rc 6\" >> /etc/inittab && echo \"\" >> /etc/inittab && echo \"ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now\" >> /etc/inittab && echo \"\" >> /etc/inittab && echo \"su:S016 nce:/sbin/sulogin\" >> /etc/inittab && echo \"\" >> /etc/inittab && echo \"1:2345:respawn:/sbin/agetty -I '\\033(K' tty1 9600\" >> /etc/inittab && echo \"2:2345:respawn:/sbin/agetty -I '\\033(K' tty2 9600\" >> /etc/inittab && echo \"3:2345:respawn:/sbin/agetty -I '\\033(K' tty3 9600\" >> /etc/inittab && echo \"4:2345:respawn:/sbin/agetty -I '\\033(K' tty4 9600\" >> /etc/inittab && echo \"5:2345:respawn:/sbin/agetty -I '\\033(K' tty5 9600\" >> /etc/inittab && echo \"6:2345:respawn:/sbin/agetty -I '\\033(K' tty6 9600\" >> /etc/inittab && echo \"\" >> /etc/inittab && echo \"# End /etc/inittab\" >> /etc/inittab "
TAR="patch -Np1 -i ../tar-1.15.1-sparse_fix-1.patch && ./configure --prefix=/usr --bindir=/bin --libexecdir=/usr/sbin && make && make install && cd .."
UDEV="make udevdir=/dev && make udevdir=/dev install && cp ../udev-config-3.rules /etc/udev/rules.d/25-lfs.rules && /sbin/udevstart && cd .."
UTIL_LINUX="sed -i 's@etc/adjtime@var/lib/hwclock/adjtime@g' hwclock/hwclock.c && mkdir -p /var/lib/hwclock && patch -Np1 -i ../util-linux-2.12q-cramfs-1.patch && ./configure && make HAVE_KILL=yes HAVE_SLN=yes && make HAVE_KILL=yes HAVE_SLN=yes install && mv /usr/bin/logger /bin && cd .."
第4章的环境准备脚本 su-lfs.sh
#! /bin/sh
#
# By Datahome
# 2005-09-26
#
# su-lfs.sh
#################################
export LFS=/mnt/lfs
#
#
mkdir $LFS/sources
#
mkdir $LFS/tools
#
ln -s $LFS/tools /
#
groupadd lfs
useradd -s /bin/bash -g lfs -m -k /dev/null lfs
#
chown lfs $LFS/tools
chown lfs $LFS/sources
#
#
passwd lfs
#
#
su - lfs
############## end ###############
第4章的 bash环境变量准备脚本 bash_env.sh
# !/bin/sh
# ----------------------------------------------------------
# By Datahome , 2005.09.24
# For charpter 4, LFS ver 6.1
# After loginned as lfs at the end of "Add a user: lfs", use
# this script to finish the remainder part of chapter 5.
# Especially for those who build LFS for second time. Just
# save some time, Enjoy it.
#
# bash_env.sh
# -----------------------------------------------------------
# 4.4. Setting Up the Environment
#
cat > ~/.bash_profile << "EOF"
exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash
EOF
cat > ~/.bashrc << "EOF"
set +h
umask 022
LFS=/mnt/lfs
LC_ALL=POSIX
PATH=/tools/bin:/bin:/usr/bin
export LFS LC_ALL PATH
EOF
#
source ~/.bash_profile
############## end ###############
第6章的 chroot-lfs.sh
#!/bin/sh
# By Datahome
# 2005-09-26
#
# chroot-lfs.sh
#################################
#
export LFS=/mnt/lfs
mkdir -p $LFS/{proc,sys}
#
mount -t proc proc $LFS/proc
mount -t sysfs sysfs $LFS/sys
#
mount -f -t tmpfs tmpfs $LFS/dev
mount -f -t tmpfs tmpfs $LFS/dev/shm
mount -f -t devpts -o gid=4,mode=620 devpts $LFS/dev/pts
#
chroot "$LFS" /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
############## end ###############
第6章转换根文件系统后的 创建根文件系统脚本 creat-root.sh
#! /tools/bin/sh
#################################
# By Datahome
# 2005-09-26
#
# creat-root.sh
#################################
# Changing Ownership
chown -R 0:0 /tools
# Creating Directories
install -d /{bin,boot,dev,etc/opt,home,lib,mnt}
install -d /{sbin,srv,usr/local,var,opt}
install -d /root -m 0750
install -d /tmp /var/tmp -m 1777
install -d /media/{floppy,cdrom}
install -d /usr/{bin,include,lib,sbin,share,src}
ln -s share/{man,doc,info} /usr
install -d /usr/share/{doc,info,locale,man}
install -d /usr/share/{misc,terminfo,zoneinfo}
install -d /usr/share/man/man{1,2,3,4,5,6,7,8}
install -d /usr/local/{bin,etc,include,lib,sbin,share,src}
ln -s share/{man,doc,info} /usr/local
install -d /usr/local/share/{doc,info,locale,man}
install -d /usr/local/share/{misc,terminfo,zoneinfo}
install -d /usr/local/share/man/man{1,2,3,4,5,6,7,8}
install -d /var/{lock,log,mail,run,spool}
install -d /var/{opt,cache,lib/{misc,locate},local}
install -d /opt/{bin,doc,include,info}
install -d /opt/{lib,man/man{1,2,3,4,5,6,7,8}}
# Creating Essential Symlinks
ln -s /tools/bin/{bash,cat,pwd,stty} /bin
ln -s /tools/bin/perl /usr/bin
ln -s /tools/lib/libgcc_s.so{,.1} /usr/lib
ln -s bash /bin/sh
# Creating the passwd, group, and log Files
cat > /etc/passwd << "EOF"
root:x:0:0:root:/root:/bin/bash
EOF
#
cat > /etc/group << "EOF"
root:x:0:
bin:x:1:
sys:x:2:
kmem:x:3:
tty:x:4:
tape:x:5:
daemon:x:6:
floppy:x:7:
disk:x:8:
lp:x:9:
dialout:x:10:
audio:x:11:
video:x:12:
utmp:x:13:
usb:x:14:
EOF
# exec /tools/bin/bash --login +h
touch /var/run/utmp /var/log/{btmp,lastlog,wtmp}
chgrp utmp /var/run/utmp /var/log/lastlog
chmod 664 /var/run/utmp /var/log/lastlog
# exec /tools/bin/bash --login +h
############## end ###############
执行完本脚本后需要执行 exec /tools/bin/bash --login +h 才能消除"I have no name!"的信息
第6章转换根文件系统后的 创建驱动程序的脚本 creat-dev.sh
#! /bin/sh
# By Datahome
# 2005-09-26
#
# creat-dev.sh
#################################
#
# touch /var/run/utmp /var/log/{btmp,lastlog,wtmp}
# chgrp utmp /var/run/utmp /var/log/lastlog
# chmod 644 /var/run/utmp /var/log/lastlog
#
mknod -m 600 /dev/console c 5 1
mknod -m 666 /dev/null c 1 3
#
mount -n -t tmpfs none /dev
#
mknod -m 622 /dev/console c 5 1
mknod -m 666 /dev/null c 1 3
mknod -m 666 /dev/zero c 1 5
mknod -m 666 /dev/ptmx c 5 2
mknod -m 666 /dev/tty c 5 0
mknod -m 444 /dev/random c 1 8
mknod -m 444 /dev/urandom c 1 9
chown root:tty /dev/{console,ptmx,tty}
#
ln -s /proc/self/fd /dev/fd
ln -s /proc/self/fd/0 /dev/stdin
ln -s /proc/self/fd/1 /dev/stdout
ln -s /proc/self/fd/2 /dev/stderr
ln -s /proc/kcore /dev/core
mkdir /dev/pts
mkdir /dev/shm
#
mount -t devpts -o gid=4,mode=620 none /dev/pts
mount -t tmpfs none /dev/shm
############## end ###############
以上几个脚本的执行顺序
su-lfs.sh ==> bash_env.sh ==> build.sh ==> chroot-lfs.sh ==> creat-root.sh ==> creat-dev.sh ==> build.sh
其中su-lfs.sh 和 chroot-lfs.sh需要在宿主机中执行,其他脚本在目标机中执行
BTW:将dos格式的txt文件转换为UNIX格式文本可以用下面这条命令实现,请将$1和$2分别换成合适的文件名
cat $1 | tr -d '\r' > $2
例如执行 cat build.txt | r -d '\r' > build.sh 可以将本文提到的脚本转换为合适的脚本文件 |
|