Tutorial: Setting up CodeBlocks for ps2dev

Discuss the development of software, tools, libraries and anything else that helps make ps2dev happen.

Moderators: cheriff, Herben

Post Reply
ragnarok2040
Posts: 202
Joined: Wed Aug 09, 2006 1:00 am

Tutorial: Setting up CodeBlocks for ps2dev

Post by ragnarok2040 »

Goal
This guide breaks down into two parts:
Setting up a ps2dev environment, for those who want to try this without ps2dev experience
Setting up CodeBlocks to compile ps2dev projects, works for Cygwin, MinGW, or precompiled toolchain users

What you need for CodeBlocks
CodeBlocks, www.codeblocks.org/nightly
Get the latest nightly build
These dlls are listed in each nightly build release thread: mingwm10.7z wxmsw26u_gcc_cb_wx2.6.3p2.7z

What you need for ps2dev environment
MinGW/MSYS, www.mingw.org
Download MinGW-5.0.2.exe, it's an installer like Cygwin's
I have MSYS-1.0.11-2004.04.30-1.exe, which was the latest MSYS installer snapshot.
This has all the commandline tools, make, sh, tar, gawk, sed, generally used in buildscripts/makefiles.

ps2dev-project template, http://homebrew.thewaffleiron.net/ragna ... project.7z
This is a simple CodeBlocks project file for setting up ps2 projects, you should copy it into the same dir as a project's main Makefile

A Subversion client to download ps2sdk/usb_mass
I used RapidSVN, http://rapidsvn.tigris.org/

Setting up a ps2dev environment

MinGW Setup:
Run MinGW-5.0.2.exe, it will go online to check the latest version of MinGW
Click Next, select a mirror near you in the list, select download and install Click Next
Click either Current or Candidate, Click Next
You want the MinGW base tools, and G++ checked, Click Next, and it will start downloading
Install to C:\MinGW

MSYS setup:
Install MSYS to C:\msys not C:\msys\1.0
Continue with the post-install, so put y and hit Enter.
Hit y and Enter when it asks if you have MinGW installed.
c:/mingw for your MinGW installation, Hit Enter to continue
All done.

The colors for the terminal are set in msys.bat.
You can change LightYellow/Navy to Black/LightGrey so it resembled a more normal terminal window.
You can also add -norxvt to the MSYS shortcut on the desktop to start off with just a simple shell.

Toolchain setup:
Compile or Install a precompiled toolchain to /c/ps2dev or /opt/ps2dev

Open up C:\msys\etc\profile and paste the following at the bottom:
export PS2DEV="/c/ps2dev"
export PS2SDK="$PS2DEV/ps2sdk"
export PATH="$PATH:$PS2DEV/bin:$PS2DEV/ee/bin:$PS2DEV/iop/bin:$PS2DEV/dvp/bin:$PS2SDK/bin"

This sets MSYS's environment up with all the ps2dev dependent variables for compiling with ps2sdk.

Setting up CodeBlocks

CodeBlocks setup:
Extract the latest nightly build, mingwm10.7z, and wxmsw26u_gcc_cb_wx2.6.3p2.7z into C:\Program Files\CodeBlocks
Right click codeblocks.exe and click Send To->Desktop (create shortcut), if you want, you can rename the shortcut CodeBlocks.

Start CodeBlocks, if you get the following error
"Can not enumerate files in directory: 'C:\Documents and Settings\<username>\Application Data\codeblocks/share/codeblocks/plugins' (error 3: the system can not find the file specified.)"
You just need to create that plugins folder.

You can go to Settings->Environment, and enable file associations, if you want.
If you wish to retain your file associations for source files. Click Manage... and just have .cbp and .workspace checked before doing anything

Compiler Setup:
Inside CodeBlocks
Go to Settings-> Environment
Scroll down to Environment variables and click on the icon
Add the following:
Key: PS2DEV
Value: C:/ps2dev (for Cygwin users, change that to your ps2dev dir) it needs forward /'s

Key: PS2SDK
Value: $(PS2DEV)/ps2sdk
Click the Add now (or Set now) button, Click OK

Go to Settings-> Compiler and debugger settings

Select GNU GCC Compiler in the dropdown box at the top, and click the Copy button.
Put PS2 GCC Compiler in the Input box and click OK.
Select the PS2 GCC Compiler in the dropdown list

For MinGW users, CodeBlocks has all the MinGW directories configured by default
For Cygwin users, http://wiki.codeblocks.org/index.php?ti ... n_Compiler

