diff options
author | Nicholas Clark <nick@ccl4.org> | 2013-07-06 00:28:50 +0200 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2013-07-07 12:52:36 +0200 |
commit | a78951c8adf2702a1136eae4f11657b13ee6697f (patch) | |
tree | b6bd3d90262b522ee9a106aaa2a797caa1d44398 /ext/ExtUtils-Miniperl | |
parent | c8935f6cd34349a50bf080be1bb4c46f2a00adfb (diff) | |
download | perl-a78951c8adf2702a1136eae4f11657b13ee6697f.tar.gz |
Clean up ExtUtils::Miniperl
Give it a $VERSION.
Bring the joy of strict (and warnings) to it.
Inline the C code into writemain() instead of using $head, $tail and a regex
to split the $tail into $tail1, $tail2 and $tail3.
Tweak the NAME section so that ABSTRACT_FROM parses it.
Document the updated functionality of writemain().
Diffstat (limited to 'ext/ExtUtils-Miniperl')
-rw-r--r-- | ext/ExtUtils-Miniperl/lib/ExtUtils/Miniperl.pm | 131 |
1 files changed, 64 insertions, 67 deletions
diff --git a/ext/ExtUtils-Miniperl/lib/ExtUtils/Miniperl.pm b/ext/ExtUtils-Miniperl/lib/ExtUtils/Miniperl.pm index 3a43094e2c..b14b216697 100644 --- a/ext/ExtUtils-Miniperl/lib/ExtUtils/Miniperl.pm +++ b/ext/ExtUtils-Miniperl/lib/ExtUtils/Miniperl.pm @@ -1,18 +1,26 @@ -# This File keeps the contents of miniperlmain.c. -# -# It was generated automatically by minimod.PL from the contents -# of miniperlmain.c. Don't edit this file! -# -# ANY CHANGES MADE HERE WILL BE LOST! -# - - +#!./perl -w package ExtUtils::Miniperl; +use strict; require Exporter; + +use vars qw($VERSION @ISA @EXPORT); + @ISA = qw(Exporter); -@EXPORT = qw(&writemain); +@EXPORT = qw(writemain); +$VERSION = 1; + +sub writemain{ + my $fh; + if (ref $_[0]) { + $fh = shift; + } else { + $fh = \*STDOUT; + } + + my(@exts) = @_; -$head= <<'EOF!HEAD'; + my($dl) = canon('/','DynaLoader'); + print $fh <<'EOF!HEAD'; /* miniperlmain.c * * Copyright (C) 1994, 1995, 1996, 1997, 1999, 2000, 2001, 2002, 2003, @@ -167,35 +175,6 @@ main(int argc, char **argv, char **env) /* Register any extra external extensions */ EOF!HEAD -$tail=<<'EOF!TAIL'; - -static void -xs_init(pTHX) -{ - PERL_UNUSED_CONTEXT; -} - -/* - * Local variables: - * c-indentation-style: bsd - * c-basic-offset: 4 - * indent-tabs-mode: nil - * End: - * - * ex: set ts=8 sts=4 sw=4 et: - */ -EOF!TAIL - -sub writemain{ - my $old_fh; - if (ref $_[0]) { - $old_fh = select shift; - } - my(@exts) = @_; - - my($pname); - my($dl) = canon('/','DynaLoader'); - print $head; foreach $_ (@exts){ my($pname) = canon('/', $_); @@ -205,35 +184,55 @@ sub writemain{ print "EXTERN_C void boot_${cname} (pTHX_ CV* cv);\n"; } - my ($tail1,$tail2,$tail3) = ( $tail =~ /\A(.*{\s*\n)(.*\n)(\s*\}.*)\Z/s ); + print $fh <<'EOT'; - print $tail1; - print "\tstatic const char file[] = __FILE__;\n" +static void +xs_init(pTHX) +{ +EOT + + print $fh " static const char file[] = __FILE__;\n" if @exts; - print "\tdXSUB_SYS;\n" if $] > 5.002; - print $tail2; + print $fh <<'EOT'; + dXSUB_SYS; + PERL_UNUSED_CONTEXT; +EOT + my %seen; foreach $_ (@exts){ my($pname) = canon('/', $_); my($mname, $cname, $ccode); ($mname = $pname) =~ s!/!::!g; ($cname = $pname) =~ s!/!__!g; - print "\t{\n"; if ($pname eq $dl){ # Must NOT install 'DynaLoader::boot_DynaLoader' as 'bootstrap'! # boot_DynaLoader is called directly in DynaLoader.pm - $ccode = "\t/* DynaLoader is a special case */\n -\tnewXS(\"${mname}::boot_${cname}\", boot_${cname}, file);\n"; - print $ccode unless $SEEN{$ccode}++; + $ccode = <<"EOT"; + /* DynaLoader is a special case */ + newXS(\"${mname}::boot_${cname}\", boot_${cname}, file); +EOT } else { - $ccode = "\tnewXS(\"${mname}::bootstrap\", boot_${cname}, file);\n"; - print $ccode unless $SEEN{$ccode}++; + $ccode = <<"EOT"; + newXS(\"${mname}::bootstrap\", boot_${cname}, file); +EOT } - print "\t}\n"; + print $fh " {\n" . $ccode . " }\n" + unless $seen{$ccode}++; } - print $tail3; - select $old_fh - if $fh; + + print $fh <<'EOT'; +} + +/* + * Local variables: + * c-indentation-style: bsd + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * + * ex: set ts=8 sts=4 sw=4 et: + */ +EOT } sub canon{ @@ -253,28 +252,27 @@ __END__ =head1 NAME -ExtUtils::Miniperl, writemain - write the C code for perlmain.c +ExtUtils::Miniperl - write the C code for perlmain.c =head1 SYNOPSIS -C<use ExtUtils::Miniperl;> - -C<writemain(@directories);> + use ExtUtils::Miniperl; + writemain(@directories); + # or + writemain($fh, @directories); =head1 DESCRIPTION -This whole module is written when perl itself is built from a script -called minimod.PL. In case you want to patch it, please patch -minimod.PL in the perl distribution instead. - -writemain() takes an argument list of directories containing archive +C<writemain()> takes an argument list of directories containing archive libraries that relate to perl modules and should be linked into a new -perl binary. It writes to STDOUT a corresponding perlmain.c file that +perl binary. It writes a corresponding F<perlmain.c> file that is a plain C file containing all the bootstrap code to make the modules associated with the libraries available from within perl. +If the first argument to C<writemain()> is a reference is a reference it +is used as the file handle to write to. Otherwise output is to C<STDOUT>. The typical usage is from within a Makefile generated by -ExtUtils::MakeMaker. So under normal circumstances you won't have to +L<ExtUtils::MakeMaker>. So under normal circumstances you won't have to deal with this module directly. =head1 SEE ALSO @@ -282,4 +280,3 @@ deal with this module directly. L<ExtUtils::MakeMaker> =cut - |