Tuesday, May 21, 2013

Setting up an Amazon EC2 machine to compile Emscripten

To use this tutorial, you should go to the amazon ec2 management console and create an instance of Amazon Linux ami. Make sure for the group policy of your ami, you allow ports 21, 22, 80, 3389, 8080. This will make your life easier as it allows you to setup a web service and view the emscripten output live. Also, you will most likely like to sftp into the site along with ssh.

Once your Amazon Linux ami is up and running, connect via ssh and let's begin setting up your machine to build with emscripten!

Get emscripten code

Install git with this command:
$ sudo yum install git

Get the source code for emscripten:
$ git clone git://github.com/kripken/emscripten.git

Get clang/llvm

Go to the webpage http://llvm.org/releases/download.html
You're linux box should be 64 bit so you will want the download for "Clang Binaries for Ubuntu-12.04/x86_64"
Download this file, then rename it to something simpler like llvm.tar.gz
Copy this to your amazon box user folder - I used winscp to copy it to where I wanted.

Now run the command to unzip the file:
$tar -xzvf llvm.tar.gz

Rename the folder it unzipped to "llvm" to make life easier. Again I used winscp to do the rename, use whatever is comfortable for you.

Create the config file for emscripten

Go to your emscripten folder
$cd emscripten

Run the command to build the config files
$./emcc

Fix the path to the llvm code you downloaded
$nano ~/.emscripten
In the file change the path to be something like:
LLVM_ROOT='home/ec2-user/llvm/bin'

Upgrade Glib
The image comes with 2.12. Emscripten needs 2.15!

Change directory so you are in your user folder.
To get the installer run:
$wget http://ftp.gnu.org/gnu/glibc/glibc-2.15.tar.gz

Unzip the installer and navigate to the folder:
$tar -xvzf glibc-2.15.tar.gz
$cd glibc-2.15

Make and navigate to a build folder
$mkdir glibc-build
$cd glibc-build

Create the config file, build and install
$../configure --prefix='/usr'
$make
$sudo make install

This process takes a while so get coffee after you run $make!

Install JS Node

Follow these instructions:
http://faantasticcoder.blogspot.com/2013/05/installing-nodejs-on-amazon-ec2-linux.html

Run emscripten

At this point emscripten is installed and you should be able to run emscripten.

Navigate to the emscripten folder under your user folder (where you ran git).

Run:
$cd emscripten
$./emcc




You should see the following output:


No comments:

Post a Comment