[Clfs-support] Script build toolchain for x86
Milan Buska
newishi at newishi.net
Sun Mar 7 08:38:33 PST 2010
Hi all.
I wrote a crude script to build toolchain for x86 architecture.
Please excuse me for this insolence. I am a beginner.
I like to leave from you to advise you to edit and put better.
Thanks
00.stage1-toolchain.sh
-------------------------------------------
#!/bin/bash
#
#
# Written by Milan Buska - newishi at newishi dot net
# Created with resources to
# http://crux.nu
# http://cross-lfs.org/view/clfs-sysroot/x86
# http://www.eglibc.org/cgi-bin/viewcvs.cgi/branches/eglibc- 2_10/libc/EGLIBC.cross-building? rev = 8421 & view = markup /
#
# Before running, select the disk is formatted
# partition and attach it to the directory /mnt/sysroot
#
set +h
set -e
# Settings variables
#
build="i686-pc-linux-gnu"
host=$build
target="i686-saux-linux-gnu"
sysroot="/mnt/sysroot"
linux_arch="x86"
# stage1
gmpv=gmp-4.3.2
mpfrv=mpfr-2.4.2
pplv=ppl-0.10.2
cloogv=cloog-ppl-0.15.7
mpcv=mpc-0.8.1
binutilsv=binutils-2.20
gccv=gcc-4.4.3
eglibcv=eglibc-2.10
linuxv=linux-2.6.32.8
filev=file-5.03
groffv=groff-1.20.1
shadowv=shadow-4.1.4.2
ncursesv=ncurses-5.7
#
src=$sysroot/src
mkdir -pv $src
gnu="http://ftp.sh.cvut.cz/MIRRORS/gnu/pub/gnu"
wget -nc -P $src \
$gnu/binutils/binutils-2.20.tar.bz2 \
$gnu/groff/groff-1.20.1.tar.gz \
$gnu/ncurses/ncurses-5.7.tar.gz \
http://ftp.sh.cvut.cz/MIRRORS/kernel/linux/kernel/v2.6/linux-2.6.32.8.tar.bz2
\
http://gcc.fyxm.net/releases/gcc-4.4.3/gcc-4.4.3.tar.bz2 \
http://gcc.fyxm.net/infrastructure/gmp-4.3.2.tar.bz2 \
http://gcc.fyxm.net/infrastructure/mpfr-2.4.2.tar.bz2 \
http://gcc.fyxm.net/infrastructure/mpc-0.8.1.tar.gz \
http://gcc.fyxm.net/infrastructure/ppl-0.10.2.tar.gz \
http://gcc.fyxm.net/infrastructure/cloog-ppl-0.15.7.tar.gz \
ftp://ftp.astron.com/pub/file/file-5.03.tar.gz \
ftp://pkg-shadow.alioth.debian.org/pub/pkg-shadow/shadow-4.1.4.2.tar.bz2
\
http://www.lfs-matrix.org/pub/clfs/conglomeration/eglibc/eglibc-2.10.tar.bz2
\
http://patches.cross-lfs.org/sysroot-dev/shadow-4.1.4.2-sysroot_hacks-1.patch
\
http://patches.cross-lfs.org/sysroot-dev/ncurses-5.7-bash_fix-1.patch
echo ""
#
#
cd $src
echo ""
echo " == Unpacking GMP == "
tar -xf gmp-4.3.2.tar.bz2
echo ""
echo " == Unpacking MPFR == "
tar -xf mpfr-2.4.2.tar.bz2
echo ""
echo " == Unpacking MPC == "
tar -xf mpc-0.8.1.tar.gz
echo ""
echo " == Unpacking PPL == "
tar -xf ppl-0.10.2.tar.gz
echo ""
echo " == Unpacking CLOOG-PPL == "
tar -xf cloog-ppl-0.15.7.tar.gz
echo ""
echo " == Unpacking BINUTILS == "
tar -xf binutils-2.20.tar.bz2
echo ""
echo " == Unpacking GCC == "
tar -xf gcc-4.4.3.tar.bz2
echo ""
echo " == Unpacking KERNEL == "
tar -xf linux-2.6.32.8.tar.bz2
echo ""
echo " == Unpacking EGLIBC == "
tar -xf eglibc-2.10.tar.bz2
echo ""
echo " == Unpacking FILE == "
tar -xf file-5.03.tar.gz
echo ""
echo " == Unpacking GROFF == "
tar -xf groff-1.20.1.tar.gz
echo ""
echo " == Unpacking SHADOW == "
tar -xf shadow-4.1.4.2.tar.bz2
echo ""
echo " == Unpacking NCURSES == "
tar -xf ncurses-5.7.tar.gz
echo ""
echo " == All O.K == "
echo ""
#
#
#
work=$sysroot/work
mkdir -pv $work
tools=$sysroot/tools
mkdir -pv $tools
echo ""
# Creating Directories
mkdir -v $sysroot/bin
mkdir -v $sysroot/sbin
mkdir -v $sysroot/boot
mkdir -v $sysroot/dev
mkdir -v $sysroot/proc
mkdir -v $sysroot/sys
mkdir -v $sysroot/etc
mkdir -v $sysroot/tmp
mkdir -v $sysroot/mnt
mkdir -v $sysroot/root
mkdir -v $sysroot/lib
mkdir -v $sysroot/lib/modules
mkdir -v $sysroot/opt
mkdir -v $sysroot/opt/bin
mkdir -v $sysroot/opt/sbin
mkdir -v $sysroot/usr
mkdir -v $sysroot/usr/{bin,include,lib,sbin,share,src,man}
mkdir -v $sysroot/usr/man/man{1,2,3,4,5,6,7,8}
ln -sv ../var $sysroot/usr/var
mkdir -v $sysroot/var
mkdir -v $sysroot/var/cache
mkdir -v $sysroot/var/lib
mkdir -v $sysroot/var/lib/pkg
mkdir -v $sysroot/var/lock
mkdir -v $sysroot/var/log
mkdir -v $sysroot/var/log/old
mkdir -v $sysroot/var/run
touch $sysroot/var/run/utmp
mkdir -v $sysroot/var/spool
mkdir -v $sysroot/var/spool/mail
mkdir -v $sysroot/var/tmp
mkdir -v $sysroot/var/ftp
mkdir -v $sysroot/var/www
mkdir -v $sysroot/var/empty
ln -sv spool/mail $sysroot/var/mail
mkdir -v $sysroot/home
chmod -v 1777 $sysroot/var/spool/mail
chmod -v 1777 $sysroot/tmp
chmod -v 1777 $sysroot/var/lock
chmod -v 1777 $sysroot/var/tmp
chmod -v 0750 $sysroot/root
### /dev
mknod $sysroot/dev/console c 5 1
chmod -v 0600 $sysroot/dev/console
#
### Creating the passwd, group, fstab, issue,
# mime.types, motd, mtab,securetty, shadow,
# shells and log Files
#
# passwd
cat > $sysroot/etc/passwd << EOF
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:
daemon:x:2:2:daemon:/sbin:
mail:x:8:12:mail:/var/spool/mail:
ftp:x:14:11:ftp:/var/ftp:
www:x:15:15:www:/var/www:/bin/false
messagebus:x:81:81::/var/empty:/bin/false
nobody:x:99:99:nobody:/:
EOF
# group
cat > $sysroot/etc/group << EOF
root::0:root
bin::1:root,bin,daemon
daemon::2:root,bin,daemon
sys::3:root,bin
adm::4:root,daemon
tty::5:
disk::6:root
lp::7:daemon
mem::8:
kmem::9:
wheel::10:root
ftp::11:
mail::12:
mlocate::13:
dialout::14:
www::15:
audio::16:
video::17:
floppy::18:
tape::19:
scanner::20:
cdrom::21:
nobody::99:
messagebus::81:
users::100:
EOF
# fstab
cat > $sysroot/etc/fstab << EOF
# /etc/fstab: static file system information
#
# <file system> <dir> <type> <options> <dump>
# <pass>
#/dev/#REISERFS_ROOT# / reiserfs defaults 0 0
#/dev/#EXT3FS_ROOT# / ext3 defaults 0 1
#/dev/#EXT4FS_ROOT# / ext4 defaults 0 1
#/dev/#JFS_ROOT# / jfs defaults 1 1
#/dev/#XFS_ROOT# / xfs defaults 0 0
#/dev/#SWAP# swap swap defaults 0 0
#/dev/#REISERFS_HOME# /home reiserfs defaults 0 0
#/dev/#EXT3FS_HOME# /home ext3 defaults 0 2
#/dev/#EXT4FS_HOME# /home ext4 defaults 0 2
#/dev/#JFS_HOME# /home jfs defaults 1 2
#/dev/#XFS_HOME# /home xfs defaults 0 0
#/dev/cdrom /cdrom iso9660 ro,user,noauto,unhide 0 0
#/dev/dvd /dvd udf ro,user,noauto,unhide 0 0
#/dev/floppy/0 /floppy vfat user,noauto,unhide 0 0
devpts /dev/pts devpts defaults 0 0
none /sys sysfs defaults 0 0
none /proc proc defaults 0 0
#tmp /tmp tmpfs defaults 0 0
#shm /dev/shm tmpfs defaults 0 0
#usb /proc/bus/usb usbfs defaults 0 0
# End of file
EOF
# issue
cat > $sysroot/etc/issue << EOF
Welcome to new system (\n) (\l)
EOF
# mime.types
cat > $sysroot/etc/mime.types << EOF
# /etc/mime.types: mime types
#
application/andrew-inset ez
application/excel xls
application/octet-stream bin
application/oda oda
application/pdf pdf
application/pgp pgp
application/postscript ps PS eps
application/rtf rtf
application/x-arj-compressed arj
application/x-bcpio bcpio
application/x-chess-pgn pgn
application/x-cpio cpio
application/x-csh csh
application/x-debian-package deb
application/x-msdos-program com exe bat
application/x-dvi dvi
application/x-gtar gtar
application/x-gunzip gz
application/x-hdf hdf
application/x-latex latex
application/x-mif mif
application/x-netcdf cdf nc
application/x-perl pl pm
application/x-rar-compressed rar
application/x-sh sh
application/x-shar shar
application/x-sv4cpio sv4cpio
application/x-sv4crc sv4crc
application/x-tar tar
application/x-tar-gz tgz tar.gz
application/x-tcl tcl
application/x-tex tex
application/x-texinfo texi texinfo
application/x-troff t tr roff
application/x-troff-man man
application/x-troff-me me
application/x-troff-ms ms
application/x-ustar ustar
application/x-wais-source src
application/x-zip-compressed zip
audio/basic snd
audio/midi mid midi
audio/ulaw au
audio/x-aiff aif aifc aiff
audio/x-wav wav
image/gif gif
image/ief ief
image/jpeg jpe jpeg jpg
image/png png
image/tiff tif tiff
image/x-cmu-raster ras
image/x-portable-anymap pnm
image/x-portable-bitmap pbm
image/x-portable-graymap pgm
image/x-portable-pixmap ppm
image/x-rgb rgb
image/x-xbitmap xbm
image/x-xpixmap xpm
image/x-xwindowdump xwd
text/html html htm
text/plain asc txt
text/css css
text/richtext rtx
text/tab-separated-values tsv
text/x-setext etx
video/dl dl
video/fli fli
video/gl gl
video/mpeg mp2 mpe mpeg mpg
video/quicktime mov qt
video/x-msvideo avi
video/x-sgi-movie movie
x-world/x-vrml vrm vrml wrl
# End of file
EOF
# motd
touch $sysroot/etc/motd
# mtab
touch $sysroot/etc/mtab
# securetty
cat > $sysroot/etc/securetty << EOF
# /etc/securetty: defines which devices root can log in on
#
console
ttyS0
tty1
tty2
tty3
tty4
tty5
tty6
# End of file
EOF
# shadow
cat > $sysroot/etc/shadow << EOF
root::0::::::
bin:x:0::::::
daemon:x:0::::::
mail:x:0::::::
ftp:x:0::::::
www:x:0::::::
messagebus:x:0::::::
nobody:x:0::::::
EOF
# shells
cat > $sysroot/etc/shells << EOF
# /etc/shells: defines valid login shells
#
/bin/sh
/bin/bash
# End of file
EOF
#
touch $sysroot/var/run/utmp $sysroot/var/log/{btmp,lastlog,wtmp}
chmod -v 664 $sysroot/var/run/utmp $sysroot/var/log/lastlog
chmod -v 600 $sysroot/var/log/btmp
#
### Constructing Cross-Compile Tools
# GMP
mkdir -pv $work/gmp
cd $work/gmp
$src/$gmpv/configure --prefix=$tools \
--enable-cxx
make
make install
# MPFR
mkdir -pv $work/mpfr
cd $work/mpfr
LDFLAGS="-Wl,-rpath,$tools/lib" \
$src/$mpfrv/configure --prefix=$tools \
--enable-shared \
--with-gmp=$tools
make
make install
# MPC
mkdir -pv $work/mpc
cd $work/mpc
LDFLAGS="-Wl,-rpath,$tools/lib" \
$src/$mpcv/configure --prefix=$tools \
--enable-shared \
--with-gmp=$tools \
--with-mpfr=$tools
make
make install
# PPL
mkdir -pv $work/ppl
cd $work/ppl
LDFLAGS="-Wl,-rpath,$tools/lib" \
$src/$pplv/configure --prefix=$tools \
--enable-shared \
--enable-interfaces="c,cxx" \
--disable-optimization \
--with-libgmp-prefix=$tools \
--with-libgmpxx-prefix=$tools
make
make install
# CLOOG
mkdir -pv $work/cloog
cd $work/cloog
LDFLAGS="-Wl,-rpath,$tools/lib" \
$src/$cloogv/configure --prefix=$tools \
--enable-shared \
--with-bits=gmp \
--with-gmp=$tools \
--with-ppl=$tools
make
make install
# BINUTILS
mkdir -pv $work/binutils
cd $work/binutils
AR=ar AS=as \
$src/$binutilsv/configure --prefix=$tools \
--host=$host \
--target=$target \
--with-sysroot=$sysroot \
--disable-nls \
--enable-shared \
--disable-multilib \
--with-pkgversion="SAUX"
make configure-host
make
make install
# GCC - 1
mkdir -pv $work/gcc1
cd $work/gcc1
AR=ar LDFLAGS="-Wl,-rpath,$tools/lib" \
$src/$gccv/configure --prefix=$tools \
--build=$build \
--host=$host \
--target=$target \
--disable-multilib \
--with-sysroot=$sysroot \
--disable-nls \
--without-headers \
--with-newlib \
--disable-decimal-float \
--disable-libgomp \
--disable-libmudflap \
--disable-libssp \
--with-mpfr=$tools \
--with-gmp=$tools \
--with-mpc=$tools \
--with-ppl=$tools \
--with-cloog=$tools \
--disable-shared \
--disable-threads \
--enable-languages=c
PATH=$tools/bin:$PATH make
PATH=$tools/bin:$PATH make install
# Install kernel headers
cp -r $src/$linuxv $work/linux
cd $work/linux
PATH=$tools/bin:$PATH \
make headers_install \
ARCH=$linux_arch CROSS_COMPILE=$target- \
INSTALL_HDR_PATH=$sysroot/usr
find $sysroot/usr/include -name .install -or -name ..install.cmd | xargs
/bin/rm -fv
cp -v $src/$binutilsv/include/libiberty.h $sysroot/usr/include
# EGLIBC - HEADERS
mkdir -pv $work/eglibc-headers
cd $work/eglibc-headers
BUILD_CC=gcc \
CC=$tools/bin/$target-gcc \
AR=$tools/bin/$target-ar \
RANLIB=$tools/bin/$target-ranlib \
$src/$eglibcv/configure --prefix=/usr \
--with-headers=$sysroot/usr/include \
--build=$build \
--host=$target \
--disable-profile \
--without-gd \
--without-cvs \
--enable-add-ons
make install-headers install_root=$sysroot \
install-bootstrap-headers=yes
#
#
#
mkdir -pv $sysroot/usr/lib
make csu/subdir_lib
cp -v csu/{crt1.o,crti.o,crtn.o} $sysroot/usr/lib
#
$tools/bin/$target-gcc -nostdlib -nostartfiles -shared -x c /dev/null \
-o $sysroot/usr/lib/libc.so
# GCC - 2
mkdir -pv $work/gcc2
cd $work/gcc2
AR=ar LDFLAGS="-Wl,-rpath,$tools/lib" \
$src/$gccv/configure --prefix=$tools \
--build=$build \
--host=$host \
--target=$target \
--with-sysroot=$sysroot \
--disable-libssp \
--disable-libgomp \
--disable-libmudflap \
--with-mpfr=$tools \
--with-gmp=$tools \
--with-mpc=$tools \
--with-ppl=$tools \
--with-cloog=$tools \
--disable-nls \
--disable-multilib \
--disable-decimal-float \
--enable-languages=c
PATH=$tools/bin:$PATH make
PATH=$tools/bin:$PATH make install
# EGLIBC
mkdir -pv $work/eglibc
cd $work/eglibc
cat > configparms << EOF
install_root=$sysroot
EOF
CFLAGS="-march=i686 -g -O2" \
BUILD_CC=gcc \
CC=$tools/bin/$target-gcc \
AR=$tools/bin/$target-ar \
RANLIB=$tools/bin/$target-ranlib \
$src/$eglibcv/configure --prefix=/usr \
--with-headers=$sysroot/usr/include \
--build=$build \
--host=$target \
--disable-profile \
--without-gd \
--without-cvs \
--enable-add-ons \
--with-pkgversion="SAUX"
PATH=$tools/bin:$PATH make
PATH=$tools/bin:$PATH make install install_root=$sysroot
PATH=$tools/bin:$PATH make install_root=$sysroot
localedata/install-locales
ln -sfv ../usr/share/zoneinfo/UTC $sysroot/etc/localtime
mkdir -pv $sysroot/etc/ld.so.conf.d $sysroot/usr/lib/locale
rm $sysroot/usr/include/rpcsvc/{rquota.h,rquota.x}
rm -rf $sysroot/usr/share/info
#
# $sysroot/etc (host.conf,hosts,ld.so.conf,nsswitch.conf,resolv.conf)
#
# host.conf
cat > $sysroot/etc/host.conf << EOF
# /etc/host.conf: resolver configuration file
#
order hosts,bind
multi on
# End of file
EOF
# hosts
cat > $sysroot/etc/hosts << EOF
# /etc/hosts: static lookup table for host names
#
# IPv4
127.0.0.1 localhost
#<ip-address> <hostname.domain.org> <aliases>
# IPv6
#::1 ip6-localhost ip6-loopback
#fe00::0 ip6-localnet
#ff00::0 ip6-mcastprefix
#ff02::1 ip6-allnodes
#ff02::2 ip6-allrouters
#ff02::3 ip6-allhosts
# End of file
EOF
# ld.so.conf
cat > $sysroot/etc/ld.so.conf << EOF
# /etc/ld.so.conf: dynamic linker configuration file
#
include /etc/ld.so.conf.d/*.conf
# End of file
EOF
# nsswitch.conf
cat > $sysroot/etc/nsswitch.conf << EOF
# /etc/nsswitch.conf: name service switch configuration file
#
passwd: files
group: files
shadow: files
hosts: files dns
networks: files
services: files
protocols: files
rpc: files
publickey: files
ethers: files
netmasks: files
netgroup: files
bootparams: files
automount: files
aliases: files
# End of file
EOF
# resolv.conf
cat > $sysroot/etc/resolv.conf << EOF
# /etc/resolv.conf: resolver configuration file
#
#search <domain.org>
#nameserver <ip-address>
# End of file
EOF
# GCC - 3
mkdir -pv $work/gcc3
cd $work/gcc3
AR=ar LDFLAGS="-Wl,-rpath,$tools/lib" \
$src/$gccv/configure --prefix=$tools \
--build=$build \
--host=$host \
--target=$target \
--enable-c99 \
--enable-long-long \
--enable-threads=posix \
--enable-shared \
--enable-__cxa_atexit \
--disable-libssp \
--disable-libgomp \
--disable-libmudflap \
--disable-nls \
--disable-multilib \
--enable-languages=c,c++,objc \
--with-sysroot=$sysroot \
--with-mpfr=$tools \
--with-gmp=$tools \
--with-mpc=$tools \
--with-ppl=$tools \
--with-cloog=$tools \
--with-pkgversion="SAUX"
PATH=$tools/bin:$PATH make \
AS_FOR_TARGET="$target-as" \
LD_FOR_TARGET="$target-ld"
PATH=$tools/bin:$PATH make install
#
# FILE
mkdir -pv $work/file
cd $work/file
$src/$filev/configure --prefix=$tools
make
make install
# GROFF
mkdir -pv $work/groff
cd $work/groff
PAGE="A4" \
$src/$groffv/configure --prefix=$tools \
--without-x
make
make install
# SHADOW
cd $src/$shadowv
patch -Np1 -i ../shadow-4.1.4.2-sysroot_hacks-1.patch
mkdir -pv $work/shadow
cd $work/shadow
cat > config.cache << EOF
shadow_cv_passwd_dir=$sysroot/bin"
EOF
cat >> config.cache << EOF
ac_cv_func_lckpwdf=no
EOF
$src/$shadowv/configure --prefix=$tools \
--sbindir=$tools/bin \
--sysconfdir=$sysroot/etc \
--disable-shared \
--without-libpam \
--without-audit \
--without-selinux \
--program-prefix=$target- \
--without-nscd
cp config.h{,.orig}
sed "/PASSWD_PROGRAM/s/passwd/$target-&/" config.h.orig > config.h
make
make install
# NCURSES
cd $src/$ncursesv
patch -Np1 -i ../ncurses-5.7-bash_fix-1.patch
mkdir -pv $work/ncurses
cd $work/ncurses
$src/$ncursesv//configure --prefix=$tools \
--without-debug \
--without-shared
make -C include
make -C progs tic
install -m755 progs/tic $tools/bin
#
echo ""
echo " == FINISH == :-)"
echo ""
echo " == Warning: Before you install other packages,
== add the variable PATH - /mnt/sysroot/tools/bin"
# End of file
Milan Buska
--
Remember, no question is too stupid and no problem too small
-- We've all been beginners
More information about the Clfs-support
mailing list