This is the mail archive of the crossgcc@sources.redhat.com mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more information.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Updating Bill's wonderful script


>Has anyone updated Bill's script along those lines?

I've made extensive modifications to Bill's script, mostly to allow
for me to build from CVS trees where I've got many different versions
of the tools lying around.  Alos dump in a logfile that indicates
what's being built. You can specify the *DISTO variables on the
command line, it creates a target named directory under the objdir
directory(so I can mix and match targets for particular
versions). I've also added m68k targets. 

I can't guarentee that this script arrives intact, much less works.
I have succesfully built m68k-elf and (a couple of times) m68k-linux
toolchains using this script.  

To use it, place this script in a directory that has subdirectories
holding all the tolls (gcc-3.*, binutils-2.*, glibc-2.*, etc) and fire
it up, kinda like:

 $ GCCDISTO=gcc-304 BINUTILSDISTO=binutils-2 NEWLIBDISTO=newlib-1.9.0 GDBDISTO=gdb-5 bash build-crossgcc.sh

Good luck!

-- 
Peter Barada                                   Peter.Barada@motorola.com
Wizard                                         781-852-2768 (direct)
WaveMark Solutions(wholly owned by Motorola)   781-270-0193 (fax)


#!/bin/bash
#
# build-crossgcc.sh
#
# Copyright (c) 2001 by Bill Gatliff, bgat@billgatliff.com All rights
# reserved.  This script is provided under the terms of the GPL.
#
# $Id: build-crossgcc.sh,v 1.10 2002/07/29 21:38:32 pbarada Exp $
#
# This script automates the tool build process for arm-linux,
# powerpc-linux, and other crosscompilers.  Over time, it will be
# extended for lots of other configurations as well.
#
# To use this script, first download copies of the binutils, gcc,
# glibc and your Linux kernel tarballs into a single directory, say,
# ~/tars.  See the declarations of LINUXDISTO, GCCDISTO, etc. below to
# know what versions of the files you need, or change them as
# appropriate.
#
# This script has been tested with the following versions:
#
# binutils-2.10.1 gcc-2.95.3 linux-2.4.3 glibc-2.2.2
# glibc-linuxthreads-2.2.2 newlib-1.9.0
#
#
# For the moment, you're on your own if you use different versions,
# although I would be interested in hearing both success and failure
# stories.
#
# Above all, THINK.  Avoid just sending me an "it didn't work" email.
#
# You will need about 1GB of disk space to build a *-linux cross
# toolchain, and about 500MB for a non *-linux one.
#
# The first line in this script should point to your "bash"
# executable.  usually, just !/bin/sh will do it; sometimes
# (especially if you're running GNU tools on a non-GNU host, like
# solaris8), you need to set it to something like
# !/usr/local/bin/bash.
#
# Some targets need a preconfigured kernel tree (as opposed to just a
# raw one).  If the target you select falls into this category, then
# this script will dump you over to menuconfig, or manually configure
# a kernel itself at the appropriate time.  If you end up in
# menuconfig, simply focus on the System Type configuration, because
# that's all we're interested in.
#
# <aside>
#
# When you do finally build your kernel (the script doesn't do this
# for you), you'll either have to hack the top-level Linux Makefile,
# or you'll need to do something like this:
#
# make ARCH=arm CROSS_COMPILE=arm-linux-
#
# If you're running a target-specific Linux kernel, this may already
# have been done for you.
#
# </aside>
#
# RUN THIS SCRIPT IN ITS OWN DIRECTORY.  It makes lots of
# subdirectories, and isn't very smart about not clobbering something
# useful that may be in its way.
#
# DO NOT RUN THIS SCRIPT AS ROOT, because if you do and something goes
# wrong (a bug in the script, or an incorrect PREFIX definition), then
# you can really hose things up on your workstation.  Instead, as root
# simply create a directory like /opt, chmod 777 it, and then return
# to non-root and aim PREFIX over to the new directory. At least then
# if the script really runs wild, you won't clobber important system
# stuff.
#
# Sample invocations:
#
#     build-crossgcc.sh
#
# You can also pre-specify the information this script needs, like this:
#
#     PREFIX=/home/me TARGET=arm-linux BINUTILSDISTO=binutils-2.12 \
#          build-crossgcc.sh 2>&1 | tee build.log
#
# PREFIX is the installation location.
# TARGET is the type of toolchain you want.
# LINUXDISTO is the location where you'll get headers for *linux targets
# BINUTILSDISTO is where binutils source is
# GCCDISTO is where GCC is
# NEWLIBDISTO is where newlib is
# GLIBCDISTO is where glibc is
# GDBDISTO is where gdb is
#
# For questions, comments or improvements see the crossgcc mailing
# list at http://sources.redhat.com/ml/crossgcc, or contact the
# author.
#
# TODO: error handling.  If a step fails, we currently blindly continue.
#       idea: test for the existence of the build products after each step.
# TODO: add capability to use a preexisting linux kernel source tree.
#


