8 $usage='h2xs [-Aachfm] [-n module_name] [headerfile [extra_libraries]]
9 -a Omit AutoLoad facilities from .pm file.
10 -c Omit the constant() function from the XS file.
11 -A Equivalent to -a -c
12 -f Force creation of the extension even if the C header does not exist.
14 -n Specify a name to use for the extension.
15 extra_libraries are any libraries that might be needed for loading
16 the extension, e.g. -lm would try to link in the math library.
19 sub usage{ die "Usage: $usage\n" }
21 getopts("fhcaAn:") || &usage;
28 elsif( ! @ARGV && ! $opt_n ){
29 die "Must supply header file or module name\n";
39 if( $path_h =~ s#::#/#g && $opt_n ){
40 warn "Nesting of headerfile ignored with -n\n";
42 $path_h .= ".h" unless $path_h =~ /\.h$/;
43 $path_h = "/usr/include/$path_h" unless $path_h =~ m#^[./]#;
44 die "Can't find $path_h\n" if( ! $opt_f && ! -f $path_h );
47 $module = $opt_n || do {
56 chdir 'ext' if -d 'ext';
58 if( $module =~ /::/ ){
60 @modparts = split(/::/,$module);
61 $modfname = $modparts[-1];
62 $modpname = join('/',@modparts);
67 $modfname = $modpname = $module;
71 die "Won't overwrite existing ext/$modpname\n" if -e $modpname;
72 # quick hack, should really loop over @modparts
73 mkdir($modparts[0], 0777) if $nested;
74 mkdir($modpname, 0777);
75 chdir($modpname) || die "Can't chdir ext/$modpname: $!\n";
77 open(XS, ">$modfname.xs") || die "Can't create ext/$modpname/$modfname.xs: $!\n";
78 open(PM, ">$modfname.pm") || die "Can't create ext/$modpname/$modfname.pm: $!\n";
82 open(CH, "<$path_h") || die "Can't open $path_h: $!\n";
84 if (/^#[ \t]*define\s+(\w+)\b\s*[^("]/) {
88 @AZ = 'A' .. 'Z' if !@AZ && /^[A-Z]/;
89 @az = 'a' .. 'z' if !@az && /^[a-z]/;
90 @under = '_' if !@under && /^_/;
94 @names = sort keys %names;
98 warn "Writing ext/$modpname/$modfname.pm\n";
107 \@ISA = qw(Exporter AutoLoader DynaLoader);
108 # Items to export into callers namespace by default
109 # (move infrequently used names to \@EXPORT_OK below)
113 # Other items we are prepared to export if requested
119 \$AutoLoader::AUTOLOAD = \$AUTOLOAD;
120 goto &AutoLoader::AUTOLOAD;
123 (\$constname = \$AUTOLOAD) =~ s/.*:://;
124 \$val = constant(\$constname, \@_ ? \$_[0] : 0);
126 if (\$! =~ /Invalid/) {
127 \$AutoLoader::AUTOLOAD = \$AUTOLOAD;
128 goto &AutoLoader::AUTOLOAD;
131 (\$pack,\$file,\$line) = caller;
132 die "Your vendor has not defined $module macro \$constname, used at \$file line \$line.\n";
135 eval "sub \$AUTOLOAD { \$val }";
141 # Preloaded methods go here. Autoload methods go after __END__, and are
142 # processed by the autosplit program.
154 \@ISA = qw(Exporter DynaLoader);
155 # Items to export into callers namespace by default
157 # Other items we are prepared to export if requested
169 warn "Writing ext/$modpname/$modfname.xs\n";
178 $h =~ s#^/usr/include/##;
191 croak("$module::%s not implemented on this architecture", s);
204 foreach $letter (@AZ, @az, @under) {
206 last if $letter eq 'a' && !@names;
208 print XS " case '$letter':\n";
210 while (substr($names[0],0,1) eq $letter) {
211 $name = shift(@names);
213 if (strEQ(name, "$name"))
236 MODULE = $module PACKAGE = $module
248 MODULE = $module PACKAGE = $module
256 warn "Writing ext/$modpname/Makefile.PL\n";
257 open(PL, ">Makefile.PL") || die "Can't create ext/$modpname/Makefile.PL: $!\n";
260 use ExtUtils::MakeMaker;
261 # See lib/ExtUtils/MakeMaker.pm for details of how to influence
262 # the contents of the Makefile that is written.
264 print PL "WriteMakefile(\n";
265 print PL " 'NAME' => '$module',\n";
266 print PL " 'VERSION' => '0.1',\n";
267 print PL " 'LIBS' => ['$extralibs'], # e.g., '-lm' \n";
268 print PL " 'DEFINE' => '', # e.g., '-DHAVE_SOMETHING' \n";
269 print PL " 'INC' => '', # e.g., '-I/usr/include/other' \n";
273 system '/bin/ls > MANIFEST';
276 ##############################################################################
278 # These next few lines are legal in both Perl and nroff.
282 'di \" finish diversion--previous line must be blank
283 .nr nl 0-1 \" fake up transition to first page again
284 .nr % 0 \" start at page 1
285 '; __END__ ############# From here on it's a standard manual page ############
286 .TH H2XS 1 "August 9, 1994"
289 h2xs \- convert .h C header files to Perl extensions
291 .B h2xs [-Aachfm] [-n module_name] [headerfile [extra_libraries]]
294 builds a Perl extension from any C header file. The extension will include
295 functions which can be used to retrieve the value of any #define statement
296 which was in the C header.
300 will be used for the name of the extension. If module_name is not supplied
301 then the name of the header file will be used, with the first character
304 If the extension might need extra libraries, they should be included
305 here. The extension Makefile.PL will take care of checking whether
306 the libraries actually exist and how they should be loaded.
307 The extra libraries should be specified in the form -lm -lposix, etc,
308 just as on the cc command line. By default, the Makefile.PL will
309 search through the library path determined by Configure. That path
310 can be augmented by including arguments of the form -L/another/library/path
311 in the extra-libraries argument.
315 Allows an extension to be created for a header even if that
316 header is not found in /usr/include.
319 Omit AutoLoad(), AUTOLOAD, and autosplit from the .pm and Makefile files.
322 Omit constant() from the .xs file.
325 Specifies a name to be used for the extension.
328 Turns on both -a and -c.
332 # Default behavior, extension is Rusers
335 # Same, but extension is RUSERS
336 h2xs -n RUSERS rpcsvc/rusers
338 # Extension is rpcsvc::rusers. Still finds <rpcsvc/rusers.h>
341 # Extension is ONC::RPC. Still finds <rpcsvc/rusers.h>
342 h2xs -n ONC::RPC rpcsvc/rusers
344 # Without AUTOLOAD, AutoLoad, autosplit
345 h2xs -a rpcsvc/rusers
347 # Creates templates for an extension named RPC
350 # Extension is ONC::RPC.
353 # Makefile.PL will look for library -lrpc in
354 # additional directory /opt/net/lib
355 h2xs rpcsvc/rusers -L/opt/net/lib -lrpc
359 No environment variables are used.
363 perl(1) ExtUtils::MakeMaker
365 The usual warnings if it can't read or write the files involved.