summaryrefslogtreecommitdiff
path: root/utils/h2xs.PL
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2002-03-04 22:48:38 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2002-03-04 22:17:56 +0000
commit1cb0fb506639f41107792256805556ee04e5463a (patch)
treeedcae7d6f9d2e1e4ca67c0e7cd70b1943e06b734 /utils/h2xs.PL
parent26f1752374957703dbfe054b7fa25c12c67ca6f3 (diff)
downloadperl-1cb0fb506639f41107792256805556ee04e5463a.tar.gz
(was Re: [PATCH @13746] h2xs)
Message-ID: <20020304224837.GA4284@Bagpuss.unfortu.net> p4raw-id: //depot/perl@15023
Diffstat (limited to 'utils/h2xs.PL')
-rw-r--r--utils/h2xs.PL71
1 files changed, 35 insertions, 36 deletions
diff --git a/utils/h2xs.PL b/utils/h2xs.PL
index f1762c9e6d..b35d769220 100644
--- a/utils/h2xs.PL
+++ b/utils/h2xs.PL
@@ -808,7 +808,13 @@ if( @path_h ){
# Save current directory so that C::Scan can use it
my $cwd = File::Spec->rel2abs( File::Spec->curdir );
-my ($ext, $nested, @modparts, $modfname, $modpname, $constsfname);
+my ($ext, $nested, @modparts, $modfname, $modpname);
+# As Ilya suggested, use a name that contains - and then it can't clash with
+# the names of any packages. A directory 'fallback' will clash with any
+# new pragmata down the fallback:: tree, but that seems unlikely.
+my $constscfname = 'const-c.inc';
+my $constsxsfname = 'const-xs.inc';
+my $fallbackdirname = 'fallback';
$ext = chdir 'ext' ? 'ext/' : '';
@@ -823,8 +829,6 @@ else {
@modparts = ();
$modfname = $modpname = $module;
}
-# Don't trip up if someone calls their module 'constants'
-$constsfname = $modfname eq 'constants' ? 'constdefs' : 'constants';
if ($opt_O) {
@@ -1345,15 +1349,20 @@ if( ! $opt_c ) {
# ExtUtils::Constant.
# h2xs will later check that these are the same as those generated by the
# code embedded into Makefile.PL
- warn "Writing $ext$modpname/fallback.c\n";
- warn "Writing $ext$modpname/fallback.xs\n";
- WriteConstants ( C_FILE => "fallback.c",
- XS_FILE => "fallback.xs",
+ unless (-d $fallbackdirname) {
+ mkdir "$fallbackdirname" or die "Cannot mkdir $fallbackdirname: $!\n";
+ }
+ warn "Writing $ext$modpname/$fallbackdirname/$constscfname\n";
+ warn "Writing $ext$modpname/$fallbackdirname/$constsxsfname\n";
+ my $cfallback = File::Spec->catfile($fallbackdirname, $constscfname);
+ my $xsfallback = File::Spec->catfile($fallbackdirname, $constsxsfname);
+ WriteConstants ( C_FILE => $cfallback,
+ XS_FILE => $xsfallback,
DEFAULT_TYPE => $opt_t,
NAME => $module,
NAMES => \@const_names,
);
- print XS "#include \"$constsfname.c\"\n";
+ print XS "#include \"$constscfname\"\n";
}
@@ -1368,7 +1377,7 @@ END
# If a constant() function was #included then output a corresponding
# XS declaration:
-print XS "INCLUDE: $constsfname.xs\n" unless $opt_c;
+print XS "INCLUDE: $constsxsfname\n" unless $opt_c;
print XS <<"END" if $opt_g;
@@ -1817,16 +1826,7 @@ EOC
$Icomment 'INC' => '$I', # e.g., '${Ihelp}-I/usr/include/other'
END
- if (!$opt_c) {
- print PL <<"END";
- # Without this the constants xs files are spotted, and cause rules to be
- # added to delete the similarly names C files, which isn't what we want.
- 'XS' => {'$modfname.xs' => '$modfname.c'},
- realclean => {FILES => '$constsfname.c $constsfname.xs'},
-END
- }
-
- my $C = grep {$_ ne "$modfname.c" && $_ ne "fallback.c"}
+ my $C = grep {$_ ne "$modfname.c"}
(glob '*.c'), (glob '*.cc'), (glob '*.C');
my $Cpre = ($C ? '' : '# ');
my $Ccomment = ($C ? '' : <<EOC);
@@ -1840,8 +1840,8 @@ END
print PL ");\n";
if (!$opt_c) {
my $generate_code =
- WriteMakefileSnippet ( C_FILE => "$constsfname.c",
- XS_FILE => "$constsfname.xs",
+ WriteMakefileSnippet ( C_FILE => $constscfname,
+ XS_FILE => $constsxsfname,
DEFAULT_TYPE => $opt_t,
NAME => $module,
NAMES => \@const_names,
@@ -1849,17 +1849,18 @@ if (!$opt_c) {
print PL <<"END";
if (eval {require ExtUtils::Constant; 1}) {
# If you edit these definitions to change the constants used by this module,
- # you will need to use the generated $constsfname.c and $constsfname.xs
+ # you will need to use the generated $constscfname and $constsxsfname
# files to replace their "fallback" counterparts before distributing your
# changes.
$generate_code
}
else {
use File::Copy;
- copy ('fallback.c', '$constsfname.c')
- or die "Can't copy fallback.c to $constsfname.c: \$!";
- copy ('fallback.xs', '$constsfname.xs')
- or die "Can't copy fallback.xs to $constsfname.xs: \$!";
+ use File::Spec;
+ foreach my \$file ('$constscfname', '$constsxsfname') {
+ my \$fallback = File::Spec->catfile('$fallbackdirname', \$file);
+ copy (\$fallback, \$file) or die "Can't copy \$fallback to \$file: \$!";
+ }
}
END
@@ -1876,10 +1877,11 @@ EOM
} else {
my $fail;
- foreach ('c', 'xs') {
- if (compare("fallback.$_", "$constsfname.$_")) {
+ foreach my $file ($constscfname, $constsxsfname) {
+ my $fallback = File::Spec->catfile($fallbackdirname, $file);
+ if (compare($file, $fallback)) {
warn << "EOM";
-Files "$ext$modpname/fallback.$_" and "$ext$modpname/$constsfname.$_" differ.
+Files "$ext$modpname/$fallbackdirname/$file" and "$ext$modpname/$file" differ.
EOM
$fail++;
}
@@ -1887,14 +1889,14 @@ EOM
if ($fail) {
warn fill ('','', <<"EOM") . "\n";
It appears that the code in $ext$modpname/Makefile.PL does not autogenerate
-the files $ext$modpname/$constsfname.c and $ext$modpname/$constsfname.xs
+the files $ext$modpname/$constscfname and $ext$modpname/$constsxsfname
correctly.
-
+
Please report the circumstances of this bug in h2xs version $H2XS_VERSION
using the perlbug script.
EOM
} else {
- unlink "$constsfname.c", "$constsfname.xs";
+ unlink $constscfname, $constsxsfname;
}
}
}
@@ -2087,7 +2089,7 @@ EOP
warn "Writing $ext$modpname/MANIFEST\n";
open(MANI,'>MANIFEST') or die "Can't create MANIFEST: $!";
-my @files = grep { -f } (<*>, <t/*>);
+my @files = grep { -f } (<*>, <t/*>, <$fallbackdirname/*>);
if (!@files) {
eval {opendir(D,'.');};
unless ($@) { @files = readdir(D); closedir(D); }
@@ -2103,9 +2105,6 @@ if ($^O eq 'VMS') {
$_ = 'Makefile.PL' if $_ eq 'makefile.pl';
}
}
-if (!$opt_c) {
- @files = grep {$_ ne "$constsfname.c" and $_ ne "$constsfname.xs"} @files;
-}
print MANI join("\n",@files), "\n";
close MANI;
!NO!SUBS!