View Single Post
Old 7th February 2014
thirdm thirdm is offline
Spam Deminer
 
Join Date: May 2009
Posts: 234
Default

Quote:
Originally Posted by J65nko View Post
Right now, I don't have time to work on this anymore, but maybe somebody else has
wonder_why.pl:
Code:
#!/usr/bin/perl

use warnings;
use strict;
use feature 'say';
my @PKGPATH = '/usr/lib/pkgconfig';

sub show_env {
   say "The environment:\n===============";
   foreach my $key (sort keys %ENV) {
     say $key, '=', $ENV{$key};
   } 
   say "===============\n";
}

sub orig {
        defined($ENV{PKG_CONFIG_LIBDIR}) ?  say "YES defined" : say "NOT defined"; 
        $ENV{PKG_CONFIG_LIBDIR} ? say "YES bare" : say "NO bare";

        if (defined($ENV{PKG_CONFIG_LIBDIR}) && $ENV{PKG_CONFIG_LIBDIR}) {
                say "\nPKG_CONFIG_LIBDIR test succeeded";
                @PKGPATH = split(/:/, $ENV{PKG_CONFIG_LIBDIR});
                { local $, = "\n"; say 'PKGPATH...', @PKGPATH }
        } elsif (defined($ENV{PKG_CONFIG_PATH}) && $ENV{PKG_CONFIG_PATH}) {
                say "\nPKG_CONFIG_PATH test succeeded";
                unshift(@PKGPATH, split(/:/, $ENV{PKG_CONFIG_PATH}));
                { local $, = "\n"; say 'PKGPATH...', @PKGPATH }
        }

}

sub new {
        defined($ENV{PKG_CONFIG_LIBDIR}) ?  say "YES defined" : say "NOT defined"; 
        $ENV{PKG_CONFIG_LIBDIR} ? say "YES bare" : say "NO bare";

        if ($ENV{PKG_CONFIG_LIBDIR}) {
	    say "\nPKG_CONFIG_LIBDIR test succeeded";
	    @PKGPATH = split(/:/, $ENV{PKG_CONFIG_LIBDIR});
	    { local $, = "\n"; say 'PKGPATH...', @PKGPATH }
        } elsif ($ENV{PKG_CONFIG_PATH}) {
	    say "\nPKG_CONFIG_PATH test succeeded";
	    unshift(@PKGPATH, split(/:/, $ENV{PKG_CONFIG_PATH}));
	    { local $, = "\n"; say 'PKGPATH...', @PKGPATH }
        }
}

show_env();
die unless @ARGV == 1;
#say 'running ', @ARGV;
no strict 'refs';
$ARGV[0]->();
say "\n";
testit
Code:
#!/bin/sh

pkg_config_libdir='PKG_CONFIG_LIBDIR=/usr/bin/local/lib:/sbin/lib:/usr/sbin/lib'
pkg_config_path='PKG_CONFIG_PATH=/usr/X11R6/lib/pkgconfig:/usr/X11R6/share/pkgconfig';

for fn in orig new; do
    {
	env -i ${pkg_config_libdir} ${pkg_config_path} ./wonder_why.pl $fn
	env -i ${pkg_config_path} ./wonder_why.pl $fn
    } | tee $fn.out
done

if cmp orig.out new.out; then
    echo Result: output identical
else
    diff -u orig.out new.out
fi
Output...
Code:
The environment:
===============
PKG_CONFIG_LIBDIR=/usr/bin/local/lib:/sbin/lib:/usr/sbin/lib
PKG_CONFIG_PATH=/usr/X11R6/lib/pkgconfig:/usr/X11R6/share/pkgconfig
===============

YES defined
YES bare

PKG_CONFIG_LIBDIR test succeeded
PKGPATH...
/usr/bin/local/lib
/sbin/lib
/usr/sbin/lib


The environment:
===============
PKG_CONFIG_PATH=/usr/X11R6/lib/pkgconfig:/usr/X11R6/share/pkgconfig
===============

NOT defined
NO bare

PKG_CONFIG_PATH test succeeded
PKGPATH...
/usr/X11R6/lib/pkgconfig
/usr/X11R6/share/pkgconfig
/usr/lib/pkgconfig


The environment:
===============
PKG_CONFIG_LIBDIR=/usr/bin/local/lib:/sbin/lib:/usr/sbin/lib
PKG_CONFIG_PATH=/usr/X11R6/lib/pkgconfig:/usr/X11R6/share/pkgconfig
===============

YES defined
YES bare

PKG_CONFIG_LIBDIR test succeeded
PKGPATH...
/usr/bin/local/lib
/sbin/lib
/usr/sbin/lib


The environment:
===============
PKG_CONFIG_PATH=/usr/X11R6/lib/pkgconfig:/usr/X11R6/share/pkgconfig
===============

NOT defined
NO bare

PKG_CONFIG_PATH test succeeded
PKGPATH...
/usr/X11R6/lib/pkgconfig
/usr/X11R6/share/pkgconfig
/usr/lib/pkgconfig


Result: output identical

$
Reply With Quote