summaryrefslogtreecommitdiff
path: root/utils/h2xs.PL
diff options
context:
space:
mode:
authorPerl 5 Porters <perl5-porters@africa.nicoh.com>1996-02-05 20:30:34 -0600
committerAndy Dougherty <doughera@lafcol.lafayette.edu>1996-02-05 20:30:34 -0600
commit2920c5d2b358b11ace52104b6944bfa0e89256a7 (patch)
tree8b561e2eaeba25dd353ef1615841ef89ca9b46d4 /utils/h2xs.PL
parentb276c83ddda3f6f594aec5ed6b44c39a9ac218dc (diff)
downloadperl-2920c5d2b358b11ace52104b6944bfa0e89256a7.tar.gz
perl 5.002gamma: utils/h2xs.PL
>From roehrich@cray.comTue Feb 6 10:10:30 1996 >Date: Mon, 5 Feb 1996 20:30:34 -0600 >From: Dean Roehrich <roehrich@cray.com> >To: perl5-porters@africa.nicoh.com >Subject: h2xs 1.15 > >This is h2xs version 1.15. Apply over beta3. > >From roehrich@cray.comWed Feb 7 09:17:51 1996 >Date: Tue, 6 Feb 1996 18:31:53 -0600 >From: Dean Roehrich <roehrich@cray.com> >To: perl5-porters@africa.nicoh.com >Subject: h2xs 1.16 > >Following a suggestion from PaulM, I have updated the AUTOLOAD() that h2xs >creates. It uses Carp::croak now.
Diffstat (limited to 'utils/h2xs.PL')
-rw-r--r--utils/h2xs.PL114
1 files changed, 93 insertions, 21 deletions
diff --git a/utils/h2xs.PL b/utils/h2xs.PL
index 26f10c7687..4e64d86885 100644
--- a/utils/h2xs.PL
+++ b/utils/h2xs.PL
@@ -41,7 +41,7 @@ h2xs - convert .h C header files to Perl extensions
=head1 SYNOPSIS
-B<h2xs> [B<-APcf>] [B<-v> version] [B<-n> module_name] [headerfile [extra_libraries]]
+B<h2xs> [B<-AOPXcf>] [B<-v> version] [B<-n> module_name] [headerfile [extra_libraries]]
B<h2xs> B<-h>
@@ -73,6 +73,10 @@ in the extra-libraries argument.
Omit all autoload facilities. This is the same as B<-c> but also removes the
S<C<require AutoLoader>> statement from the .pm file.
+=item B<-O>
+
+Allows a pre-existing extension directory to be overwritten.
+
=item B<-P>
Omit the autogenerated stub POD section.
@@ -100,6 +104,11 @@ Specifies a name to be used for the extension, e.g., S<-n RPC::DCE>
Specify a version number for this extension. This version number is added
to the templates. The default is 0.01.
+=item B<-X>
+
+Omit the XS portion. Used to generate templates for a module which is not
+XS-based.
+
=back
=head1 EXAMPLES
@@ -149,20 +158,22 @@ The usual warnings if it can't read or write the files involved.
=cut
-my( $H2XS_VERSION ) = '$Revision: 1.14 $' =~ /\$Revision:\s+([^\s]+)/;
+my( $H2XS_VERSION ) = '$Revision: 1.16 $' =~ /\$Revision:\s+([^\s]+)/;
my $TEMPLATE_VERSION = '0.01';
use Getopt::Std;
sub usage{
warn "@_\n" if @_;
- die "h2xs [-APcfh] [-v version] [-n module_name] [headerfile [extra_libraries]]
+ die "h2xs [-AOPXcfh] [-v version] [-n module_name] [headerfile [extra_libraries]]
version: $H2XS_VERSION
-f Force creation of the extension even if the C header does not exist.
-n Specify a name to use for the extension (recommended).
-c Omit the constant() function and specialised AUTOLOAD from the XS file.
-A Omit all autoloading facilities (implies -c).
+ -O Allow overwriting of a pre-existing extension directory.
-P Omit the stub POD section.
+ -X Omit the XS portion.
-v Specify a version number for this extension.
-h Display this help message
extra_libraries
@@ -172,7 +183,7 @@ extra_libraries
}
-getopts("APcfhv:n:") || usage;
+getopts("AOPXcfhv:n:") || usage;
usage if $opt_h;
@@ -237,7 +248,11 @@ else {
}
-die "Won't overwrite existing $ext$modpname\n" if -e $modpname;
+if ($opt_O) {
+ warn "Overwriting existing $ext$modpname!!!\n" if -e $modpname;
+} else {
+ die "Won't overwrite existing $ext$modpname\n" if -e $modpname;
+}
if( $nested ){
$modpath = "";
foreach (@modparts){
@@ -248,7 +263,9 @@ if( $nested ){
mkdir($modpname, 0777);
chdir($modpname) || die "Can't chdir $ext$modpname: $!\n";
-open(XS, ">$modfname.xs") || die "Can't create $ext$modpname/$modfname.xs: $!\n";
+if( ! $opt_X ){ # use XS, unless it was disabled
+ open(XS, ">$modfname.xs") || die "Can't create $ext$modpname/$modfname.xs: $!\n";
+}
open(PM, ">$modfname.pm") || die "Can't create $ext$modpname/$modfname.pm: $!\n";
$" = "\n\t";
@@ -257,31 +274,72 @@ warn "Writing $ext$modpname/$modfname.pm\n";
print PM <<"END";
package $module;
+use strict;
+END
+
+if( $opt_X || $opt_c || $opt_A ){
+ # we won't have our own AUTOLOAD(), so won't have $AUTOLOAD
+ print PM <<'END';
+use vars qw($VERSION @ISA @EXPORT);
+END
+}
+else{
+ # we'll have an AUTOLOAD(), and it will have $AUTOLOAD and
+ # will want Carp.
+ print PM <<'END';
+use Carp;
+use vars qw($VERSION @ISA @EXPORT $AUTOLOAD);
+END
+}
+
+print PM <<'END';
+
require Exporter;
+END
+
+print PM <<"END" if ! $opt_X; # use DynaLoader, unless XS was disabled
require DynaLoader;
END
-if( ! $opt_A ){
+# require autoloader if XS is disabled.
+# if XS is enabled, require autoloader unless autoloading is disabled.
+if( $opt_X || (! $opt_A) ){
print PM <<"END";
require AutoLoader;
END
}
-if( $opt_c && ! $opt_A ){
+if( $opt_X || ($opt_c && ! $opt_A) ){
# we won't have our own AUTOLOAD(), so we'll inherit it.
- print PM <<"END";
+ if( ! $opt_X ) { # use DynaLoader, unless XS was disabled
+ print PM <<"END";
\@ISA = qw(Exporter AutoLoader DynaLoader);
END
+ }
+ else{
+ print PM <<"END";
+
+\@ISA = qw(Exporter AutoLoader);
+END
+ }
}
else{
# 1) we have our own AUTOLOAD(), so don't need to inherit it.
# or
# 2) we don't want autoloading mentioned.
- print PM <<"END";
+ if( ! $opt_X ){ # use DynaLoader, unless XS was disabled
+ print PM <<"END";
\@ISA = qw(Exporter DynaLoader);
END
+ }
+ else{
+ print PM <<"END";
+
+\@ISA = qw(Exporter);
+END
+ }
}
print PM<<"END";
@@ -295,23 +353,22 @@ print PM<<"END";
END
-print PM <<"END" unless $opt_c;
+print PM <<"END" unless $opt_c or $opt_X;
sub AUTOLOAD {
# This AUTOLOAD is used to 'autoload' constants from the constant()
# XS function. If a constant is not found then control is passed
# to the AUTOLOAD in AutoLoader.
- local(\$constname);
+ my \$constname;
(\$constname = \$AUTOLOAD) =~ s/.*:://;
- \$val = constant(\$constname, \@_ ? \$_[0] : 0);
+ my \$val = constant(\$constname, \@_ ? \$_[0] : 0);
if (\$! != 0) {
if (\$! =~ /Invalid/) {
\$AutoLoader::AUTOLOAD = \$AUTOLOAD;
goto &AutoLoader::AUTOLOAD;
}
else {
- (\$pack,\$file,\$line) = caller;
- die "Your vendor has not defined $module macro \$constname, used at \$file line \$line.\n";
+ croak "Your vendor has not defined $module macro \$constname";
}
}
eval "sub \$AUTOLOAD { \$val }";
@@ -320,12 +377,24 @@ sub AUTOLOAD {
END
-print PM <<"END";
+if( ! $opt_X ){ # print bootstrap, unless XS is disabled
+ print PM <<"END";
bootstrap $module \$VERSION;
+END
+}
+
+if( $opt_P ){ # if POD is disabled
+ $after = '__END__';
+}
+else {
+ $after = '=cut';
+}
+
+print PM <<"END";
# Preloaded methods go here.
-# Autoload methods go after __END__, and are processed by the autosplit program.
+# Autoload methods go after $after, and are processed by the autosplit program.
1;
__END__
@@ -371,6 +440,7 @@ print PM $pod unless $opt_P;
close PM;
+if( ! $opt_X ){ # print XS, unless it is disabled
warn "Writing $ext$modpname/$modfname.xs\n";
print XS <<"END";
@@ -474,7 +544,7 @@ constant(name,arg)
END
close XS;
-
+} # if( ! $opt_X )
warn "Writing $ext$modpname/Makefile.PL\n";
open(PL, ">Makefile.PL") || die "Can't create $ext$modpname/Makefile.PL: $!\n";
@@ -487,9 +557,11 @@ END
print PL "WriteMakefile(\n";
print PL " 'NAME' => '$module',\n";
print PL " 'VERSION_FROM' => '$modfname.pm', # finds \$VERSION\n";
-print PL " 'LIBS' => ['$extralibs'], # e.g., '-lm' \n";
-print PL " 'DEFINE' => '', # e.g., '-DHAVE_SOMETHING' \n";
-print PL " 'INC' => '', # e.g., '-I/usr/include/other' \n";
+if( ! $opt_X ){ # print C stuff, unless XS is disabled
+ print PL " 'LIBS' => ['$extralibs'], # e.g., '-lm' \n";
+ print PL " 'DEFINE' => '', # e.g., '-DHAVE_SOMETHING' \n";
+ print PL " 'INC' => '', # e.g., '-I/usr/include/other' \n";
+}
print PL ");\n";
close(PL) || die "Can't close $ext$modpname/Makefile.PL: $!\n";