=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/pkg-config/pkg-config,v retrieving revision 1.95 retrieving revision 1.96 diff -c -r1.95 -r1.96 *** src/usr.bin/pkg-config/pkg-config 2020/09/15 07:18:45 1.95 --- src/usr.bin/pkg-config/pkg-config 2023/06/08 08:55:27 1.96 *************** *** 1,5 **** #!/usr/bin/perl ! # $OpenBSD: pkg-config,v 1.95 2020/09/15 07:18:45 jasper Exp $ # Copyright (c) 2006 Chris Kuethe # Copyright (c) 2011-2020 Jasper Lievisse Adriaanse --- 1,5 ---- #!/usr/bin/perl ! # $OpenBSD: pkg-config,v 1.96 2023/06/08 08:55:27 espie Exp $ # Copyright (c) 2006 Chris Kuethe # Copyright (c) 2011-2020 Jasper Lievisse Adriaanse *************** *** 16,29 **** # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ! use strict; ! use warnings; use Config; use Getopt::Long; use File::Basename; use File::stat; use OpenBSD::PkgConfig; my @PKGPATH = qw(/usr/lib/pkgconfig /usr/local/lib/pkgconfig /usr/local/share/pkgconfig --- 16,35 ---- # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ! use v5.36; use Config; use Getopt::Long; use File::Basename; use File::stat; use OpenBSD::PkgConfig; + use constant { + ONLY_I => 1, + ONLY_l => 2, + ONLY_L => 4, + ONLY_OTHER => 8 + }; + my @PKGPATH = qw(/usr/lib/pkgconfig /usr/local/lib/pkgconfig /usr/local/share/pkgconfig *************** *** 70,76 **** if ($logfile) { open my $L, ">>" , $logfile or die; ! print $L beautify_list($0, @ARGV), "\n"; close $L; } --- 76,82 ---- if ($logfile) { open my $L, ">>" , $logfile or die; ! say $L beautify_list($0, @ARGV); close $L; } *************** *** 87,93 **** 'help' => \&help, #does not return 'usage' => \&help, #does not return 'list-all' => \$mode{list}, ! 'version' => sub { print "$version\n" ; exit(0);} , 'errors-to-stdout' => sub { $mode{estdout} = 1}, 'print-errors' => sub { $mode{printerr} = 1}, 'silence-errors' => sub { $mode{printerr} = 0}, --- 93,99 ---- 'help' => \&help, #does not return 'usage' => \&help, #does not return 'list-all' => \$mode{list}, ! 'version' => sub { say $version ; exit(0);} , 'errors-to-stdout' => sub { $mode{estdout} = 1}, 'print-errors' => sub { $mode{printerr} = 1}, 'silence-errors' => sub { $mode{printerr} = 0}, *************** *** 97,109 **** 'print-requires' => \$mode{printrequires}, 'print-requires-private' => \$mode{printrequiresprivate}, ! 'cflags' => sub { $mode{cflags} = 3}, ! 'cflags-only-I' => sub { $mode{cflags} |= 1}, ! 'cflags-only-other' => sub { $mode{cflags} |= 2}, ! 'libs' => sub { $mode{libs} = 7}, ! 'libs-only-l' => sub { $mode{libs} |= 1}, ! 'libs-only-L' => sub { $mode{libs} |= 2}, ! 'libs-only-other' => sub { $mode{libs} |= 4}, 'exists' => sub { $mode{exists} = 1} , 'validate' => sub { $mode{validate} = 1}, 'static' => sub { $mode{static} = 1}, --- 103,115 ---- 'print-requires' => \$mode{printrequires}, 'print-requires-private' => \$mode{printrequiresprivate}, ! 'cflags' => sub { $mode{cflags} = ONLY_I|ONLY_OTHER}, ! 'cflags-only-I' => sub { $mode{cflags} |= ONLY_I}, ! 'cflags-only-other' => sub { $mode{cflags} |= ONLY_OTHER}, ! 'libs' => sub { $mode{libs} = ONLY_L|ONLY_l|ONLY_OTHER}, ! 'libs-only-l' => sub { $mode{libs} |= ONLY_l}, ! 'libs-only-L' => sub { $mode{libs} |= ONLY_L}, ! 'libs-only-other' => sub { $mode{libs} |= ONLY_OTHER}, 'exists' => sub { $mode{exists} = 1} , 'validate' => sub { $mode{validate} = 1}, 'static' => sub { $mode{static} = 1}, *************** *** 164,192 **** # When we got here we're supposed to have had at least one # package as argument. ! if (!@ARGV){ say_error("No package name(s) specified."); exit 1; } # Return the next module from @ARGV, if it turns out to be a comma separated # module list, take the first one and put the rest back to the front. ! sub get_next_module { my $module = shift @ARGV; my $m; if ($module =~ m/,/) { my @ms = split(/,/, $module); $m = shift @ms; ! unshift(@ARGV, @ms) if (scalar(@ms) > 0); } else { ! return $module; } return $m; } ! while (@ARGV){ my $p = get_next_module(); my $op = undef; my $v = undef; --- 170,198 ---- # When we got here we're supposed to have had at least one # package as argument. ! if (!@ARGV) { say_error("No package name(s) specified."); exit 1; } # Return the next module from @ARGV, if it turns out to be a comma separated # module list, take the first one and put the rest back to the front. ! sub get_next_module() { my $module = shift @ARGV; my $m; if ($module =~ m/,/) { my @ms = split(/,/, $module); $m = shift @ms; ! unshift(@ARGV, @ms) if @ms != 0; } else { ! return $module; } return $m; } ! while (@ARGV) { my $p = get_next_module(); my $op = undef; my $v = undef; *************** *** 267,282 **** if ($mode{cflags} || $mode{libs} || $mode{variable}) { push @vlist, do_cflags($dep_cfg_list) if $mode{cflags}; push @vlist, do_libs($dep_cfg_list) if $mode{libs}; ! print join(' ', @vlist), "\n" if $rc == 0; } exit $rc; ########################################################################### ! sub handle_config { - my ($p, $op, $v, $list) = @_; my $cfg = cache_find_config($p); unshift @$list, $p if defined $cfg; --- 273,287 ---- if ($mode{cflags} || $mode{libs} || $mode{variable}) { push @vlist, do_cflags($dep_cfg_list) if $mode{cflags}; push @vlist, do_libs($dep_cfg_list) if $mode{libs}; ! say join(' ', @vlist) if $rc == 0; } exit $rc; ########################################################################### ! sub handle_config($p, $op, $v, $list) { my $cfg = cache_find_config($p); unshift @$list, $p if defined $cfg; *************** *** 294,301 **** } } ! my $get_props = sub { ! my $property = shift; my $pkg; # See if there's anything in the environment that we need to --- 299,305 ---- } } ! my $get_props = sub($property) { my $pkg; # See if there's anything in the environment that we need to *************** *** 316,322 **** my $deps = $cfg->get_property($property, $variables); return unless defined $deps; for my $dep (@$deps) { ! if ($dep =~ m/^(.*?)\s*([<=>]+)\s*([\d\.]+|[\d\.]+[\w]*[\d]+)$/) { handle_config($1, $2, $3, $list); } else { handle_config($dep, undef, undef, $list); --- 320,326 ---- my $deps = $cfg->get_property($property, $variables); return unless defined $deps; for my $dep (@$deps) { ! if ($dep =~ m/^(.*?)\s*([<=>]+)\s*([\d\.]+|[\d\.]+\w*\d+)$/) { handle_config($1, $2, $3, $list); } else { handle_config($dep, undef, undef, $list); *************** *** 339,348 **** # look for the .pc file in each of the PKGPATH elements. Return the path or # undef if it's not there ! sub pathresolve { - my ($p) = @_; - if ($allow_uninstalled && $p !~ m/\-uninstalled$/) { for my $d (@PKGPATH) { my $f = "$d/$p-uninstalled.pc"; --- 343,350 ---- # look for the .pc file in each of the PKGPATH elements. Return the path or # undef if it's not there ! sub pathresolve($p) { if ($allow_uninstalled && $p !~ m/\-uninstalled$/) { for my $d (@PKGPATH) { my $f = "$d/$p-uninstalled.pc"; *************** *** 362,374 **** return undef; } ! sub get_config { - my ($f) = @_; - my $cfg; eval { ! $cfg = OpenBSD::PkgConfig->read_file($f); }; if (!$@) { return validate_config($f, $cfg); --- 364,374 ---- return undef; } ! sub get_config($f) { my $cfg; eval { ! $cfg = OpenBSD::PkgConfig->read_file($f); }; if (!$@) { return validate_config($f, $cfg); *************** *** 378,387 **** return undef; } ! sub cache_find_config { - my $name = shift; - say_debug("processing $name"); if (exists $configs{$name}) { --- 378,385 ---- return undef; } ! sub cache_find_config($name) { say_debug("processing $name"); if (exists $configs{$name}) { *************** *** 392,400 **** } # Required elements for a valid .pc file: Name, Description, Version ! sub validate_config { - my ($f, $cfg) = @_; my @required_elems = ('Name', 'Description', 'Version'); # Check if we're dealing with an empty file, but don't error out just --- 390,397 ---- } # Required elements for a valid .pc file: Name, Description, Version ! sub validate_config($f, $cfg) { my @required_elems = ('Name', 'Description', 'Version'); # Check if we're dealing with an empty file, but don't error out just *************** *** 417,423 **** # pkg-config won't install a pkg-config.pc file itself, but it may be # listed as a dependency in other files. so prime the cache with self. ! sub setup_self { my $pkg_pc = OpenBSD::PkgConfig->new; $pkg_pc->add_property('Version', $version); --- 414,420 ---- # pkg-config won't install a pkg-config.pc file itself, but it may be # listed as a dependency in other files. so prime the cache with self. ! sub setup_self() { my $pkg_pc = OpenBSD::PkgConfig->new; $pkg_pc->add_property('Version', $version); *************** *** 427,436 **** $configs{'pkg-config'} = $pkg_pc; } ! sub find_config { - my ($p) = @_; - # Differentiate between getting a full path and just the module name. my $f = ($p =~ m/\.pc$/ ? $p : pathresolve($p)); --- 424,431 ---- $configs{'pkg-config'} = $pkg_pc; } ! sub find_config($p) { # Differentiate between getting a full path and just the module name. my $f = ($p =~ m/\.pc$/ ? $p : pathresolve($p)); *************** *** 441,451 **** return undef; } ! sub stringize { - my $list = shift; - my $sep = shift || ','; - if (defined $list) { return join($sep, @$list) } else { --- 436,443 ---- return undef; } ! sub stringize($list, $sep = ',') { if (defined $list) { return join($sep, @$list) } else { *************** *** 454,463 **** } #if the variable option is set, pull out the named variable ! sub do_variable { - my ($p, $v) = @_; - my $cfg = cache_find_config($p); if (defined $cfg) { --- 446,453 ---- } #if the variable option is set, pull out the named variable ! sub do_variable($p, $v) { my $cfg = cache_find_config($p); if (defined $cfg) { *************** *** 472,491 **** #if the modversion or print-provides options are set, #pull out the compiler flags ! sub do_modversion { - my ($p) = @_; - my $cfg = cache_find_config($p); if (defined $cfg) { my $value = $cfg->get_property('Version', $variables); if (defined $value) { if (defined($mode{printprovides})){ ! print "$p = " . stringize($value) . "\n"; return undef; } else { ! print stringize($value), "\n"; return undef; } } --- 462,479 ---- #if the modversion or print-provides options are set, #pull out the compiler flags ! sub do_modversion($p) { my $cfg = cache_find_config($p); if (defined $cfg) { my $value = $cfg->get_property('Version', $variables); if (defined $value) { if (defined($mode{printprovides})){ ! say "$p = " , stringize($value); return undef; } else { ! say stringize($value); return undef; } } *************** *** 494,525 **** } #if the cflags option is set, pull out the compiler flags ! sub do_cflags { - my $list = shift; - my $cflags = []; for my $pkg (@$list) { my $l = $configs{$pkg}->get_property('Cflags', $variables); PATH: for my $path (@$l) { for my $sys_path (@sys_includes) { ! next PATH if ($path =~ /${sys_path}\/*$/); } push(@$cflags, $path); } } my $a = OpenBSD::PkgConfig->compress($cflags, ! sub { ! local $_ = shift; ! if (($mode{cflags} & 1) && /^-I/ || ! ($mode{cflags} & 2) && !/^-I/) { return 1; } else { return 0; } }); ! if (defined($a) && defined($variables->{pc_sysrootdir})){ $a =~ s/[\w]?-I/$&$variables->{pc_sysrootdir}/g; } --- 482,510 ---- } #if the cflags option is set, pull out the compiler flags ! sub do_cflags($list) { my $cflags = []; for my $pkg (@$list) { my $l = $configs{$pkg}->get_property('Cflags', $variables); PATH: for my $path (@$l) { for my $sys_path (@sys_includes) { ! next PATH if $path =~ /\Q${sys_path}\E\/*$/; } push(@$cflags, $path); } } my $a = OpenBSD::PkgConfig->compress($cflags, ! sub($r) { ! if (($mode{cflags} & ONLY_I) && $r =~ /^-I/ || ! ($mode{cflags} & ONLY_OTHER) && $r !~ /^-I/) { return 1; } else { return 0; } }); ! if (defined($variables->{pc_sysrootdir})){ $a =~ s/[\w]?-I/$&$variables->{pc_sysrootdir}/g; } *************** *** 527,536 **** } #if the lib option is set, pull out the linker flags ! sub do_libs { - my $list = shift; - my $libs = []; # In static mode, we have to make sure we discover the libs in dependency --- 512,519 ---- } #if the lib option is set, pull out the linker flags ! sub do_libs($list) { my $libs = []; # In static mode, we have to make sure we discover the libs in dependency *************** *** 556,566 **** # Get the linker path directives (-L) and store it in $a. # $b will be the actual libraries. ! my $a = OpenBSD::PkgConfig->compress($libs, ! sub { ! local $_ = shift; ! if (($mode{libs} & 2) && /^-L/ || ! ($mode{libs} & 4) && !/^-[lL]/) { return 1; } else { return 0; --- 539,548 ---- # Get the linker path directives (-L) and store it in $a. # $b will be the actual libraries. ! my $r = OpenBSD::PkgConfig->compress_list($libs, ! sub($r) { ! if (($mode{libs} & ONLY_L) && $r =~ /^-L/ || ! ($mode{libs} & ONLY_OTHER) && $r !~ /^-[lL]/) { return 1; } else { return 0; *************** *** 568,589 **** }); if (defined($variables->{pc_sysrootdir})){ ! $a =~ s/[\w]?-[lL]/$&$variables->{pc_sysrootdir}/g; } ! if ($mode{libs} & 1) { ! my $b = OpenBSD::PkgConfig->rcompress($libs, ! sub { shift =~ m/^-l/; }); ! return ($a, $b); ! } else { ! return $a; } } #list all packages ! sub do_list { my ($p, $x, $y, @files, $fname, $name); my $error = 0; for my $p (@PKGPATH) { --- 550,572 ---- }); if (defined($variables->{pc_sysrootdir})){ ! for my $i (@$r) { ! $i =~ s/[\w]?-[lL]/$&$variables->{pc_sysrootdir}/; ! } } ! if ($mode{libs} & ONLY_l) { ! push(@$r, OpenBSD::PkgConfig->rcompress($libs, ! sub($l) { $l =~ m/^-l/; })); } + return @$r; } #list all packages ! sub do_list() { my ($p, $x, $y, @files, $fname, $name); + my $error = 0; for my $p (@PKGPATH) { *************** *** 616,622 **** return $error; } ! sub help { print < $y; return -1 if $x < $y; return 0 if (($x == $y) and ($eq == 1)); --- 750,757 ---- } # simple numeric comparison, with optional equality test. ! sub compare_numeric($x, $y, $eq) { return 1 if $x > $y; return -1 if $x < $y; return 0 if (($x == $y) and ($eq == 1)); *************** *** 780,789 **** } # got a package meeting the requested specific version? ! sub versionmatch { - my ($cfg, $op, $want) = @_; - # can't possibly match if we can't find the file return 0 if !defined $cfg; --- 759,766 ---- } # got a package meeting the requested specific version? ! sub versionmatch($cfg, $op, $want) { # can't possibly match if we can't find the file return 0 if !defined $cfg; *************** *** 802,810 **** elsif ($op eq '<=') { return $value <= 0; } } ! sub mismatch { - my ($p, $cfg, $op, $v) = @_; my $name = stringize($cfg->get_property('Name'), ' '); my $version = stringize($cfg->get_property('Version')); my $url = stringize($cfg->get_property('URL')); --- 779,786 ---- elsif ($op eq '<=') { return $value <= 0; } } ! sub mismatch($p, $cfg, $op, $v) { my $name = stringize($cfg->get_property('Name'), ' '); my $version = stringize($cfg->get_property('Version')); my $url = stringize($cfg->get_property('URL')); *************** *** 813,821 **** say_warning("You may find new versions of $name at $url") if $url; } ! sub simplify_and_reverse { - my $reqlist = shift; my $dejavu = {}; my $result = []; --- 789,796 ---- say_warning("You may find new versions of $name at $url") if $url; } ! sub simplify_and_reverse($reqlist) { my $dejavu = {}; my $result = []; *************** *** 829,838 **** } # retrieve and print Requires(.private) ! sub print_requires { - my ($p) = @_; - my $cfg = cache_find_config($p); if (defined($cfg)) { --- 804,811 ---- } # retrieve and print Requires(.private) ! sub print_requires($p) { my $cfg = cache_find_config($p); if (defined($cfg)) { *************** *** 848,854 **** } if (defined($value)) { ! print "$_\n" for @$value; return undef; } } --- 821,827 ---- } if (defined($value)) { ! say $_ for @$value; return undef; } } *************** *** 856,885 **** $rc = 1; } ! sub beautify_list { ! return join(' ', map {"[$_]"} @_); } ! sub say_debug { ! say_msg(shift) if $mode{debug}; } ! sub say_error { ! say_msg(shift) if $mode{printerr} } ! sub say_warning { ! say_msg(shift); } ! sub say_msg { - my $str = shift; - # If --errors-to-stdout was given, close STDERR (to be safe), # then dup the output to STDOUT and delete the key from %mode so we # won't keep checking it. STDERR stays dup'ed. --- 829,856 ---- $rc = 1; } ! sub beautify_list(@p) { ! return join(' ', map {"[$_]"} @p); } ! sub say_debug($msg) { ! say_msg($msg) if $mode{debug}; } ! sub say_error($msg) { ! say_msg($msg) if $mode{printerr} } ! sub say_warning($msg) { ! say_msg($msg); } ! sub say_msg($str) { # If --errors-to-stdout was given, close STDERR (to be safe), # then dup the output to STDOUT and delete the key from %mode so we # won't keep checking it. STDERR stays dup'ed. *************** *** 889,893 **** delete($mode{estdout}); } ! print STDERR $str, "\n"; } --- 860,864 ---- delete($mode{estdout}); } ! say STDERR $str; }