Archive for March, 2010

Cross compilers for Solaris 2.8

Using the following URL: http://www.cis.upenn.edu/~milom/cross-compile.html
I setup a bash shell script to build a cross compiler tool chain under Linux for Solaris 8: gcc 3.4.6 and 4.4.3.
You need to create a sysroot using a Solaris 8 hosts for includes and libs.

Here is a tiny patch for gcc 3.4.6 (gcc/collect2.c):

1537c1537
<       redir_handle = open (redir, O_WRONLY | O_TRUNC | O_CREAT, S_IRWXU);

>       redir_handle = open (redir, O_WRONLY | O_TRUNC | O_CREAT);

The script is as follow:

FTPMIRROR=ftp.gnu.org
FTPPATH=gnu
WGET=wget

BINUTILS=binutils-2.20.1
GCC3=gcc-3.4.6
GCC4=gcc-4.4.3
TARSUFFIX=.tar.gz

TAR=tar
GUNZIP=gunzip

SYSROOT=SYSROOT.tar
TARGET=sparc-sun-solaris2.8
PREFIX=/home/boucaron/cross/solaris8

function check {
    if  which ${WGET}
	then
	echo "WGET found"
	else
	echo "WGET is missing, we need WGET"
	exit
    fi
    if which ${TAR}
	then
	echo "TAR found"
	else
	echo "TAR is missing, we need TAR"
	exit
    fi
    if which ${GUNZIP}
	then
	echo "GUNZIP found"
	else
	echo "GUNZIP is missing, we need GUNZIP"
	exit
    fi
}

function download {
    if [ -f ${BINUTILS}${TARSUFFIX} ]
	then
	 echo "${BINUTILS}${TARSUFFIX} present"
	else
	    ${WGET} ftp://${FTPMIRROR}/${FTPPATH}/binutils/${BINUTILS}${TARSUFFIX}

    fi
    if [ -f ${GCC3}${TARSUFFIX} ]
	then
	echo "${GCC3}${TARSUFFIX} present"
	else
	${WGET} ftp://${FTPMIRROR}/${FTPPATH}/gcc/${GCC3}/${GCC3}${TARSUFFIX}

    fi
    if [ -f ${GCC4}${TARSUFFIX} ]
	then
	echo "${GCC4}${TARSUFFIX} present"
	else
	${WGET} ftp://${FTPMIRROR}/${FTPPATH}/gcc/${GCC4}/${GCC4}${TARSUFFIX}
    fi
}

function decompress {
    if [ ! -d ${BINUTILS} ]
	then
	${TAR} xfz ${BINUTILS}${TARSUFFIX}
    fi
    if [ ! -d ${GCC3} ]
	then
	${TAR} xfz ${GCC3}${TARSUFFIX}
    fi
    if [ ! -d ${GCC4} ]
	then
	${TAR} xfz ${GCC4}${TARSUFFIX}
    fi
}

function create_build_dirs {
    mkdir -p binutils-build
    mkdir -p gcc3-build
    mkdir -p gcc4-build
}

function sysroot {
    if [ -d SYSROOT ]
	then
	echo "SYSROOT present"
    else
	if [ -f ${SYSROOT} ]
	    then
	    ${TAR} -xf ${SYSROOT}
	else
	    echo "Missing sysroot file"
	fi
    fi
}

function build_prefix {
    mkdir -p ${PREFIX}
}

function build_binutils {
    echo "Building binutils"
    cd binutils-build && \
	./../${BINUTILS}/configure -target=${TARGET} --prefix=${PREFIX} -with-sysroot=../SYSROOT -v  && \
	make && \
	make install && \
	cd ..
    export PATH=${PREFIX}/bin:${PATH}
}

function build_gcc3 {
    echo "Building gcc3"
    cd gcc3-build && \
	./../${GCC3}/configure  --target=${TARGET} --with-gnu-as --with-gnu-ld  --prefix=${PREFIX} -with-sysroot="`pwd`/../SYSROOT" --disable-libgcj --disable-gomp --disable-nls --enable-languages=c,c++ -v && \
#	cp -f ../gcc-3.4.6-gcc-collect2.c ../gcc-3.4.6/gcc/collect2.c && \
	make all && \
	make install && \
	cd ..
}

function build_gcc4 {
    echo "Building gcc4"
     cd gcc4-build && \
	./../${GCC4}/configure --target=${TARGET} --with-gnu-as --with-gnu-ld  --prefix=${PREFIX} -with-sysroot="`pwd`/../SYSROOT" --disable-libgcj --disable-libgomp --disable-nls --enable-languages=c,c++ -v && \
	make all && \
	make install && \
	cd ..
}

function main {
    check
    download
    decompress
    create_build_dirs
    sysroot
    build_binutils
    build_gcc3
    build_gcc4
}
main

syntax highlighted by Code2HTML, v. 0.9.1

No Comments