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

Korcan Hussein korcan_h at hotmail.com
Sun Jul 25 17:34:44 EDT 2010

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!
We want to hear all your funny, exciting and crazy Hotmail stories. Tell us now
-------------- next part --------------
#define __DBL_MIN_EXP__ (-1021)
#define __FLT_MIN__ 1.17549435e-38F
#define __CHAR_BIT__ 8
#define _ARCH_PPCGR 1
#define __WCHAR_MAX__ 2147483647
#define __DBL_DENORM_MIN__ 4.9406564584124654e-324
#define __FLT_EVAL_METHOD__ 0
#define __DBL_MIN_10_EXP__ (-307)
#define __FINITE_MATH_ONLY__ 0
#define __GNUC_PATCHLEVEL__ 3
#define __DEC64_MAX_EXP__ 385
#define __SHRT_MAX__ 32767
#define __LDBL_MAX__ 1.7976931348623157e+308L
#define _ARCH_PPC 1
#define __UINTMAX_TYPE__ long long unsigned int
#define __DEC32_EPSILON__ 1E-6DF
#define __CHAR_UNSIGNED__ 1
#define __LDBL_MAX_EXP__ 1024
#define __SCHAR_MAX__ 127
#define __DBL_DIG__ 15
#define __SIZEOF_INT__ 4
#define __SIZEOF_POINTER__ 4
#define __USER_LABEL_PREFIX__ 
#define __STDC_HOSTED__ 1
#define __LDBL_HAS_INFINITY__ 1
#define __FLT_EPSILON__ 1.19209290e-7F
#define _CALL_SYSV 1
#define __LDBL_MIN__ 2.2250738585072014e-308L
#define __DEC32_MAX__ 9.999999E96DF
#define __SIZEOF_LONG__ 4
#define __DECIMAL_DIG__ 17
#define __LDBL_HAS_QUIET_NAN__ 1
#define __GNUC__ 4
#define __FLT_HAS_DENORM__ 1
#define __SIZEOF_LONG_DOUBLE__ 8
#define __BIGGEST_ALIGNMENT__ 16
#define __DBL_MAX__ 1.7976931348623157e+308
#define __DBL_HAS_INFINITY__ 1
#define __DEC32_MIN_EXP__ (-94)
#define __LDBL_HAS_DENORM__ 1
#define __DEC128_MAX__ 9.999999999999999999999999999999999E6144DL
#define __DEC32_MIN__ 1E-95DF
#define __DBL_MAX_EXP__ 1024
#define __DEC128_EPSILON__ 1E-33DL
#define __LONG_LONG_MAX__ 9223372036854775807LL
#define __SIZEOF_SIZE_T__ 4
#define __PPC__ 1
#define __SIZEOF_WINT_T__ 4
#define __GXX_ABI_VERSION 1002
#define __FLT_MIN_EXP__ (-125)
#define __DBL_MIN__ 2.2250738585072014e-308
#define __DEC128_MIN__ 1E-6143DL
#define __REGISTER_PREFIX__ 
#define __DBL_HAS_DENORM__ 1
#define __NO_INLINE__ 1
#define __FLT_MANT_DIG__ 24
#define __VERSION__ "4.4.3"
#define __embedded__ 1
#define __BIG_ENDIAN__ 1
#define __DEC64_EPSILON__ 1E-15DD
#define __DEC128_MIN_EXP__ (-6142)
#define __SIZE_TYPE__ unsigned int
#define __ELF__ 1
#define __FLT_RADIX__ 2
#define __LDBL_EPSILON__ 2.2204460492503131e-16L
#define __SIZEOF_PTRDIFF_T__ 4
#define __DEC32_SUBNORMAL_MIN__ 0.000001E-95DF
#define __FLT_HAS_QUIET_NAN__ 1
#define __FLT_MAX_10_EXP__ 38
#define __LONG_MAX__ 2147483647L
#define __DEC128_SUBNORMAL_MIN__ 0.000000000000000000000000000000001E-6143DL
#define __FLT_HAS_INFINITY__ 1
#define __DEC64_MAX__ 9.999999999999999E384DD
#define __CHAR16_TYPE__ short unsigned int
#define __DEC64_MANT_DIG__ 16
#define __DEC32_MAX_EXP__ 97
#define _BIG_ENDIAN 1
#define __PPC 1
#define __LDBL_MANT_DIG__ 53
#define __DBL_HAS_QUIET_NAN__ 1
#define __WCHAR_TYPE__ long int
#define __SIZEOF_FLOAT__ 4
#define __DEC64_MIN_EXP__ (-382)
#define __FLT_DIG__ 6
#define __INT_MAX__ 2147483647
#define __FLT_MAX_EXP__ 128
#define __DBL_MANT_DIG__ 53
#define __DEC64_MIN__ 1E-383DD
#define __WINT_TYPE__ unsigned int
#define __SIZEOF_SHORT__ 2
#define __LDBL_MIN_EXP__ (-1021)
#define __LDBL_MAX_10_EXP__ 308
#define __DBL_EPSILON__ 2.2204460492503131e-16
#define PPC 1
#define __SIZEOF_WCHAR_T__ 4
#define __DEC_EVAL_METHOD__ 2
#define __INTMAX_MAX__ 9223372036854775807LL
#define __FLT_DENORM_MIN__ 1.40129846e-45F
#define __CHAR32_TYPE__ unsigned int
#define __FLT_MAX__ 3.40282347e+38F
#define __SIZEOF_DOUBLE__ 8
#define __FLT_MIN_10_EXP__ (-37)
#define __INTMAX_TYPE__ long long int
#define __DEC128_MAX_EXP__ 6145
#define __GNUC_MINOR__ 4
#define __DEC32_MANT_DIG__ 7
#define __DBL_MAX_10_EXP__ 308
#define __LDBL_DENORM_MIN__ 4.9406564584124654e-324L
#define __STDC__ 1
#define __PTRDIFF_TYPE__ int
#define __DEC64_SUBNORMAL_MIN__ 0.000000000000001E-383DD
#define __DEC128_MANT_DIG__ 34
#define __LDBL_MIN_10_EXP__ (-307)
#define __SIZEOF_LONG_LONG__ 8
#define __LDBL_DIG__ 15
#define __GNUC_GNU_INLINE__ 1

More information about the jhc mailing list