forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Ubuntu 9.04 Script to Build PSPToolchain and PSPLibraries

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
qbradq



Joined: 04 May 2009
Posts: 4

PostPosted: Sat May 09, 2009 2:00 pm    Post subject: Ubuntu 9.04 Script to Build PSPToolchain and PSPLibraries Reply with quote

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:

#! /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
    Back to top
    View user's profile Send private message
    xantares



    Joined: 30 Dec 2008
    Posts: 16

    PostPosted: Sat Jun 20, 2009 10:10 am    Post subject: Reply with quote

    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:
    #!/bin/sh

    # this script installs the psptoolchain and the psplibraries on ubuntu
    # must be run with root priviledges type : 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 || { exit 1; }

    # 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:$PSPDEV/bin:$PSPDEV/psp/bin
    fi

    # temporary download location
    cd /tmp

    # build psptoolchain from repository
    svn checkout svn://svn.ps2dev.org/psp/trunk/psptoolchain psptoolchain || { exit 1; }
    sudo psptoolchain/toolchain-sudo.sh || { exit 1; }
    sudo rm -rf psptoolchain

    # build psplibrairies from repository
    svn checkout svn://svn.ps2dev.org/psp/trunk/psplibraries psplibraries || { exit 1; }

    # 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://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 || { exit 1; }
    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:$PSPDEV/bin:$PSPDEV/psp/bin' >> ~/.bashrc
      bash --login
    fi
    Back to top
    View user's profile Send private message
    xantares



    Joined: 30 Dec 2008
    Posts: 16

    PostPosted: Mon Jun 22, 2009 5:46 pm    Post subject: Reply with quote

    the patch for libbulletml is useless as it as been fixed now
    Back to top
    View user's profile Send private message
    Display posts from previous:   
    Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
    Page 1 of 1

     
    Jump to:  
    You cannot post new topics in this forum
    You cannot reply to topics in this forum
    You cannot edit your posts in this forum
    You cannot delete your posts in this forum
    You cannot vote in polls in this forum


    Powered by phpBB © 2001, 2005 phpBB Group