[PATCH] m4: provide additional pkg-config macros

Dan Nicholson dbn.lists at gmail.com
Tue May 8 14:14:21 PDT 2012


On 5/3/12, Luca Barbato <lu_zero at gentoo.org> wrote:
> The macros provide a succint way to run a pkg-config check over modules
> depending on a --with-name configure option.
>
> There is a flexible variant to have custom behaviour if the package is
> found or not and two more limited ones that just set HAVE_NAME make and
> preprocessor variables.

Overall I like these a lot once you explained what they did. I just
want to make sure we get the interface right before it goes into the
public macros.

> ---
>  pkg.m4 |   74
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 74 insertions(+), 0 deletions(-)
>
> diff --git a/pkg.m4 b/pkg.m4
> index 9a71878..4748f99 100644
> --- a/pkg.m4
> +++ b/pkg.m4
> @@ -157,3 +157,77 @@ else
>  	$3
>  fi[]dnl
>  ])# PKG_CHECK_MODULES
> +
> +# PKG_WITH_MODULES(VARIABLE-PREFIX, MODULES,
> +#                  [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND],
> +#                  [DESCRIPTION], [DEFAULT])
> +#
> +# Prepare a "--with-" configure option using the lowercase
> [VARIABLE-PREFIX]
> +# name, merging the behaviour of AC_ARG_WITH and PKG_CHECK_MODULES in a
> single
> +# macro
> +#
> +# --------------------------------------------------------------
> +AC_DEFUN([PKG_WITH_MODULES],
> +[
> +m4_pushdef([with_arg], m4_tolower([$1]))
> +
> +m4_pushdef([description],
> +           [m4_default([$5], [build with ]with_arg[ support])])
> +
> +m4_pushdef([def_arg], [m4_default([$6], [auto])])
> +m4_pushdef([def_action_if_found], [AS_TR_SH([with_]with_arg)=yes])
> +m4_pushdef([def_action_if_not_found], [AS_TR_SH([with_]with_arg)=no])
> +
> +m4_case(def_arg,
> +            [yes],[m4_pushdef([with_without], [--without-]with_arg)],
> +            [m4_pushdef([with_without],[--with-]with_arg)])
> +
> +AC_ARG_WITH(with_arg,
> +     AS_HELP_STRING(with_without, description[
> @<:@default=]def_arg[@:>@]),,
> +    [AS_TR_SH([with_]with_arg)=def_arg])
> +
> +AS_CASE([$AS_TR_SH([with_]with_arg)],
> +            [yes],[PKG_CHECK_MODULES([$1],[$2],$3,$4)],

Is it problematic to not quote $3/$4? In my experience, people will
want to put multiline commands in these arguments and autoconf can get
easily screwed up without the quotes. I believe m4_default in
PKG_CHECK_MODULES will continue to use the fallback even if $3/$4 are
quoted empty strings.

> +            [auto],[PKG_CHECK_MODULES([$1],[$2],
> +                                        [m4_n([def_action_if_found]) $3],
> +                                        [m4_n([def_action_if_not_found])
> $4])])

If I understand this correctly, when the condition is auto, we set
with_$arg to yes or no followed by the user specified actions. Is that
right? I was thinking it was bad to put in actions here which will
override the PKG_CHECK_MODULES defaults, but I guess that's what you
want in the auto case since otherwise it will fail configure if you
don't have the modules.

> +
> +m4_popdef([with_arg])
> +m4_popdef([description])
> +m4_popdef([def_arg])
> +
> +]) dnl PKG_WITH_MODULES
> +
> +# PKG_HAVE_WITH_MODULES(VARIABLE-PREFIX, MODULES,
> +#                       [DESCRIPTION], [DEFAULT])
> +#
> +# Convenience macro to trigger AM_CONDITIONAL after
> +# PKG_WITH_MODULES check.
> +#
> +# HAVE_[VARIABLE-PREFIX] is exported as make variable.

Not exactly. AM_CONDITIONAL turns this into HAVE_$var_TRUE/FALSE.
Better to say this creates an automake conditional named
HAVE_[VARIABLE-PREFIX]. That's how the automake documentation
describes it.

> +#
> +# --------------------------------------------------------------
> +AC_DEFUN([PKG_HAVE_WITH_MODULES],

This might need a better name. Maybe PKG_WITH_MODULES_CONDITIONAL to
signify you're creating an AM_CONDITIONAL?

> +[
> +PKG_WITH_MODULES([$1],[$2],,,[$3],[$4])

Why not pass all the same arguments as PKG_WITH_MODULES?

> +
> +AM_CONDITIONAL([HAVE_][$1],
> +               [test "$AS_TR_SH([with_]m4_tolower([$1]))" = "yes"])
> +])
> +
> +# PKG_HAVE_DEFINE_WITH_MODULES(VARIABLE-PREFIX, MODULES,
> +#                              [DESCRIPTION], [DEFAULT])
> +#
> +# Convenience macro to run AM_CONDITIONAL and AC_DEFINE after
> +# PKG_WITH_MODULES check.
> +#
> +# HAVE_[VARIABLE-PREFIX] is exported as make and preprocessor variable.

exported as an automake conditional and preprocessor macro.

> +#
> +# --------------------------------------------------------------
> +AC_DEFUN([PKG_HAVE_DEFINE_WITH_MODULES],

Again, I'm not so sure about the name.
PKG_WITH_MODULES_DEFINE_CONDITIONAL? Kind of a mouthful. I do prefer
to have the extra action as an addendum to the base name, though.

> +[
> +PKG_HAVE_WITH_MODULES([$1],[$2],[$3],[$4])

Same as above, any reason not to pass all the arguments through to
PKG_WITH_MODULES?

--
Dan


More information about the pkg-config mailing list