How to use:
First, export your desired PSPDEV directory (or accept the default of ~/pspdev)
export PSPDEV=/home/you/bin/pspdev
Next, execute the script.
The script will ask for your password for SUDO commands. Press CTRL+C to quit or enter your password to start the process.
The script will:
- Install needed packages from APT
Download the packages from SVN (if they are not already present)
Build the packages (if they have not already been built)
Automatically patches the freetype build script
Changes file permissions to your user id
Makes changes needed to the top-level build scripts to put PSPDEV where you want it
Updates your ~/.bashrc if needed
Code: Select all
#! /bin/bash
# Functions
function chownThis
{
echo $SUDOPASS | sudo -S chown $MYUSER:$MYUSER "$1"
}
# Setup
if [ -z "$PSPDEV" ]; then
PSPDEV=~/pspdev
fi
export PSPDEV
export PATH=$PATH:$PSPDEV/bin
MYUSER=`whoami`
# Intro message
echo "This script will download the psptoolchain and psplibraries packages"
echo "from SVN and compile them. This script will install several packages"
echo "to support this process. This script is intended for Ubuntu 9.04 ONLY"
echo
echo "The base directory for the toolchain will be $PSPDEV"
echo "This can be changed at the top of this script, or by exporting this"
echo "variable before executing this script."
echo
printf "Please enter your password for sudo, or press CTRL+C to Quit: "
read SUDOPASS
# Create the PSPDEV directory
if [ ! -d "$PSPDEV" ]; then
echo $SUDOPASS | sudo -S mkdir "$PSPDEV"
echo $SUDOPASS | sudo -S chmod 755 "$PSPDEV"
echo $SUDOPASS | sudo -S chown $MYUSER:$MYUSER "$PSPDEV"
fi
# Install packages
echo "Installing needed packages from the APT repositories."
echo $SUDOPASS | sudo -S apt-get install build-essential autoconf automake bison flex \
libncurses5-dev libreadline-dev libusb-dev texinfo libgmp3-dev gcc-4.2 \
subversion libmpfr-dev libtool wget doxygen
# Move into the build directory
if [ ! -d src ]; then
mkdir src
fi
cd src
# Download the packages from SVN
if [ ! -d psptoolchain ]; then
echo "Downloading psptoolchain package from SVN"
svn co svn://svn.ps2dev.org/psp/trunk/psptoolchain psptoolchain
fi
if [ ! -d psplibraries ]; then
echo "Downloading psplibraries package from SVN"
svn co svn://svn.ps2dev.org/psp/trunk/psplibraries psplibraries
fi
# Build psptoolchain
if [ ! -r psptoolchain.built ]; then
echo "Building psptoolchain"
cd psptoolchain
# Patch the installer script for our custom path
if [ -r temp.sh ]; then rm -f temp.sh; fi
sed s%export\ PSPDEV=.*%export\ PSPDEV=$PSPDEV% toolchain-sudo.sh > temp.sh
chmod +x temp.sh
# IMPORTANT: Invoke the build script with GCC version 4.2!
echo $SUDOPASS | sudo -S CC=gcc-4.2 ./temp.sh
rm -f temp.sh
if [ $? -ne 0 ]; then
echo "ERROR: Building psptoolchain failed."
exit 1
fi
# Now there's a bunch of files scattered around that are owned by root. We need
# to fix that before we continue.
echo "Correcting file ownership, this will take a while (like 15 minutes on a"
echo "fast machine!)"
find ./ -print | while read FNAME; do chownThis "$FNAME"; done
find $PSPDEV -print | while read FNAME; do chownThis "$FNAME"; done
# This file tells us not to try to build this package again
cd ..
touch psptoolchain.built
fi
# Build the psplibraries package
if [ ! -r psplibraries.built ]; then
echo "Building psplibraries"
cd psplibraries
# Patch the freetype library script if needed
grep -- --add-missing scripts/003-freetype.sh > /dev/null
if [ $? != 0 ]; then
echo "Patching scripts/003-freetype.sh, backing up to"
echo "scripts/003-freetype.sh.bak"
cp scripts/003-freetype.sh scripts/003-freetype.sh.bak
patch scripts/003-freetype.sh - > /dev/null <<ENDDIFF
13a14,18
> ## This fixes the infamous freetype build bug
> cd builds/unix
> automake --add-missing
> cd ../..
>
ENDDIFF
fi
# Patch the installer script for our custom path
if [ -r temp.sh ]; then rm -f temp.sh; fi
sed s%export\ PSPDEV=.*%export\ PSPDEV=$PSPDEV% libraries-sudo.sh > temp.sh
chmod +x temp.sh
# Note to self, DO NOT set CC here because we are using psp-gcc
#echo $SUDOPASS | sudo -S ./temp.sh
#if [ $? -ne 0 ]; then
# echo "ERROR: Building psplibraries failed."
# exit 1
#fi
# Now there's a bunch of files scattered around that are owned by root. We need
# to fix that before we continue (again).
echo "Correcting file ownership, this will take a while (again)"
find ./ -print | while read FNAME; do chownThis "$FNAME"; done
find $PSPDEV -print | while read FNAME; do chownThis "$FNAME"; done
# This file tells us not to try to build this package again
cd ..
touch psplibraries.built
fi
# Now patch the user's .bashrc
grep "PSPDEV=" ~/.bashrc > /dev/null
if [ $? -ne 0 ]; then
echo "Added line to .bashrc: export PSPDEV=\"$PSPDEV\""
echo "export PSPDEV=\"$PSPDEV\"" >> ~/.bashrc
fi
grep "PSPSDK=" ~/.bashrc > /dev/null
if [ $? -ne 0 ]; then
echo "Added line to .bashrc: export PSPSDK=\"\$PSPDEV/psp/sdk\""
echo "export PSPSDK=\"\$PSPDEV/psp/sdk\"" >> ~/.bashrc
fi
grep "PSPDEV/bin" ~/.bashrc > /dev/null
if [ $? -ne 0 ]; then
echo "Added line to .bashrc: export PATH=\"\$PATH:\$PSPDEV/bin:\$PSPSDK/bin\""
echo "export PATH=\"\$PATH:\$PSPDEV/bin:\$PSPSDK/bin\"" >> ~/.bashrc
fi