Support for C/C++

Rant can automatically determine the dependencies between C/C++ source files. Use the C::Dependencies generator:

    import "c/dependencies"
    gen C::Dependencies

This generates a task called "c_dependencies" which will scan all C/C++ source files in the current directory and all subdirectories for include statements and write the dependencies to the file "c_dependencies". It searches for include files in the current directory.

If you want to specify which directories it should search for include files, give the search option:

    gen C::Dependencies, :search => %w(. include)

Rant will search for include files in the current and in the "include" directory now.

If you want to create the dependencies only for a specific set of source files or for source files with non-standard filename extensions, give a list with the sources option:

    gen C::Dependencies, :sources => sys["**/*.cxx"]

This task will create the dependencies for all files ending in ".cxx".

Of course you can combine this options and you can give another task/filename as first argument:

    gen C::Dependencies, "depend.rf"
        :search => "include",
        :sources => sys["**/*.cxx"]

This creates a file task with the name "depend.rf".

Note that all our previous examples only created a filetask with the dependencies, to use them you have to load them in your Rantfile. So you probably want to call the source command:

    gen C::Dependencies

    # invoke task "c_dependencies" and load the created file
    source "c_dependencies"

And a good habit would be to wrap the source expression in an Action block:

    gen C::Dependencies

    # Do dependency checking only if at least one task will be
    # invoked.
    gen Action do source "c_dependencies" end

or more selective:

    gen C::Dependencies

    # Do dependency checking when Rant looks at the first file
    # ending in ".h" or ".c"
    gen Action, /\.(h|c)$/ do source "c_dependencies" end

For a little example project using the C::Dependency generator look into the doc/examples/c_dependencies directory of the Rant distribution.

Issues on case-insensitive file systems

If you are building on a case insensitive file system, your Compiler will usually ignore the case of filenames in include statements. Thus if you have a header file called myutils.h and the following preprocessor statement main.c:

    #include "MyUtils.h"

The preprocessor will include the contents of myutils.h. The problem is that Rant’s node names are case sensitive. In the above example Rant wouldn’t track changes in files included by myutils.h when compiling main.c.

To overcome this problem, set the :correct_case option to true, e.g.:

    gen C::Dependencies, :correct_case => true

Note that this option makes only sense on case-insensitive file systems. It can also significantly slow down dependency checking.

Currently, the implementation of this option has one limit. In the following statement

    #include "someDir/MyUtils.h"

the case of someDir must be identical to the actual directory name on disk!

See also

Rantfile basics:doc/rantfile.rdoc
Advanced Rantfiles:doc/advanced.rdoc
Tasks with command change recognition:doc/command.rdoc
Rant Overview:README