1#!perl
2use 5.006;
3BEGIN { pop @INC if $INC[-1] eq '.' }
4use strict;
5eval {
6  require ExtUtils::ParseXS;
7  1;
8}
9or do {
10  my $err = $@ || 'Zombie error';
11  my $v = $ExtUtils::ParseXS::VERSION;
12  $v = '<undef>' if not defined $v;
13  die "Failed to load or import from ExtUtils::ParseXS (version $v). Please check that ExtUtils::ParseXS is installed correctly and that the newest version will be found in your \@INC path: $err";
14};
15
16use Getopt::Long;
17
18my %args = ();
19
20my $usage = "Usage: xsubpp [-v] [-csuffix csuffix] [-except] [-prototypes] [-noversioncheck] [-nolinenumbers] [-nooptimize] [-noinout] [-noargtypes] [-strip|s pattern] [-typemap typemap]... file.xs\n";
21
22Getopt::Long::Configure qw(no_auto_abbrev no_ignore_case);
23
24@ARGV = grep {$_ ne '-C++'} @ARGV;  # Allow -C++ for backward compatibility
25GetOptions(\%args, qw(hiertype!
26		      prototypes!
27		      versioncheck!
28		      linenumbers!
29		      optimize!
30		      inout!
31		      argtypes!
32		      object_capi!
33		      except!
34		      v
35		      typemap=s@
36		      output=s
37		      s|strip=s
38		      csuffix=s
39		     ))
40  or die $usage;
41
42if ($args{v}) {
43  print "xsubpp version $ExtUtils::ParseXS::VERSION\n";
44  exit;
45}
46
47@ARGV == 1 or die $usage;
48
49$args{filename} = shift @ARGV;
50
51my $pxs = ExtUtils::ParseXS->new;
52$pxs->process_file(%args);
53exit( $pxs->report_error_count() ? 1 : 0 );
54
55__END__
56
57=head1 NAME
58
59xsubpp - compiler to convert Perl XS code into C code
60
61=head1 SYNOPSIS
62
63B<xsubpp> [B<-v>] [B<-except>] [B<-s pattern>] [B<-prototypes>] [B<-noversioncheck>] [B<-nolinenumbers>] [B<-nooptimize>] [B<-typemap typemap>] [B<-output filename>]... file.xs
64
65=head1 DESCRIPTION
66
67This compiler is typically run by the makefiles created by L<ExtUtils::MakeMaker>
68or by L<Module::Build> or other Perl module build tools.
69
70I<xsubpp> will compile XS code into C code by embedding the constructs
71necessary to let C functions manipulate Perl values and creates the glue
72necessary to let Perl access those functions.  The compiler uses typemaps to
73determine how to map C function parameters and variables to Perl values.
74
75The compiler will search for typemap files called I<typemap>.  It will use
76the following search path to find default typemaps, with the rightmost
77typemap taking precedence.
78
79	../../../typemap:../../typemap:../typemap:typemap
80
81It will also use a default typemap installed as C<ExtUtils::typemap>.
82
83=head1 OPTIONS
84
85Note that the C<XSOPT> MakeMaker option may be used to add these options to
86any makefiles generated by MakeMaker.
87
88=over 5
89
90=item B<-hiertype>
91
92Retains '::' in type names so that C++ hierarchical types can be mapped.
93
94=item B<-except>
95
96Adds exception handling stubs to the C code.
97
98=item B<-typemap typemap>
99
100Indicates that a user-supplied typemap should take precedence over the
101default typemaps.  This option may be used multiple times, with the last
102typemap having the highest precedence.
103
104=item B<-output filename>
105
106Specifies the name of the output file to generate.  If no file is
107specified, output will be written to standard output.
108
109=item B<-v>
110
111Prints the I<xsubpp> version number to standard output, then exits.
112
113=item B<-prototypes>
114
115By default I<xsubpp> will not automatically generate prototype code for
116all xsubs. This flag will enable prototypes.
117
118=item B<-noversioncheck>
119
120Disables the run time test that determines if the object file (derived
121from the C<.xs> file) and the C<.pm> files have the same version
122number.
123
124=item B<-nolinenumbers>
125
126Prevents the inclusion of '#line' directives in the output.
127
128=item B<-nooptimize>
129
130Disables certain optimizations.  The only optimization that is currently
131affected is the use of I<target>s by the output C code (see L<perlguts>).
132This may significantly slow down the generated code, but this is the way
133B<xsubpp> of 5.005 and earlier operated.
134
135=item B<-noinout>
136
137Disable recognition of C<IN>, C<OUT_LIST> and C<INOUT_LIST> declarations.
138
139=item B<-noargtypes>
140
141Disable recognition of ANSI-like descriptions of function signature.
142
143=item B<-C++>
144
145Currently doesn't do anything at all.  This flag has been a no-op for
146many versions of perl, at least as far back as perl5.003_07.  It's
147allowed here for backwards compatibility.
148
149=item B<-s=...> or B<-strip=...>
150
151I<This option is obscure and discouraged.>
152
153If specified, the given string will be stripped off from the beginning
154of the C function name in the generated XS functions (if it starts with that prefix).
155This only applies to XSUBs without C<CODE> or C<PPCODE> blocks.
156For example, the XS:
157
158  void foo_bar(int i);
159
160when C<xsubpp> is invoked with C<-s foo_> will install a C<foo_bar>
161function in Perl, but really call C<bar(i)> in C. Most of the time,
162this is the opposite of what you want and failure modes are somewhat
163obscure, so please avoid this option where possible.
164
165=back
166
167=head1 ENVIRONMENT
168
169No environment variables are used.
170
171=head1 AUTHOR
172
173Originally by Larry Wall.  Turned into the C<ExtUtils::ParseXS> module
174by Ken Williams.
175
176=head1 MODIFICATION HISTORY
177
178See the file F<Changes>.
179
180=head1 SEE ALSO
181
182perl(1), perlxs(1), perlxstut(1), ExtUtils::ParseXS
183
184=cut
185
186