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 …
or:
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 ../mk_funcs.so
will load the dynamic object ../mk_funcs.so. 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 ../mk_funcs.so(init_mk_func)
will load the dynamic object ../mk_funcs.so. 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.
Copyright © 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Free Software Foundation, Inc.
Licensed under the GNU Free Documentation License.
https://www.gnu.org/software/make/manual/html_node/load-Directive.html