Chapter 11. Batch bakefile generation with bakefile_gen
Prev |  | Next

## Chapter 11. Batch bakefile generation with bakefile_gen

## Introduction

As soon as you start using Bakefile for your project and you need to generate many makefile formats from your bakefiles (after all, this is the purpose of Bakefile!), you'll find very useful to automate the regeneration process.

Here is where bakefile_gen(1) comes into play. You can script all the bakefile calls you would have to do manually in a single `Bakefiles.bkgen` file and then just call: `bakefile_gen` to run Bakefile for all the formats you need to regenerate on all the bakefiles which are required by your project.

`Bakefiles.bkgen` files use a simple XML format to describe what outputs and how to generate. The root tag is called `bakefile-gen` and inside it you can use any of the tags described below.

## bakefile_gen tags

In addition to the following tags, bakefile_gen also supports the include tag.

Tag | Description |
input | Adds the given list of whitespace-separed bakefiles to the list of bakefiles which must be regenerated. You can use wildcards and relative paths to match all the bakefiles scattered in the directory tree of your project. Example:
    <!-- tell bakefile_gen to regenerate all the bakefiles of this project -->
    <input>
        mybakefile1.bkl
        ../mybakefile2.bkl
        ../../../build/bakefiles/*.bkl
    </input>
add-formats | Adds the comma-separed list of formats contained in this tag, to the list of formats to regenerate. You can use the files attribute of this tag to selectively add the listed formats to a (set of) bakefile(s) only.
    <!-- add the GNU format to all bakefiles under 'build/bakefiles' -->
    <add-formats files="build/bakefiles/*.bkl">gnu</add-formats>
del-formats | Removes the comma-separed list of formats contained in this tag, from the list of formats to regenerate. You can use the `files` attribute of this tag to selectively add the listed formats to a (set of) bakefile(s) only.
    <!-- remove some rarely used formats from the bakefiles under the 'a' and 'b' subfolders -->
    <del-formats files="a/*.bkl,b/*.bkl">cbuilderx,dmars,dmars_smake,msevc4prj,symbian,xcode2</disable-formats>
enable-formats | Enables the regeneration of the comma-separed list of formats contained in this tag. Note that by default all formats supported by Bakefile are enabled, thus this tag will actually have some effect only if you used the disable-formats tag before.
    <disable-formats>msvc,gnu</disable-formats>
    ...
    <!-- we've changed idea; turn GNU format on -->
    <enable-formats>gnu</enable-formats>
disable-formats | Disables the regeneration of the comma-separed list of formats contained in this tag. Typically you'll want to use this tag to disable all those formats you are not interested to.
    <!-- disable rarely used formats: -->
    <disable-formats>cbuilderx,dmars,dmars_smake,msevc4prj,symbian,xcode2</disable-formats>
add-flags | Adds some flags to the command executed to regenerate the bakefiles. You can use the `files` attribute of this tag to selectively add the flags to a (set of) bakefile(s) only. You can use the `formats` attribute of this tag to selectively add the flags to a (set of) format(s) only. Additionally, inside this tag, bakefile_gen recognizes various variables: `$(INPUT_FILE)` is the path of the bakefile being processed; `$(INPUT_FILE_BASENAME)` is the filename of the bakefile being processed; `$(INPUT_FILE_BASENAME_NOEXT)` is the filename of the bakefile being processed without the extension; `$(INPUT_FILE_DIR)` is the directory of the bakefile being processed.
    <!-- tell bakefile to output the generated Makefile.in for bake.bkl two levels up -->
    <add-flags files="bake.bkl" formats="autoconf">
        -o../../Makefile.in
    </add-flags>

    <!-- always generate the windows makefiles in ../msw respect the bakefile's being processed: -->
    <add-flags formats="borland">-o$(INPUT_FILE_DIR)/../msw/makefile.bcc</add-flags>
    <add-flags formats="mingw">-o$(INPUT_FILE_DIR)/../msw/makefile.gcc</add-flags>
    <add-flags formats="msvc">-o$(INPUT_FILE_DIR)/../msw/makefile.vc</add-flags>
    <add-flags formats="watcom">-o$(INPUT_FILE_DIR)/../msw/makefile.wat</add-flags>
del-flags | Removes some flags to the command executed to regenerate the bakefiles. You can use the `files` attribute of this tag to selectively remove the flags to a (set of) bakefile(s) only. You can use the `formats` attribute of this tag to selectively remove the flags to a (set of) format(s) only.
    <add-flags>-DVARIABLE1=value</add-flags>

    <!-- delete the -DVARIABLE1=value option from the MSVC and BORLAND formats -->
    <del-flags formats="msvc,borland">
        -DVARIABLE1=value
    </del-flags>

## Processing order

`Bakefiles.bkgen` file is processed in the following order:

1. `disable-formats` entries are read into blacklist of formats to globally ignore

2. `enable-formats` entries are read and the formats listed are removed from the blacklist (so that your `Bakefiles.local.bkgen` file can re-enable something disabled by default).

3. `add-formats` and `del-formats` are processed in the order they appear in the file. They specify which formats should be generated for which files (the default being all files), assuming the blacklist is empty (in other words, they describe what this `Bakefiles.bkgen` is capable of generating).

4. The list from step 3. is filtered using the blacklist from steps 1. and 2.

Prev |  | Next
Chapter 10. Modules | Home | Running Bakefile