summaryrefslogtreecommitdiff
path: root/setup
diff options
context:
space:
mode:
Diffstat (limited to 'setup')
-rwxr-xr-xsetup384
1 files changed, 384 insertions, 0 deletions
diff --git a/setup b/setup
new file mode 100755
index 0000000..3790d22
--- /dev/null
+++ b/setup
@@ -0,0 +1,384 @@
+#!/bin/bash
+
+BINUTILS=2.46.0
+GCC_VERSION=16.1.0
+GLIBC_VERSION=2.43
+
+DISTRO_SPEC="x221e"
+
+DESTDIR_STAGE0="${HOME}/opt/cross"
+SYSROOT_LOC="${HOME}/opt/cross/"
+HEADERS_LOC="${HOME}/opt/cross/usr/include"
+
+BINUTILS_CONF_DIR="binutils-conf"
+GLIBC_CONF_DIR="glibc-conf"
+GCC_CONF_DIR="gcc-conf"
+LIBSTDCXX_CONF_DIR="libstdc++-conf"
+
+function binutils_configure {
+ CURRDIR=$(pwd)
+
+ compiler=$1
+
+ conf_flags=("${@:2}")
+
+ if [[ $compiler == "distro" ]]
+ then
+ compiler=x86_64-${DISTRO_SPEC}-linux-gnu-gcc
+ elif [[ $compiler == "default" ]]
+ then
+ compiler=x86_64-linux-gnu-gcc
+ fi
+
+ mkdir "${BINUTILS_CONF_DIR}"
+ cd "${BINUTILS_CONF_DIR}"
+
+ CC=${compiler} ../binutils-${BINUTILS}/configure --prefix=/usr\
+ --disable-nls\
+ --disable-multilib\
+ --target=x86_64-${DISTRO_SPEC}-linux-gnu\
+ --with-sysroot=${SYSROOT_LOC}\
+ --disable-werror \
+ "${conf_flags[@]}"
+
+ if [ $? -eq 0 ]
+ then
+ echo "Succesfully configured binutils!"
+ else
+ echo "Configuration of binutils failed!!! With error code: " $?
+ exit 1
+ fi
+
+ cd ${CURRDIR}
+}
+
+function binutils_make {
+ echo "Building binutils"
+
+ arg=$1
+
+ CURRDIR=$(pwd)
+
+ if [[ ! -e "${BINUTILS_CONF_DIR}" || ! -d "${BINUTILS_CONF_DIR}" ]]
+ then
+ echo "Could not find the binutils-conf directory!"
+ exit 1
+ fi
+
+ cd "${BINUTILS_CONF_DIR}"
+
+ make ${arg} -j$(nproc)
+
+ if [ $? -ne 0 ]
+ then
+ echo "Could not '${arg}' binutils!!! With error code: " $?
+ exit 1
+ fi
+
+ echo "Succesfully completed '${arg}' in binutils!"
+ cd "${CURRDIR}"
+}
+
+function gcc_configure {
+
+ gcc_flags=("$@")
+
+ currdir=$(pwd)
+
+ mkdir "${GCC_CONF_DIR}"
+ cd "${GCC_CONF_DIR}"
+
+ echo -e "building gcc with flags: ${gcc_flags}"
+
+ ../gcc-${GCC_VERSION}/configure\
+ --disable-multilib\
+ --disable-nls\
+ --target=x86_64-${DISTRO_SPEC}-linux-gnu\
+ --disable-werror\
+ "${gcc_flags[@]}"
+
+ if [ $? -eq 0 ]
+ then
+ echo -e "Succesfully configured gcc!"
+ else
+ echo -e "Configuration of binutils failed!!! With error code: " $?
+ exit 1
+ fi
+
+ cd "${currdir}"
+}
+
+function gcc_make {
+ arg=$1
+
+ currdir=$(pwd)
+
+ if [[ ! -e "${GCC_CONF_DIR}" || ! -d "${GCC_CONF_DIR}" ]]
+ then
+ echo -e "Could not find the binutils-conf directory!"
+ exit 1
+ fi
+
+ cd "${GCC_CONF_DIR}"
+
+ make ${arg} -j$(nproc)
+
+ if [ $? -eq 0 ]
+ then
+ echo -e "Succesfully built all-gcc!"
+ else
+ echo -e "make '${arg}' failed!!! With error code: " $?
+ exit 1
+ fi
+
+ cd "${currdir}"
+}
+
+function libstdc++_configure {
+ gcc_flags=("$@")
+
+ currdir=$(pwd)
+
+ mkdir "${LIBSTDCXX_CONF_DIR}"
+ cd "${LIBSTDCXX_CONF_DIR}"
+
+ echo -e "building libstdc++ with flags: ${gcc_flags}"
+
+ ../gcc-${GCC_VERSION}/libstdc++-v3/configure\
+ --disable-multilib\
+ --disable-nls\
+ --target=x86_64-${DISTRO_SPEC}-linux-gnu\
+ --disable-werror\
+ --disable-libstdcxx-pch\
+ --with-gxx-include-dir=${DESTDIR_STAGE0}/usr/x86_64-${DISTRO_SPEC}-linux-gnu/include/${GCC-VERSION}/
+ "${gcc_flags[@]}"
+
+ if [ $? -eq 0 ]
+ then
+ echo -e "Succesfully configured libstdcxx!"
+ else
+ echo -e "Configuration of binutils failed!!! With error code: " $?
+ exit 1
+ fi
+
+ cd "${currdir}"
+
+}
+
+function libstdc++_make {
+ arg=$1
+
+ currdir=$(pwd)
+
+ if [[ ! -e "${LIBSTDCXX_CONF_DIR}" || ! -d "${LIBSTDCXX_CONF_DIR}" ]]
+ then
+ echo -e "Could not find the ${LIBSTDCXX_CONF_DIR} directory!"
+ exit 1
+ fi
+
+ cd "${GCC_CONF_DIR}"
+
+ make ${arg} -j$(nproc)
+
+ if [ $? -eq 0 ]
+ then
+ echo -e "Succesfully built '${arg}'!"
+ else
+ echo -e "make '${arg}' failed!!! With error code: " $?
+ exit 1
+ fi
+
+ cd "${currdir}"
+
+}
+
+function glibc_configure {
+
+ compiler="$1"
+
+ conf_flags=("${@:2}")
+
+ if [[ $compiler == "distro" ]]
+ then
+ compiler=x86_64-${DISTRO_SPEC}-linux-gnu-gcc
+ fi
+
+ currdir=$(pwd)
+
+ mkdir ${GLIBC_CONF_DIR}
+ cd ${GLIBC_CONF_DIR}
+
+ CC=${compiler} ../glibc-${GLIBC_VERSION}/configure\
+ --host=x86_64-${DISTRO_SPEC}-linux-gnu\
+ --build=x86_64-linux-gnu\
+ --with-headers="${HEADERS_LOC}"\
+ --disable-werror\
+ "${conf_flags[@]}"
+
+ cd "${currdir}"
+}
+
+function glibc_make {
+ arg=$1
+
+ currdir=$(pwd)
+
+ if [[ ! -e "${GLIBC_CONF_DIR}" || ! -d "${GLIBC_CONF_DIR}" ]]
+ then
+ echo -e "Could not find the '${GLIBC_CONF_DIR} directory!"
+ exit 1
+ fi
+
+ cd ${GLIBC_CONF_DIR}
+
+ make ${arg} -j$(nproc)
+
+ if [ $? -eq 0 ]
+ then
+ echo -e "Succesful '${arg}'!"
+ else
+ echo -e "make '${arg}' failed!!! With error code: " $?
+ exit 1
+ fi
+
+ cd "${currdir}"
+}
+
+
+function stage0_binutils {
+ rm -rf "${BINUTILS_CONF_DIR}"
+
+ conf_flags=(
+ --prefix=/usr
+ )
+
+ binutils_configure "default" "${conf_flags[@]}"
+ binutils_make
+ binutils_make "DESTDIR=${DESTDIR_STAGE0} install"
+ echo "Stage 0 binutils completed."
+}
+
+function stage0_gcc {
+ rm -rf "${GCC_CONF_DIR}"
+
+ conf_flags=(
+ --prefix=/tools
+ --with-sysroot="/home/cool/opt/cross/"
+ --with-glibc-version=2.43
+ --with-newlib
+ --without-headers
+ --enable-languages=c,c++
+ --disable-shared
+ --disable-threads
+ --disable-gcov
+ --disable-libgcov
+ --disable-libatomic
+ --disable-libgomp
+ --disable-libssp
+ --disable-libvtv
+ --disable-libstdcxx
+ --disable-libquadmath
+ --disable-libssp
+ )
+
+ gcc_configure "${conf_flags[@]}"
+ gcc_make all-gcc
+ gcc_make all-target-libgcc
+ gcc_make "DESTDIR=${DESTDIR_STAGE0} install-gcc"
+ gcc_make "DESTDIR=${DESTDIR_STAGE0} install-target-libgcc"
+ echo "Stage 0 gcc completed."
+}
+
+function stage0_glibc {
+ rm -rf "${GLIBC_CONF_DIR}"
+
+ conf_flags=(
+ --prefix=/usr
+ )
+
+ glibc_configure "distro" "${conf_flags[@]}"
+ glibc_make
+ glibc_make "DESTDIR=${DESTDIR_STAGE0} install"
+}
+
+function stage0 {
+ stage0_binutils
+ stage0_gcc
+ stage0_glibc
+ echo -e "Stage 0 completed."
+}
+
+function stage1_binutils {
+ rm -rf "${BINUTILS_CONF_DIR}"
+
+ conf_flags=(
+ --prefix=/usr
+ )
+
+ binutils_configure "distro" "${conf_flags[@]}"
+ binutils_make
+ binutils_make "DESTDIR=${DESTDIR_STAGE0} install"
+}
+
+function stage1_gcc {
+ rm -rf "${GCC_CONF_DIR}"
+
+ conf_flags=(
+ --prefix=/usr
+ --enable-languages=c,c++
+ --enable-threads=posix
+ --enable-default-pie
+ --enable-default-ssp
+ --enable-shared
+ --with-sysroot="${SYSROOT_LOC}"
+ --with-build-sysroot="${SYSROOT_LOC}"
+ --disable-libvtv
+ --disable-libssp
+ --disable-libgomp
+ --disable-quadmath
+ )
+
+ gcc_configure "${conf_flags[@]}"
+ gcc_make
+ gcc_make "DESTDIR=${DESTDIR_STAGE0} install"
+}
+
+function stage1_glibc {
+ rm -rf "${GLIBC_CONF_DIR}"
+
+ conf_flags=(
+ --prefix=/usr
+ )
+
+ glibc_configure "distro" "${conf_flags[@]}"
+ glibc_make
+ glibc_make "DESTDIR=${DESTDIR_STAGE0} install"
+}
+
+function stage1_libstdc++ {
+ libstdc++_configure "distro"
+ libstdc++_make
+ libstdc++_make "DESTDIR=${DESTDIR_STAGE0} install"
+ echo -e "Libstdc++-3 is installed!"
+}
+
+function stage1 {
+ stage1_gcc
+ stage1_glibc
+ stage1_libstdc++
+ echo -e "Cross compiler installed!"
+}
+
+case "$1" in
+ "stage0") stage0 ;;
+ "stage0-gcc") stage0_gcc ;;
+ "stage0-binutils") stage0_binutils ;;
+ "stage0-glibc") stage0_glibc ;;
+ "stage1") stage1 ;;
+ "stage1-gcc") stage1_gcc ;;
+ "stage1-binutils") stage1_binutils ;;
+ "stage1-glibc") stage1_glibc ;;
+ "stage1-libstdc++") stage1_libstdc++ ;;
+ "install") stage0 && stage1 ;;
+ *) echo -e "you must supply an argument!" && exit 1 ;;
+esac