We can include in scripts the code needed to source a library at run–time or we can embed a whole library itself. Searching and sourcing libraries at run–time for details on how to use the linker library to load libraries.
Expands into the contents of a library file; the resulting output script does not need to load the library at runtime, let’s say it is “statically linked”.
mbflpp.bash
:
the library libmbfl-core.bash installed on the system is embedded.
mbflpp.bash
: the
file pathname selected by the option is used to locate the library libmbfl-core.bash to be embedded.
The macro expands into a use of the m4 built–in m4_undivert()
:
m4_undivert(LIBRARY_FILE_PATHNAME)
so the argument LIBRARY_FILE_PATHNAME must be a m4 expression expanding into a file system pathname. See Including named files, for details on including files. See Undiverting output, for details on undiverting named files.
As example, we could preprocess a script with the following command line:
mbflpp.bash --define=__LIBFILE_PTN__=/path/to/libmy.bash -oscript.bash script.bash.m4
and in the script’s source file we write:
mbfl_embed_library(__LIBFILE_PTN__)
Expand to a block of code that sources a library file; the resulting output script does need to source the library at runtime, let’s say it is “dynamically linked”.
mbflpp.bash
:
the macro use expands into shell code that sources the library libmbfl-core.bash installed on the
system.
mbflpp.bash
: the
macro use expands into shell code that sources the file pathname selected by the option; it is meant
to be an implementation of libmbfl-core.bash.
The macro use expands into:
source LIBRARY_FILE_PATHNAME || exit 100
so, in the general case, the argument LIBRARY_FILE_PATHNAME must be a M4 expression expanding into a Bash expression evaluating into a file system pathname.
As example, we can load a library selecting it from an environment variable as follows:
mbfl_load_library("${MY_LIBPTN:?'variable not set'}")
or we can select only the library’s installation directory with an environment variable:
mbfl_load_library("${MY_LIBPATH:?'variable not set'}/libmy.bash")
As other example, we could preprocess a script with the following command line:
mbflpp.bash --define=__LIBFILE_PTN__=/path/to/libmy.bash -oscript.bash script.bash.m4
and in the script’s source file we write:
mbfl_load_library('__LIBFILE_PTN__')
This document describes version 3.0.0-devel.9 of Marcos Bash Functions Library.