Okay I've tidied and documenated this up into a template project on my github account: http://github.com/snkkid/jhc_wii_template you can find my targets.ini and a patch file showing my changes (it's not a lot really). I've put details in the README file.
Hello, I've managed to get a hello world Haskell program working on the Wii (homebrew), cross-compiling JHC compiling the C code using devkitPPC (http://wiibrew.org/wiki/DevkitPPC). Unfortunately I had to hack the generated C code to get this working because devkitPPC doesn't seems to fully support POSIX standards, there where two headers missing from devkitPPC that the C code referenced which was sys/select.h and sys/utsname.h, I was also having problems with __WORDSIZE not being defined even though in my targets.ini I've explicated stated the bit-size, byte-ordering, etc. so I added this define to my targets.ini definition.
Cool! I have a hacked Wii too but have not tried to develop for it.
Actually it's quite easy to setup, a lot more than I imagined at first! I have to say I'm quite impressed by devkitpro and the wii homebrew community. I also want to do the same thing for the xbox360 but last time I checked my firmware version is too new at the moment to be exploited.
There is no particular dependence on POSIX, the simple reason it works better on POSIX systems is because that is what I test on. But adding support for more targets is a good thing, I add them as they are needed.
Ah, setting the wordsize via the targets file is a good idea. You can also edit wsize.h and add an appropriate #ifdef, please send me patches for anything you have to do and I'll integrate them into the main tree.
can you post the output of 'wii-gcc -E -dM -x c /dev/null' (for whatever gcc the wii uses), I am curious what it defines by default.
There is a patch file on my github repo and i've attached an email of those define outputs.
The headers that was missing the actual functions that depended on those headers didn't seem completely essential code so I commented out the includes and problematic code, I also changed the value of the define JHC_isPosix to 0.
Depending on how different it is, I can add a JHC_isWii or maybe JHC_isConsole if it looks like you
That would be cool, what ever you find to be best way.
Of-course this isn't ideal, the proper solution would be for me (or devkitpro) to implement those missing headers but does jhc require a full implementation of posix standard? is it possible to use jhc cross compiling with non-posix platforms?
Actually, the right fix will be to modify jhc to not need these extra features that don't exist. Generally, this can be done via simple #ifdefs in the RTS file if the difference isn't big, like it is fine for hiding the differences between linux and bsd, and even mingw for a windows target. Chances are, you may want to make changes to the jhc libraries as they probably FFI bind some functions that arn't available on the Wii, I can add a isWii to Jhc.Options so you can test for it portably.
which headers are missing BTW?
The only ones I know of thus far are the headers I previously mentioned, this is what headers are available in the 'sys' folder: cdefs.h errno.h lock.h signal.h timeb.h utime.h config.h fcntl.h param.h stat.h time.h wait.h custom_file.h features.h queue.h statvfs.h times.h _default_fcntl.h file.h reent.h stdio.h _types.h dirent.h iconvnls.h resource.h string.h types.h dir.h iosupport.h sched.h syslimits.h unistd.h Those aren't all of the headers available but those are the POSIX related ones I guess?
I also added some other code to the generated C code to setup the Wii, prepare the system for console output, etc but this has nothing to do with jhc and of-course this stuff would need a FFI binding, I just did this for testing purposes.
Yeah, the right way to do this would be to take the C generated by jhc and compile it with the -DJHC_STANDALONE=0 flag, this will cause 'main' to not be generated. then provide your own C file that has a main that does the Wii setup, calls hs_init, then calls your haskell main function (which you should export via the FFI) then hs_exit. I currently don't have a command line option to automate this, but it is on the todo list.
Done, I made a separate driver.c with my own main. One thing I noticed is jhc doesn't generate stub headers for foreign exports? but this wasn't a problem to overcome. Keep up the good work on jhc! _________________________________________________________________ http://clk.atdmt.com/UKM/go/195013117/direct/01/ We want to hear all your funny, exciting and crazy Hotmail stories. Tell us now