#!/bin/sh # # The original script is # Copyright (C) 2001 David McCullough # Modifications: # Copyright (C) 2001 Adrian von Bidder # # This one here is modified to allow for # - gcc-3.0 and new binutils # - installation as non-root # - source is in cvs, not in tarballs # # Prerequisites: # - directories without versions, all necessary patches applied: # - gcc: gcc-core and gcc-c++, edit GCCVER. # - binutils: I tested with 2.11.2 # - elf2flt: make sure it's elf2flt-20011217 or newer # - genromfs: never had any problems here. # - uClibc: uClibc cvs 20011219 or newer # - ../linux: uClinux sources, make sure fs/binfmt_flat.c is new enough # (again: 20011219 should do). # - a recent enough native x86 C compiler # - kernel tree must be configured (make config) # # Installation # a arm-uclinux-... toolchain will be installed in ${INSTDIR} - adjust # as necessary. Any tools present in that directory will be overwritten. # ############################################################# # # our build starts here # BASEDIR="`pwd`" ############################################################# # # EDIT these to suit your system and source locations # MAKE=make UCLIBC="$BASEDIR/uClibc" KERNEL="$BASEDIR/../linux" INSTDIR="$BASEDIR/../toolchain" TARGET=arm-uclinux TARGETCPU=arm7tdmi GCCVER="3.0.2" ############################################################# # # mark stage done # mark() { echo "STAGE $1 - complete" touch "$BASEDIR/STAGE$1" } # # check if stage should be built # schk() { echo "--------------------------------------------------------" [ -f "$BASEDIR/STAGE$1" ] && echo "STAGE $1 - already built" && return 1 echo "STAGE $1 - needs building" return 0 } ############################################################# # # clean any previous runs # stage1() { schk 1 || return 0 # this leaves info pages and manpages lying around. Oh, well... rm -rf ${INSTDIR}/${TARGET} rm -rf ${INSTDIR}/lib/gcc-lib/${TARGET} rm -rf ${INSTDIR}/bin/${TARGET}* # clean up sources: rm -rf gcc/libstdc++-v3 mark 1 } ############################################################# # # build binutils # stage2() { schk 2 || return 0 rm -rf ${TARGET}-build-binutils mkdir ${TARGET}-build-binutils cd ${TARGET}-build-binutils ../binutils/configure --prefix=${INSTDIR} --target=${TARGET} \ --with-cpu=${TARGETCPU} ${MAKE} ${MAKE} install cd $BASEDIR rm -f ${INSTDIR}/bin/${TARGET}-ld.real mark 2 } ############################################################# # # common uClibc Config substitutions # fix_uclibc_config() { sed "s?^[ ]*KERNEL_SOURCE[ ]*=.*\$?KERNEL_SOURCE=${KERNEL}?" | if [ "${NOMMU}" ]; then sed -e "s?^[ ]*HAS_MMU[ ]*=.*\$?HAS_MMU=false?" \ -e "s?^[ ]*HAVE_SHARED[ ]*=.*\$?HAVE_SHARED=false?" \ -e "s?^[ ]*BUILD_UCLIBC_LDSO[ ]*=.*\$?BUILD_UCLIBC_LDSO=false?" \ -e "s?^[ ]*DOPIC[ ]*=.*\$?DOPIC=${1:-false}?" else cat fi } ############################################################# # # hack the env up for gcc build # stage3() { schk 3 || return 0 # # fix up the uClibc auto gen files # cd ${UCLIBC}/. fix_uclibc_config < extra/Configs/Config.${_CPU} > Config rm -f ${KERNEL}/include/asm ln -s ${KERNEL}/include/asm-${_CPU}${NOMMU} ${KERNEL}/include/asm ${MAKE} uClibc_config.h CROSS="${TARGET}-" chmod 644 uClibc_config.h rm -rf ${INSTDIR}/${TARGET}/include rm -f ${UCLIBC}/include/asm cp -r ${UCLIBC}/include ${INSTDIR}/${TARGET}/include rm -rf ${INSTDIR}/${TARGET}/include/asm rm -rf ${INSTDIR}/${TARGET}/include/bits cp -r ${UCLIBC}/libc/sysdeps/linux/${_CPU}/bits \ ${INSTDIR}/${TARGET}/include/. cp uClibc_config.h ${INSTDIR}/${TARGET}/include/bits/. rm -rf ${INSTDIR}/${TARGET}/include/linux cp -r ${KERNEL}/include/linux ${INSTDIR}/${TARGET}/include/linux touch ${INSTDIR}/${TARGET}/include/linux/autoconf.h cp -r ${KERNEL}/include/asm-${_CPU}${NOMMU} \ ${INSTDIR}/${TARGET}/include/. # 2.4 headers also need this (may not be there for some archs) cp -r ${KERNEL}/include/asm-${_CPU} ${INSTDIR}/${TARGET}/include/. ||\ true ln -s ${INSTDIR}/${TARGET}/include/asm-${_CPU}${NOMMU} \ ${INSTDIR}/${TARGET}/include/asm case ${TARGET} in arm*) ln -s ${INSTDIR}/${TARGET}/include/asm-${_CPU}${NOMMU}/proc-armv \ ${INSTDIR}/${TARGET}/include/asm/proc ;; esac # # clean out any CVS files, don't fail on this one # set +e find ${INSTDIR}/${TARGET}/include -name CVS | xargs rm -rf set -e mkdir -p ${INSTDIR}/lib/gcc-lib || true chmod 755 ${INSTDIR}/lib/gcc-lib cd $BASEDIR mark 3 } ############################################################# # # first pass, just the C compiler so we can build uClibc # stage4() { schk 4 || return 0 rm -rf ${TARGET}-build-gcc mkdir ${TARGET}-build-gcc cd ${TARGET}-build-gcc ../gcc/configure --prefix=${INSTDIR} --target=${TARGET} \ --with-cpu=${TARGETCPU} --enable-languages=c ${MAKE} ${MAKE} install cd $BASEDIR mark 4 } ############################################################# # # build uCLibc with first pass compiler # stage5() { schk 5 || return 0 cd ${UCLIBC}/. fix_uclibc_config < extra/Configs/Config.${_CPU} > Config rm -f ${KERNEL}/include/asm ln -s ${KERNEL}/include/asm-${_CPU}${NOMMU} ${KERNEL}/include/asm ${MAKE} clean CROSS="${TARGET}-" ${MAKE} CROSS="${TARGET}-" cd $BASEDIR mark 5 } ############################################################# # # second pass, build everything, all compilers of use :-) # stage6() { schk 6 || return 0 # # We need these files for the configure parts of this stage # cp ${UCLIBC}/lib/libc.a ${INSTDIR}/${TARGET}/lib/. cp ${UCLIBC}/lib/crt0.o ${INSTDIR}/${TARGET}/lib/. rm -rf ${TARGET}-build-gcc mkdir ${TARGET}-build-gcc cd ${TARGET}-build-gcc # case "${TARGET}" in # arm-*) ar rv ${INSTDIR}/${TARGET}/lib/libg.a ;; # create if not there # esac case "${TARGET}" in sh-*) ../gcc/configure --prefix=${INSTDIR} --enable-languages=c \ --target=${TARGET} --with-cpu=${TARGETCPU} --enable-multilib ${MAKE} LIBS=-lc ${MAKE} install ;; *) ../gcc/configure --prefix=${INSTDIR} --enable-languages=c,c++ \ --target=${TARGET} --with-cpu=${TARGETCPU} --enable-multilib ${MAKE} LIBS=-lc ${MAKE} install ;; esac # # Don't leave these around as they will not work for all targets # If you want uClibc-multilib, build that later # rm -f ${INSTDIR}/${TARGET}/lib/libc.a rm -f ${INSTDIR}/${TARGET}/lib/crt0.o cd $BASEDIR mark 6 } ############################################################# # # build genromfs # stage7() { schk 7 || return 0 rm -rf build-genromfs cp -a genromfs build-genromfs cd build-genromfs ${MAKE} cp genromfs ${INSTDIR}/bin/. chmod 755 ${INSTDIR}/bin/genromfs cd $BASEDIR mark 7 } ############################################################# # # build elf2flt # stage8() { schk 8 || return 0 rm -rf build-elf2flt cp -a elf2flt build-elf2flt cd build-elf2flt mv Makefile Makefile.tmp echo "EXTRA_CFLAGS=-DTARGET_${_CPU}" > Makefile sed "s?^[ ]*PREFIX.*=.*\$?PREFIX=../${TARGET}-build-binutils?" \ < Makefile.tmp >> Makefile cp $KERNEL/include/linux/flat.h . ${MAKE} cp flthdr ${INSTDIR}/bin/${TARGET}-flthdr chmod 755 ${INSTDIR}/bin/${TARGET}-flthdr ln -f ${INSTDIR}/bin/${TARGET}-flthdr ${INSTDIR}/bin/flthdr cp elf2flt ${INSTDIR}/bin/${TARGET}-elf2flt ln -f ${INSTDIR}/bin/${TARGET}-elf2flt ${INSTDIR}/bin/elf2flt ln -f ${INSTDIR}/bin/${TARGET}-elf2flt ${INSTDIR}/${TARGET}/bin/elf2flt chmod 755 ${INSTDIR}/bin/elf2flt [ -f ${INSTDIR}/bin/${TARGET}-ld.real ] || \ cp ${INSTDIR}/bin/${TARGET}-ld ${INSTDIR}/bin/${TARGET}-ld.real [ -f ${INSTDIR}/${TARGET}/bin/ld.real ] || \ cp ${INSTDIR}/${TARGET}/bin/ld ${INSTDIR}/${TARGET}/bin/ld.real cp ld-elf2flt ${INSTDIR}/bin/${TARGET}-ld cp ld-elf2flt ${INSTDIR}/${TARGET}/bin/ld cp elf2flt.ld ${INSTDIR}/${TARGET}/lib/. cd $BASEDIR mark 8 } ############################################################# # # build multilib versions of uCLibc for a fuller install # build_uclibc_mlib() { # set -x cd ${UCLIBC}/. case "${_CPU}" in m68k*) ALL_BUILDS="-Wa,--bitwise-or -D__linux__=1" ;; *) ALL_BUILDS="-D__linux__=1" ;; esac ( echo ". $ALL_BUILDS" case "${_CPU}" in m68k*) echo "msoft-float false $ALL_BUILDS -msoft-float" echo "m5200 false $ALL_BUILDS -m5200 -Wa,-m5200" echo "m5200/msep-data true $ALL_BUILDS -m5200 -Wa,-m5200 -msep-data" echo "m5307 false $ALL_BUILDS -m5307 -Wa,-m5307" echo "m5307/msep-data true $ALL_BUILDS -m5307 -Wa,-m5307 -msep-data" echo "m68000 false $ALL_BUILDS -m68000" echo "m68000/msep-data true $ALL_BUILDS -m68000 -msep-data" echo "mcpu32 false $ALL_BUILDS -mcpu32" echo "mcpu32/msep-data true $ALL_BUILDS -mcpu32 -msep-data" ;; arm*) echo "pic true $ALL_BUILDS -fpic" ;; sh*) # don't know what is needed here yet ;; esac ) | while read mlibdir pic cflags do fix_uclibc_config $pic < extra/Configs/Config.${_CPU} | sed -e "s?^[ ]*ARCH_CFLAGS[ ]*=.*?ARCH_CFLAGS=${cflags}?g" \ > Config ${MAKE} clean CROSS="${TARGET}-" ${MAKE} CROSS="${TARGET}-" mkdir -p ${INSTDIR}/${TARGET}/lib/$mlibdir cp lib/crt0.o ${INSTDIR}/${TARGET}/lib/$mlibdir/crt0.o || exit 1 cp lib/libc.a ${INSTDIR}/${TARGET}/lib/$mlibdir/libc.a || exit 1 cp lib/libcrypt.a ${INSTDIR}/${TARGET}/lib/$mlibdir/libcrypt.a || exit 1 cp lib/libm.a ${INSTDIR}/${TARGET}/lib/$mlibdir/libm.a || exit 1 cp lib/libresolv.a ${INSTDIR}/${TARGET}/lib/$mlibdir/libresolv.a || \ exit 1 cp lib/libutil.a ${INSTDIR}/${TARGET}/lib/$mlibdir/libutil.a || exit 1 chmod 644 ${INSTDIR}/${TARGET}/lib/$mlibdir/libc.a || exit 1 chmod 644 ${INSTDIR}/${TARGET}/lib/$mlibdir/crt0.o || exit 1 done cd $BASEDIR } ############################################################# # # cleanup # clean_all() { echo "Cleaning everything up..." rm -f STAGE* rm -rf build-genromfs rm -rf build-elf2flt rm -rf ${TARGET}-build-gcc rm -rf ${TARGET}-build-binutils } ############################################################# # # main - put everything together in order. # # Some setup # case ${TARGET} in m68k*) _CPU=m68k; NOMMU=nommu ;; arm*) _CPU=arm; NOMMU=nommu ;; sh*) _CPU=sh; NOMMU= ;; esac # # first check some args # case "$1" in build) rm -f $BASEDIR/STAGE* ;; continue) # do nothing here ;; uclibc) build_uclibc_mlib exit 0 ;; clean) clean_all exit 0 ;; *) echo "usage: $0 (build|continue|clean)" >&2 echo "" echo " build = build everything from scratch." echo " continue = continue building from last error." echo " uclibc = build multilib versions of uClibc (if wanted)." echo " tar = build for distribution of binaries." echo " clean = clean all temporary files etc." exit 1 ;; esac mkdir -p $INSTDIR if [ ! -d $INSTDIR ]; then echo "target directory ($INSTDIR) must exist and be in your PATH" exit 1 fi if [ ! -f ${KERNEL}/include/linux/version.h -o \ ! -f ${KERNEL}/include/linux/autoconf.h ]; then echo "Your kernel is not configured, cannot continue." >&2 echo "The following files do not exist:" echo echo " ${KERNEL}/include/linux/version.h" echo " ${KERNEL}/include/linux/autoconf.h" echo echo "These are need by the build. You should do the following:" echo echo " cd ${KERNEL}" echo " make ARCH=${_CPU}${NOMMU} oldconfig" echo " make dep" echo echo "You should then be able to continue." exit 1 fi # set -x # debug script set -e # if anything fails, stop stage1 stage2 stage3 stage4 stage5 stage6 stage7 stage8 echo "--------------------------------------------------------" echo "Build successful !" echo "--------------------------------------------------------" #############################################################