-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Building Projects
See the emmaken tool (tools/emmaken.py
), and instructions inside, which helps with building large projects. Also see how the large tests in tests/runner.py
are built - the C/C++ project is actually built using configure
, make
and so forth (using emmaken.py
). Specifically, the large tests include: freetype
, openjpeg
, zlib
and poppler
.
Also worth looking at the build scripts in the following projects:
- https://github.com/kripken/ammo.js/blob/master/make.py
- https://github.com/mbebenita/Broadway/blob/master/Avc/make.py
- https://github.com/kripken/j2k.js/blob/master/make.py
The documentation below gives more low-level details of the process, most of which you do not need if you use emmaken.py (but it might help to understand things).
-
The basic idea is replacing the normal compiler with Clang or llvm-gcc, and telling it to emit LLVM bitcode. Also replace the linker with
llvm-link
.-
In CMake this can be done with:
SET(CMAKE_C_COMPILER "/..PATH../llvm-gcc") SET(CMAKE_CXX_COMPILER "/..PATH../llvm-g++") SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -emit-llvm)` SET(CMAKE_LINKER "/..PATH../llvm-link") SET(CMAKE_CXX_LINKER "/..PATH../llvm-link") SET(CMAKE_C_LINK_EXECUTABLE "/..PATH../llvm-link") SET(CMAKE_CXX_LINK_EXECUTABLE "/..PATH../llvm-link") SET(CMAKE_AR "/..PATH../llvm-link") SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> -S -o <TARGET> <LINK_FLAGS> <OBJECTS>") SET(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> -S -o <TARGET> <LINK_FLAGS> <OBJECTS>") SET(CMAKE_RANLIB "echo") # Hackish way to disable it
-
In a Makefile, this can be done with:
C = /..PATH../llvm-gcc CXX = /..PATH../llvm-g++ LINKER = /..PATH../llvm-link CXX_LINKER = /..PATH../llvm-link # Undefining architecture stuff means code will not generate ASM CXXFLAGS=' -emit-llvm -U__i386__ -U__x86_64__'
-
-
Build the project using its normal build system, makefiles, etc. Note that it might fail if it tries to generate executables; you should probably just create libraries. Use
make VERBOSE=1
to see the commands being run, so you can make sure you are using the right compiler, etc. -
Run
llvm-link
to combine libraries. -
Compile the generated
.bc
file using Emscripten.
See the readmes and makefiles in the big tests, like tests/python
, tests/lua
, tests/bullet
, etc., they explain how the project was built into a .bc or .ll file.