a partial first attempt at a rewrite of crosstool

Robert P. J. Day rpjday@mindspring.com
Tue Sep 30 21:01:00 GMT 2003


  only partway through my redesign, but here's what i have so far -- 
some of it's obviously temporary.

  currently (but this will change later), all of my setup variables 
are stuffed into a single file, allvars.conf, which is passed as an
argument to my main script, btc.sh (BuildToolChain.sh), and any other
args are after that.

  sample invocation:

  $ sh btc.sh allvars.conf --nounpack  etc ... etc ...

sample allvars.conf:
---------------------------------------------------------------------
#
#  crosstool info
#
CROSSTOOL_DIR=/embedded/ct			# helper
PATCHES_DIR=${CROSSTOOL_DIR}/patches
KERNEL_CONFIGS_DIR=${CROSSTOOL_DIR}/configs
#
#  source and unloading info
#
TARBALLS_DIR=/embedded/tarballs			# helper

BINUTILS_SRC=${TARBALLS_DIR}/binutils-2.14.tar.gz
GCC_SRC=${TARBALLS_DIR}/gcc-3.3.1.tar.gz
GLIBC_SRC=${TARBALLS_DIR}/glibc-2.3.2.tar.bz2
GLIBC_LINUXTHREADS_SRC=$(echo $GLIBC_SRC | sed 's/glibc-/glibc-linuxthreads-/')
KERNEL_SRC=/home/rpjday/build/kernel/linux-2.6.0-test6.tar.bz2
COMBOCODE=rday

PATCHED_SOURCES_DIR=/embedded/patched_sources
KERNELS_DIR=/embedded/kernels
#
#  architecture info
#
TARGET=arm-linux
TARGET_CFLAGS="-O"
KERNEL_CONFIG_FILE=${KERNEL_CONFIGS_DIR}/arm.config
#
#  project and build info
#
PROJECT=z5500
PRJROOT=/embedded/projects/${PROJECT}
BUILD_DIR=${PRJROOT}/${COMBOCODE}/build
PREFIX=${PRJROOT}/${COMBOCODE}/tools
---------------------------------------------------------------------

  sample btc.sh, with plenty of common code stuffed into helper functions
to cut down on the main routine.  note that i bail out of the main routine
fairly early since i'm still converting, but i'm interested in feedback.

btc.sh
----------------------------------------------------------------------
#!/bin/sh

##########################################################
#
#  Input validation functions.
#
##########################################################
abort () {
	echo "$@"
	exit 1
}

validate_all_input () {

	verify_set_variables

	verify_existing_objects \
		${PATCHES_DIR} \
		${KERNEL_CONFIGS_DIR} \
		${GCC_SRC} \
		${GLIBC_SRC} \
		${GLIBC_LINUXTHREADS_SRC} \
		${BINUTILS_SRC} \
		${KERNEL_SRC}

	verify_output_directories \
		${PATCHED_SOURCES_DIR} \
		${BUILD_DIR} \
		${PREFIX}
		
}
#
#  All of these variables should at least be non-empty.
#
verify_set_variables() {

	: ${PATCHES_DIR?"error, unset variable"}
	: ${KERNEL_CONFIGS_DIR?"error, unset variable"}

	: ${GCC_SRC?"error, unset variable"}
	: ${GLIBC_SRC?"error, unset variable"}
	: ${GLIBC_LINUXTHREADS_SRC?"error, unset variable"}
	: ${BINUTILS_SRC?"error, unset variable"}
	: ${KERNEL_SRC?"error, unset variable"}
	: ${PATCHED_SOURCES_DIR?"error, unset variable"}
	: ${COMBOCODE?"error, unset variable"}

	: ${TARGET?"error, unset variable"}
	: ${TARGET_CFLAGS?"error, unset variable"}
	: ${KERNEL_CONFIG_FILE?"error, unset variable"}

	: ${PROJECT?"error, unset variable"}
	: ${BUILD_DIR?"error, unset variable"}
	: ${PREFIX?"error, unset variable"}

}
#
#  All of the file/directory arguments to this function should exist.
#
verify_existing_objects () {
	for obj in $* ; do
		test -e $obj || abort "Error, required object $obj does not exist, exiting."
	done
}
#
#  All of the directory arguments to this function should either exist and be
# writable, or they should be creatable.
#
verify_output_directories () {
	for dir in $* ; do
		if test -d $dir ; then
			test -w $dir || abort "Directory $dir is not writable by you, exiting."
			continue
		fi
		mkdir -p $dir || abort "Non-existent output dir $dir can't be created, exiting."
	done
}

