Bakefile Internals (1/6)


In this this tutorial we explain the internal implementation details of Bakefile. Reading this tutorial may help you better understand how to use Bakefile or prepare you for making changes to it.


This tutorial assumes you know how to use the Bakefile tool to generate GNU makefiles and Visual Studio projects. We provide a a Bakefile tutorial that you can read if you are not familiar with Bakefile.

The Processing Pipeline

The Bakefile processing pipeline is illustrated on Figure 1.

The pipeline can be divided in two steps. First the input files files will be parsed and their contents turned into a model. The model will then be transformed into makefiles or Visual Studio project files by the toolsets.

Bakefile Processing Pipeline
Figure 1: Bakefile Processing Pipeline

In the next sections we will briefly present each of the elements of this pipeline.

The Parser

The parser transforms each input file into an Abstract Syntax Tree (AST). The purpose of the parsing stage is to built one AST per input file which can then be used to generate the model. Using an AST allows for a cleaner separation between the parsing of the files and the model generation. This is similar to what many compilers do.

The parser code is generated with ANTLR v3 [1].

The Model

As its name implies the model is the plan that needs to be followed to generate the makefiles. The input files of a Bakefile project are combined together to create a single model for the project.

To better understand what a model does it's probably best to simply show what one looks like.

A command line option can be used to dump the model rather than generating the makefiles: --dump-model. We will use that option on the first example we studied in our Bakefile tutorial. The Bakefile makefile for that example is reproduced below.

File: Bakefile/Basics/Win32Console1/Win32Console1.bkl
toolsets = vs2013;

program Win32Console1

If we run bkl on this bakefile and specify the --dump-model option we get the output below.

Output of "bkl Win32Console1.bkl --dump-model"
module {
  variables {
    toolsets = [vs2013]
  targets {
    program Win32Console1 {
      sources {
        file @top_srcdir/main.cpp

A complete description of the model is beyond the scope of this brief introduction and will be covered in more details later on. But you can already see from this example what kind of information the model contains. For instance it has one target, Win32Console1, which is a program. This target has a list of source files associated with it which has just one file: main.cpp. This is the same information that can be found in the Win32Console1.bkl file but in a different format.

The Toolsets

Each toolset is able to generate a specific type of native makefile from the model. Toolsets are available for the GNU build system and various versions of Visual Studio.


  1. ANTLR v3

blog comments powered by Disqus

Copyright(c) 2006-2017 Xavier Leclercq | Privacy policy

Contact Us