To source a library at run–time, we have to first embed the linker library; Embedding the linker library. The linker library visits the file systems searching for MBFL library files in a list of directories.
The linker library defines a default search path containing the following directories:
/usr/local/share/mbfl /usr/share/mbfl /share/mbfl
We can define a search path, which takes precedence over the default one, by exporting the
environment variable MBFL_LIBRARY_PATH
. For example, we can put the following line in a
~/.bash_profile file:
export MBFL_LIBRARY_PATH=/home/marco/share/mbfl
Once the search path is configured, we start a script with the following preprocessor macro uses:
mbfl_embed_library(__LIBMBFL_LINKER__) mbfl_linker_source_library_by_stem(core)
the use of macro mbfl_linker_source_library_by_stem()
expands into code that will search a
library whose file name is built from the “stem” ‘core’ as follows:
printf -v FILENAME 'libmbfl-%s.bash' "$STEM"
in this case the result is libmbfl-core.bash; if the library is found: it is loaded using
mbfl_load_library()
; if the library is not found: the script exits with
exit_because_error_loading_library()
.
We can insert uses of mbfl_linker_source_library_by_stem()
to load all the libraries we need:
mbfl_linker_source_library_by_stem(git) mbfl_linker_source_library_by_stem(passwords) mbfl_linker_source_library_by_stem(containers)
If a library with a specific stem has already been loaded: nothing happens. In the following code:
mbfl_linker_source_library_by_stem(containers) mbfl_linker_source_library_by_stem(containers)
the first use of mbfl_linker_source_library_by_stem()
will source the library, the second use
will do nothing.
This document describes version 3.0.0-devel.9 of Marcos Bash Functions Library.