Manually Building Emscripten on Mac OS X

This page contains basic instructions on how to manually build and configure Emscripten from source on a clean Mac OS X box (tested on OS X version 10.8.2).

Note

The instructions clone from the main Emscripten repository (https://github.com/kripken/emscripten). Contributors should instead clone from their own Emscripten fork, and submit changes as pull requests.

Tip

You can also build Emscripten from source using the SDK. This is recommended if you need easily switch between SDK and source builds.

What you’ll need

The specific versions of tools that are needed are listed in the Emscripten Toolchain Requirements.

Installing required tools

These instructions explain how to install all the required tools. You can test whether some of these are already installed on the platform and skip those steps.

  1. Install the XCode Command Line Tools. These include the toolchain to build Fastcomp, and are a precondition for git.

    • Install XCode from the Mac OS X App Store.
    • In XCode | Preferences | Downloads, install Command Line Tools.
  2. Install git:

  3. Install cmake if you do not have it yet:

    Tip

    This specific version (2.8.10) is recommended — it has been tested and shown to work. Other versions may not correctly set up the PATH variables, with the result that running cmake gives you “not found” errors.

  4. Install node.js from http://nodejs.org/

  5. Setup python2 (this step is needed to workaround a bug reported in #763):

    • In terminal, type python2 --version. If you get a “command not found”, type the following:

      cd /usr/bin
      sudo ln python python2
      sudo ln ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 python22.7
      
    • Enter python2 --version again. It should now print Python 2.7.2

  6. Build Fastcomp (LLVM + Clang) from source using these instructions.

  7. Clone the kripken/emscripten repository from Github. This repository contains the main compiler tool for compiling C/C++ programs to JavaScript:

    • Create a directory (with no spaces in the name) to contain the clone.

    • Enter the following command into the terminal:

      git clone https://github.com/kripken/emscripten.git
      

Configuring Emscripten settings

Almost all the compiler settings used by Emscripten are defined in the compiler configuration file (~/.emscripten), a user-specific file located in the user’s home directory.

Instructions for creating and manually configuring up this file are given in Configuring Emscripten Settings when Manually Building from Source.

Validating the environment

The best way to validate the environment is to build some code. Open the terminal in your Emscripten directory (where emcc is located) and enter:

./emcc tests/hello_world.cpp

If this builds a.out.js in the current directory, and you don’t see any build errors in the terminal, Emscripten is good to go!

There are additional validation and troubleshooting instructions in the topic: Verifying the Emscripten Development Environment.