| Home | Libraries | People | FAQ | More

## Main target rules

A main target rule (e.g “`exe`” Or “`lib`”) creates a top-level target. It's quite likely that you'll want to declare your own and there are two ways to do that.

The first way applies when your target rule should just produce a target of specific type. In that case, a rule is already defined for you! When you define a new type, Boost.Build automatically defines a corresponding rule. The name of the rule is obtained from the name of the type, by downcasing all letters and replacing underscores with dashes. For example, if you create a module `obfuscate.jam` containing:

    import type ;
    type.register OBFUSCATED_CPP  : ocpp ;

    import generators ;
    generators.register-standard obfuscate.file : CPP : OBFUSCATED_CPP ;

and import that module, you'll be able to use the rule "obfuscated-cpp" in Jamfiles, which will convert source to the OBFUSCATED_CPP type.

The second way is to write a wrapper rule that calls any of the existing rules. For example, suppose you have only one library per directory and want all cpp files in the directory to be compiled into that library. You can achieve this effect with:

    lib codegen : [ glob *.cpp ] ;

but if you want to make it even simpler, you could add the following definition to the `project-root.jam` file:

    rule glib ( name : extra-sources * : requirements * )
    {
        lib $(name) : [ glob *.cpp ] $(extra-sources) : $(requirements) ;
    }

which would allow you to reduce the Jamfile to

    glib codegen ;

Note that because you can associate a custom generator with a target type, the logic of building can be rather compiler. For example, the `boostbook` module declares a target type `BOOSTBOOK_MAIN` and a custom generator for that type. You can use that as example if your main target rule is non-trivial.