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 subversion
Make sure to uninstall previous versions of Haxe 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 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 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://code.google.com/p/haxe/source/browse/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 sudo grep "HAXE_LIBRARY_PATH" /etc/environment || echo "export HAXE_LIBRARY_PATH=/usr/local/haxe/std:." >> /etc/environment
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
Additionaly it doesn't hurt to define the location of your Haxe installation.
# somewhere in your ~/.bashrc # ... 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
To initialize the variables you have to call your ~/.basrc file:
source ~/.bashrc
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
Compile it:
haxe compile.hxml
And here the html code for calling 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>
Troubleshooting
From the step:
Compile it:
haxe compile.hxml
In case you get the following error:Class not found : Test
make sure that your environment variables are correct:
echo $HAXE_LIBRARY_PATH
You should get something like
/usr/local/haxe/std:.
then check if the files are there
$ ls /usr/local/haxe/std/ Enum.hx flash9 IntHash.hx Lambda.hx ...