maanantai 27. kesäkuuta 2016

Running COBOL on Arduino using the Meson Build System



In my previous post we found out how to compile projects for the Arduino, which is a bare metal 8 bit microcontroller. One of the advantages of using a full fledged build system is that you can use all the tools in the world as opposed to the basic ones that come with the Arduino IDE. Like, for example, the GNU COBOL compiler.


The implementation is actually quite simple. GNU COBOL does not compile to machine code. Instead it transpiles to plain C and does most of the COBOLy things with a runtime library. The design is pretty clever and there is very little setup and configuration. Best of all, it is easy (well, relatively easy at least) to write code that does not cause the COBOL runtime to call into malloc.

The rest of the implementation work is straightforward. We compile the COBOL code into a C file and try to compile it. First it fails due to a missing libcob.h. We just create one that is empty. After that it fails with missing struct and function definitions. Struct definitions can be stolen from the real libcob.h. The functions are a bit more work, but writing skeleton implementations that do just the bare minimum to get the program running did not take particularly long.

Then it is just a question of hooking the COBOL compilation to the build system and we are done. The code is available in this Github repo.


perjantai 24. kesäkuuta 2016

Meson build system now has Arduino support

After some midsummer hacking Meson now has support for building and uploading Arduino projects. (caveat: this MR needs to land to master first). This is what it looks like.

A sample project to clone has been set up in Github. It currently only supports Linux and Arduino Uno but the repo has documentation on how to adapt it to your configuration.