Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

872 lines
22 KiB

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