Bakefile Tutorial (1/4)


Bakefile ( is a cross-platform build system. Bakefile doesn't directy perform the build itself, instead it generates native makefiles (e.g. Visual Studio projects on Windows and GNU make makefiles on Linux) that can then be used to perform the actual build.


Installation of Bakefile is straightforward. Binary releases are available from

For Linux


For Windows

For Windows, download the bakefile-<version> file for the desired version. Inside this zip file you'll find the Bakefile executable, bkl.exe, along with some documentation. There is no complex installation procedure: bkl.exe is a standalone executable that doesn't require any specific setup and can be installed anywhere you want. For simplicity we copied it to C:\Program Files (x86)\Bakefile\bkl.exe and added this directory to the search path.

Creating a Visual Studio Project

We start with a simple example which shows how Bakefile can generate a Visual Studio project. The full example is available from our Codeplex repository at Bakefile/Basics/Win32Console1/Win32Console1.bkl.

The Bakefile makefile we created to achieve this is shown below.

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

program Win32Console1

As you can see the Bakefile syntax follows a syntax that looks a bit like the C programming language syntax.

The toolsets variable is the list of build systems we want to generate makefiles for. In this case we just specify vs2013 to generate files for Visual Studio 2013.

The program statement indicates that we want to build an executable (as opposed to a library) called Win32Console1. The details of how to build the executable are put inside a block delimited by curly brackets. In this case we only have to provide the list of source files. By default Bakefile creates console applications and 32-bit Debug and Release configurations.

The main.cpp file is shown below. It simply has a main function that prints "Hello World!" on the console.

File: Bakefile/Basics/Win32Console1/main.cpp
#include <stdio.h>

int main(int argc, char* argv[])
    printf("Hello World!\r\n");
    return 0;

The Visual Studio project can now be generated with the following command.

Building the makefiles
C:\...\Bakefile\Basics\Win32Console1>bkl Win32Console1.bkl


bkl follows the Unix convention and doesn't print anything on the console if the action is a success. The command created the project files as shown below.

Created files
 Volume in drive C has no label.
 Volume Serial Number is B3D9-926C

 Directory of C:\GitRepositories\needfulsoftwaretutorials\Bakefile\Basics\Win32Console1

08/02/2015  14:12    <DIR>          .
08/02/2015  14:12    <DIR>          ..
07/02/2015  17:16               104 main.cpp
07/02/2015  17:13                94 Win32Console1.bkl
08/02/2015  14:12               971 Win32Console1.sln
08/02/2015  14:12             4,325 Win32Console1.vcxproj
08/02/2015  14:12             1,078 Win32Console1.vcxproj.filters
               5 File(s)          6,572 bytes
               2 Dir(s)  91,007,893,504 bytes free


We can now open the Win32Console project with Visual Studio 2013. As can be see in Figure 1 it looks like any other Visual Studio project.

Win32Console1 opened with Visual Studio
Figure 1: Win32Console1 opened with Visual Studio

Verbose Output

The -v option can be used to get a more verbose output while running bkl.

We delete the generated files (Win32Console1.sln, Win32Console1.vcxproj and Win32Console1.vcxproj.filters) and rerun bkl with the -v option. This is shown below.

Building the makefiles with verbose output
C:\...\Bakefile\Basics\Win32Console1>bkl -v Win32Console1.bkl
processing Win32Console1.bkl
A       Win32Console1.vcxproj
A       Win32Console1.vcxproj.filters
A       Win32Console1.sln
created files: 3, updated files: 0 (time: 0.5s)


Rerunning bkl without deleting the output or changing the input file will produce the result below. Bakefile checks the makefiles that have already been generated and only generates or updates the files that need to.

Rerunning bkl on unchanged input
C:\...\Bakefile\Basics\Win32Console1>bkl -v Win32Console1.bkl
processing Win32Console1.bkl
.       Win32Console1.vcxproj
.       Win32Console1.vcxproj.filters
.       Win32Console1.sln
created files: 0, updated files: 0 (time: 0.4s)


Multiple Versions of Visual Studio

In the previous example we only generated the project files for Visual Studio 2013. In this example we will generate them for 3 different version (Visual Studio .NET 2003, 2012 and 2013). The full example is available from our Codeplex repository at Bakefile/Basics/MultipleVisualStudio1/MultipleVisualStudio1.bkl.

The only detail we need to take care of beyond adding extra versions to the toolsets variable is to put the generated project files in different locations to avoid name clashes. By default the project files will be put in the same directory as the bkl file and be named after the program they are meant to build. If we kept these defaults all project files would be put in the same directory and the Visual Studio 2012 and 2013 projects would clash (2003 uses different extensions so it would not clash). bkl would inform you of such a clash at runtime.

Overriding the defaults is fortunately very easy. For each of the vs<N> targets there is a corresponding vs<N>.solutionfile variable that is the path of the solution file.

The new Bakefile file is shown below. We put each of the projects in its own subdirectory. We use the same main.cpp file as in the previous example. Note that its path has not changed as by default the location of the source files is relative to the location of the Bakefile makefile itself. When generating the project files bkl will adjust the path so that it is relative to the project file. So in this case it will become ..\main.cpp. You can verify this by opening one of the generated project files in a text editor.

File: Bakefile/Basics/MultipleVisualStudio1/MultipleVisualStudio1.bkl
toolsets = vs2003 vs2012 vs2013;

vs2003.solutionfile = VC71/MultipleVisualStudio1.sln;
vs2012.solutionfile = VC11/MultipleVisualStudio1.sln;
vs2013.solutionfile = VC12/MultipleVisualStudio1.sln;

program MultipleVisualStudio1

By default all the other project files are put in the same directory as the .sln file so there is no need to speficy their location.

If we now execute this Bakefile makefile we get the result shown below.

Building the project
C:\...\Bakefile\Basics\MultipleVisualStudio1>bkl -v MultipleVisualStudio1.bkl
processing MultipleVisualStudio1.bkl
A       VC11\MultipleVisualStudio1.vcxproj
A       VC11\MultipleVisualStudio1.vcxproj.filters
A       VC11\MultipleVisualStudio1.sln
A       VC12\MultipleVisualStudio1.vcxproj
A       VC12\MultipleVisualStudio1.vcxproj.filters
A       VC12\MultipleVisualStudio1.sln
A       VC71\MultipleVisualStudio1.vcproj
A       VC71\MultipleVisualStudio1.sln
created files: 8, updated files: 0 (time: 0.5s)


Creating a GNU Makefile

So far we have only used Visual Studio but of course the main strength of Bakefile is that it is cross-platform so we now show an example that generates a GNU makefile. The full example is available from our Codeplex repository at Bakefile/Basics/GnuMakefile1/GnuMakefile1.bkl.

File: Bakefile/Basics/GnuMakefile1/GnuMakefile1.bkl
toolsets = gnu;

program GnuMakefile1

As you can see the toolset is now set to "gnu".

We generate the GNU makefile by running bkl as follows. This example was executed on Ubuntu but should behave identically on any platform that has GNU make installed on it.

Building the makefile with verbose output
xl@Sojourner:~/.../Bakefile/Basics/GnuMakefile1$ bkl -v GnuMakefile1.bkl 
processing GnuMakefile1.bkl
A	GNUmakefile
created files: 1, updated files: 0 (time: 0.0s)

The output is a makefile called GNUmakefile. This makes it clear that the makefile is intended to be executed by GNU make. Traditional make versions will only look for a file called makefile but GNU make will look for either GNUmakefile or makefile.


blog comments powered by Disqus

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

Contact Us