This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl 5.003_03: utils/h2ph.PL
[perl5.git] / utils / h2xs.PL
1 #!/usr/local/bin/perl
2
3 use Config;
4 use File::Basename qw(&basename &dirname);
5
6 # List explicitly here the variables you want Configure to
7 # generate.  Metaconfig only looks for shell variables, so you
8 # have to mention them as if they were shell variables, not
9 # %Config entries.  Thus you write
10 #  $startperl
11 # to ensure Configure will look for $Config{startperl}.
12
13 # This forces PL files to create target in same directory as PL file.
14 # This is so that make depend always knows where to find PL derivatives.
15 chdir(dirname($0));
16 ($file = basename($0)) =~ s/\.PL$//;
17 $file =~ s/\.pl$//
18         if ($^O eq 'VMS' or $^O eq 'os2');  # "case-forgiving"
19
20 open OUT,">$file" or die "Can't create $file: $!";
21
22 print "Extracting $file (with variable substitutions)\n";
23
24 # In this section, perl variables will be expanded during extraction.
25 # You can use $Config{...} to use Configure variables.
26
27 print OUT <<"!GROK!THIS!";
28 $Config{'startperl'}
29     eval 'exec perl -S \$0 "\$@"'
30         if 0;
31 !GROK!THIS!
32
33 # In the following, perl variables are not expanded during extraction.
34
35 print OUT <<'!NO!SUBS!';
36 =head1 NAME
37
38 h2xs - convert .h C header files to Perl extensions
39
40 =head1 SYNOPSIS
41
42 B<h2xs> [B<-AOPXcf>] [B<-v> version] [B<-n> module_name] [B<-p> prefix] [B<-s> sub] [headerfile [extra_libraries]]
43
44 B<h2xs> B<-h>
45
46 =head1 DESCRIPTION
47
48 I<h2xs> builds a Perl extension from any C header file.  The extension will
49 include functions which can be used to retrieve the value of any #define
50 statement which was in the C header.
51
52 The I<module_name> will be used for the name of the extension.  If
53 module_name is not supplied then the name of the header file will be used,
54 with the first character capitalized.
55
56 If the extension might need extra libraries, they should be included
57 here.  The extension Makefile.PL will take care of checking whether
58 the libraries actually exist and how they should be loaded.
59 The extra libraries should be specified in the form -lm -lposix, etc,
60 just as on the cc command line.  By default, the Makefile.PL will
61 search through the library path determined by Configure.  That path
62 can be augmented by including arguments of the form B<-L/another/library/path>
63 in the extra-libraries argument.
64
65 =head1 OPTIONS
66
67 =over 5
68
69 =item B<-A>
70
71 Omit all autoload facilities.  This is the same as B<-c> but also removes the
72 S<C<require AutoLoader>> statement from the .pm file.
73
74 =item B<-O>
75
76 Allows a pre-existing extension directory to be overwritten.
77
78 =item B<-P>
79
80 Omit the autogenerated stub POD section. 
81
82 =item B<-c>
83
84 Omit C<constant()> from the .xs file and corresponding specialised
85 C<AUTOLOAD> from the .pm file.
86
87 =item B<-f>
88
89 Allows an extension to be created for a header even if that header is
90 not found in /usr/include.
91
92 =item B<-h>
93
94 Print the usage, help and version for this h2xs and exit.
95
96 =item B<-n> I<module_name>
97
98 Specifies a name to be used for the extension, e.g., S<-n RPC::DCE>
99
100 =item B<-p> I<prefix>
101
102 Specify a prefix which should be removed from the Perl function names, e.g., S<-p sec_rgy_> 
103 This sets up the XS B<PREFIX> keyword and removes the prefix from functions that are
104 autoloaded via the C<constant()> mechansim.
105
106 =item B<-s> I<sub1,sub2>
107
108 Create a perl subroutine for the specified macros rather than autoload with the constant() subroutine.
109 These macros are assumed to have a return type of B<char *>, e.g., S<-s sec_rgy_wildcard_name,sec_rgy_wildcard_sid>.
110
111 =item B<-v> I<version>
112
113 Specify a version number for this extension.  This version number is added
114 to the templates.  The default is 0.01.
115
116 =item B<-X>
117
118 Omit the XS portion.  Used to generate templates for a module which is not
119 XS-based.
120
121 =item B<-x>
122
123 Automatically generate XSUBs basing on function declarations in the
124 header file.  The package C<C::Scan> should be installed. If this
125 option is specified, the name of the header file may look like
126 C<NAME1,NAME2>. In this case NAME1 is used instead of the specified string,
127 but XSUBS are emited only for the declarations included from file NAME2.
128
129 =item B<-F>
130
131 Additional flags to specify to C preprocessor when scanning header for
132 function declarations. Should not be used without B<-x>.
133
134 =back
135
136 =head1 EXAMPLES
137
138
139         # Default behavior, extension is Rusers
140         h2xs rpcsvc/rusers
141
142         # Same, but extension is RUSERS
143         h2xs -n RUSERS rpcsvc/rusers
144
145         # Extension is rpcsvc::rusers. Still finds <rpcsvc/rusers.h>
146         h2xs rpcsvc::rusers
147
148         # Extension is ONC::RPC.  Still finds <rpcsvc/rusers.h>
149         h2xs -n ONC::RPC rpcsvc/rusers
150
151         # Without constant() or AUTOLOAD
152         h2xs -c rpcsvc/rusers
153
154         # Creates templates for an extension named RPC
155         h2xs -cfn RPC
156
157         # Extension is ONC::RPC.
158         h2xs -cfn ONC::RPC
159
160         # Makefile.PL will look for library -lrpc in 
161         # additional directory /opt/net/lib
162         h2xs rpcsvc/rusers -L/opt/net/lib -lrpc
163
164         # Extension is DCE::rgynbase
165         # prefix "sec_rgy_" is dropped from perl function names
166         h2xs -n DCE::rgynbase -p sec_rgy_ dce/rgynbase
167
168         # Extension is DCE::rgynbase
169         # prefix "sec_rgy_" is dropped from perl function names
170         # subroutines are created for sec_rgy_wildcard_name and sec_rgy_wildcard_sid
171         h2xs -n DCE::rgynbase -p sec_rgy_ \
172         -s sec_rgy_wildcard_name,sec_rgy_wildcard_sid dce/rgynbase
173
174         # Make XS with defines in perl.h, and function declarations
175         # visible from perl.h. Name of the extension is perl1.
176         # When scanning perl.h, define -DEXT=extern -DdEXT= -DINIT(x)=
177         # Extra backslashes below because the string is passed to shell.
178         h2xs -xn perl1 -F "-DEXT=extern -DdEXT= -DINIT\(x\)=" \
179         ../perl5_003_01/perl.h
180
181         # Same with function declaration in proto.h as visible from perl.h.
182         perl H:\get\perl\perl5_003_01.try\utils\h2xs -xn perl1 \
183         ../perl5_003_01/perl.h,proto.h
184
185 =head1 ENVIRONMENT
186
187 No environment variables are used.
188
189 =head1 AUTHOR
190
191 Larry Wall and others
192
193 =head1 SEE ALSO
194
195 L<perl>, L<perlxstut>, L<ExtUtils::MakeMaker>, and L<AutoLoader>.
196
197 =head1 DIAGNOSTICS
198
199 The usual warnings if it cannot read or write the files involved.
200
201 =cut
202
203 my( $H2XS_VERSION ) = ' $Revision: 1.16 $ ' =~ /\$Revision:\s+([^\s]+)/;
204 my $TEMPLATE_VERSION = '0.01';
205
206 use Getopt::Std;
207
208 sub usage{
209         warn "@_\n" if @_;
210     die "h2xs [-AOPXcfh] [-v version] [-n module_name] [-p prefix] [-s subs] [headerfile [extra_libraries]]
211 version: $H2XS_VERSION
212     -f   Force creation of the extension even if the C header does not exist.
213     -n   Specify a name to use for the extension (recommended).
214     -c   Omit the constant() function and specialised AUTOLOAD from the XS file.
215     -p   Specify a prefix which should be removed from the Perl function names.
216     -s   Create subroutines for specified macros.
217     -A   Omit all autoloading facilities (implies -c).
218     -O   Allow overwriting of a pre-existing extension directory.
219     -P   Omit the stub POD section.
220     -X   Omit the XS portion.
221     -v   Specify a version number for this extension.
222     -x   Autogenerate XSUBs using C::Scan.
223     -F   Additional flags for C preprocessor (used with -x).
224     -h   Display this help message
225 extra_libraries
226          are any libraries that might be needed for loading the
227          extension, e.g. -lm would try to link in the math library.
228 ";
229 }
230
231
232 getopts("AOPXcfhxv:n:p:s:F:") || usage;
233
234 usage if $opt_h;
235
236 if( $opt_v ){
237         $TEMPLATE_VERSION = $opt_v;
238 }
239 $opt_c = 1 if $opt_A;
240 %const_xsub = map { $_,1 } split(/,+/, $opt_s) if $opt_s;
241
242 $path_h    = shift;
243 $extralibs = "@ARGV";
244
245 usage "Must supply header file or module name\n"
246         unless ($path_h or $opt_n);
247
248
249 if( $path_h ){
250     $name = $path_h;
251     if( $path_h =~ s#::#/#g && $opt_n ){
252         warn "Nesting of headerfile ignored with -n\n";
253     }
254     $path_h .= ".h" unless $path_h =~ /\.h$/;
255     $fullpath = $path_h;
256     $path_h =~ s/,.*$// if $opt_x;
257     if ($^O eq 'VMS') {  # Consider overrides of default location
258         if ($path_h !~ m![:>\[]!) {
259             my($hadsys) = ($path_h =~ s!^sys/!!i);
260             if ($ENV{'DECC$System_Include'})     { $path_h = "DECC\$System_Include:$path_h";    }
261             elsif ($ENV{'DECC$Library_Include'}) { $path_h = "DECC\$Library_Include:$path_h";   }
262             elsif ($ENV{'GNU_CC_Include'})       { $path_h = 'GNU_CC_Include:' .
263                                                     ($hadsys ? '[vms]' : '[000000]') . $path_h; }
264             elsif ($ENV{'VAXC$Include'})         { $path_h = "VAXC\$_Include:$path_h";          }
265             else                                 { $path_h = "Sys\$Library:$path_h";            }
266         }
267     }
268     elsif ($^O eq 'os2') {
269         $path_h = "/usr/include/$path_h" unless $path_h =~ m#^([a-z]:)?[./]#i; 
270     }
271     else { $path_h = "/usr/include/$path_h" unless $path_h =~ m#^[./]#; }
272     die "Can't find $path_h\n" if ( ! $opt_f && ! -f $path_h );
273
274     # Scan the header file (we should deal with nested header files)
275     # Record the names of simple #define constants into const_names
276     # Function prototypes are not (currently) processed.
277     open(CH, "<$path_h") || die "Can't open $path_h: $!\n";
278     while (<CH>) {
279         if (/^#[ \t]*define\s+([\$\w]+)\b\s*[^("]/) {
280             print "Matched $_ ($1)\n";
281             $_ = $1;
282             next if /^_.*_h_*$/i; # special case, but for what?
283             if (defined $opt_p) {
284                 if (!/^$opt_p(\d)/) {
285                     ++$prefix{$_} if s/^$opt_p//;
286                 }
287                 else {
288                     warn "can't remove $opt_p prefix from '$_'!\n";
289                 }
290             }
291             $const_names{$_}++;
292         }
293     }
294     close(CH);
295     @const_names = sort keys %const_names;
296 }
297
298
299 $module = $opt_n || do {
300         $name =~ s/\.h$//;
301         if( $name !~ /::/ ){
302                 $name =~ s#^.*/##;
303                 $name = "\u$name";
304         }
305         $name;
306 };
307
308 (chdir 'ext', $ext = 'ext/') if -d 'ext';
309
310 if( $module =~ /::/ ){
311         $nested = 1;
312         @modparts = split(/::/,$module);
313         $modfname = $modparts[-1];
314         $modpname = join('/',@modparts);
315 }
316 else {
317         $nested = 0;
318         @modparts = ();
319         $modfname = $modpname = $module;
320 }
321
322
323 if ($opt_O) {
324         warn "Overwriting existing $ext$modpname!!!\n" if -e $modpname;
325 } else {
326         die "Won't overwrite existing $ext$modpname\n" if -e $modpname;
327 }
328 if( $nested ){
329         $modpath = "";
330         foreach (@modparts){
331                 mkdir("$modpath$_", 0777);
332                 $modpath .= "$_/";
333         }
334 }
335 mkdir($modpname, 0777);
336 chdir($modpname) || die "Can't chdir $ext$modpname: $!\n";
337
338 if( ! $opt_X ){  # use XS, unless it was disabled
339   open(XS, ">$modfname.xs") || die "Can't create $ext$modpname/$modfname.xs: $!\n";
340 }
341 open(PM, ">$modfname.pm") || die "Can't create $ext$modpname/$modfname.pm: $!\n";
342
343 $" = "\n\t";
344 warn "Writing $ext$modpname/$modfname.pm\n";
345
346 print PM <<"END";
347 package $module;
348
349 use strict;
350 END
351
352 if( $opt_X || $opt_c || $opt_A ){
353         # we won't have our own AUTOLOAD(), so won't have $AUTOLOAD
354         print PM <<'END';
355 use vars qw($VERSION @ISA @EXPORT);
356 END
357 }
358 else{
359         # we'll have an AUTOLOAD(), and it will have $AUTOLOAD and
360         # will want Carp.
361         print PM <<'END';
362 use Carp;
363 use vars qw($VERSION @ISA @EXPORT $AUTOLOAD);
364 END
365 }
366
367 print PM <<'END';
368
369 require Exporter;
370 END
371
372 print PM <<"END" if ! $opt_X;  # use DynaLoader, unless XS was disabled
373 require DynaLoader;
374 END
375
376 # require autoloader if XS is disabled.
377 # if XS is enabled, require autoloader unless autoloading is disabled.
378 if( $opt_X || (! $opt_A) ){
379         print PM <<"END";
380 require AutoLoader;
381 END
382 }
383
384 if( $opt_X || ($opt_c && ! $opt_A) ){
385         # we won't have our own AUTOLOAD(), so we'll inherit it.
386         if( ! $opt_X ) { # use DynaLoader, unless XS was disabled
387                 print PM <<"END";
388
389 \@ISA = qw(Exporter AutoLoader DynaLoader);
390 END
391         }
392         else{
393                 print PM <<"END";
394
395 \@ISA = qw(Exporter AutoLoader);
396 END
397         }
398 }
399 else{
400         # 1) we have our own AUTOLOAD(), so don't need to inherit it.
401         # or
402         # 2) we don't want autoloading mentioned.
403         if( ! $opt_X ){ # use DynaLoader, unless XS was disabled
404                 print PM <<"END";
405
406 \@ISA = qw(Exporter DynaLoader);
407 END
408         }
409         else{
410                 print PM <<"END";
411
412 \@ISA = qw(Exporter);
413 END
414         }
415 }
416
417 print PM<<"END";
418 # Items to export into callers namespace by default. Note: do not export
419 # names by default without a very good reason. Use EXPORT_OK instead.
420 # Do not simply export all your public functions/methods/constants.
421 \@EXPORT = qw(
422         @const_names
423 );
424 \$VERSION = '$TEMPLATE_VERSION';
425
426 END
427
428 print PM <<"END" unless $opt_c or $opt_X;
429 sub AUTOLOAD {
430     # This AUTOLOAD is used to 'autoload' constants from the constant()
431     # XS function.  If a constant is not found then control is passed
432     # to the AUTOLOAD in AutoLoader.
433
434     my \$constname;
435     (\$constname = \$AUTOLOAD) =~ s/.*:://;
436     my \$val = constant(\$constname, \@_ ? \$_[0] : 0);
437     if (\$! != 0) {
438         if (\$! =~ /Invalid/) {
439             \$AutoLoader::AUTOLOAD = \$AUTOLOAD;
440             goto &AutoLoader::AUTOLOAD;
441         }
442         else {
443                 croak "Your vendor has not defined $module macro \$constname";
444         }
445     }
446     eval "sub \$AUTOLOAD { \$val }";
447     goto &\$AUTOLOAD;
448 }
449
450 END
451
452 if( ! $opt_X ){ # print bootstrap, unless XS is disabled
453         print PM <<"END";
454 bootstrap $module \$VERSION;
455 END
456 }
457
458 if( $opt_P ){ # if POD is disabled
459         $after = '__END__';
460 }
461 else {
462         $after = '=cut';
463 }
464
465 print PM <<"END";
466
467 # Preloaded methods go here.
468
469 # Autoload methods go after $after, and are processed by the autosplit program.
470
471 1;
472 __END__
473 END
474
475 $author = "A. U. Thor";
476 $email = 'a.u.thor@a.galaxy.far.far.away';
477
478 $pod = <<"END" unless $opt_P;
479 ## Below is the stub of documentation for your module. You better edit it!
480 #
481 #=head1 NAME
482 #
483 #$module - Perl extension for blah blah blah
484 #
485 #=head1 SYNOPSIS
486 #
487 #  use $module;
488 #  blah blah blah
489 #
490 #=head1 DESCRIPTION
491 #
492 #Stub documentation for $module was created by h2xs. It looks like the
493 #author of the extension was negligent enough to leave the stub
494 #unedited.
495 #
496 #Blah blah blah.
497 #
498 #=head1 AUTHOR
499 #
500 #$author, $email
501 #
502 #=head1 SEE ALSO
503 #
504 #perl(1).
505 #
506 #=cut
507 END
508
509 $pod =~ s/^\#//gm unless $opt_P;
510 print PM $pod unless $opt_P;
511
512 close PM;
513
514
515 if( ! $opt_X ){ # print XS, unless it is disabled
516 warn "Writing $ext$modpname/$modfname.xs\n";
517
518 print XS <<"END";
519 #ifdef __cplusplus
520 extern "C" {
521 #endif
522 #include "EXTERN.h"
523 #include "perl.h"
524 #include "XSUB.h"
525 #ifdef __cplusplus
526 }
527 #endif
528
529 END
530 if( $path_h ){
531         my($h) = $path_h;
532         $h =~ s#^/usr/include/##;
533         if ($^O eq 'VMS') { $h =~ s#.*vms\]#sys/# or $h =~ s#.*[:>\]]##; }
534 print XS <<"END";
535 #include <$h>
536
537 END
538 }
539
540 if( ! $opt_c ){
541 print XS <<"END";
542 static int
543 not_here(s)
544 char *s;
545 {
546     croak("$module::%s not implemented on this architecture", s);
547     return -1;
548 }
549
550 static double
551 constant(name, arg)
552 char *name;
553 int arg;
554 {
555     errno = 0;
556     switch (*name) {
557 END
558
559 my(@AZ, @az, @under);
560
561 foreach(@const_names){
562     @AZ = 'A' .. 'Z' if !@AZ && /^[A-Z]/;
563     @az = 'a' .. 'z' if !@az && /^[a-z]/;
564     @under = '_'  if !@under && /^_/;
565 }
566
567 foreach $letter (@AZ, @az, @under) {
568
569     last if $letter eq 'a' && !@const_names;
570
571     print XS "    case '$letter':\n";
572     my($name);
573     while (substr($const_names[0],0,1) eq $letter) {
574         $name = shift(@const_names);
575         $macro = $prefix{$name} ? "$opt_p$name" : $name;
576         next if $const_xsub{$macro};
577         print XS <<"END";
578         if (strEQ(name, "$name"))
579 #ifdef $macro
580             return $macro;
581 #else
582             goto not_there;
583 #endif
584 END
585     }
586     print XS <<"END";
587         break;
588 END
589 }
590 print XS <<"END";
591     }
592     errno = EINVAL;
593     return 0;
594
595 not_there:
596     errno = ENOENT;
597     return 0;
598 }
599
600 END
601 }
602
603 $prefix = "PREFIX = $opt_p" if defined $opt_p;
604 # Now switch from C to XS by issuing the first MODULE declaration:
605 print XS <<"END";
606
607 MODULE = $module                PACKAGE = $module               $prefix
608
609 END
610
611 foreach (sort keys %const_xsub) {
612     print XS <<"END";
613 char *
614 $_()
615
616     CODE:
617 #ifdef $_
618     RETVAL = $_;
619 #else
620     croak("Your vendor has not defined the $module macro $_");
621 #endif
622
623     OUTPUT:
624     RETVAL
625
626 END
627 }
628
629 # If a constant() function was written then output a corresponding
630 # XS declaration:
631 print XS <<"END" unless $opt_c;
632
633 double
634 constant(name,arg)
635         char *          name
636         int             arg
637
638 END
639
640 sub print_decl {
641   my $fh = shift;
642   my $decl = shift;
643   my ($type, $name, $args) = @$decl;
644   my @argnames = map {$_->[1]} @$args;
645   my @argtypes = map { normalize_type( $_->[0] ) } @$args;
646   my $numargs = @$args;
647   if ($numargs and $argtypes[-1] eq '...') {
648     $numargs--;
649     $argnames[-1] = '...';
650   }
651   local $" = ', ';
652   $type = normalize_type($type);
653   
654   print $fh <<"EOP";
655
656 $type
657 $name(@argnames)
658 EOP
659
660   for $arg (0 .. $numargs - 1) {
661     print $fh <<"EOP";
662         $argtypes[$arg] $argnames[$arg]
663 EOP
664   }
665 }
666
667 my $ignore_mods = '(?:\b(?:__const__|static|inline|__inline__)\b\s*)*';
668
669 sub normalize_type {
670   my $type = shift;
671   $type =~ s/$ignore_mods//go;
672   $type =~ s/\s+/ /g;
673   $type =~ s/\s+$//;
674   $type =~ s/^\s+//;
675   $type =~ s/\b\*/ */g;
676   $type =~ s/\*\b/* /g;
677   $type =~ s/\*\s+(?=\*)/*/g;
678   $type;
679 }
680
681 if ($opt_x) {
682   require C::Scan;              # Run-time directive
683   require Config;               # Run-time directive
684   my $c;
685   my $filter;
686   my $filename = $path_h;
687   my $addflags = $opt_F || '';
688   if ($fullpath =~ /,/) {
689     $filename = $`;
690     $filter = $';
691   }
692   $c = new C::Scan 'filename' => $filename, 'filename_filter' => $filter,
693                    'add_cppflags' => $addflags;
694   $c->set('includeDirs' => [$Config::Config{shrpdir}]);
695   
696   my $fdec = $c->get('parsed_fdecls');
697   
698   for $decl (@$fdec) { print_decl(\*XS, $decl) }
699 }
700
701 close XS;
702 } # if( ! $opt_X )
703
704 warn "Writing $ext$modpname/Makefile.PL\n";
705 open(PL, ">Makefile.PL") || die "Can't create $ext$modpname/Makefile.PL: $!\n";
706
707 print PL <<'END';
708 use ExtUtils::MakeMaker;
709 # See lib/ExtUtils/MakeMaker.pm for details of how to influence
710 # the contents of the Makefile that is written.
711 END
712 print PL "WriteMakefile(\n";
713 print PL "    'NAME'    => '$module',\n";
714 print PL "    'VERSION_FROM' => '$modfname.pm', # finds \$VERSION\n"; 
715 if( ! $opt_X ){ # print C stuff, unless XS is disabled
716   print PL "    'LIBS'  => ['$extralibs'],   # e.g., '-lm' \n";
717   print PL "    'DEFINE'        => '',     # e.g., '-DHAVE_SOMETHING' \n";
718   print PL "    'INC'   => '',     # e.g., '-I/usr/include/other' \n";
719 }
720 print PL ");\n";
721 close(PL) || die "Can't close $ext$modpname/Makefile.PL: $!\n";
722
723 warn "Writing $ext$modpname/test.pl\n";
724 open(EX, ">test.pl") || die "Can't create $ext$modpname/test.pl: $!\n";
725 print EX <<'_END_';
726 # Before `make install' is performed this script should be runnable with
727 # `make test'. After `make install' it should work as `perl test.pl'
728
729 ######################### We start with some black magic to print on failure.
730
731 # Change 1..1 below to 1..last_test_to_print .
732 # (It may become useful if the test is moved to ./t subdirectory.)
733
734 BEGIN { $| = 1; print "1..1\n"; }
735 END {print "not ok 1\n" unless $loaded;}
736 _END_
737 print EX <<_END_;
738 use $module;
739 _END_
740 print EX <<'_END_';
741 $loaded = 1;
742 print "ok 1\n";
743
744 ######################### End of black magic.
745
746 # Insert your test code below (better if it prints "ok 13"
747 # (correspondingly "not ok 13") depending on the success of chunk 13
748 # of the test code):
749
750 _END_
751 close(EX) || die "Can't close $ext$modpname/test.pl: $!\n";
752
753 warn "Writing $ext$modpname/Changes\n";
754 open(EX, ">Changes") || die "Can't create $ext$modpname/Changes: $!\n";
755 print EX "Revision history for Perl extension $module.\n\n";
756 print EX "$TEMPLATE_VERSION  ",scalar localtime,"\n";
757 print EX "\t- original version; created by h2xs $H2XS_VERSION\n\n";
758 close(EX) || die "Can't close $ext$modpname/Changes: $!\n";
759
760 warn "Writing $ext$modpname/MANIFEST\n";
761 open(MANI,'>MANIFEST') or die "Can't create MANIFEST: $!";
762 @files = <*>;
763 if (!@files) {
764   eval {opendir(D,'.');};
765   unless ($@) { @files = readdir(D); closedir(D); }
766 }
767 if (!@files) { @files = map {chomp && $_} `ls`; }
768 print MANI join("\n",@files);
769 close MANI;
770 !NO!SUBS!
771
772 close OUT or die "Can't close $file: $!";
773 chmod 0755, $file or die "Can't reset permissions for $file: $!\n";
774 exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';