Building Haxe on Ubuntu / Debian

Debian / Ubuntu

Prerequisities


The Haxe compiler is written in the OCaml language. Therefore we have to install Ocaml first. Additionally we make sure to have the most important tools and libraries installed.
sudo apt-get install ocaml camlp4 ocaml-findlib cvs zlib1g-dev make wget tar git subversion

Make sure to uninstall existing versions of Haxe which you may have previously installed via .deb packages or manually.

sudo apt-get remove haxe

and
sudo rm -rf /usr/lib/haxe
sudo rm -rf /usr/bin/haxe*

Installation


You can use the following shell script which handles the complete process. It will download the haxe source, build haxe and install it.

installation script:


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

# My libz was in a different place, maybe uncommenting helps
# sudo ln -s /usr/lib/i386-linux-gnu/libz.so /usr/lib/libz.so

mkdir haxesrc
cd haxesrc

wget http://haxe.googlecode.com/svn/trunk/doc/install.ml
ocaml install.ml

# reset previous installations
sudo rm -rf /usr/local/haxe
sudo rm -rf /usr/local/bin/haxe*


# 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
grep "HAXE_LIBRARY_PATH" /etc/environment || echo "export HAXE_LIBRARY_PATH=/usr/local/haxe/std:." | sudo tee -a /etc/environment
  • Since Haxe3 r6354 HAXE_LIBRARY_PATH is named HAXE_STD_PATH

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

vim installhaxe.sh

2. make it executable:
chmod +x installhaxe.sh

3. run it:
./installhaxe.sh

Environment variables

The following two variables should be defined in the etc/profile file:

1.) $HAXE_LIBRARY_PATH


Please make sure that the haxe compiler finds its libraries (the std folder) by correctly setting this environment variable.

2.) $HAXE_HOME


Additionaly it doesn't hurt to define the location of your Haxe installation.
# in /etc/profile
# ...
export HAXE_LIBRARY_PATH=/usr/local/haxe/std:. # the ':.' part is important
export HAXE_HOME=/usr/local/haxe
PATH=$PATH:$HAXE_LIBRARY_PATH:$HAXE_HOME/bin
  • Since Haxe3 r6354 HAXE_LIBRARY_PATH is named HAXE_STD_PATH

Final function test

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

File Test.hx :

 
class Test { 
    static function main() { 
        trace("Hello World !"); 
    } 
}

File compile.hxml :

  
-js test.js
-main Test

Run from command line:

 haxe compile.hxml 

File index.html :
Html code for testing the JavaScript:

  
<html>
    <head>
        <title>Haxe JS</title>
    </head>
    <body>
        <div id="haxe:trace"></div>
        <script type="text/javascript" src="test.js"></script>
    </body>
</html>

version #20086, modified 2014-04-24 20:10:38 by mechagk