# SHORT DESC:
# LONG DESC:
# Determine software versions from our version string
# which is in the format of:
# SUM.gccmaj.gccmin.gccrev.glibcmaj.glibcmin.glibcrev.binutilsmaj.binutilsmin.binutilsrev
BINUTILS_VERS=`echo ${pkgver} | cut -d . -f 8-10`
GCC_VERS=`echo ${pkgver} | cut -d . -f 2-4`
GLIBC_VERS=`echo ${pkgver} | cut -d . -f 5-7`
KERNEL_VERS=2.4.32
KERNEL_VERS_SHORT=2.4
# Binutils version umbers do not always have three parts
BINUTILS_VERS=`echo ${BINUTILS_VERS} | sed 's@\.0$@@'`
if [ ( ${GCC_VERS} = "3.4.5" -a ${GLIBC_VERS} = "2.3.2" ) \
-o ( ${BINUTILS_VERS} = "2.16.1" -a ${GCC_VERS} = "3.3.6" -a ${GLIBC_VERS} = "2.3.2" ) ]; then
echo 'Known-bad build configuration rejected.' >&2
exit 1
fi
# Determine URLS and local names
if [ -z "${cachedir}" ]; then
cachedir="."
fi
BINUTILS_URL=http://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VERS}.tar.bz2
GCC_URL=http://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERS}/gcc-${GCC_VERS}.tar.bz2
GLIBC_URL=http://ftp.gnu.org/gnu/glibc/glibc-${GLIBC_VERS}.tar.bz2
KERNEL_URL=http://www.kernel.org/pub/linux/kernel/v${KERNEL_VERS_SHORT}/linux-${KERNEL_VERS}.tar.bz2
BINUTILS_FILE=${cachedir}/binutils-${BINUTILS_VERS}.tar.bz2
GCC_FILE=${cachedir}/gcc-core-${GCC_VERS}.tar.bz2
GLIBC_FILE=${cachedir}/glibc-${GLIBC_VERS}.tar.bz2
KERNEL_FILE=${cachedir}/linux-${KERNEL_VERS}.tar.bz2
# Assume what directory will be created for each package
BINUTILS_DIR=binutils-${BINUTILS_VERS}
GCC_DIR=gcc-${GCC_VERS}
GLIBC_DIR=glibc-${GLIBC_VERS}
KERNEL_DIR=linux-${KERNEL_VERS}
# Fetch source
if [ ! -e ${BINUTILS_FILE} ]; then
wget -O ${BINUTILS_FILE} ${BINUTILS_URL} || rm -f ${BINUTILS_FILE}
fi
if [ ! -e ${GCC_FILE} ]; then
wget -O ${GCC_FILE} ${GCC_URL} || rm -f ${GCC_FILE}
fi
if [ ! -e ${GLIBC_FILE} ]; then
wget -O ${GLIBC_FILE} ${GLIBC_URL} || rm -f ${GLIBC_FILE}
fi
if [ ! -e ${KERNEL_FILE} ]; then
wget -O ${KERNEL_FILE} ${KERNEL_URL} || rm -f ${KERNEL_FILE}
fi
# Step 1: Build binutils
tar -jxf ${BINUTILS_FILE} || exit 1
(
cd ${BINUTILS_DIR} || exit 1
./configure --prefix=/usr --with-gnu-ld --with-gnu-as --target=arm-unknown-linux-gnu i486-slackware-linux && \
make && \
make install || exit 1
) || exit 1
rm -rf ${BINUTILS_DIR}
# Step 2: Install kernel headers
tar -jxf ${KERNEL_FILE} || exit 1
(
cd ${KERNEL_DIR} || exit 1
yes '' | make oldconfig ARCH=arm || exit 1
make dep
mkdir /usr/arm-unknown-linux-gnu/include
cp -a include/linux /usr/arm-unknown-linux-gnu/include/ || exit 1
cp -a include/asm-arm /usr/arm-unknown-linux-gnu/include/asm || exit 1
ln -s include /usr/arm-unknown-linux-gnu/sys-linux
) || exit 1
rm -rf ${KERNEL_DIR}
# Step 3: Build the GCC cross-compiler
tar -jxf ${GCC_FILE} || exit 1
(
cd ${GCC_DIR} || exit 1
mkdir arm-unknown-linux-gnu
cd arm-unknown-linux-gnu
../configure --prefix=/usr --disable-threads --with-gnu-ld --with-gnu-as --target=arm-unknown-linux-gnu --enable-languages=c i486-slackware-linux || exit 1
make || (
if [ ! -e gcc/crti.o ]; then
arm-unknown-linux-gnu-as ../gcc/config/arm/crti.asm -o gcc/crti.o || exit 1
fi
if [ ! -e gcc/crtn.o ]; then
arm-unknown-linux-gnu-as ../gcc/config/arm/crtn.asm -o gcc/crtn.o || exit 1
fi
make || exit 1
) || (
# Hope nobody cares we create a libc.so that contains no
# exported symbols...
cd gcc/
echo 'static void *__empty = &__empty;' > libc.c
./xgcc libc.c -shared -nostdlib -o libc.so || exit 1
cd ../
make || exit 1
) || exit 1
make install || exit 1
) || exit 1
rm -rf ${GCC_DIR}
# Step 4: Build glibc (this does not need to produce a usable glibc, just
# provide all the headers and libraries)
tar -jxf ${GLIBC_FILE} || exit 1
(
cd ${GLIBC_DIR} || exit 1
mkdir arm-unknown-linux-gnu
cd arm-unknown-linux-gnu
mv ../nptl .nptl_gone
echo '#include <linux/input.h>' > ../sysdeps/unix/sysv/linux/arm/ioperm.c.1
cat ../sysdeps/unix/sysv/linux/arm/ioperm.c >> ../sysdeps/unix/sysv/linux/arm/ioperm.c.1
cat ../sysdeps/unix/sysv/linux/arm/ioperm.c.1 > ../sysdeps/unix/sysv/linux/arm/ioperm.c
rm -f ../sysdeps/unix/sysv/linux/arm/ioperm.c.1
echo '#include <sys/uio.h>' > ../sysdeps/unix/sysv/linux/libc_fatal.c.1
cat ../sysdeps/unix/sysv/linux/libc_fatal.c >> ../sysdeps/unix/sysv/linux/libc_fatal.c.1
cat ../sysdeps/unix/sysv/linux/libc_fatal.c.1 > ../sysdeps/unix/sysv/linux/libc_fatal.c
rm -f ../sysdeps/unix/sysv/linux/libc_fatal.c.1
../configure --prefix=/usr/arm-unknown-linux-gnu --with-gnu-ld --with-gnu-as --target=arm-unknown-linux-gnu --build=i486-slackware-linux --host=arm-unknown-linux-gnu --disable-sanity-checks || exit 1
make || (
echo '#define FATAL_PREPARE /**/' > ../sysdeps/unix/sysv/linux/fatal-prepare.h
make || exit 1
) || (
sed 's@_IO_lock_t *\*@void *@g' ../libio/libio.h > ../libio/libio.h.1
cat ../libio/libio.h.1 > ../libio/libio.h
rm -f ../libio/libio.h.1
grep -v '^ *#error' ../sysdeps/generic/bits/stdio-lock.h > ../sysdeps/generic/bits/stdio-lock.h.1
cat ../sysdeps/generic/bits/stdio-lock.h.1 > ../sysdeps/generic/bits/stdio-lock.h
rm -f ../sysdeps/generic/bits/stdio-lock.h.1
make || exit 1
) || (
rm -f ../sysdeps/unix/sysv/linux/if_index.c
touch ../sysdeps/unix/sysv/linux/if_index.c
make || exit 1
) || (
echo 'int *__errno_location(void) { return(0); }' > ../elf/rtld.c.1
echo 'int errno;' >> ../elf/rtld.c.1
cat ../elf/rtld.c >> ../elf/rtld.c.1
cat ../elf/rtld.c.1 > ../elf/rtld.c
rm -f ../elf/rtld.c.1
cat <<\__EOF > ../libio/fileno.c.1
void *_IO_acquire_lock(void) { return(0); }
void *_IO_release_lock(void) { return(0); }
void *__GI_if_indextoname(void) { return(0); }
void *__GI_if_nametoindex(void) { return(0); }
__EOF
cat ../libio/fileno.c >> ../libio/fileno.c.1
cat ../libio/fileno.c.1 > ../libio/fileno.c
rm -f ../libio/fileno.c.1
sed 's@__attribute__ *((nocommon))@@g' ../sysdeps/generic/errno.c | grep -v -e '^ *compat_symbol' -e '^ *strong_alias' > ../sysdeps/generic/errno.c.1
cat ../sysdeps/generic/errno.c.1 > ../sysdeps/generic/errno.c
rm -f ../sysdeps/generic/errno.c.1
sed 's@__attribute__ *((.*))@@g' ../inet/herrno.c | grep -v -e '^ *compat_symbol' -e '^ *weak_alias' > ../inet/herrno.c.1
cat ../inet/herrno.c.1 > ../inet/herrno.c
rm -f ../inet/herrno.c.1
sed 's@struct *__res_state *_res *__attribute__ *((.*)).*@struct __res_state _res;@' ../resolv/res_libc.c | grep -v -e '^ *compat_symbol.*_res,' > ../resolv/res_libc.c.1
cat ../resolv/res_libc.c.1 > ../resolv/res_libc.c
rm -f ../resolv/res_libc.c.1
make || exit 1
) || (
# GCC doesn't handle math stuff very well.. we provide simple (but wrong) replacements
cat <<\__EOF > ../sysdeps/generic/s_fmax.c
#include <math.h>
double __fmax (double x, double y) { return (0); }
double fmax (double x, double y) { return (0); }
#ifdef NO_LONG_DOUBLE
double __fmaxl (double x, double y) { return (0); }
double fmaxl (double x, double y) { return (0); }
#endif
__EOF
cat <<\__EOF > ../sysdeps/generic/s_fmin.c
#include <math.h>
double __fmin (double x, double y) { return (0); }
double fmin (double x, double y) { return (0); }
#ifdef NO_LONG_DOUBLE
double __fminl (double x, double y) { return (0); }
double fminl (double x, double y) { return (0); }
#endif
__EOF
cat <<\__EOF > ../sysdeps/ieee754/dbl-64/e_exp2.c
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <stdlib.h>
#include <float.h>
#include <ieee754.h>
#include <math.h>
#include <fenv.h>
#include <inttypes.h>
#include <math_private.h>
#include "t_exp2.h"
static const volatile double TWO1023 = 8.988465674311579539e+307;
static const volatile double TWOM1000 = 9.3326361850321887899e-302;
double __ieee754_exp2 (double x) { return(0); }
__EOF
cat <<\__EOF > ../sysdeps/ieee754/flt-32/e_expf.c
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <float.h>
#include <ieee754.h>
#include <math.h>
#include <fenv.h>
#include <inttypes.h>
#include <math_private.h>
extern const float __exp_deltatable[178];
extern const double __exp_atable[355] /* __attribute__((mode(DF))) */;
static const volatile float TWOM100 = 7.88860905e-31;
static const volatile float TWO127 = 1.7014118346e+38;
float __ieee754_expf (float x) { return(0); }
__EOF
cat <<\__EOF > ../sysdeps/generic/s_fmaxf.c
#include <math.h>
float __fmaxf (float x, float y) { return (0); }
float fmaxf (float x, float y) { return (0); }
__EOF
cat <<\__EOF > ../sysdeps/generic/s_fminf.c
#include <math.h>
float __fminf (float x, float y) { return (0); }
float fminf (float x, float y) { return (0); }
__EOF
cat <<\__EOF > ../sysdeps/ieee754/flt-32/e_exp2f.c
#ifndef _GNU_SOURCE
# define _GNU_SOURCE
#endif
#include <stdlib.h>
#include <float.h>
#include <ieee754.h>
#include <math.h>
#include <fenv.h>
#include <inttypes.h>
#include <math_private.h>
#include "t_exp2f.h"
static const volatile float TWOM100 = 7.88860905e-31;
static const volatile float TWO127 = 1.7014118346e+38;
float __ieee754_exp2f (float x) { return(0); }
__EOF
make || exit 1
) || exit 1
make install || exit 1
cat <<\__EOF > .nptl/sysdeps/pthread/pthread.h.1
#ifndef _PTHREAD_H_TYPEDEFS
#define _PTHREAD_H_TYPEDEFS 1
typedef unsigned long int pthread_t;
typedef unsigned long int pthread_attr_t;
typedef unsigned long int pthread_once_t;
typedef unsigned long int pthread_mutex_t;
typedef unsigned long int pthread_mutexattr_t;
typedef unsigned long int pthread_cond_t;
typedef unsigned long int pthread_condattr_t;
typedef unsigned long int pthread_key_t;
typedef unsigned long int pthread_rwlock_t;
typedef unsigned long int pthread_rwlockattr_t;
typedef unsigned long int pthread_spinlock_t;
typedef unsigned long int pthread_spinlockattr_t;
typedef unsigned long int pthread_barrier_t;
typedef unsigned long int pthread_barrierattr_t;
#endif
__EOF
cat .nptl/sysdeps/pthread/pthread.h >> .nptl/sysdeps/pthread/pthread.h.1
cat .nptl/sysdeps/pthread/pthread.h.1 > .nptl/sysdeps/pthread/pthread.h
rm -f .nptl/sysdeps/pthread/pthread.h.1
cp .nptl/sysdeps/pthread/*.h /usr/arm-unknown-linux-gnu/include/ || true
) || exit 1
rm -rf ${GLIBC_DIR}
# Step 5: Rebuild gcc
tar -jxf ${GCC_FILE} || exit 1
(
cd ${GCC_DIR} || exit 1
mkdir arm-unknown-linux-gnu
cd arm-unknown-linux-gnu
../configure --prefix=/usr --enable-c99 --enable-long-long --disable-nls --enable-shared --with-gnu-ld --with-gnu-as --target=arm-unknown-linux-gnu i486-slackware-linux || exit 1
make || exit 1
make install || exit 1
) || exit 1
rm -rf ${GCC_DIR}
# Step 6: Rebuild glibc
tar -jxf ${GLIBC_FILE} || exit 1
(
cd ${GLIBC_DIR} || exit 1
mkdir arm-unknown-linux-gnu
cd arm-unknown-linux-gnu
echo '#include <linux/input.h>' > ../sysdeps/unix/sysv/linux/arm/ioperm.c.1
cat ../sysdeps/unix/sysv/linux/arm/ioperm.c >> ../sysdeps/unix/sysv/linux/arm/ioperm.c.1
cat ../sysdeps/unix/sysv/linux/arm/ioperm.c.1 > ../sysdeps/unix/sysv/linux/arm/ioperm.c
rm -f ../sysdeps/unix/sysv/linux/arm/ioperm.c.1
echo '#include <sys/uio.h>' > ../sysdeps/unix/sysv/linux/libc_fatal.c.1
cat ../sysdeps/unix/sysv/linux/libc_fatal.c >> ../sysdeps/unix/sysv/linux/libc_fatal.c.1
cat ../sysdeps/unix/sysv/linux/libc_fatal.c.1 > ../sysdeps/unix/sysv/linux/libc_fatal.c
rm -f ../sysdeps/unix/sysv/linux/libc_fatal.c.1
../configure --prefix=/usr/arm-unknown-linux-gnu --with-gnu-ld --with-gnu-as --target=arm-unknown-linux-gnu --build=i486-slackware-linux --host=arm-unknown-linux-gnu --enable-add-ons || exit 1
make || exit 1
make instll || exit 1
) || exit 1
rm -rf ${GLIBC_DIR}
|