Edit on GitHub

[Pro] Headless: Make

Overview

Invoke headless code generation with make.

Integration in GNU Make

With Makefiles, you are able to define your compile targets and its dependencies. Every time a dependency is changed, the next run of Make will recompile said target. Using this infrastructure it is pretty simple to generate code from statecharts whenever needed.

The build of this project can be viewed as a dependency tree. To build the executable, we would need to link the object files main.o and defaultSM.o. To create these, we need to compile main.c and defaultSM.c. To have defaultSM.c we need to generate the statechart from defaultSM.sct and defaultSM.sgen – that’s it. The makefile looks like this:

.PHONY: all.PHONY: cleanall: mainmain: src-gen/DefaultSM.o main.o    gcc -o main src-gen/DefaultSM.o main.oclean:    rm -rf src src-gen *.o mainmain.o: main.c    gcc -Wall -c main.csrc-gen/DefaultSM.o: src-gen/DefaultSM.c    gcc -Wall -c src-gen/DefaultSM.c -o src-gen/DefaultSM.osrc-gen/DefaultSM.c: defaultSM.sct defaultSM.sgen    scc

It’s a good practice to name the default target ‘all’, but you could remove it. The line main: src-gen/DefaultSM.o main.o states that the file main (the final executable, no file ending is needed on Linux) depends on both these object files. The order is important here, because otherwise the compiler would fail, stating that the header files also generated from the statechart are not available when compiling main.c – you could work around this but this is an easy solution. Both these dependencies are reinterpreted as targets, which have other dependencies. This is standard make stuff. The most interesting entry is this:

src-gen/DefaultSM.c: defaultSM.sct defaultSM.sgen    scc

This says “to produce src-gen/DefaultSM.c, which depends on defaultSM.sct and defaultSM.sgen, call ‘scc’". Calling scc without arguments is possible here, because the Makefile is located in the project and scc will just generate everything in there. Adding both the *.sct and the *.sgen file has the additional benefit that a change in either of them results in a re-generation of the statechart sources – for example when you change the options in the *.sgen file. The clean target removes all object files and the folders src and src-gen, both generated by YAKINDU Statechart Tools. Pay attention when you have sources in ‘src’ as well.

Download examples

Drag to install

Drag to your running YAKINDU Statechart Tools (min. version 2.8.0) workspace.

Back to overview