FCX-Installer/build-fcx-toolchain
2025-02-28 12:58:19 +00:00

265 lines
9.2 KiB
Bash
Executable file

#!/bin/bash
# originally written by Uwe Hermann <uwe@hermann-uwe.de>, released as public domain.
# changed for xenon by Felix Domke <tmbinc@elitedvb.net>, still public domain
# changed for FreeChainXenon by Aiden Isik <aidenisik+git@member.fsf.org>, still public domain
TARGET_MAIN=powerpc64-fcx-xenon
TARGET_PE=powerpc64-fcx-xenonpe
PREFIX=${PREFIX:-/usr/local/fcx} # Install location of your final toolchain
PARALLEL=-j$(nproc)
BINUTILS=binutils-2.43.1
GCC=gcc-14.2.0
NEWLIB=newlib-4.5.0
SYNTHXEX=synthxex-0.0.2
SUPFILES=fcx-support-files
# path to the logfile
LOGFILE="`pwd`/build.log"
# temp variables export
export FREECHAINXENON="$PREFIX"
export PATH="$PATH:$FREECHAINXENON/bin:$FREECHAINXENON/usr/bin"
function fail_with_info()
{
echo "[-] Script failed, check build.log!" >> /dev/stderr
exit 1
}
function toolchain_install
{
# Make working directory
echo -e "Creating final toolchain directory: $PREFIX"
if [ ! -d $PREFIX ]; then
mkdir -p $PREFIX
chown -R `whoami`:`whoami` $PREFIX
fi
# Check if binutils sources are available, download if needed
if [ ! -d $BINUTILS ]; then
echo -e "Cloning $BINUTILS"
git clone --depth 1 -b $BINUTILS https://git.aidenisik.scot/FreeChainXenon/binutils-gdb $BINUTILS || fail_with_info
fi
# Check if gcc sources are available, download if needed
if [ ! -d $GCC ]; then
echo -e "Cloning $GCC"
git clone --depth 1 -b $GCC https://git.aidenisik.scot/FreeChainXenon/gcc $GCC || fail_with_info
fi
# Check if SynthXEX sources are available, download if needed
if [ ! -d $SYNTHXEX ]; then
echo -e "Cloning $SYNTHXEX"
git clone --depth 1 -b $SYNTHXEX https://git.aidenisik.scot/FreeChainXenon/SynthXEX $SYNTHXEX || fail_with_info
fi
if [ ! -d $NEWLIB ]; then
echo -e "Cloning $NEWLIB"
git clone --depth 1 -b $NEWLIB https://git.aidenisik.scot/FreeChainXenon/newlib-cygwin $NEWLIB || fail_with_info
fi
if [ ! -d $SUPFILES ]; then
echo -e "Cloning $SUPFILES"
git clone --depth 1 -b main https://git.aidenisik.scot/FreeChainXenon/FCX-Support-Files $SUPFILES || fail_with_info
fi
rm -rf build
mkdir build
# Build binutils (main)
cd build
echo -e "Configuring binutils..."
../$BINUTILS/configure --target=$TARGET_MAIN --prefix=$PREFIX --enable-multilib --disable-nls --disable-werror >> $LOGFILE 2>&1 || fail_with_info
echo -e "Building binutils (powerpc64-fcx-xenon), this could take a while..."
make $PARALLEL 2>&1 >> $LOGFILE || fail_with_info
make install 2>&1 >> $LOGFILE || fail_with_info
rm -rf *
# Build binutils (PE linker)
echo -e "Configuring binutils (powerpc64-fcx-xenonpe)..."
../$BINUTILS/configure --target=$TARGET_PE --prefix=$PREFIX --enable-multilib --disable-nls --disable-werror >> $LOGFILE 2>&1 || fail_with_info
echo -e "Building binutils (powerpc64-fcx-xenonpe), this could take a while..."
make $PARALLEL 2>&1 >> $LOGFILE || fail_with_info
make install 2>&1 >> $LOGFILE || fail_with_info
cd ..
rm -rf build/*
# Build GCC
cd build
echo -e "Configuring gcc..."
../$GCC/configure --target=$TARGET_MAIN --prefix=$PREFIX --with-libiconv-prefix=/opt/local -enable-interwork \
--enable-languages="c" --without-headers --disable-shared --disable-multilib \
--with-newlib --disable-libmudflap --disable-libssp --disable-nls --disable-shared --without-headers \
--disable-decimal-float --enable-altivec\
--with-gmp=/opt/local --with-mpfr=/opt/local --with-cpu=cell >> $LOGFILE 2>&1 || fail_with_info
echo -e "Building gcc, this could take a while..."
make $PARALLEL all-gcc 2>&1 >> $LOGFILE || fail_with_info
make install-gcc 2>&1 >> $LOGFILE || fail_with_info
cd ..
rm -rf build/*
# Build newlib
cd build
echo -e "Configuring newlib..."
../$NEWLIB/configure --target=$TARGET_MAIN --prefix=$PREFIX --disable-multilib --disable-nls \
CFLAGS="-DHAVE_BLKSIZE -O2"\
--enable-newlib-io-long-long --enable-newlib-io-long-double >> $LOGFILE 2>&1 || fail_with_info
echo -e "Building newlib, this could take a while..."
make $PARALLEL 2>&1 >> $LOGFILE || fail_with_info
make install 2>&1 >> $LOGFILE || fail_with_info
# Build GCC, for the second time
echo -e "Configuring gcc - 2nd pass..."
unset LIBRARY_PATH
../$GCC/configure --target=$TARGET_MAIN --prefix=$PREFIX --with-libiconv-prefix=/opt/local --with-cpu=cell \
--with-gmp=/opt/local --with-mpfr=/opt/local --disable-decimal-float --disable-libquadmath --disable-multilib \
--enable-languages=c,c++ --disable-libssp --disable-libsanitizer --with-newlib --enable-cxx-flags="-G0" \
--disable-libmudflap --disable-nls --disable-shared --disable-linux-futex --enable-altivec \
--disable-libatomic --disable-threads --disable-libgomp --disable-libitm -v >> $LOGFILE 2>&1 || fail_with_info
echo -e "Building gcc - 2nd pass, this could take a while..."
make $PARALLEL 2>&1 >> $LOGFILE || fail_with_info
make install 2>&1 >> $LOGFILE || fail_with_info
cd ..
rm -rf build/*
# Build SynthXEX
cd build
echo -e "Building SynthXEX..."
cmake -DCMAKE_INSTALL_PREFIX=$PREFIX -DCMAKE_BUILD_TYPE=Release ../$SYNTHXEX >> $LOGFILE 2>&1 || fail_with_info
make $PARALLEL 2>&1 >> $LOGFILE || fail_with_info
make install 2>&1 >> $LOGFILE || fail_with_info
cd ..
rm -rf build/*
# Copy supporting toolchain files (linker scripts etc)
echo -e "Copying supporting files..."
cp -r $SUPFILES/* $PREFIX
rm -rf build
rm -rf $BINUTILS
rm -rf $GCC
rm -rf $NEWLIB
rm -rf $SYNTHXEX
rm -rf $SUPFILES
rm -rf build.log
echo -e "Done"
}
function all_done
{
RED='\e[0;31m'
NC='\e[0m'
echo
echo -e "All done, your FreeChainXenon toolchain is located here: $PREFIX"
echo
echo -e "${RED}Please add the following path to your login script (~/.bashrc)"
echo
echo -e "export FREECHAINXENON=\"$PREFIX\""
echo -e "export PATH=\"\$PATH:\$FREECHAINXENON/bin:\$FREECHAINXENON/usr/bin\""
echo -e "${NC}"
}
function check_build-essential
{
echo -e "Ubuntu or Debian is detected."
dpkg -s build-essential >> $LOGFILE 2>&1
if [ $? -eq 1 ]; then
echo -e "The build-essential package was not detected on your system"
echo -e "To build the toolchain you need to download and install the build-essential package."
echo -e "Do you want this script to do it for you ? (y/n)"
read answer >> $LOGFILE 2>&1
if [ "$answer" == "y" ]; then
echo -e "Please wait while installing build-essential..."
apt install -y build-essential >> $LOGFILE 2>&1
fi
else
echo -e "The build-essential package was detected on your system"
fi
dpkg -s flex bison >> $LOGFILE 2>&1
if [ $? -eq 1 ]; then
echo -e "Flex / Bison were not detected on your system (binutils)"
echo -e "Do you want this script to attempt to install them for you? (y/n)"
read answer >> $LOGFILE 2>&1
if [ "$answer" == "y" ]; then
echo -e "Please wait while installing flex and bison..."
apt install -y flex bison >> $LOGFILE 2>&1
fi
fi;
dpkg -s gcc-multilib >> $LOGFILE 2>&1
if [ $? -eq 1 ]; then
echo -e "gcc-multilib was not detected on your system (binutils)"
echo -e "Do you want this script to attempt to install it for you? (y/n)"
read answer >> $LOGFILE 2>&1
if [ "$answer" == "y" ]; then
echo -e "Please wait while installing gcc-multilib..."
apt install -y gcc-multilib >> $LOGFILE 2>&1
fi
fi;
dpkg -s git >> $LOGFILE 2>&1
if [ $? -eq 1 ]; then
echo -e "git was not detected on your system"
echo -e "Do you want this script to attempt to install it for you? (y/n)"
read answer >> $LOGFILE 2>&1
if [ "$answer" == "y" ]; then
echo -e "Please wait while installing git..."
apt install -y git >> $LOGFILE 2>&1
fi
fi;
dpkg -s rename >> $LOGFILE 2>&1
if [ $? -eq 1 ]; then
echo -e "rename was not detected on your system"
echo -e "Do you want this script to attempt to install it for you? (y/n)"
read answer >> $LOGFILE 2>&1
if [ "$answer" == "y" ]; then
echo -e "Please wait while installing rename..."
apt install -y rename >> $LOGFILE 2>&1
fi
fi;
dpkg -s nettle-dev >> $LOGFILE 2>&1
if [ $? -eq 1 ]; then
echo -e "nettle-dev was not detected on your system"
echo -e "Do you want this script to attempt to install it for you? (y/n)"
read answer >> $LOGFILE 2>&1
if [ "$answer" == "y" ]; then
echo -e "Please wait while installing nettle-dev..."
apt install -y nettle-dev >> $LOGFILE 2>&1
fi
fi;
dpkg -s cmake >> $LOGFILE 2>&1
if [ $? -eq 1 ]; then
echo -e "cmake was not detected on your system"
echo -e "Do you want this script to attempt to install it for you? (y/n)"
read answer >> $LOGFILE 2>&1
if [ "$answer" == "y" ]; then
echo -e "Please wait while installing cmake..."
apt install -y cmake >> $LOGFILE 2>&1
fi
fi;
}
# start
rm $LOGFILE &>/dev/null
if [ "$1" == "toolchain" ]; then
if command -v apt-get &> /dev/null; then
check_build-essential
fi
toolchain_install
all_done
else
echo -e "Usage:"
echo -e "\"$0 toolchain\" (install toolchain)"
echo
exit 0
fi;