HiveBrain v1.2.0
Get Started
← Back to all entries
patternyamlMinor

Autotools detect YAML library

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
yamlautotoolsdetectlibrary

Problem

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=], [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=

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:

  • Disable the use of YAML



  • Provide the location where YAML is installed (not default)



  • Instructions on how to install

Solution

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

Code Snippets

[test "x$enable_yaml" != "xno"],
[test "$enable_yaml" != no],
if test "${with_yamlroot}" != ""; then
if test "${with_yamlroot}"; then
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

Context

StackExchange Code Review Q#79970, answer score: 3

Revisions (0)

No revisions yet.