##########################################################
#
#  Lots of helper functions.
#
##########################################################

set_helper_variables () {

GCC_VER=$(basename $(strip_archive_suffix "$GCC_SRC"))
GLIBC_VER=$(basename $(strip_archive_suffix "$GLIBC_SRC"))
BINUTILS_VER=$(basename $(strip_archive_suffix "$BINUTILS_SRC"))
KERNEL_VER=$(basename $(strip_archive_suffix "$KERNEL_SRC"))
GLIBC_LINUXTHREADS_VER=$(basename $(strip_archive_suffix "$GLIBC_LINUXTHREADS_SRC"))

GCC_SRC_DIR=${PATCHED_SOURCES_DIR}/${GCC_VER}
GLIBC_SRC_DIR=${PATCHED_SOURCES_DIR}/${GLIBC_VER}
BINUTILS_SRC_DIR=${PATCHED_SOURCES_DIR}/${BINUTILS_VER}
KERNEL_SRC_DIR=${PATCHED_SOURCES_DIR}/${KERNEL_VER}

GCC_BUILD_DIR=${BUILD_DIR}/${GCC_VER}
GLIBC_BUILD_DIR=${BUILD_DIR}/${GLIBC_VER}
BINUTILS_BUILD_DIR=${BUILD_DIR}/${BINUTILS_VER}
KERNEL_BUILD_DIR=${BUILD_DIR}/${KERNEL_VER}

ARCH=$(map_target_to_arch $TARGET)
}

strip_archive_suffix () {
	echo $1 | sed 's,\.tar\.gz$,, ; s,\.tar\.bz2$,, ; s,\.tgz$,,;'
}

unpack_archive_into_directory () {

	ARCHIVE=$1
	DIR=$2

	test -w $DIR || abort "Trying to unpack into non-writable directory $DIR, exiting."

	case $ARCHIVE in 
		*tar.gz)	tar xzf $ARCHIVE -C $DIR ;;
		*tgz)		tar xzf $ARCHIVE -C $DIR ;;
		*tar.bz2)	tar xjf $ARCHIVE -C $DIR ;;
	esac
}

apply_patches_to_directory () {

	DIR=$1 ; shift

	for patch in $* ; do
		patch -p1 -force --directory $DIR < $patch
	done
}
	
