Download raw body.
pkg-config relocatable .pc support
On Mon, Jan 13, 2025 at 01:23:03PM -0500, George Koehler wrote:
> On Mon, 13 Jan 2025 14:17:54 +0100
> Jeremie Courreges-Anglas <jca@wxcvbn.org> wrote:
>
> > Thanks for the suggestion, but that doesn't work. At the call site
> > we're within "package OpenBSD::PkgConfig;", so a bare dirname() would
> > be looked up as OpenBSD::PkgConfig::dirname. Hence the fully
> > qualified call used in the diff.
>
> Sorry, I forgot that Perl modules have "package _;" lines.
> The bare dirname() works only if I move the "use" after "package",
>
> package OpenBSD::PkgConfig;
> use File::Basename;
>
> For example, src/usr.sbin/pkg_add/OpenBSD/Delete.pm has multiple
> packages doing "use File::Basename;". In general, "use" goes after
> "package" unless it is a lexical pragma like "use v5.36;".
>
> If code calls "File::Basename::dirname" by the full name, then I would
> expect it to "use File::Basename ();" to import the empty list.
Heh, that looks better and appears more consistent with the rest of
the tree.
> The rest of your diff looks correct. While running it with the bare
> dirname() and the moved "use", I confirm that --cflags and --libs
> give the same output (or same error) for every package in --list-all
> on my OpenBSD/amd64. I made a .pc with "prefix=${pcfiledir}/../.."
> and it behaved the same on OpenBSD (with your diff) and Linux (where
> pkg-config is pkgconf).
Thanks for checking, updated diff below.
Index: OpenBSD/PkgConfig.pm
===================================================================
RCS file: /cvs/src/usr.bin/pkg-config/OpenBSD/PkgConfig.pm,v
diff -u -p -r1.12 PkgConfig.pm
--- OpenBSD/PkgConfig.pm 11 Feb 2024 03:57:10 -0000 1.12
+++ OpenBSD/PkgConfig.pm 13 Jan 2025 18:30:49 -0000
@@ -19,6 +19,7 @@ use v5.36;
# interface to the *.pc file format of pkg-config.
package OpenBSD::PkgConfig;
+use File::Basename;
# specific properties may have specific needs.
@@ -106,6 +107,8 @@ sub read_fh($class, $fh, $name = '')
{
my $cfg = $class->new;
+ $cfg->add_variable('pcfiledir', dirname($name));
+
while (<$fh>) {
chomp;
# continuation lines
@@ -145,6 +148,8 @@ sub read_file($class, $filename)
sub write_fh($self, $fh)
{
foreach my $variable (@{$self->{vlist}}) {
+ # writing out pcfiledir makes no sense
+ next if $variable eq 'pcfiledir';
say $fh "$variable=", $self->{variables}{$variable};
}
print $fh "\n\n";
--
jca
pkg-config relocatable .pc support