DEFAULT_PREFIX=/tmp/junk
DEFAULT_OBJDIR=obj

REVISION="$Id: build-crossgcc.sh,v 1.10 2002/07/29 21:38:32 pbarada Exp $"
BASEDIR=`pwd`
TARGET_LIST="arm-elf arm-linux h8300-coff m68k-coff m68k-elf m68k-linux powerpc-linux powerpc-eabi sh-elf sh-hms"


echo
echo Linux crosscompiler building script,
echo revision $REVISION
echo
echo Building in $BASEDIR
echo

#
# Tweak these for the versions you will use.  Their names must
# correspond to the base names of the tarballs they come from,
# i.e. if you define BINUTILSDISTO=my-binutils.
#
if [ x${BINUTILSDISTO} = x ] ; then
BINUTILSDISTO=binutils-2.12
fi
if [ x${GCCDISTO} = x ] ; then
GCCDISTO=gcc-3.0.4
fi
if [ x${LINUXDISTO} = x ] ; then
LINUXDISTO=linux-2.4.3
fi
if [ x${GLIBCDISTO} = x ] ; then
GLIBCDISTO=glibc-2.2.4
GLIBCTHREADSDISTO=glibc-linuxthreads-2.2.2
fi
if [ x${NEWLIBDISTO} = x ] ; then
NEWLIBDISTO=newlib-1.9.0
fi
if [ x${GDBDISTO} = x ] ; then
GDBDISTO=gdb-5.2
fi
if [ x${LANGUAGES} = x ]; then
LANGUAGES=c,c++
fi

echo " binutils:   " ${BINUTILSDISTO}
echo " gcc:        " ${GCCDISTO}
echo "  languages: " ${LANGUAGES}
echo " gdb:        " ${GDBDISTO}
echo " newlib:     " ${NEWLIBDISTO}
echo " glibc:      " ${GLIBCDISTO}
echo " linux:      " ${LINUXDISTO}
echo

# only prompt if we're missing information
if [ x${TARGET} = x ] ; then
  PS3="Please select a target: "
  select TARGET in ${TARGET_LIST};
    do echo; break; done
fi

if [ x${PREFIX} = x ]; then
  PREFIX=${DEFAULT_PREFIX}/${TARGET}
  echo "Install the tools where?"
  read -p "[${PREFIX}]: "
  if [ x${REPLY} != x ]; then PREFIX=$REPLY; fi
  echo
fi

if [ x${OBJDIR} = x ] ; then
  OBJDIR=${DEFAULT_OBJDIR}
  echo "Object directory name to use?"
  read -p "[${OBJDIR}]: "
  if [ x${REPLY} != x ]; then OBJDIR=$REPLY; fi
  echo
fi


# test that we have write permissions to the install dir
mkdir -p ${PREFIX}/${TARGET}
touch ${PREFIX}/${TARGET}/test-if-write
if [ ! -f ${PREFIX}/${TARGET}/test-if-write ]; then
    echo "You don't appear to have write permissions to ${PREFIX}/${TARGET}."
    echo "You must fix that before continuing."
    exit
fi

mkdir -p ${OBJDIR}/${TARGET}
LOGFILE=${OBJDIR}/${TARGET}/build-crossgcc.log
rm -f ${LOGFILE}

echo Building for:			> ${LOGFILE}
echo "    --target=$TARGET"		>> ${LOGFILE}
echo "    --prefix=$PREFIX"		>> ${LOGFILE}
echo "    objdir=$OBJDIR"		>> ${LOGFILE}
echo					>> ${LOGFILE}
echo " binutils:   " ${BINUTILSDISTO}	>> ${LOGFILE}
echo " gcc:        " ${GCCDISTO}	>> ${LOGFILE}
echo "  languages: " ${LANGUAGES}	>> ${LOGFILE}
echo " gdb:        " ${GDBDISTO}	>> ${LOGFILE}
echo " newlib:     " ${NEWLIBDISTO}	>> ${LOGFILE}
echo " glibc:      " ${GLIBCDISTO}	>> ${LOGFILE}
echo " linux:      " ${LINUXDISTO}	>> ${LOGFILE}

cat ${LOGFILE}

###
#
# Don't modify anything below here, unless you're fixing bugs.
#


# make sure the build product's binaries are in the search path

export PATH=${PATH}:${PREFIX}/bin


# map TARGET to Linux equivalent, if applicable
case $TARGET in
    m68k-linux) ARCH=m68k ;;
    powerpc-linux) ARCH=ppc ;;
    arm-linux)  ARCH=arm ;;