The programs should be setup like this (both MinGW and Cygwin):

Toolchain executables
C Compiler: gcc.exe (or mingw-gcc.exe)
C++ Compiler: g++.exe (or mingw-g++.exe)
Linker for dynamic libs: g++.exe (or mingw-g++.exe)
Linker for static libs: ar.exe
Debugger: gdb.exe
Resource compiler: windres.exe
Make program: make.exe

Additional Paths tab
C:\msys\bin
C:\ps2dev\ee\bin
C:\ps2dev\iop\bin
C:\ps2dev\dvp\bin
C:\ps2dev\ps2sdk\bin
C:\ps2dev\bin

Cygwin users can change those to their relevant paths, they don't need C:\msys\bin

Example project setup:
Get the usb_mass source from ps2dev's subversion repository, this was my test project as it had separate iop and ee projects.

Copy the ps2dev.cbp into the ee folder. For any ps2 project, you want the .cbp file in the same directory as the main makefile for the project, as it keeps the same relative paths in CodeBlocks when you do that.

You can rename it to mass_example.cbp, then doubleclick it

Configuring project for compiling:
Right-click the project, ps2dev, in Codeblocks, click Properties, replace the ps2dev title with whatever you want, I chose mass_example.
Right-clik the project, click Add files recursively... and select the ee dir (should already be selected since that's whare the .cbp is). Make sure all the source files are checked, plus the Makefile

You should now see:

Code: Select all

-#usb_mass
  - Sources
      mass_example.c
      mass_rpc.c
  + Headers
  + Others
Building:
Right-click the Project name and click Build, you should get some warning messages, but it should complete without errors. Cygwin users/Cygwin-based toolchain users, if there are no line numbers or filenames with the warning messages, please read below.

You can also put a fresh copy of ps2dev.cbp into the iop folder, add the files recursively from the iop folder, click Build, it will compile, too.

Cygwin-hosted toolchain users
For those with Cygwin or those with a toolchain from a cygwin-hosted ps2dev environment installer (needs cygwin1.dll), CodeBlocks' regex's didn't capture GCC's output correctly for me
If, when compiling mass_example, the warnings in the Build messages box do not have line numbers or file names listed, then do the following:

Open CodeBlocks, go to Settings-> Compiler and debugger settings
Select the PS2 GCC Compiler from the dropdown list
Click the Other tab, click Advanced options..., you will get a warning about the ramifications of changing things and asks if you wish to continue, make sure you have the PS2 GCC Compiler selected, and click Yes
Click the Output Parsing tab
For the following, you need to replace the regex's with ones that can parse the cygwin-hosted gcc output. The messages under Testing: are example warnings/errors. Paste them into the Test string box, you should get a dialog with everything parsed correctly.

Code: Select all

Click Compiler warning
Replace 
&#40;&#91; \tA-Za-z0-9_&#58;+/\.-&#93;+&#41;&#58;&#40;&#91;0-9&#93;+&#41;&#58;&#91; \t&#93;&#40;&#91;Ww&#93;arning&#58;&#91; \t&#93;.*&#41;
with
&#40;&#91; \tA-Za-z0-9_&#58;+/\.-&#93;+&#41;\&#40;&#40;&#91;0-9&#93;+&#41;\&#41;&#91; \t&#93;&#58;&#91; \t&#93;&#40;&#91;Ww&#93;arning&#58;&#91; \t&#93;.*&#41;

Testing
main.c&#58;38&#58; warning&#58; implicit declaration of function `InitPS2'
main.c&#40;38&#41; &#58; warning&#58; implicit declaration of function `InitPS2'

Click Compiler error
Replace
&#40;&#91; \tA-Za-z0-9_&#58;+/\.-&#93;+&#41;&#58;&#40;&#91;0-9&#93;+&#41;&#58;&#91; \t&#93;&#40;.*&#41;
with
&#40;&#91; \tA-Za-z0-9_&#58;+/\.-&#93;+&#41;\&#40;&#40;&#91;0-9&#93;+&#41;\&#41;&#91; \t&#93;&#58;&#91; \t&#93;&#40;.*&#41;

Testing&#58;
init.c&#58;80&#58; parse error before '*' token
init.c&#40;80&#41; &#58; parse error before '*' token

Click Linker error &#40;lib not found&#41;
Replace 
.*&#40;ld.exe&#41;&#58;&#91; \t&#93;&#40;cannot find.*&#41;
with
.*&#40;ld&#41;&#58;&#91; \t&#93;&#40;cannot find.*&#41;

Testing&#58;
C&#58;\ps2dev\ee\bin\..\lib\gcc-lib\ee\3.2.2\..\..\..\..\ee\bin\ld.exe&#58; cannot find -ldmkit
/cygdrive/c/ps2dev/ee/bin/../lib/gcc-lib/ee/3.2.2/../../../../ee/bin/ld&#58; cannot find -ldmkit
Now CodeBlocks should catch warnings and errors correctly, allowing you to jump straight to where said warning/error occurred from the Build messages box.

Updating PS2SDK:
Get the latest ps2sdk's source from ps2dev's svn repository.

Comments
Ok, I've spent a few days creating this guide, I'm pretty sure I've caught anything that might mess CodeBlocks up with setting it up with a ps2dev environment on any platform. As for Linux users, there is an Ubuntu edgy nightly build, but I'm not familiar with it, but you can probably figure out how to set it up from this guide.
Last edited by ragnarok2040 on Sat Jan 23, 2010 10:13 pm, edited 10 times in total.
sincodes
Posts: 2
Joined: Wed Sep 13, 2006 4:43 pm

assembly source

Post by sincodes »

Hi,

I am having problem on compiling assembly source by using CodeBlock. Anyone could help?
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Really nice guide! I was just getting set to setup CB to do this and the guide really came in handy. Thanks!

I run Fedora Core 6 for the x86_64. You can use the guide almost straight, but a few changes need to be made...

Make sure the extras repo is added. You should have added it during install, but in case you didn't, here's how:

Open a terminal and go into superuser mode.

Code: Select all

su -
Import the key for the extras repo.

Code: Select all

rpm --import http&#58;//download.fedora.redhat.com/pub/fedora/linux/extras/RPM-GPG-KEY-Fedora-Extras
Save the following as "/etc/yum.repos.d/fedora-extras.repo"

Code: Select all

&#91;extras&#93;
name=Fedora Extras $releasever - $basearch
#baseurl=http&#58;//download.fedora.redhat.com/pub/fedora/linux/extras/$releasever/$basearch/
mirrorlist=http&#58;//mirrors.fedoraproject.org/mirrorlist?repo=extras-$releasever&arch=$basearch
enabled=1
gpgkey=file&#58;///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-extras
gpgcheck=1

&#91;extras-debuginfo&#93;
name=Fedora Extras $releasever - $basearch - Debug
#baseurl=http&#58;//download.fedora.redhat.com/pub/fedora/linux/extras/$releasever/$basearch/debug/
mirrorlist=http&#58;//mirrors.fedoraproject.org/mirrorlist?repo=extras-debug-$releasever&arch=$basearch
enabled=0
gpgkey=file&#58;///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-extras
gpgcheck=1

&#91;extras-source&#93;
name=Fedora Extras $releasever - Source
#baseurl=http&#58;//download.fedora.redhat.com/pub/fedora/linux/extras/$releasever/SRPMS/
mirrorlist=http&#58;//mirrors.fedoraproject.org/mirrorlist?repo=extras-source-$releasever&arch=$basearch
enabled=0
gpgkey=file&#58;///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-extras
gpgcheck=1
If you haven't already, install the Smart Package Manager. It's the best package manager you can use with Fedora Core, and it's in the extras repo.

Code: Select all

yum install smart smart-gui smart-update
Now you can use Smart to install packages with a click of the button. Open Smart (it's in the Gnome Menus under System Tools) and click okay for all the repos it asks about (only does this the first time you open it). Check gcc34 and g++34 for installation. The ps2dev toolchain won't compile under gcc 4.1 included with FC6. Check CodeBlocks for installation (yes, CodeBlocks is in the FC6 extras repo!). Check 7zip for installation. Note - if you're having trouble finding them, use the search feature in Smart. Check subversion for installation. Click the apply button to download and install the above and any dependencies.

Now back to the terminal. If you've never made the ps2dev toolchain before, you need to make the directory explicitly for some reason.

Code: Select all

mkdir -p /usr/local/ps2dev
Set up a few temporary environment variables. These will vanish when you close the terminal. If you wish to always have them, add them to .bash_profile.

Code: Select all

export PS2DEV="/usr/local/ps2dev"
export PS2SDK="$PS2DEV/ps2sdk"
export PATH="$PATH&#58;$PS2DEV/bin&#58;$PS2DEV/ee/bin&#58;$PS2DEV/iop/bin&#58;$PS2DEV/dvp/bin&#58;$PS2SDK/bin"
Now change directories to where you want to put all the junk the toolchain script uses during the toolchain building process.

Code: Select all

cd /tmp
Checkout the ps2 toolchain.

Code: Select all

svn co svn&#58;//svn.ps2dev.org/ps2/trunk/ps2toolchain
Go into that directory and run the toolchain. Don't forget to use gcc 3.4!

Code: Select all

cd ps2toolchain
CC=gcc34 ./toolchain.sh
Once it's done, you should have a full ps2 toolchain and ps2sdk in /usr/local/ps2dev.

Now go into CodeBlocks and set the environment variables as shown in the guide, except that PS2DEV is set to "/usr/local/ps2dev" instead of what he shows. PS2SDK is the same since it's set relative to PS2DEV. Note that setting these environment variables here means you DON'T need to set them in .bash_profile unless you intend to use the terminal to compile stuff. If you just stick to CB, don't bother.

Follow the guide until you reach the part about setting the PS2 GCC Compiler Program Files tab. Leave them set as they are with the exception of changing gcc to gcc34, and g++ to g++34. In the Additional Paths tab, add the following.

Code: Select all

/usr/local/ps2dev/ee/bin
/usr/local/ps2dev/iop/bin
/usr/local/ps2dev/dvp/bin
/usr/local/ps2dev/ps2sdk/bin
/usr/local/ps2dev/bin
To unarc the project file linked to in the guide, use this:

Code: Select all

7za x ps2dev-project.7z
The rest is like the guide, but CB had no trouble capturing GCC's output, so the part about setting CB to capture CygWin output doesn't apply. Note that all of the above applies equally well to the PSP toolchain! The main difference is that gcc 4.1 will compile the PSP toolchain fine - no need for gcc 3.4, and you don't need to create /usr/local/pspdev first, nor set the environment vars before compiling the psp toolchain.

Hope this helps folks wishing to try it under linux. Other distros should be pretty similar, but you might not have CodeBlocks in a handy repository.
ragnarok2040
Posts: 202
Joined: Wed Aug 09, 2006 1:00 am

Post by ragnarok2040 »

Nice, thanks J.F.

sincodes:

Make sure you have a rule like:

something_assembly.o: something_assembly.s

in your Makefile, and include $PS2SDK/samples/Makefile.pref and $PS2SDK/samples/Makefile.eeglobal or .iopglobal depending on your project. They have the %.o: %.s rule for compiling assembly into object files.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

ragnarok2040 wrote:Nice, thanks J.F.
No problem. I was making .cbp files for SMS when I noticed that some folks will need another environment variable: PS2SDKSRC needs to be set to where you have checked out the source for the SDK. This is for when projects make their own custom IRXs instead of just using the normal ones. In my case, it's

Code: Select all

PS2SDKSRC=~/projects/sony/ps2/trunk/ps2sdk
n2liquid
Posts: 4
Joined: Tue Jan 02, 2007 7:27 pm

Post by n2liquid »

First, hi there folks.

I'm new here, sorry if I am beginning.
Well, I did everything just as said on this tutorial(thx ragnarok2040), but when I try to compile, the compiler is not able to find sifrpc.h, and of course, a bunch of declaration errors follow it.

Here it is>

Code: Select all

C&#58;\ps2dev\ee\mass_rpc.c&#58;15&#58; sifrpc.h&#58; No such file or directory
C&#58;\ps2dev\ee\mass_rpc.c&#58;21&#58; error&#58; syntax error before "client"
C&#58;\ps2dev\ee\mass_rpc.c&#58;21&#58; warning&#58; type defaults to `int' in declaration of `client'
C&#58;\ps2dev\ee\mass_rpc.c&#58;21&#58; warning&#58; data definition has no type or storage class
C&#58;\ps2dev\ee\mass_rpc.c&#58;40&#58; warning&#58; implicit declaration of function `SifBindRpc'
C&#58;\ps2dev\ee\mass_rpc.c&#58;44&#58; error&#58; request for member `server' in something not a structure or union
C&#58;\ps2dev\ee\mass_rpc.c&#58;62&#58; warning&#58; implicit declaration of function `SifCallRpc'
C&#58;\ps2dev\ee\mass_rpc.c&#58;66&#58; warning&#58; implicit declaration of function `memcpy'
C&#58;\ps2dev\ee\mass_rpc.c&#58;21&#58; warning&#58; alignment of 'client' is greater than maximum object file alignment.  Using 16
C&#58;\ps2dev\ee\mass_rpc.c&#58;22&#58; warning&#58; alignment of 'rpcBuffer' is greater than maximum object file alignment.  Using 16
&#58;&#58; === Build finished&#58; 3 errors, 7 warnings ===
I didn't update ps2dev sdk, I wonder if it's because of that..
cosmito
Posts: 307
Joined: Sun Mar 04, 2007 4:26 am
Location: Portugal
Contact:

Post by cosmito »

Hmm interesting the Code Block thing.

I'm going to try as soon I have some time.
The ps2dev toolchain won't compile under gcc 4.1
Aha! I knew it (well, suspect it :) )
cosmito
Posts: 307
Joined: Sun Mar 04, 2007 4:26 am
Location: Portugal
Contact:

Post by cosmito »

Hi

the ps2dev-project template cannot be found at http://d.turboupload.com/d/1222919/ps2d ... ct.7z.html ...

Could you please host it again and/or send me a copy ?
Thanks
User avatar
kouky
Posts: 48
Joined: Tue Sep 25, 2007 5:38 am
Location: London
Contact:

Post by kouky »

As ptek

I can't download the project template,
could you please update the hosting?

Thank you :)
User avatar
kouky
Posts: 48
Joined: Tue Sep 25, 2007 5:38 am
Location: London
Contact:

