5
\$\begingroup\$

I have been updating my build tools to optionally use autotools (autoconfig/automake/libtool etc.).

As part of this change I have written a couple of M4 macros. This not being something I have done before, any input is appreciated on style or if things can be done better.

This macro checks to see if the YAML libraries are installed:

AC_DEFUN([AX_FUNC_THOR_USE_YAML],
[
    AC_ARG_WITH(
        [yamlroot],
        AS_HELP_STRING([--with-yamlroot=<location>], [Directory of YAML_ROOT])
    )
    AC_ARG_ENABLE(
        [yaml],
        AS_HELP_STRING([--disable-yaml], [Disable yaml serializsation])
    )
    AS_IF(
        [test "x$enable_yaml" != "xno"],

        ORIG_LDFLAGS="${LDFLAGS}"
        if test "${with_yamlroot}" != ""; then
            LDFLAGS="$LDFLAGS -L$with_yamlroot/lib"
        fi

        AC_CHECK_LIB(
            [yaml],
            [yaml_parser_initialize],
            [
                AC_DEFINE([HAVE_YAML], 1, [When on Yaml Serialization code will be compiled])
                with_yamllib=-lyaml
            ],
            [AC_MSG_ERROR([

Error: Could not find libyaml

You can solve this by installing libyaml
    see http://pyyaml.org/wiki/LibYAML

Alternately specify install location with:
    --with-yamlroot=<location of yaml installation>

If you do not want to use yaml serialization then it
can be disabled with:
    --disable-yaml

                ], [1])]
        )

        LDFLAGS="${ORIG_LDFLAGS}"
    )
])

If YAML is detected, then no problems. If the configure script cannot find them, the error message is generated with three options:

  1. Disable the use of YAML
  2. Provide the location where YAML is installed (not default)
  3. Instructions on how to install
\$\endgroup\$
3
\$\begingroup\$

I only have some comments about the shell scripting elements.


This is a very archaic (and silly) way of testing flags:

    [test "x$enable_yaml" != "xno"],

You can write simpler as:

    [test "$enable_yaml" != no],

This can be simplified:

    if test "${with_yamlroot}" != ""; then

To just:

    if test "${with_yamlroot}"; then

I also find it odd to use sometimes $this_style and sometimes ${that_style}. I prefer less typing (especially the shift key for }), so the first, simpler style. The only time I use braces is when appending some text directly after the variable would break the script, for example in situations like this:

authtype=...  # something
# broken, not using the $authtype variable
#modpath=/usr/libexec/apache2/mod_$authtype_dbd.so
# good
modpath=/usr/libexec/apache2/mod_${authtype}_dbd.so
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.