# 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/' : '';
@modparts = ();
$modfname = $modpname = $module;
}
-# Don't trip up if someone calls their module 'constants'
-$constsfname = $modfname eq 'constants' ? 'constdefs' : 'constants';
if ($opt_O) {
# 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";
}
# 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;
$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);
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,
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
} 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++;
}
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;
}
}
}
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); }
$_ = '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!