Next: , Previous: , Up: overview   [Contents][Index]


1.3 Direct inclusion

Another solution is to directly include the library in the script; this is easy if we preprocess our scripts with GNU m4. We only need to put the following in the script:

m4_include(libmbfl.sh)

then preprocess the script with:

$ m4 --prefix-builtins --include=/path/to/library \
         script.sh.m4 >script.sh

easy to do in a Makefile. The installation directory pathname of the library (/path/to/library in the example) is the output of mbfl-config --libpath.

It is also interesting to process the script with the following rule of GNU Make: assuming that the source scripts are in the src/modules directory of the source tree:

vpath	%.sh.m4		$(srcdir)/src/modules

M4      = ...
M4FLAGS = --prefix-builtins --include=/path/to/library

%.sh: %.sh.m4
        $(M4) $(M4FLAGS) $(<) | \
        grep --invert-match -e '^#' -e '^$$' | \
        sed -e "s/^ \\+//" >$(@)

this will remove all the comments and blank lines, decreasing the size of the script significantly if one makes use of verbose comments; note that this will wipe out the #!/bin/bash first line, too.

Usually we want the script to begin with #!/bin/bash followed by a comment describing the license terms. We can do it by preparing a script like the following:

#!/bin/bash
# ... license ...

m4_include(realscript.sh)

### end of file

and processing it with the following makefile rule:

M4      = ...
M4FLAGS = --prefix-builtins --include=/path/to/library

script.sh: script.sh.m4 realscript.sh
        $(M4) $(M4FLAGS) $(<) >$(@)

realscript.sh can be processed as explained above.

At this point, though, it is better to use the MBFL preprocessor. Using the script preprocessor.


Next: , Previous: , Up: overview   [Contents][Index]

This document describes version 3.0.0-devel.0 of Marcos Bash Functions Library.