Skip to content

Compiling

nepx edited this page Jan 7, 2020 · 2 revisions

Compiling

You will need the following installed:

  • A C99-compliant compiler
  • zlib
  • SDL 1.2
  • nodejs
  • Emscripten (optional)

The project doesn't have a traditional Makefile. In its place, I created a messy script that cobbles together different compiler flags for different builds and lets you produce object files for multiple targets without having to clear the build directory.

No build configuration needs to be done. Simply run makefile.js.

Examples

The following command produces a debug executable: no optimizations, full debugging information.

 $ node makefile.js

The following command produces a release executable: full optimizations, no debugging information.

 $ node makefile.js release

The following command produces a debug version of halfix.js:

 $ node makefile.js emscripten

The following command produces a release version of halfix.js:

 $ node makefile.js emscripten release

The following command produces a release version of halfix.wasm:

 $ node makefile.js emscripten release --enable-wasm

After compilation is finished, simply run the executable from the command line or serve up index.html in your local browser.

How does the build system work?

The build system is transparent: you modify files, and the script compiles the ones that have been modified since the executable has been last created. All object files go in build/objs.

The build system produces a unique hash constant that describes which combination of compiler flags each source file has been compiled with. It also checksums all the bytes in the name and adds them together to get a unique value identifies the file. Each object file is named {file name checksum}-{source directory}-{compiler flags hash}.o.

This system allows you to compile multiple versions of Halfix at once without having to clean the object file cache every time you switch between versions.

Compilation Notes

Halfix is written with code quality in mind, so each source file is compiled with -Wall -Wextra -Werror. This has caught many bugs. However, in some cases, these command line flags will cause problems when one compiler causes a warning/error that another compiler does not.

*If Halfix does not build on the first run, then try removing -Werror from the build flags.`

On Windows, command output is garbled due to NodeJS stdio piping issues. In this case, simply copy down the build flags for the offending files.

It's impossible for me to test compilation and runtime execution on every combination of operating system and compiler, so if something goes wrong, please send a pull request or create an issue.

Clone this wiki locally