Monday, June 29, 2009

SDCC on OpenSolaris

SDCC?

Yes, SDCC, the free small device c-compiler. I just gave it a try, wanting to do some programming for a MicroChip PIC, and it seems to work fine on OpenSolaris 2009.06. You do however need to compile it yourself, as there seems to be no packages available yet (that I'm aware of). But, do not fear.

Since I'm a complete noob when it comes to PIC programming, I aided myself with Micah Carricks tutorial on c-programming for PICs using SDCC on linux, and some OpenSolaris development knowledge, and was able to get sdcc working on OpenSolaris. So, thanks Micah!
http://www.micahcarrick.com/04-25-2005/pic-c-programming-linux.html

Step 1: Getting the packages
  • Get the SDCC source (currently 2.9.0)
  • Get the gputils source (currently 0.3.17)
  • Install gcc 4.3.x from your favorite location
  • Install g++ 4.3.x from your favorite location
You might also want to get gpsim and gpicd for simulation and In-circuit debugging respectively, too. But I didn't get to those yet.

Step 2: Environment
Set you PATH to point to gcc4/g++ if it doesn't already. In case you used opencsw or similar, do:
export PATH=$PATH:/opt/csw/gcc4/bin

Set your LD_LIBRARY_PATH to point to libstdc++
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/csw/gcc4/lib

Step 3: Build and install gputils
GNU tools normally build right out of the box :)
pfexec make install takes care of installation.

Step 4: Build and install SDCC
You'll need to make a couple of adjustments to all Makefile.in in the sdcc code. OpenSolaris' ar doesn't accept the -S option, but that can be removed safely. Do that for any Makefile.in in your project.

Step 5: ./configure
A simple
./configure
should configure the build for you.

If it doesn't, it's likely because you either didn't fix all Makefile.ins as described above, or configure/gcc/g++ can't find all libs due to an missing or incorrectly set LD_LIBRARY_PATH.

With gputils and gcc available in $PATH, sdcc configured nicely AFAICT.

Step 6: ./make
With gputils and gcc available in $PATH, sdcc also built nicely AFAICT.

Step 7: Testing sdcc
Using the first two, very small, examples in Micah Carricks tutorial, I put sdcc through its paces and it produced the expected output.

Now, out of the box, configure will make your install go to /usr/local/bin, which is kinda non-opensolaris-ishy, but playing around with the options to configure will put it where you (might) want it to go.

That's all there is (was) to it :)

Plotting on OpenSolaris

If you, like me, want to do large-format PDF plots from OpenSolaris with that old, unsupported, driver-nowhere-to-be-found HPGL plotter, then you might fancy having a look at Alfreds Klomps blog on pushing HPGL data to the plotter linux/(open)solaris/osx style

http://www.alfredklomp.com/technology/plotter/

To covert your PDFs to HGPL, go grab ps2edit

http://www.pstoedit.net/

and you'll be pumping PDFs off that old plotter in no time!

Your CTRLs?

"Your controls" is the term a flight instructor use when the student pilot is handed the controls. Being somewhat of a computer geek and flight instructor, the observant reader will hopefully be able to connect the dots on that play of words...

No matter the result of that mental exercise, I hope my blogging will be of help to someone, somewhere.