=item B<-F>, B<--cpp-flags>=I<addflags>
Additional flags to specify to C preprocessor when scanning header for
-function declarations. Should not be used without B<-x>.
+function declarations. Writes these options in the generated F<Makefile.PL>
+too.
=item B<-M>, B<--func-mask>=I<regular expression>
Will force the generation of test code that uses the older C<Test> module.
+=item B<--skip-exporter>
+
+Do not use C<Exporter> and/or export any symbol.
+
+=item B<--skip-ppport>
+
+Do not use C<Devel::PPPort>: no portability to older version.
+
+=item B<--skip-autoloader>
+
+Do not use the module C<AutoLoader>; but keep the constant() function
+and C<sub AUTOLOAD> for constants.
+
+=item B<--skip-strict>
+
+Do not use the pragma C<strict>.
+
+=item B<--skip-warnings>
+
+Do not use the pragma C<warnings>.
+
=item B<-v>, B<--version>=I<version>
Specify a version number for this extension. This version number is added
$Text::Wrap::columns = 80;
use ExtUtils::Constant qw (WriteConstants WriteMakefileSnippet autoload);
use File::Compare;
-use Devel::PPPort;
sub usage {
warn "@_\n" if @_;
-A, --omit-autoload Omit all autoloading facilities (implies -c).
-C, --omit-changes Omit creating the Changes file, add HISTORY heading
to stub POD.
- -F, --cpp-flags Additional flags for C preprocessor (used with -x).
+ -F, --cpp-flags Additional flags for C preprocessor/compile.
-M, --func-mask Mask to select C functions/macros
(default is select all).
-O, --overwrite-ok Allow overwriting of a pre-existing extension directory.
-t, --default-type Default type for autoloaded constants (default is IV)
--use-new-tests Use Test::More in backward compatible modules
--use-old-tests Use the module Test rather than Test::More
+ --skip-exporter Do not export symbols
+ --skip-ppport Do not use portability layer
+ --skip-autoloader Do not use the module C<AutoLoader>
+ --skip-strict Do not use the pragma C<strict>
+ --skip-warnings Do not use the pragma C<warnings>
-v, --version Specify a version number for this extension.
-x, --autogen-xsubs Autogenerate XSUBs using C::Scan.
$opt_b,
$opt_t,
$new_test,
- $old_test
+ $old_test,
+ $skip_exporter,
+ $skip_ppport,
+ $skip_autoloader,
+ $skip_strict,
+ $skip_warnings,
);
Getopt::Long::Configure('bundling');
'version|v=s' => \$opt_v,
'autogen-xsubs|x' => \$opt_x,
'use-new-tests' => \$new_test,
- 'use-old-tests' => \$old_test
+ 'use-old-tests' => \$old_test,
+ 'skip-exporter' => \$skip_exporter,
+ 'skip-ppport' => \$skip_ppport,
+ 'skip-autoloader' => \$skip_autoloader,
+ 'skip-warnings' => \$skip_warnings,
+ 'skip-strict' => \$skip_strict,
);
GetOptions(%options) || usage;
}
# -A implies -c.
-$opt_c = 1 if $opt_A;
+$skip_autoloader = $opt_c = 1 if $opt_A;
# -X implies -c and -f
$opt_c = $opt_f = 1 if $opt_X;
}
}
elsif ($opt_o or $opt_F) {
- warn <<EOD;
-Options -o and -F do not make sense without -x.
+ warn <<EOD if $opt_o;
+Option -o does not make sense without -x.
+EOD
+ warn <<EOD if $opt_F and $opt_X ;
+Option -F does not make sense with -X.
EOD
}
my $module = $opt_n;
if( @path_h ){
- use Config;
use File::Spec;
my @paths;
my $pre_sub_tri_graphs = 1;
# 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) {
my @vdecls;
if( ! $opt_X ){ # use XS, unless it was disabled
- warn "Writing $ext$modpname/ppport.h\n";
- Devel::PPPort::WriteFile('ppport.h')
- || die "Can't create $ext$modpname/ppport.h: $!\n";
-
+ unless ($skip_ppport) {
+ require Devel::PPPort;
+ warn "Writing $ext$modpname/ppport.h\n";
+ Devel::PPPort::WriteFile('ppport.h')
+ || die "Can't create $ext$modpname/ppport.h: $!\n";
+ }
open(XS, ">$modfname.xs") || die "Can't create $ext$modpname/$modfname.xs: $!\n";
if ($opt_x) {
- require Config; # Run-time directive
warn "Scanning typemaps...\n";
get_typemap();
my @td;
package $module;
use $compat_version;
+END
+
+print PM <<"END" unless $skip_strict;
use strict;
END
-print PM "use warnings;\n" unless $compat_version < 5.006;
+
+print PM "use warnings;\n" unless $skip_warnings or $compat_version < 5.006;
unless( $opt_X || $opt_c || $opt_A ){
# we'll have an AUTOLOAD(), and it will have $AUTOLOAD and
END
}
-print PM <<'END';
+print PM <<'END' unless $skip_exporter;
require Exporter;
END
-print PM <<"END" if ! $opt_X; # use DynaLoader, unless XS was disabled
+my $use_Dyna = (not $opt_X and $compat_version < 5.006);
+print PM <<"END" if $use_Dyna; # use DynaLoader, unless XS was disabled
require DynaLoader;
END
# Are we using AutoLoader or not?
-unless ($opt_A) { # no autoloader whatsoever.
+unless ($skip_autoloader) { # no autoloader whatsoever.
unless ($opt_c) { # we're doing the AUTOLOAD
print PM "use AutoLoader;\n";
}
if ( $compat_version < 5.006 ) {
if ( $opt_X || $opt_c || $opt_A ) {
- print PM 'use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);';
+ if ($skip_exporter) {
+ print PM 'use vars qw($VERSION @ISA);';
+ } else {
+ print PM 'use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);';
+ }
} else {
- print PM 'use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $AUTOLOAD);';
+ if ($skip_exporter) {
+ print PM 'use vars qw($VERSION @ISA $AUTOLOAD);';
+ } else {
+ print PM 'use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $AUTOLOAD);';
+ }
}
}
# Determine @ISA.
-my $myISA = 'our @ISA = qw(Exporter'; # We seem to always want this.
-$myISA .= ' DynaLoader' unless $opt_X; # no XS
-$myISA .= ');';
+my @modISA;
+push @modISA, 'Exporter' unless $skip_exporter;
+push @modISA, 'DynaLoader' if $use_Dyna; # no XS
+my $myISA = "our \@ISA = qw(@modISA);";
$myISA =~ s/^our // if $compat_version < 5.006;
print PM "\n$myISA\n\n";
my @exported_names = (@const_names, @fnames_no_prefix, map '$'.$_, @vdecls);
-my $tmp=<<"END";
+my $tmp='';
+$tmp .= <<"END" unless $skip_exporter;
# Items to export into callers namespace by default. Note: do not export
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.
our \@EXPORT = qw(
@const_names
);
+
+END
+
+$tmp .= <<"END";
our \$VERSION = '$TEMPLATE_VERSION';
END
print PM autoload ($module, $compat_version) unless $opt_c or $opt_X;
if( ! $opt_X ){ # print bootstrap, unless XS is disabled
+ if ($use_Dyna) {
print PM <<"END";
bootstrap $module \$VERSION;
END
+ } else {
+ print PM <<"END";
+require XSLoader;
+XSLoader::load('$module', \$VERSION);
+END
+ }
}
# tying the variables can happen only after bootstrap
#
EOT
-my $exp_doc = <<EOD;
+my $exp_doc = $skip_exporter ? '' : <<EOD;
#
#=head2 EXPORT
#
EOD
if (@const_names and not $opt_P) {
- $exp_doc .= <<EOD;
+ $exp_doc .= <<EOD unless $skip_exporter;
#=head2 Exportable constants
#
# @{[join "\n ", @const_names]}
}
if (defined $fdecls and @$fdecls and not $opt_P) {
- $exp_doc .= <<EOD;
+ $exp_doc .= <<EOD unless $skip_exporter;
#=head2 Exportable functions
#
EOD
#When accessing these functions from Perl, prefix C<$opt_p> should be removed.
#
#EOD
- $exp_doc .= <<EOD;
+ $exp_doc .= <<EOD unless $skip_exporter;
# @{[join "\n ", @known_fnames{@fnames}]}
#
EOD
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
+
+END
+
+print XS <<"END" unless $skip_ppport;
#include "ppport.h"
END
+
if( @path_h ){
foreach my $path_h (@path_h_ini) {
my($h) = $path_h;
# 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!