Build Haxe on Mac OS X

Mac OS X Intel

Prerequisities

Installing XCode

Before you begin you have to make sure, that your system has a compiler (gcc) and compiling tools (make, automake,...) installed. You can check this at your Terminal:

gcc

If nothing can be found it's time to install the compiler with XCode. Download and install it from here http://developer.apple.com/technology/xcode.html

Installing Macports


Macports is an open source package manager that helps you to compile and install typical GNU/Linux software. Download and install it from here http://www.macports.org/install.php and then open your Terminal.

Installing the required packages with Macports


The Haxe compiler is written in the OCaml language. Therefore we have to install Ocaml first. Additionally we make sure that the most essential tools are installed.

sudo port install ocaml cvs wget subversion

Installation


You can use the following shell script for the complete build and install process.

1. copy the contents of the installation script into a shell script, like "installhaxe.sh"

vim installhaxe.sh

2. make it executable:
sudo chmod 0755 installhaxe.sh

3. run it:
./installhaxe.sh

installation script:


#!/bin/sh
# installhaxe.sh
#
# Build the haxe compiler
# =====================
# - download 'install.ml' and execute it (compiles the haxe compiler)
# - copy the executables and modify the evironment variables

if [ ! -d haxesrc ] 
    then mkdir haxesrc 
fi
cd haxesrc

if [ -f install.ml ] 
    then rm install.ml 
fi
    
wget http://haxe.googlecode.com/svn/trunk/doc/install.ml
ocaml install.ml

# reset previous installations
sudo rm -rf /usr/lib/haxe

# install haxe in /usr/lib
sudo mkdir /usr/lib/haxe
sudo cp bin/haxe /usr/lib/haxe/
sudo rsync -av --exclude='*/.svn*' haxe/std /usr/lib/haxe

# setup environment variables for haxe
sudo grep "HAXE_LIBRARY_PATH" ~/.bash_profile || echo "export HAXE_LIBRARY_PATH=/usr/lib/haxe/std:." >> ~/.bash_profile
source ~/.bash_profile

Environment variables

The following two variables should be defined in your ~/.bashrc file:

1.) $HAXE_LIBRARY_PATH


Please make sure that the haxe compiler finds its libraries by correctly setting up the environment variable in your ~/.bashrc.

2.) $HAXE_HOME


Additionally, it doesn't hurt to define the location of your Haxe installation.
# somewhere in your ~/.bashrc
# ...
# the ':.' part after std is important
export HAXE_LIBRARY_PATH=/usr/lib/haxe/std:. 
export HAXE_HOME=/usr/lib/haxe
PATH=$PATH:$HAXE_LIBRARY_PATH:$HAXE_HOME/bin

To initialize the variables you have to call your ~/.bashrc file:

source ~/.bashrc

It is also a good idea to run:

ls -l `which haxe`

Verify that the haxe binary is now called from /usr/lib/haxe/haxe (or wherever you specified), and that the date created is today.

Final function test

Please run this little test to see if Haxe is able to compile your code.

File Test.hx

 
class Test{
    public static function main(){
        trace('hello world!');
    }
}

File compile.hxml:

  
-main Test
-x Test

Compile it:

 haxe compile.hxml 

Troubleshooting

In case you get the following error:
Standard library not found

make sure that your environment variables are correct:

echo $HAXE_LIBRARY_PATH

You should get something like
/usr/lib/haxe/std:.

then check if the files are there

$ ls /usr/lib/haxe/std/
 Enum.hx  flash9   IntHash.hx  Lambda.hx ...

Other Information about Building on Mac Intel

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

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/ you need to change Plugin.class_path in main.ml to your preferred location and start over.

Finally, if you wish to update your installation to the newest svn version, simply run the installhaxe.sh script again. It will update the install.ml file, update the svn copies, and reinstall everything.

version #19812, modified 2013-10-10 15:25:57 by vault