Skip to content

DynaLoader.pm on Win32 bake in Config.pm (PERL_BUILD_EXPAND_CONFIG_VARS) #23423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: blead
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions ext/DynaLoader/DynaLoader_pm.PL
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,16 @@ sub expand_os_specific {
$s;
}

# On Win32, there are no values from Config.pm that ever need to be changed
# between WinPerl builds, or major interp versions, or by end users.
# libpth points to CC's .a/.lib not a dir of .dlls. LoadLibraryEx() will not
# accept .obj .o .a and .lib files.
# ldlibpthname = '' path_sep = ';' dlext = 'dll' so = 'dll' dlsrc = 'dl_win32.xs'
my $expand_config_vars = $^O eq 'MSWin32' ? 1 : $ENV{PERL_BUILD_EXPAND_CONFIG_VARS};

unlink "DynaLoader.pm" if -f "DynaLoader.pm";
open OUT, '>', "DynaLoader.pm" or die $!;
binmode(OUT) if $^O eq 'MSWin32';
print OUT <<'EOT';

# Generated from DynaLoader_pm.PL, this file is unique for every OS
Expand All @@ -90,7 +98,7 @@ package DynaLoader;
# [email protected], August 1994

BEGIN {
our $VERSION = '1.57';
our $VERSION = '1.58';
}

# Note: in almost any other piece of code "our" would have been a better
Expand All @@ -103,7 +111,7 @@ use vars qw(@dl_library_path @dl_resolve_using @dl_require_symbols

EOT

if (!$ENV{PERL_BUILD_EXPAND_CONFIG_VARS}) {
if (!$expand_config_vars) {
print OUT "use Config;\n";
}

Expand All @@ -128,11 +136,11 @@ sub dl_load_flags { 0x00 }

EOT

if ($ENV{PERL_BUILD_EXPAND_CONFIG_VARS}) {
if ($expand_config_vars) {
print OUT "(\$dl_dlext, \$dl_so, \$dlsrc) = (",
to_string($Config{'dlext'}), ",",
to_string($Config{'so'}), ",",
to_string($Config{'dlsrc'}), ")\n;" ;
to_string($Config{'dlsrc'}), ");\n" ;
}
else {
print OUT <<'EOT';
Expand Down Expand Up @@ -162,15 +170,26 @@ my $do_expand = <<$^O-eq-VMS>>1<<|$^O-eq-VMS>>0<</$^O-eq-VMS>>;

EOT

my $cfg_dl_library_path = <<'EOT';
my $cfg_dl_library_path;

if ($^O eq 'MSWin32') {
require Text::ParseWords;
my @w32libpths = Text::ParseWords::parse_line('\s+', 1, $Config::Config{libpth});
@w32libpths = map({if (substr($_, 0, 1) eq '"') {$_ =~ tr/"/'/;} $_;} @w32libpths);
my $w32libpths = join(',',@w32libpths);
$cfg_dl_library_path = "push(\@dl_library_path, $w32libpths);";
}
else {
$cfg_dl_library_path = <<'EOT';
push(@dl_library_path, split(' ', $Config::Config{libpth}));
EOT
}

sub dquoted_comma_list {
join(", ", map {'"'.quotemeta($_).'"'} @_);
}

if ($ENV{PERL_BUILD_EXPAND_CONFIG_VARS}) {
if ($expand_config_vars) {
eval $cfg_dl_library_path;
if (!$ENV{PERL_BUILD_EXPAND_ENV_VARS}) {
my $dl_library_path = dquoted_comma_list(@dl_library_path);
Expand All @@ -196,7 +215,7 @@ my $ldlibpthname;
my $ldlibpthname_defined;
my $pthsep;

if ($ENV{PERL_BUILD_EXPAND_CONFIG_VARS}) {
if ($expand_config_vars) {
$ldlibpthname = to_string($Config::Config{ldlibpthname});
$ldlibpthname_defined = to_string(defined $Config::Config{ldlibpthname} ? 1 : 0);
$pthsep = to_string($Config::Config{path_sep});
Expand All @@ -215,6 +234,7 @@ EOT

my $env_dl_library_path = <<'EOT';
if ($ldlibpthname_defined &&
length($ldlibpthname) &&
exists $ENV{$ldlibpthname}) {
push(@dl_library_path, split(/$pthsep/, $ENV{$ldlibpthname}));
}
Expand All @@ -228,7 +248,7 @@ if ($ldlibpthname_defined &&
}
EOT

if ($ENV{PERL_BUILD_EXPAND_CONFIG_VARS} && $ENV{PERL_BUILD_EXPAND_ENV_VARS}) {
if ($expand_config_vars && $ENV{PERL_BUILD_EXPAND_ENV_VARS}) {
eval $env_dl_library_path;
}
else {
Expand All @@ -241,7 +261,7 @@ $env_dl_library_path
EOT
}

if ($ENV{PERL_BUILD_EXPAND_CONFIG_VARS} && $ENV{PERL_BUILD_EXPAND_ENV_VARS}) {
if ($expand_config_vars && $ENV{PERL_BUILD_EXPAND_ENV_VARS}) {
my $dl_library_path = dquoted_comma_list(@dl_library_path);
print OUT <<EOT;
# The below \@dl_library_path has been expanded (%Config, %ENV)
Expand Down
Loading