esac



#
# get Linux headers, if we need them
#
case $TARGET in

    powerpc-linux | arm-linux | m68k-linux)
    
	echo
	echo Configuring and installing linux headers. 

#	gunzip -c ${TARDIR}/${LINUXDISTO}.tar.gz | tar $TARFLAGS - 
#	mv linux $LINUXDISTO
	;;

esac


#
# some headers need tweaking before use, so tweak and install
#
case $TARGET in

    powerpc-linux | m68k-linux)

	# we don't need to do anything funky with the kernel first,
	# so just grab the parts we need, and go
	pushd $LINUXDISTO
	make ARCH=$ARCH symlinks include/linux/version.h

	echo mkdir -p ${PREFIX}/${TARGET}/include
	mkdir -p ${PREFIX}/${TARGET}/include
	echo cp -r include/linux ${PREFIX}/${TARGET}/include/linux
	cp -r include/linux ${PREFIX}/${TARGET}/include/linux
	echo cp -r include/asm-${ARCH} ${PREFIX}/${TARGET}/include/asm
	cp -r include/asm-${ARCH} ${PREFIX}/${TARGET}/include/asm
	popd

	;;

    arm-linux)

	# we need target-specific and platform-specific headers, so
        # that we can build the right libgcc2 and glibc.

	echo "This target requires configured kernel headers."
	echo "(actually, it just needs ARM processor and platform selections---"
	echo "the rest you can do later, after the tools are built)"
	read -p "Press ENTER to run menuconfig."

	# don't try to combine these two, the dependencies in the makefile
	# cause symlinks to get run before menuconfig, which is wrong here
        # TODO: this is currently broken.

	pushd $LINUXDISTO
	make ARCH=$ARCH menuconfig
	make ARCH=$ARCH symlinks include/linux/version.h

	mkdir -p ${PREFIX}/${TARGET}/include
	cp -r include/linux ${PREFIX}/${TARGET}/include
	cp -r include/asm-${ARCH} ${PREFIX}/${TARGET}/include/asm
	popd

	;;

esac



#
# build binutils
#

echo
echo --- Building binutils.

mkdir -p ${OBJDIR}/${TARGET}/binutils
pushd ${OBJDIR}/${TARGET}/binutils
${BASEDIR}/${BINUTILSDISTO}/configure --target=$TARGET --prefix=$PREFIX \
    2>&1 | tee configure.log
make all install 2>&1 | tee make.log
popd

# test to see if this step passed
if [ ! -f ${PREFIX}/bin/${TARGET}-ld ]; then
    echo --- Build failed during binutils && exit 1
fi


#
# build gcc-bootstrap
#

echo
echo --- Building gcc-bootstrap.

mkdir -p ${OBJDIR}/${TARGET}/gcc-bootstrap
pushd ${OBJDIR}/${TARGET}/gcc-bootstrap

case $TARGET in

    arm-linux)

    # like the above, only we have to modify gcc/config/arm/t-linux,
    # for reasons I can't entirely explain right now.  One would
    # *think* that the procedure above for powerpc-eabi et al would be
    # fine...

    # we add -D__gthr_posix_h and -Dinhibit_libc to
    # TARGET_LIBGCC2_CFLAGS, so that libgcc2 will be built without
    # needing "gthr" (gnu pthreads).

#    mv ${BASEDIR}/${GCCDISTO}-core/gcc/config/arm/t-linux \
#	${BASEDIR}/${GCCDISTO}-core/gcc/config/arm/t-linux-original
    sed "s/TARGET_LIBGCC2_CFLAGS =/TARGET_LIBGCC2_CFLAGS = -D__gthr_posix_h -Dinhibit_libc/" \
	< ${BASEDIR}/${GCCDISTO}-core/gcc/config/arm/t-linux-original \
	> ${BASEDIR}/${GCCDISTO}-core/gcc/config/arm/t-linux

    # now configure

    ${BASEDIR}/${GCCDISTO}/configure --target=$TARGET --prefix=$PREFIX \
	--enable-languages=c --without-headers --with-newlib \
	--with-local-prefix=${PREFIX}/${TARGET} \
	2>&1 | tee configure.log
    ;;

    * )

    # for these targets, gcc's libgcc2 assumes the presence of some
    # header files that we won't have until after glibc or newlib are
    # built.  When we throw in --without-headers --without-newlib, the
    # configure process throws in a:
    #
    # TARGET_LIBGCC2_CFLAGS=-Dinhibit_libc
    #
    # in the makefiles, to cut out pieces of libgcc code that need
    # target-specific header files.
    #
    # the result is a compiler that *almost* works, that should only
    # be used to build libraries and target-specific header files.
    # After we we do that, we build a full-up gcc crosscompiler.

    # first, configure

    ${BASEDIR}/${GCCDISTO}/configure --target=$TARGET --prefix=$PREFIX \
	--enable-languages=c --with-local-prefix=${PREFIX}/${TARGET} \
	--without-headers --with-newlib --disable-shared --verbose \
	2>&1 | tee configure.log

    ;;


