Posts Tagged ‘neko’

SamHaXe + Snow Leopard

Sunday, November 29th, 2009

Ex spies and big cats don’t always get along well. The main problem you will face when trying to compile SamHaXe on OS X 10.6 is that the Neko version you got from installing HaXe (Which I will assume you have installed) is a 32 bit one. SamHaXe will not be able to link against libneko.dylib when you compile, because your target architecture is 64-bit in Snow Leopard.

After some fiddling around and some kick-ass help from the SamHaXe mailing list I finally managed to get SamHaXe up and running on Snow Leopard. In a nutshell, the solution is to compile a 64-bit Neko before you compile SamHaXe.

Here’s how how to do it:

  1. First install MacPorts. It will make it a lot easier to get the right dependencies.
  2. Then install PCRE and ImageMagick:
    $ sudo port install ImageMagick pcre

    This will take ages, so go get a good book or something. :)

  3. Neko will need to link against Hans Boehms garbage collector, so you will need to compile and install that before getting on with Neko. Go and get version 7.1 from the downloads section at http://www.hpl.hp.com/personal/Hans_Boehm/gc/.
    If you configure and compile it right away you will get an error due to Apples aggressive deprecation policy, so you will have to get your hands dirty with some preprocessor code here.
    Open mach_dep.c and find these lines:

    #if !defined(HAVE_PUSH_REGS) && defined(UNIX_LIKE)
    # include <ucontext.h>
    #endif

    Change them to this:

    #if !defined(HAVE_PUSH_REGS) && defined(UNIX_LIKE) && !defined(DARWIN)
    # include <ucontext.h>
    #elif defined(DARWIN)
    # include <sys/ucontext.h>
    #endif

    Now you can do the usual

    $ ./configure
    $ make
    $ make install
  4. Ok, now you’re all set for compiling a 64-bit Neko. Version 1.8.1 that is the current official version has a bug in it that prevents using modules on Snow Leopard, so you will have to get the CVS version. There’s instructions on the Neko downloads page: http://nekovm.org/download.
    Unfortunately, there’s a new OS X bug in the CVS version that you will have to work around manually for now (Hopefully this is fixed soon though). Here’s how:

    • Create a file called “clock_gettime_stub.c” in [neko-source-dir]/libs/std. Copy the contents from http://le-depotoir.googlecode.com/svn/trunk/misc/clock_gettime_stub.c into that file.
      [Edit: It appears that this file doesn't get compiled. So all you need is the change to neko.h below. This will allow Neko to compile, but I suspect it will crash at run time if something accesses the sys_thread_cpu_time() function. I will leave this be as long as it works for me though.]
    • Open [neko-source-dir]/vm/neko.h and put the following lines right above C_FUNCTION_END at the bottom of the file:
      #ifdef NEKO_MAC
       typedef enum {
           CLOCK_REALTIME,
           CLOCK_MONOTONIC,
           CLOCK_PROCESS_CPUTIME_ID,
           CLOCK_THREAD_CPUTIME_ID
       } clockid_t;
       EXTERN int clock_gettime(clockid_t clk_id, struct timespec *tp);
       #endif
      

      [Edit: This has been fixed on CVS now, so this step should no longer be needed]

    Now you can compile Neko like this:

    $ make MACOSX=1

    You will be asked three times about headers for mod_neko, mod_tora and mysql. I decided to simply skip these as I won’t need them.

  5. Now you have a 64-bit binary version of neko in the [neko-source-dir]/bin directory. To install it to your system, make a backup copy of /usr/lib/neko and then copy the contents of [neko-source-dir]/bin into it and replace what ever is in there.
  6. Now you should be able to compile SamHaXe. Follow these steps:
    • Create ant.config and put these lines in it. The paths should be correct for a default installation of MacPorts.
       haxe.path=/usr/bin
       haxe.stdpath=/usr/lib/haxe/std
       imagemagick.path=/opt/local/bin
       imagemagick.include.path=/opt/local/include/ImageMagick
       imagemagick.library.path=/opt/local/lib
       imagemagick.library.name=MagickWand
       neko.path=/usr/lib/neko/
       neko.include.path=/usr/lib/neko/include
       neko.library.path=${neko.path}
       freetype.path=/opt/local/bin
       freetype.include.path=/opt/local/include/
       freetype.library.path=/opt/local/lib
    • Open build.xml and change image-imagemagick.dylib to libimage-imagemagick.dylib on line 238 and font.dylib to libfont.dylib on line 317
    • Now type ‘ant’ in the terminal to compile.
  7. That’s it! If all went like it should you now have a fully working SamHaXe in the [samhaxe-source-dir]/bin directory.

A problem you might encounter is that haxelib won’t work with the 64-bit neko, since haxelib is 32-bit by default. To fix this, you can compile a new haxelib from /usr/lib/haxe/std/tools/haxelib/. Simply cd to that directory and do “haxe haxelib.hxml”. Then copy the new binary over the old /usr/bin/haxelib.