Ubuntu 9.04 Script to Build PSPToolchain and PSPLibraries

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
qbradq
Posts: 4
Joined: Mon May 04, 2009 5:00 am

Ubuntu 9.04 Script to Build PSPToolchain and PSPLibraries

Post by qbradq »

I have taken the information found in this post http://forums.ps2dev.org/viewtopic.php?t=11935 and added some practical experience to produce a fairly robust shell script to build it.

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
Please execute with care!

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 &#91; -r temp.sh &#93;; 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 &#91; $? -ne 0 &#93;; then
	#	echo "ERROR&#58; 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 &#40;again&#41;.
	echo "Correcting file ownership, this will take a while &#40;again&#41;"
	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 &#91; $? -ne 0 &#93;; then
	echo "Added line to .bashrc&#58; export PSPDEV=\"$PSPDEV\""
	echo "export PSPDEV=\"$PSPDEV\"" >> ~/.bashrc
fi
grep "PSPSDK=" ~/.bashrc > /dev/null
if &#91; $? -ne 0 &#93;; then
	echo "Added line to .bashrc&#58; export PSPSDK=\"\$PSPDEV/psp/sdk\""
	echo "export PSPSDK=\"\$PSPDEV/psp/sdk\"" >> ~/.bashrc
fi
grep "PSPDEV/bin" ~/.bashrc > /dev/null
if &#91; $? -ne 0 &#93;; then
	echo "Added line to .bashrc&#58; export PATH=\"\$PATH&#58;\$PSPDEV/bin&#58;\$PSPSDK/bin\""
	echo "export PATH=\"\$PATH&#58;\$PSPDEV/bin&#58;\$PSPSDK/bin\"" >> ~/.bashrc
fi
    xantares
    Posts: 16
    Joined: Tue Dec 30, 2008 4:09 am

    Post by xantares »

    Hi,

    I just updated a similar script for ubuntu 9.04
    Difference is mine installs in /usr/local/pspdev, your's seems more robust, verbose, documented, and slow due to the recursive chmod
    Also, i added a fix for libbulletml, so ALL librairies compile now

    Latest version available at :
    http://my-trac.assembla.com/ayn5-84BSr3BJRab7jnrAJ/

    Here it is :

    Code: Select all

    #!/bin/sh
    
    # this script installs the psptoolchain and the psplibraries on ubuntu
    # must be run with root priviledges type &#58; sudo ./install_psp_utils.sh
    
    # install the required software packages
    sudo apt-get install -y build-essential autoconf automake gcc bison flex m4 libreadline-dev libusb-dev libtool make libncurses-dev patch libreadline-dev subversion texinfo wget libmpfr-dev libgmp3-dev gcc-4.2 || &#123; exit 1; &#125;
    
    # use gcc 4.2
    ln --symbolic /usr/bin/gcc-4.2 /usr/bin/gcc --backup
    
    # setup directories
    sudo mkdir -p /usr/local/pspdev
    export PSPDEV=/usr/local/pspdev
    export PSPSDK=$PSPDEV/psp/sdk
    if test `echo $PATH | grep -c pspdev` -eq 0
    then
      export PATH=$PATH&#58;$PSPDEV/bin&#58;$PSPDEV/psp/bin
    fi
    
    # temporary download location
    cd /tmp
    
    # build psptoolchain from repository
    svn checkout svn&#58;//svn.ps2dev.org/psp/trunk/psptoolchain psptoolchain || &#123; exit 1; &#125;
    sudo psptoolchain/toolchain-sudo.sh || &#123; exit 1; &#125;
    sudo rm -rf psptoolchain
    
    # build psplibrairies from repository
    svn checkout svn&#58;//svn.ps2dev.org/psp/trunk/psplibraries psplibraries || &#123; exit 1; &#125;
    
    # fix for freetype
    sed '12a\ mkdir -p builds/unix\
     cp /usr/share/libtool/config/config.guess builds/unix' psplibraries/scripts/003-freetype.sh > 003-freetype.sh.tmp
    mv 003-freetype.sh.tmp psplibraries/scripts/003-freetype.sh
    sudo chmod u+x psplibraries/scripts/003-freetype.sh
    
    # fix for libbulletml
    svn checkout svn&#58;//svn.ps2dev.org/psp/trunk/libbulletml psplibraries/build/libbulletml
    sed '10a \#include <cstring>' psplibraries/build/libbulletml/src/calc.yy > calc.yy.tmp
    mv calc.yy.tmp psplibraries/build/libbulletml/src/calc.yy
    
    sudo psplibraries/libraries-sudo.sh || &#123; exit 1; &#125;
    sudo rm -rf psplibraries
    
    # revert gcc
    sudo mv /usr/bin/gcc~ /usr/bin/gcc
    
    # add directories .bashrc to set directories at login
    if test `cat ~/.bashrc | grep -c PSPDEV` -lt 3
    then
      echo 'export PSPDEV=/usr/local/pspdev' >> ~/.bashrc
      echo 'export PSPSDK=$PSPDEV/psp/sdk' >> ~/.bashrc
      echo 'export PATH=$PATH&#58;$PSPDEV/bin&#58;$PSPDEV/psp/bin' >> ~/.bashrc
      bash --login
    fi
    xantares
    Posts: 16
    Joined: Tue Dec 30, 2008 4:09 am

    Post by xantares »

    the patch for libbulletml is useless as it as been fixed now
    Post Reply