esac

# with that done, now we can make and install gcc-bootstrap
make all-gcc install-gcc 2>&1 | tee make.log

echo "Done building gcc-bootstrap."
popd


# test to see if this step passed
if [ ! -f ${PREFIX}/bin/${TARGET}-gcc ]; then
    echo --- Build failed during gcc-bootstrap && exit 1
fi

echo "Building libc."

#
# build glibc or newlib, as appropriate
#

case $TARGET in 

# these targets use glibc
    arm-linux | powerpc-linux | m68k-linux)

    echo
    echo --- Building glibc and linuxthreads.

#    gunzip -c ${TARDIR}/${GLIBCDISTO}.tar.gz | tar $TARFLAGS - 
#    cd ${GLIBCDISTO}
#    gunzip -c ${TARDIR}/${GLIBCTHREADSDISTO}.tar.gz | tar $TARFLAGS - 
#    cd ..
    mkdir -p ${OBJDIR}/${TARGET}/glibc
pushd ${OBJDIR}/${TARGET}/glibc

    CC=${TARGET}-gcc AR=${TARGET}-ar RANLIB=${TARGET}-ranlib \
	${BASEDIR}/${GLIBCDISTO}/configure --host=$TARGET --prefix=${PREFIX}/${TARGET} \
	--enable-add-ons=linuxthreads --with-headers=${PREFIX}/${TARGET}/include \
	2>&1 | tee configure.log
    ;;

# these targets use newlib
    *-elf | *-coff | powerpc-eabi | sh-hms)

    echo
    echo --- Building newlib.

    mkdir -p ${OBJDIR}/${TARGET}/newlib

pushd ${OBJDIR}/${TARGET}/newlib
    ${BASEDIR}/${NEWLIBDISTO}/configure --target=$TARGET --prefix=$PREFIX \
	2>&1 | tee configure.log

    ;;

    *)
    echo "Huh? target is" $TARGET
    ;;

esac


make all install info install-info 2>&1 | tee make.log
popd

# test to see if this step passed
if [ ! -f ${PREFIX}/${TARGET}/lib/libc.a ]; then
    echo --- Building libc failed && exit 1
fi


#
# finally, build a full-up gcc c/c++ compiler
#


echo
echo --- Building gcc.

mkdir -p ${OBJDIR}/${TARGET}/gcc
pushd ${OBJDIR}/${TARGET}/gcc

case $TARGET in

    *-linux)
# glibc compilers just build straight
${BASEDIR}/${GCCDISTO}/configure --target=$TARGET --prefix=$PREFIX \
    --enable-languages=${LANGUAGES} --with-local-prefix=${PREFIX}/${TARGET} \
    2>&1 | tee configure.log
    ;;

    *)
# newlib compilers need to add --with-newlib to the configure line
${BASEDIR}/${GCCDISTO}/configure --target=$TARGET --prefix=$PREFIX \
    --enable-languages=${LANGUAGES} --with-local-prefix=${PREFIX}/${TARGET} \
    --with-newlib 2>&1 | tee configure.log
    ;;

esac


case $TARGET in

    powerpc-eabi)

    # powerpc-eabi doesn't come with a "default" build target, so to
    # the configuration process, the compiler looks broken because it
    # won't link to produce executables (because it doesn't know what
    # linker command file to use).  To fix that, we just specify a
    # build target.  This doesn't affect anything other than it lets
    # the configuration steps that happen internal to the build
    # process know that the compiler indeed works.

    make all install 2>&1 | tee make.log
    make CFLAGS="-myellowknife -O" all 2>&1 | tee -a make.log
    make install 2>&1 | tee -a make.log

    ;;


    *)

    # everyone else can use the standard procedure

    make all install 2>&1 | tee make.log

    ;;
esac

# test to see if this step passed
if [ ! -f ${PREFIX}/bin/${TARGET}-gcc ]; then
    echo --- Build failed during gcc && exit 1
fi

popd

echo
echo --- Building gdb.

mkdir -p ${OBJDIR}/${TARGET}/gdb ; pushd ${OBJDIR}/${TARGET}/gdb
${BASEDIR}/${GDBDISTO}/configure --target=$TARGET --prefix=${PREFIX} \
    2>&1 | tee configure.log

make all install

# test to see if this step passed
if [ ! -f ${PREFIX}/bin/${TARGET}-gdb ]; then
    echo --- Build failed during gdb && exit 1
fi

popd

------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sources.redhat.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]