Bug 48098 - Reading pkg-config variables with autoconf
Reading pkg-config variables with autoconf
Status: RESOLVED FIXED
Product: pkg-config
Classification: Unclassified
Component: src
unspecified
All All
: low enhancement
Assigned To: Dan Nicholson
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-03-30 09:30 UTC by fedora.dm0
Modified: 2012-12-14 22:16 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description fedora.dm0 2012-03-30 09:30:10 UTC
Would it be feasible to include a macro in pkg.m4 to access pkg-config variables with autoconf?  The following is what I have locally, but I find it useful and would like to request similar functionality in pkg-config itself (if you agree that it makes sense).  Thanks.

# PKG_CHECK_VAR([VARIABLE-PREFIX], [MODULES], [VARIABLE],
# [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
# -------------------------------------------------------
AC_DEFUN([PKG_CHECK_VAR],
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
AC_ARG_VAR([$1][_][$3], [value of $3 for $1, overriding pkg-config])dnl

_PKG_CONFIG([$1][_][$3], [variable="][$3]["], [$2])dnl
AS_VAR_COPY([$1][_][$3], [pkg_cv_][$1][_][$3])dnl

AS_VAR_IF([$1][_][$3], [""], [$5], [$4])dnl
])# PKG_CHECK_VAR
Comment 1 Dan Nicholson 2012-12-08 20:31:46 UTC
Sorry for taking so long to reply. It's not really high priority, but this looks nice. If you can get it into a git patch and add documentation in both comments in pkg.m4 and in pkg-config(1), I can probably apply it. I have one comment below.

(In reply to comment #0)
> Would it be feasible to include a macro in pkg.m4 to access pkg-config
> variables with autoconf?  The following is what I have locally, but I find
> it useful and would like to request similar functionality in pkg-config
> itself (if you agree that it makes sense).  Thanks.
> 
> # PKG_CHECK_VAR([VARIABLE-PREFIX], [MODULES], [VARIABLE],
> # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])

Is the VARIABLE-PREFIX ($1) necessary? It seems like just using the name as provided would be fine in this case since the user can decide to prefix it with the package name or not. The reason we do this for PKG_CHECK_MODULES is since we're setting two variables. Here you're just setting one.

Also, I'd make the comment say MODULE instead of MODULES since pkg-config returning the variable setting from multiple modules is pretty useless.

> # -------------------------------------------------------
> AC_DEFUN([PKG_CHECK_VAR],
> [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
> AC_ARG_VAR([$1][_][$3], [value of $3 for $1, overriding pkg-config])dnl
> 
> _PKG_CONFIG([$1][_][$3], [variable="][$3]["], [$2])dnl
> AS_VAR_COPY([$1][_][$3], [pkg_cv_][$1][_][$3])dnl

Does the AC_ARG_VAR actually work here if we blindly AS_VAR_COPY? Looking again at _PKG_CONFIG, I guess it takes care of using the variable set in the environment and assigning it to pkg_cv_$1. So, this seems fine.

What do you think? With the change above and more documentation, I'd be happy to add this. Otherwise, you'll have to convince me why VARIABLE-PREFIX is useful.
Comment 2 fedora.dm0 2012-12-12 00:58:53 UTC
You're right; there was no technical reason to use a variable prefix.  It was just for consistency with PKG_CHECK_MODULES.

I've put the changes into git, which is available here: https://github.com/dm0-/pkg-config .  Thanks.
Comment 3 Dan Nicholson 2012-12-14 22:16:15 UTC
I squashed the two commits, added the bug to the commit message and made the documentation a little more detailed. Pushed in commit 5b463c9. Thanks for the patch!