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