Skip to content

Embedding sc (bring your own build system)

Johan Sköld edited this page Nov 16, 2016 · 2 revisions

sc is meant to be embeddable. That is, you should be able to drop the source files inside your project and compile directly, without having to build and link sc separately. The fact that much of it is assembly can make this seem more complicated than it is. This page is meant to serve as a guide for how to achieve it in different configurations.

I am constantly looking for ways to make this easier to do, so if you have any ideas I am open to suggestions!

GCC / Clang

When building with GCC or Clang, embedding is fairly trivial:

  • Add src/sc.c and all src/asm/*.S files to your project, and ensure all of them are being compiled.
  • Ensure the .S files are being assembled with preprocessor support. This is most easily achieved by making sure the compiler being used is gcc or clang rather than as, as the two former both recognize the uppercase extension to mean that it needs preprocessor support.
  • Ensure src/sc.c can find include/sc.h through #include.

As long as the above is done, it should compile properly for any supported platform. Please note that for the Visual Studio wrapper of Clang that is installed as part of the LLVM installation on Windows, you should instead follow the Visual Studio steps below.

Visual Studio

Unfortunately the assembler that ships with Visual Studio isn't quite as feature rich as GCC and Clang, so it requires a bit more manual work:

  • First, enable MASM support for the Visual Studio project that will contain the sc source files. To do so in Visual Studio, open the Build Customizations dialog through the project's context menu (VS2013+: 🖼; VS2012-: 🖼), tick the checkbox for masm, and click OK. 🖼
  • Add src/sc.c, src/asm/jump_masm.asm, and src/asm/make_masm.asm to your project, and ensure all of them are being compiled.
  • Ensure src/sc.c can find include/sc.h through #include.
  • For 32-bit Windows, make sure the symbol SC_WIN32 is defined for the two .asm files. For 64-bit Windows, the symbol should instead be SC_WIN64. In Visual Studio this is done through the properties window for either the project or the individual files. Take special note to put it under the Microsoft Macro Assembler section, not C/C++. 🖼

That should be it. If you are using a project generation system, you may have to figure out how to do these steps on your own. If you do however, I would be happy to hear how you did it so it can be documented!