Post by kouky »

I've nearly done all the steps, but can't find your "usb_mass source",

should it be in http://svn.ps2dev.org/ ??
this URL return me a forbidden 403 error...
cosmito
Posts: 307
Joined: Sun Mar 04, 2007 4:26 am
Location: Portugal
Contact:

Post by cosmito »

kouky wrote:As ptek

I can't download the project template,
could you please update the hosting?

Thank you :)
In the meanwhile, I mirrored here :
http://www.4shared.com/file/43976115/3c ... s2dev.html
cosmito
Posts: 307
Joined: Sun Mar 04, 2007 4:26 am
Location: Portugal
Contact:

Post by cosmito »

kouky wrote:I've nearly done all the steps, but can't find your "usb_mass source",

should it be in http://svn.ps2dev.org/ ??
this URL return me a forbidden 403 error...
Point your SVN client to svn://svn.ps2dev.org/ps2/trunk/usb_mass/
superfrog12
Posts: 14
Joined: Sun Jun 22, 2008 11:20 pm

Post by superfrog12 »

hi,

I am trying to set up CodeBlocks for PS2SDK but when I try to build a project I get
/samples/Makefile.pref No such file or directory
/samples/Makefile.eeglobal No such file or directory
the corresponding lines in my makefile are
include $(PS2SDK)/samples/Makefile.pref
include $(PS2SDK)/samples/Makefile.eeglobal
I am using version 8.0.2 of CodeBlocks and there is no such option as Settings->Environment anymore. I added the PS2DEV and PS2SDK environment variables under Settings->Compiler and debugger in the "PS2 GCC Compiler" tab under "custom variables". Do I need to add them some other place?

thank you
ragnarok2040
Posts: 202
Joined: Wed Aug 09, 2006 1:00 am

Post by ragnarok2040 »

It's still there on the latest builds and on 8.02, Settings->Environment which pops open with the General Settings tab selected. You scroll down to Environment variables and you can set them up there. I checked using 8.02 and svn build 5102 built on Jun 22, 2008.

The "Custom variables" under the "Compilers and debuggers" menu are for use when Codeblocks invokes the compiler or linker and you want to use a variable to replace some options or something instead of defining them manually and they don't affect the environment from which make is called.
superfrog12
Posts: 14
Joined: Sun Jun 22, 2008 11:20 pm

Post by superfrog12 »

oh you are right! I wasn't using the nightly build. the option is missing in the stable build.

thanks
ragnarok2040
Posts: 202
Joined: Wed Aug 09, 2006 1:00 am

Post by ragnarok2040 »

That's weird :?, Perhaps the plugin went missing or was disabled somehow. If you have the problem in the future, you can check Plugins->Manage Plugins and see if the Environment variables plugin is disabled. Reinstalling CodeBlocks with a nightly build was the better option, I think :D, since they're always fixing bugs.
Post Reply