#!/bin/bash # # I think this would be more fun if it were combined with # explanatory text in a kind of "literate build system" style. # As a result, I intend to spend as little time and energy # maintaining it as possible. # # This version just installs a standard toolchain into SYSROOT, # Since we have a /cross-toolchain directory for our cross-tools, # let's put it under there. # define all these things the way you want them. it would be # better if we just defined the ones that are missing, but that's # too much work since we're going to re-implement this in ruby. # always set these... export CLFS=/home/clfs export LC_ALL=POSIX export PATH=/cross-tools/bin:/bin:/usr/bin export CLFS_HOST=i686-cross-linux-gnu export SYSROOT=/cross-tools/sysroot unset CFLAGS unset CXXFLAGS unset CC CXX AR AS RANLIB LD STRIP if [ $# -ne 2 ] then echo "usage: $0 architecture(mipsel,mips,x86) libc(glibc,uclibc)" exit 1 fi if [ $1 == 'x86' ] then export CLFS_TARGET=i686-pc-linux-gnu export KERNEL_VERSION=2.6.25 MARCH="$(cut -d- -f1 <<< $CLFS_TARGET)" export GLIBCFLAG="-march=$MARCH -mtune=generic -g -O2" unset KERNEL_ARCH export UCLIBC_CONFIG=$CONFIG_DIR/uclibc-config-x86 export UCLIBC_MAKE_PARAM='' else if [ $1 == 'mipsel' ] then export ENDIANNESS=little export CLFS_TARGET=mipsel-unknown-linux-gnu else export ENDIANNESS=big export CLFS_TARGET=mips-unknown-linux-gnu fi export KERNEL_VERSION=2.6.23 export GLIBCFLAG="-g -O2" export KERNEL_ARCH="ARCH=mips" export UCLIBC_CONFIG=$CONFIG_DIR/uclibc-config-mips export UCLIBC_MAKE_PARAM="CROSS=${CLFS_TARGET}-" fi if [ ! -f $UCLIBC_CONFIG ] then echo "Hmm, have you not set CONFIG_DIR?" exit 2 fi export BUILD_DIR=$PWD set -e function step00_prepare_sources() { echo "STEP 00" lzma -d < ../Sources/binutils*tar.lzma | tar xf - lzma -d < ../Sources/gcc*tar.lzma | tar xf - lzma -d < ../Sources/glibc*tar.lzma | tar xf - lzma -d < ../Sources/linux*tar.lzma | tar xf - lzma -d < ../Sources/uclibc*tar.lzma | tar xf - } function step01_kernel_headers() { echo "STEP 01" cd linux* && make mrproper && make $KERNEL_ARCH headers_check && make $KERNEL_ARCH headers_install INSTALL_HDR_PATH=$SYSROOT/usr && cd ${BUILD_DIR} && echo WOOT || exit 1 } function step02_binutils() { echo "STEP 02" mkdir build-binutils && cd build-binutils ../binutils*/configure --prefix=/cross-tools \ --build=${CLFS_HOST} --target=${CLFS_TARGET} \ --disable-nls --enable-shared --disable-multilib \ --with-sysroot=$SYSROOT --with-build-sysroot=$SYSROOT && make configure-host && make && make install && cp -v ../binutils*/include/libiberty.h $SYSROOT/usr/include && cd ${BUILD_DIR} && rm -rf build-binutils && echo WOOT || exit 2 } function step03_glibc_headers() { echo "STEP 03" mkdir build-glibc && cd build-glibc CC=gcc ../glibc*/configure --prefix=/usr \ --host=${CLFS_HOST} --build=${CLFS_TARGET} \ --disable-sanity-checks --enable-kernel=${KERNEL_VERSION} \ --with-headers=$SYSROOT/usr/include \ --with-binutils=/cross-tools/${CLFS_TARGET}/bin && make cross-compiling=yes install_root=$SYSROOT install-headers && cp -v bits/stdio_lim.h $SYSROOT/usr/include/bits && touch $SYSROOT/usr/include/gnu/stubs.h && cp -v ../glibc*/nptl/sysdeps/pthread/pthread.h $SYSROOT/usr/include && cp -v ../glibc*/nptl/sysdeps/unix/sysv/linux/i386/bits/pthreadtypes.h \ $SYSROOT/usr/include/bits && cd ${BUILD_DIR} && rm -rf build-glibc && echo WOOT || exit 3 } function step03b_uclibc_headers() { echo "STEP 03" cd uclibc && make distclean && rm -f extra/config/.depend && export UC_FIXED="/cross-tools/lib/gcc/${CLFS_TARGET}/4.3.1/include-fixed" cp $UCLIBC_CONFIG .config && cat >> .config <> .config echo "ARCH_WANTS_BIG_ENDIAN=y" >> .config echo "# ARCH_WANTS_LITTLE_ENDIAN is not set" >> .config elif [ $ENDIANNESS == 'little' ] then echo "ARCH_LITTLE_ENDIAN=y" >> .config echo "# ARCH_WANTS_BIG_ENDIAN is not set" >> .config echo "ARCH_WANTS_LITTLE_ENDIAN=y" >> .config fi unset UC_FIXED make oldconfig && make PREFIX=$SYSROOT install_headers && cd ${BUILD_DIR} && echo WOOT || exit 3 } function step04_gcc_bare() { echo "STEP 04" mkdir build-gcc && cd build-gcc ../gcc*/configure --prefix=/cross-tools \ --build=${CLFS_HOST} --host=${CLFS_HOST} --target=${CLFS_TARGET} \ --disable-multilib \ --disable-nls --disable-shared \ --disable-libmudflap --disable-libssp \ --disable-threads --enable-languages=c \ --with-sysroot=$SYSROOT --with-build-sysroot=$SYSROOT && export LDFLAGS_FOR_TARGET="--sysroot=$SYSROOT" && export CPPFLAGS_FOR_TARGET="--sysroot=$SYSROOT" && make all-gcc && make install-gcc && cd ${BUILD_DIR} && echo WOOT || exit 4 } function step05_glibc_startup() { echo "STEP 05" mkdir build-glibc && cd build-glibc echo "libc_cv_forced_unwind=yes" > config.cache echo "libc_cv_c_cleanup=yes" >> config.cache BUILD_CC="gcc" CC="${CLFS_TARGET}-gcc" \ AR="${CLFS_TARGET}-ar" RANLIB="${CLFS_TARGET}-ranlib" \ CFLAGS="${GLIBCFLAG}" \ ../glibc*/configure --prefix=/usr \ --host=${CLFS_TARGET} --build=${CLFS_HOST} \ --disable-profile --enable-add-ons \ --with-tls --enable-kernel=${KERNEL_VERSION} --with-__thread \ --with-binutils=/cross-tools/bin --with-headers=$SYSROOT/usr/include \ --cache-file=config.cache && make -r -C ../glibc*/csu objdir=$(pwd) $(pwd)/csu/crt1.o && make -r -C ../glibc*/csu objdir=$(pwd) $(pwd)/csu/crti.o && make -r -C ../glibc*/csu objdir=$(pwd) $(pwd)/csu/crtn.o && mkdir -p $SYSROOT/lib && cp csu/crt{1,i,n}.o $SYSROOT/lib && cd ${BUILD_DIR} && rm -rf build-glibc && echo WOOT || exit 5 } function step05b_uclibc_startup() { # for some reason, fenv.h doesn't get set up properly by uclibc, # so we create a dummy one. echo "#define _FENV_H" > $SYSROOT/usr/include/fenv.h && echo "#include " >> $SYSROOT/usr/include/fenv.h && # also, some headers didn't get installed properly before (e.g. # uClibc_config.h) so do another install_headers at this point. echo "STEP 05" cd uclibc && make $UCLIBC_MAKE_PARAM pregen && install -d lib/ && make $UCLIBC_MAKE_PARAM lib/crt1.o && ${CLFS_TARGET}-strip -x -R .note -R .comment lib/crt1.o && make $UCLIBC_MAKE_PARAM lib/crti.o && make $UCLIBC_MAKE_PARAM lib/crtn.o && make PREFIX=$SYSROOT install_headers && mkdir $SYSROOT/lib && cp lib/crt{1,i,n}.o $SYSROOT/lib && rm -rf lib && cd ${BUILD_DIR} && echo WOOT || exit 5 # Egad. The libgcc build uses -isystem # /cross-tools/$CLFS_TARGET/include # but there is nothing there; the header files are under $SYSROOT. Why # doesn't this happen in the glibc build? echo "STEP 05.5 -- set up include symlink" pushd /cross-tools/${CLFS_TARGET} && ln -s $SYSROOT/include include && popd && echo "woot, I guess." } function step06_gcc_libgcc() { echo "STEP 06" cd build-gcc && make all-target-libgcc && make install-target-libgcc && rm -f $SYSROOT/lib/crt{1,i,n}.o && cd ${BUILD_DIR} && rm -rf build-gcc && echo WOOT || exit 6 } function step07_glibc_full() { echo "STEP 07" mkdir build-glibc && cd build-glibc && echo "libc_cv_forced_unwind=yes" > config.cache && echo "libc_cv_c_cleanup=yes" >> config.cache && BUILD_CC="gcc" CC="${CLFS_TARGET}-gcc" \ AR="${CLFS_TARGET}-ar" RANLIB="${CLFS_TARGET}-ranlib" \ CFLAGS="$GLIBCFLAG" \ ../glibc*/configure --prefix=/usr \ --host=${CLFS_TARGET} --build=${CLFS_HOST} \ --disable-profile --enable-add-ons \ --with-tls --enable-kernel=${KERNEL_VERSION} --with-__thread \ --with-binutils=/cross-tools/bin --with-headers=$SYSROOT/usr/include \ --cache-file=config.cache && make && make install_root=$SYSROOT install && cd ${BUILD_DIR} && rm -rf build-glibc && echo WOOT || exit 7 } function step07b_uclibc_full() { echo "STEP 07" cd uclibc && make $UCLIBC_MAKE_PARAM && make PREFIX=$SYSROOT install && cd ${BUILD_DIR} && echo WOOT || exit 7 } function step08_gcc_full() { echo "STEP 08" mkdir build-gcc && cd build-gcc && ../gcc*/configure --prefix=/cross-tools \ --build=${CLFS_HOST} --host=${CLFS_HOST} --target=${CLFS_TARGET} \ --disable-multilib \ --disable-nls --enable-shared \ --enable-languages=c,c++ --enable-__cxa_atexit \ --enable-c99 --enable-long-long --enable-threads=posix \ --with-sysroot=$SYSROOT --with-build-sysroot=$SYSROOT && export LDFLAGS_FOR_TARGET="--sysroot=$SYSROOT" && export CPPFLAGS_FOR_TARGET="--sysroot=$SYSROOT" && make AS_FOR_TARGET="${CLFS_TARGET}-as" LD_FOR_TARGET="${CLFS_TARGET}-ld" && rm -f /cross-tools/i686-pc-linux-gnu/include && make install && cd ${BUILD_DIR} && rm -rf build-gcc && echo WOOT || exit 8 } function step09_kernel_headers_for_tools() { echo "STEP 09" && cd linux* && make mrproper && make $KERNEL_ARCH headers_check && make $KERNEL_ARCH headers_install INSTALL_HDR_PATH=/tools && cd ${BUILD_DIR} && echo WOOT || exit 9 } function step09b_uclibc_utilities() { cd uclibc && make $UCLIBC_MAKE_PARAM utils && make PREFIX=$SYSROOT install_utils && cd ${BUILD_DIR} && echo WOOT || exit 9 } function step10_glibc_tools() { echo "STEP 10" mkdir build-glibc && cd build-glibc echo "libc_cv_forced_unwind=yes" > config.cache echo "libc_cv_c_cleanup=yes" >> config.cache BUILD_CC="gcc" CC="${CLFS_TARGET}-gcc" \ AR="${CLFS_TARGET}-ar" RANLIB="${CLFS_TARGET}-ranlib" \ CFLAGS="$GLIBCFLAG" \ ../glibc*/configure --prefix=/tools \ --host=${CLFS_TARGET} --build=${CLFS_HOST} \ --disable-profile --enable-add-ons \ --with-tls --enable-kernel=${KERNEL_VERSION} --with-__thread \ --with-binutils=/cross-tools/bin --with-headers=/tools/include \ --cache-file=config.cache && make && make install_root=$CLFS install && cd ${BUILD_DIR} rm -rf build-glibc echo WOOT } function step11_specs() { echo "STEP 11" ${CLFS_TARGET}-gcc -dumpspecs | sed -e 's@/lib/ld@/tools/lib/ld@g' > \ $(dirname $(${CLFS_TARGET}-gcc --print-libgcc-file-name))/specs } echo "clearing out old stuff, I hope that's what you wanted." rm -rf $CLFS/{etc,lib,sbin,usr,tools,cross-tools,uclibc} mkdir -p $CLFS/tools mkdir -p $CLFS/cross-tools rm -rf build-binutils build-glibc build-gcc if [ -d ${BUILD_DIR}/Logs ] then mv ${BUILD_DIR}/Logs ${BUILD_DIR}/Logs-$(date "+%Y-%m-%d-%H%M%S") fi mkdir ${BUILD_DIR}/Logs echo "Starting at $(date)" > ${BUILD_DIR}/Logs/timing.txt if [ ! -d binutils* ] then step00_prepare_sources > ${BUILD_DIR}/Logs/step00.txt fi if [ $2 == 'glibc' ] then step01_kernel_headers > ${BUILD_DIR}/Logs/step01.txt 2>&1 step02_binutils > ${BUILD_DIR}/Logs/step02.txt 2>&1 step03_glibc_headers > ${BUILD_DIR}/Logs/step03.txt 2>&1 step04_gcc_bare > ${BUILD_DIR}/Logs/step04.txt 2>&1 step05_glibc_startup > ${BUILD_DIR}/Logs/step05.txt 2>&1 step06_gcc_libgcc > ${BUILD_DIR}/Logs/step06.txt 2>&1 step07_glibc_full > ${BUILD_DIR}/Logs/step07.txt 2>&1 step08_gcc_full > ${BUILD_DIR}/Logs/step08.txt 2>&1 step09_kernel_headers_for_tools > ${BUILD_DIR}/Logs/step09.txt 2>&1 step10_glibc_tools > ${BUILD_DIR}/Logs/step10.txt 2>&1 step11_specs > ${BUILD_DIR}/Logs/step11.txt 2>&1 else step01_kernel_headers > ${BUILD_DIR}/Logs/step01.txt 2>&1 step02_binutils > ${BUILD_DIR}/Logs/step02.txt 2>&1 step03b_uclibc_headers > ${BUILD_DIR}/Logs/step03.txt 2>&1 step04_gcc_bare > ${BUILD_DIR}/Logs/step04.txt 2>&1 step05b_uclibc_startup > ${BUILD_DIR}/Logs/step05.txt 2>&1 step06_gcc_libgcc > ${BUILD_DIR}/Logs/step06.txt 2>&1 step07b_uclibc_full > ${BUILD_DIR}/Logs/step07.txt 2>&1 step08_gcc_full > ${BUILD_DIR}/Logs/step08.txt 2>&1 step09b_uclibc_utilities > ${BUILD_DIR}/Logs/step09.txt 2>&1 fi echo "Ended at $(date)" >> ${BUILD_DIR}/Logs/timing.txt echo "WOOT WOOT WOOT WOOT"