[jhc] Is a full POSIX env required for cross-compiling?

John Meacham john at repetae.net
Sat Jul 24 21:08:19 EDT 2010

On Sat, Jul 24, 2010 at 10:40:51PM +0000, Korcan Hussein wrote:
> 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.

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.

> 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 

> 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

which headers are missing BTW?

> 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.


John Meacham - ⑆repetae.net⑆john⑈ - http://notanumber.net/

More information about the jhc mailing list