Next: , Previous: , Up: Loading Objects   [Contents][Index]

12.2.1 The load Directive

Objects are loaded into GNU make by placing the load directive into your makefile. The syntax of the load directive is as follows:

load object-file


load object-file(symbol-name) …

The file object-file is dynamically loaded by GNU make. If object-file does not include a directory path then it is first looked for in the current directory. If it is not found there, or a directory path is included, then system-specific paths will be searched. If the load fails for any reason, make will print a message and exit.

If the load succeeds make will invoke an initializing function.

If symbol-name is provided, it will be used as the name of the initializing function.

If no symbol-name is provided, the initializing function name is created by taking the base file name of object-file, up to the first character which is not a valid symbol name character (alphanumerics and underscores are valid symbol name characters). To this prefix will be appended the suffix _gmk_setup.

More than one object file may be loaded with a single load directive, and both forms of load arguments may be used in the same directive.

The initializing function will be provided the file name and line number of the invocation of the load operation. It should return a value of type int, which must be 0 on failure and non-0 on success. If the return value is -1, then GNU make will not attempt to rebuild the object file (see How Loaded Objects Are Remade).

For example:

load ../

will load the dynamic object ../ After the object is loaded, make will invoke the function (assumed to be defined by the shared object) mk_funcs_gmk_setup.

On the other hand:

load ../

will load the dynamic object ../ After the object is loaded, make will invoke the function init_mk_func.

Regardless of how many times an object file appears in a load directive, it will only be loaded (and its setup function will only be invoked) once.

After an object has been successfully loaded, its file name is appended to the .LOADED variable.

If you would prefer that failure to load a dynamic object not be reported as an error, you can use the -load directive instead of load. GNU make will not fail and no message will be generated if an object fails to load. The failed object is not added to the .LOADED variable, which can then be consulted to determine if the load was successful.

Next: , Previous: , Up: Loading Objects   [Contents][Index]