compiler_guide

In order to compile Haxe, download install.ml, install OCaml, and simply run ocaml install.ml from the commandline. After that you'll get a ./bin/haxe binary. You also need the files and directories inside the ./std directory which contain the .hx standard Haxe library and other platform specific files.

Haxe is using neko to compile for server-side development. Neko binaries are also part of the Haxe distribution and must be downloaded from NekoVM.org and compiled separately.

Here are more detailed instructions for each possible platform.

Compile Haxe Tools

Two additional tools can be compiled : haxedoc, the Haxe documentation generator and haxelib, the Haxe library manager. You can compile these by going into the directory haxe/std/tools/haxedoc and haxe/std/tools/haxelib and by running the corresponding .hxml file. It will compile a binary executable file. You need Neko to be installed first.

Windows / VisualC++

To start with you should have Microsoft Visual Studio and TortoiseCVS installed. If you install the free Visual C++ 2005 Express Edition, you will also need to install the MASM (Microsoft Assembler) and Platform SDK (or use this older version if you're on Windows 2000). Note that Visual C++ 2008 Express Edition requires Service Pack 1 for MASM support.

Add C:\Program Files\TortoiseCVS to your PATH.

Download and install the "Microsoft toolchain" version of Ocaml.

Ensure you have the aforementioned install.ml. Save this file in the same directory as you would like to put all the other Haxe files, e.g. C:\haxe\install.ml

Download zlib from http://www.zlib.net/zlib123-dll.zip and extract the contents to C:\haxe\zlib123-dll. Copy (or rename) C:\haxe\zlib123-dll\lib\zdll.lib to zlib.lib

You will now want to open the Visual Studio command prompt. (See the extra Visual Studio Tools under the main Visual Studio menu ).

In this command prompt, enter these commands:

cd C:\haxe\
SET LIB=%LIB%;"C:\haxe\zlib123-dll\lib"
SET INCLUDE=%INCLUDE%;"C:\haxe\zlib123-dll\include"

and now run the install:

ocaml install.ml

If you finish with:

copy zlib123-dll\zlib1.dll bin

you should then have a working haxe.exe in C:\haxe\bin\.

To make it work, you have to make sure the std directory is next to the haxe.exe file. So, copy c:\haxe\haxe\std and all contents to c:\haxe\bin\std.
Finally, you can use the haxesetup.exe file bundled with a binary release to set up the environment correctly: Copy haxesetup.exe to c:\haxe\bin\haxesetup.exe and run it.

Enjoy!

Windows / Cygwin

As with everything, please read all instructions before starting.

- Install Cygwin if you have not done so already.

- When installing or upgrading, don't forget to check for autoconf, automake, binutils, gcc and ocaml.
This tools are standar for compiling stuff, and ocaml is necesary for haxe compilation.

- You will also need zlib, you can install the cygwin one or get the latest version at zlib homepage, download it and compile it.

- Put the install.ml in a folder, for example haxebuild.

- In such folder, create a bin folder, and a zlib folder. ( example /path/to/haxebuild/bin, /path/to/haxebuild/zlib)

- Inside the zlib dir, create symbolic links for /usr/include/zconf.h, /usr/include/zlib.h, /usr/lib/libz.a:

ln -s /usr/include/zconf.h zconf.h
ln -s /usr/include/zlib.h zlib.h
ln -s /usr/lib/libz.a libz.a

After that you will need to modify install.ml

Comment the line that starts #load "unix.cma". Comments in this file begin with (* and end with *).
So your line will read (* #load "unix.cma" *) .
This is necessary because we are not compiling for a true unix environment.

Uncomment the line that says
let os_type = "Cygwin"

Change the next line that says:
let obj_ext = match os_type with "Win32" -> ".obj" | _ -> ".o"
for:
let obj_ext = match os_type with "Win32" -> ".obj" | "Cygwin" -> ".o" | _ -> ".o"
(you add the object extension for cygwin).

Change the sections that says:
let zlib_path = match os_type with
| "Win32" -> "../ocaml/extc/zlib/"
| _ -> "./"
for:
let zlib_path = match os_type with
| "Win32" -> "../ocaml/extc/zlib/"
| "Cygwin" -> "../zlib/"
| _ -> "./"
(You add the cygwin zlib path, the one with the symbolic links).

Change the section that says:
let zlib = match os_type with
| "Win32" -> zlib_path ^ "zlib.lib"
| _ ->
for:
let zlib = match os_type with
| "Win32" -> zlib_path ^ "zlib.lib"
| "Cygwin" -> zlib_path ^ "libz.a"
| _ ->
(added the cygwin file)

Around line 85 you'll find a line that says
cvs motiontwin "login";

remove the word "login", (it caused trouble for me).

Comment the line that says:
(try Unix.mkdir "bin" 0o740 with Unix.Unix_error(Unix.EEXIST,_,_) ->());

Write your changes and at the bash prompt type

ocaml install.ml.

It will download the necesary sources from cvs, and then proceed to compile them.
After compilation is done, you will have your brand new haxe.exe in the bin directory you created before.

Copy it to wherever you want, and don't forget the std dir also, as it's includes the haxe
standard libraries.

Windows / Mingw

Before starting, please read the notes below.

Notes

- The installations of MinGW and MSYS are standard and can be used for other projects.
- You should install the packages in directories like c:/mingw or c:/my_path_without_space/mingw.
- You might not want to use the version 4.3.1 of gcc (latest available for MinGW) as some people reported it as sometimes unstable... See Links for other versions.
- GNUWin32 packages are optional but usefull, wget for example to download the install.ml.
- If you encounter problems with make in other projects, download and extract in your msys directory the lastest MSYS Make.

MinGW (Standard Install)

- Download MinGW
- Donwload MinGW Binutils
- Download MinGW Runtime
- Download MinGW Win32Api
- Download MinGW Utils
- Download MinGW GDB
- Download MinGW Make

- Download MinGW GCC 4.3.1 - core
- Download MinGW GCC 4.3.1 - g++

- Install MinGW and then simply extract all the other archives in your mingw directory.

MSYS (Standard Install)

- Download MSYS
- Download MSYS DTK
- Download MSYS Bash

- Install MSYS then MSYS-DTK and extract the bash in your msys directory.

OCaml

- Download and install MinGW-OCaml

libZ

- Donwload MSYS zlib

Note: You can also download the latest zlib tarball and compile it under MinGW.

GNUWIN32 (Optional)

- Download and install GNUWin32 Wget
- Download other GNUWin32 packages your're interested in. See Links.

Configure MSYS

- Create ocaml and gnuwin32 directories in path/to/msys/.
- Edit path/to/msys/etc/fstab, add 2 lines at the end: X:/my/path/to/gnuwin32 /gnuwin32 and X:/my/path/to/ocaml /ocaml. See the existing line in this file for correct syntax.
- Create a .profile file in path/to/msys/home/your_name/ and add this line to the file:

export PATH=".:/usr/local/bin:/mingw/bin:/bin:/gnuwin32/bin:/ocaml/bin:$PATH"

- Create a haxe directory in path/to/msys/home/your_name/
- Create a zlib directory in path/to/msys/home/your_name/haxe/
- Extract MSYS zlib archive somewhere and copy include/zconf.h, include/zlib.h and lib/zlib.a to your haxe/zlib/ directory.

Compile Haxe

- Download the Haxe install.ml
- Edit it, see below [1] the modifications to make in this file.

- Start MSYS terminal and type

cd haxe

- Start the installation by typing
OCAMLLIB="/ocaml/lib/" ocaml install.ml

- That will download the Haxe sources and start to compile Haxe.
- You'll get an error: "Installing extLib.lib", "Aborted", "Error in etc."

- Edit the file path/to/msys/home/your_name/haxe/ocaml/extlib-dev/install.ml. See below [2].
- Restart the installation

OCAMLLIB="/ocaml/lib/" ocaml install.ml

- Everything should be fine now and once finished you'll find haxe.exe in bin/

- You're done.

Note: Don't forget to copy the haxe/std directory along with your haxe.exe

File Modifications

Note: they are reversible in both files, you just have to comment the line: let os_type = "MinGW"

Haxe install.ml Modifications:

line 32 : after (* let os_type = "Cygwin" *) add a new line: let os_type = "MinGW".
line 36 : replace "Win32" | "Cygwin" by "Win32" | "Cygwin" | "MinGW"
line 40 : add a new line: | "MinGW" -> "../zlib/"
line 45 : add a new line: | "MinGW" -> zlib_path ^ "libz.a"

extlib-dev install.ml Modifications:

line 52 : add 2 lines : let os_type = Sys.os_type and let os_type = "MinGW"
line 55 : replace Sys.os_type by os_type
line 56 : replace | "Unix" | "Cygwin" | "MacOS" by | "Unix" | "Cygwin" | "MacOS" | "MinGW"

Links

- MinGW/MSYS Home Page
- Latest MinGW/MSYS packages
- Latest GCC for MinGW
- GNUWin32 packages

Linux

The complete build and install process looks like (may contains some minor errors) :

mkdir haxe
cd haxe

# download and compile haxe, you may require some development libraries 
# like libmysql, libz, libsqlite3, ... and of course ocaml
wget http://haxe.googlecode.com/svn/trunk/doc/install.ml
ocaml install.ml

# install haxe in /usr/local
sudo mkdir /usr/local/haxe
sudo mkdir /usr/local/haxe/bin
sudo cp haxe/bin/* /usr/local/haxe/bin
sudo cp -r haxe/std /usr/local/haxe
sudo ln -s /usr/local/haxe/bin/haxe /usr/local/bin/haxe

# setup environment variables for haxe
sudo grep "HAXE_LIBRARY_PATH" /etc/environment || echo "export HAXE_LIBRARY_PATH=/usr/local/haxe/std:." >> /etc/environment

# download and compile neko
cvs -d:pserver:anonymous@cvs.motion-twin.com:/cvsroot login
cvs -d:pserver:anonymous@cvs.motion-twin.com:/cvsroot co neko
cd neko
make

# install neko
sudo mkdir /usr/local/neko
sudo cp bin/* /usr/local/neko
sudo ln -s /usr/local/neko/neko* /usr/local/bin/
sudo ln -s /usr/local/neko/libneko.so /usr/local/lib

# may be required if /usr/local/lib is not in your library search path
sudo grep "/usr/local/lib" /etc/ld.so.conf || echo "/usr/local/lib" >> /etc/ld.so.conf
sudo ldconfig

# setup environment variables for neko
sudo grep "NEKOPATH" /etc/environment || echo "export NEKOPATH=/usr/local/neko" >> /etc/environment

Two quick notes about building Neko:

  • Since subshell () is used in the Neko Makefile, you may get a segfault from bash because of insufficient stack. To avoid this problem, you can increase the stack size by 'ulimit -s 20000'.
  • If you are not using gcc or an earlier gcc version, the option -fno-stack-protector may not be recognized. All you need to do is to removed it from the Neko Makefile. (Also comment it out in src/tools/neko.install, line 82 and 83).

Some additional notes (ppelleti Thu Dec 20 00:07:05 PST 2012):

  • Uncaught exception - module.c(124) : Builtin not found : fasthash seems to be a symptom that neko is too old (e. g. the one installed from the OS distribution)
  • When building neko from source, the cvs checkout failed for me with cvs server: cannot find module `neko' - ignored - using svn checkout http://nekovm.googlecode.com/svn/trunk/ nekovm-read-only worked better for me
  • vm/alloc.c:40:19: fatal error: gc/gc.h: No such file or directory is a symptom of not having the Boehm garbage collector installed; sudo apt-get install libgc-dev fixes this on Ubuntu

Apache2

Using the debian/ubuntu apache2 configuration structure :

# add NEKOPATH variable to apache2 environment vars
sudo grep "NEKOPATH" /etc/apache2/envvars || echo "export NEKOPATH=/usr/local/neko" >> /etc/apache2/envvars

# create a neko.conf in available modules
sudo test -f /etc/apache2/mods-available/neko.conf || echo "AddHandler neko-handler .n" >> /etc/apache2/mods-available/neko.conf

# create a neko.load in available modules
sudo test -f /etc/apache2/mods-available/neko.load || echo "LoadModule neko_module /usr/local/neko/mod_neko2.ndll" >> /etc/apache2/mods-available/neko.load

# enable neko module
sudo ln -s /etc/apache2/mods-available/neko.* /etc/apache2/mods-enabled

# add index.n to DirectoryIndex in apache2.conf
sudo grep "index.n" /etc/apache2/apache2.conf || cat /etc/apache2/apache2.conf | sed -r 's/^DirectoryIndex (.*?)/DirectoryIndex index.n \1/' > apache2.conf.tmp && cp apache2.conf.tmp /etc/apache2.conf 
sudo test -f apache2.conf.tmp && rm apache2.conf.tmp

# restart apache2
/etc/init.d/apache2 restart

Linux Debian (etch)

The complete build and install process looks like (may contains some minor errors) :

mkdir haxe
cd haxe

# download and compile haxe, you may require some development libraries 
# like libmysqlclient15-dev, zlib1g-dev, libsqlite3-dev, ... 
# and of course you require ocaml, ocaml-findlib and cvs
wget http://haxe.googlecode.com/svn/trunk/doc/install.ml
ocaml install.ml

# install haxe in /usr/local
sudo mkdir /usr/local/haxe
sudo mkdir /usr/local/haxe/bin
sudo cp bin/* /usr/local/haxe/bin
sudo cp -r haxe/std /usr/local/haxe
sudo ln -s /usr/local/haxe/bin/haxe /usr/local/bin/haxe

# setup environment variables for haxe
sudo grep "HAXE_LIBRARY_PATH" /etc/environment || echo "export HAXE_LIBRARY_PATH=/usr/local/haxe/std:." >> /etc/environment

Neko from backports.org

Download and install neko from Debian Backports

OSX

Building on Mac PPC

(Please list info here)

Building on Mac Intel

Building on Mac Intel requires an Intel build version of OCaml. You can download it from http://caml.inria.fr/pub/distrib/ocaml-3.10/ or install it via Macports with port install ocaml.

Once the local Intel build OCaml version is in place, proceed with downloading install.ml. Create a folder where you'd like the sources to be downloaded to, and copy the .ml file there. Open install.ml and comment out line 20: (* #load "unix.cma" *).

Don't directly run the file but compile it first, using ocamlc unix.cma install.ml. Next, run the compiled installer using $ ./a.out

After a successful build, the Haxe compiler will be in the bin folder.

In case you want to have the final std folder location other than /usr/lib/haxe/std/ or /usr/local/lib/haxe/std/ you need to change Plugin.class_path in main.ml to your preferred location and start over.

Creating a distribution

To have your local build packaged up for distribution you can use the PackageMaker project from this repository. Make sure to place the sources in a folder adjacent to your haxe build folder (i.e., if ../projects/haxe is where you placed install.ml or checked out the Haxe sources using CVS, than the installed package sources should be at ../projects/haxe-inst)

Be sure to modify the version numbers listed within the project file, and the INFO.txt file. Open haxe.pmproj with the PackageManager. Do a quick run-through through the PackageManager Interface Editor and resolve the hard-set paths on the background image, and the LICENCE.txt and INFO.txt files to your local paths. Once this maintenance is done, save the project but leave the PackageManager application without building the package.

Open a terminal window and go to the installer sources root folder. Type $ ./package . Your distribution should be ready (at haxe.pkg).

Creating a Universal distribution

Creating a Universal distribution only requires that you have a version of the Haxe compiler build for the opposite platform of your local build. So, if you build Haxe on Intel, ask someone on the list for the eqivalent PPC version - or vice versa. This way you'll end up with two versions of the Haxe compiler.

Open a terminal at the bin folder of your Haxe source folder. Rename haxe to either haxe_ppc or haxe_i386, depending on your platfrom. Next copy the haxe compiler for the opposite platform to the folder. Rename this file either haxe_i386 or haxe_ppc.

Run $ lipo -create -arch ppc haxe_ppc -arch i386 haxe_i386 -output haxe to have the two versions merged into one single Universal executable (haxe).

Continue creating your distribution as outlined at Creating a distribution. Don't worry about making haxelib and haxedoc Universal: they already, are since the underlying Neko binaries are.

version #15806, modified 2012-12-20 09:20:19 by ppelleti