unpack_and_patch_sources () {

	rm -rf ${PATCHED_SOURCES_DIR}
	mkdir -p ${PATCHED_SOURCES_DIR}

	for src in $GCC_SRC $GLIBC_SRC $BINUTILS_SRC $KERNEL_SRC ; do
		BASE=$(basename $(strip_archive_suffix "$src"))
		echo "BASE = $BASE"
		echo "Unpacking $BASE ..."
		unpack_archive_into_directory $src ${PATCHED_SOURCES_DIR}

		echo "Patching $BASE ..."
		CURR_PATCH_DIR=${PATCHES_DIR}/${BASE}
		echo "CURR_PATCH_DIR = $CURR_PATCH_DIR"

		test -d ${CURR_PATCH_DIR} || continue

		apply_patches_to_directory  \
			${PATCHED_SOURCES_DIR}/${BASE} \
			${CURR_PATCH_DIR}/*.patch
	done
}

apply_glibc_addons () {

	for addon in $* ; do
		echo "Applying glibc addon $addon..."
		unpack_archive_into_directory $addon ${PATCHED_SOURCES_DIR}/${GLIBC_VER}

		CURR_PATCH_DIR=${PATCHES_DIR}/${GLIBC_LINUXTHREADS_VER}
		test -d ${CURR_PATCH_DIR} || continue

		apply_patches_to_directory \
			${PATCHED_SOURCES_DIR}/${GLIBC_VER} \
			${CURR_PATCH_DIR}/*.patch
	done
}

map_target_to_arch () {
	case $1 in
		alpha*)   arch=alpha ;;
		arm*)     arch=arm ;;
		cris*)    arch=cris ;;
		hppa*)    arch=parisc ;;
		i*86*)    arch=i386 ;;
		ia64*)    arch=ia64 ;;
		mips*)    arch=mips ;;
		m68k*)    arch=m68k ;;
		powerpc*) arch=ppc ;;
		ppc*)     echo "Target $TARGET incompatible with binutils and gcc regression tests; use target powerpc-* instead" ; exit 1 ;;
		s390*)    arch=s390 ;;
		sh*)      arch=sh ;;
		sparc64*) arch=sparc64 ;;
		sparc*)   arch=sparc ;;
		x86_64*)  arch=x86_64 ;;
		*) echo "Bad target $TARGET" ; exit 1
	esac
	echo "$arch"
}

##########################################################
#
#  MAIN ROUTINE
#
##########################################################
. $1 ; shift

validate_all_input
set_helper_variables

while [ $# -gt 0 ]; do
    case "$1" in
	--nounpack|-nounpack) 
	   opt_no_unpack=1
	   ;;
	--nobuild|-nobuild) 
	   opt_no_build=1
	   ;;
	--builduserland|-builduserland) 
	   opt_builduserland=1
	   ;;
	--notest|-notest) 
	   opt_no_test=1
	   ;;
	*)
	    echo "Usage: btc [--nounpack|--nobuild|--builduserland|--notest]" ; exit
    esac
    shift
done

if test "$opt_no_unpack" = ""; then
	unpack_and_patch_sources
	apply_glibc_addons ${GLIBC_LINUXTHREADS_SRC}
fi

if test "$opt_no_build" = ""; then
	echo "Starting build phase here..."

	BUILD=$(${GCC_SRC_DIR}/config.guess)
	HOST=$(echo $BUILD | sed s/-/-host_/)

	echo "Starting a build with the following values:"
	echo "  GCC_SRC_DIR = $GCC_SRC_DIR"
	echo "  GCC_BUILD_DIR = $GCC_BUILD_DIR"
	echo "  ARCH = $ARCH"
	echo "  TARGET = $TARGET"
	echo "  BUILD_DIR = $BUILD_DIR"
	echo "  PREFIX = $PREFIX"
	echo "  BUILD = $BUILD"
	echo "  HOST = $HOST"


	exit   ################## bailing here, still writing ###
	
    rm  -rf  $PREFIX
    mkdir -p $PREFIX
    mkdir -p $BUILD_DIR
    cd $BUILD_DIR
    sh $TOP_DIR/crosstool.sh
    cd $TOP_DIR

    # Cute little compile test
    sh testhello.sh
fi

if test "$opt_builduserland" = "1"; then
    # Build /bin/sh and any other non-toolchain things configured in ptx.config
    # Only needed if you can't run the target's normal /bin/sh with the new toolchain
    cd $BUILD_DIR
    sh $TOP_DIR/ptx.sh
fi

if test "$opt_no_test" = ""; then
    # Beefy test that lasts for hours
    cd $BUILD_DIR
    sh $TOP_DIR/crosstest.sh 
fi
----------------------------------------------------------------------------

rday


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



More information about the crossgcc mailing list