Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | .\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13 |
2 | .\" | |
3 | .\" Standard preamble: | |
4 | .\" ======================================================================== | |
5 | .de Sh \" Subsection heading | |
6 | .br | |
7 | .if t .Sp | |
8 | .ne 5 | |
9 | .PP | |
10 | \fB\\$1\fR | |
11 | .PP | |
12 | .. | |
13 | .de Sp \" Vertical space (when we can't use .PP) | |
14 | .if t .sp .5v | |
15 | .if n .sp | |
16 | .. | |
17 | .de Vb \" Begin verbatim text | |
18 | .ft CW | |
19 | .nf | |
20 | .ne \\$1 | |
21 | .. | |
22 | .de Ve \" End verbatim text | |
23 | .ft R | |
24 | .fi | |
25 | .. | |
26 | .\" Set up some character translations and predefined strings. \*(-- will | |
27 | .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left | |
28 | .\" double quote, and \*(R" will give a right double quote. | will give a | |
29 | .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to | |
30 | .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' | |
31 | .\" expand to `' in nroff, nothing in troff, for use with C<>. | |
32 | .tr \(*W-|\(bv\*(Tr | |
33 | .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' | |
34 | .ie n \{\ | |
35 | . ds -- \(*W- | |
36 | . ds PI pi | |
37 | . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch | |
38 | . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch | |
39 | . ds L" "" | |
40 | . ds R" "" | |
41 | . ds C` "" | |
42 | . ds C' "" | |
43 | 'br\} | |
44 | .el\{\ | |
45 | . ds -- \|\(em\| | |
46 | . ds PI \(*p | |
47 | . ds L" `` | |
48 | . ds R" '' | |
49 | 'br\} | |
50 | .\" | |
51 | .\" If the F register is turned on, we'll generate index entries on stderr for | |
52 | .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index | |
53 | .\" entries marked with X<> in POD. Of course, you'll have to process the | |
54 | .\" output yourself in some meaningful fashion. | |
55 | .if \nF \{\ | |
56 | . de IX | |
57 | . tm Index:\\$1\t\\n%\t"\\$2" | |
58 | .. | |
59 | . nr % 0 | |
60 | . rr F | |
61 | .\} | |
62 | .\" | |
63 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes | |
64 | .\" way too many mistakes in technical documents. | |
65 | .hy 0 | |
66 | .if n .na | |
67 | .\" | |
68 | .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). | |
69 | .\" Fear. Run. Save yourself. No user-serviceable parts. | |
70 | . \" fudge factors for nroff and troff | |
71 | .if n \{\ | |
72 | . ds #H 0 | |
73 | . ds #V .8m | |
74 | . ds #F .3m | |
75 | . ds #[ \f1 | |
76 | . ds #] \fP | |
77 | .\} | |
78 | .if t \{\ | |
79 | . ds #H ((1u-(\\\\n(.fu%2u))*.13m) | |
80 | . ds #V .6m | |
81 | . ds #F 0 | |
82 | . ds #[ \& | |
83 | . ds #] \& | |
84 | .\} | |
85 | . \" simple accents for nroff and troff | |
86 | .if n \{\ | |
87 | . ds ' \& | |
88 | . ds ` \& | |
89 | . ds ^ \& | |
90 | . ds , \& | |
91 | . ds ~ ~ | |
92 | . ds / | |
93 | .\} | |
94 | .if t \{\ | |
95 | . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" | |
96 | . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' | |
97 | . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' | |
98 | . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' | |
99 | . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' | |
100 | . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' | |
101 | .\} | |
102 | . \" troff and (daisy-wheel) nroff accents | |
103 | .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' | |
104 | .ds 8 \h'\*(#H'\(*b\h'-\*(#H' | |
105 | .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] | |
106 | .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' | |
107 | .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' | |
108 | .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] | |
109 | .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] | |
110 | .ds ae a\h'-(\w'a'u*4/10)'e | |
111 | .ds Ae A\h'-(\w'A'u*4/10)'E | |
112 | . \" corrections for vroff | |
113 | .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' | |
114 | .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' | |
115 | . \" for low resolution devices (crt and lpr) | |
116 | .if \n(.H>23 .if \n(.V>19 \ | |
117 | \{\ | |
118 | . ds : e | |
119 | . ds 8 ss | |
120 | . ds o a | |
121 | . ds d- d\h'-1'\(ga | |
122 | . ds D- D\h'-1'\(hy | |
123 | . ds th \o'bp' | |
124 | . ds Th \o'LP' | |
125 | . ds ae ae | |
126 | . ds Ae AE | |
127 | .\} | |
128 | .rm #[ #] #H #V #F C | |
129 | .\" ======================================================================== | |
130 | .\" | |
131 | .IX Title "H2XS 1" | |
132 | .TH H2XS 1 "2002-08-28" "perl v5.8.0" "Perl Programmers Reference Guide" | |
133 | .SH "NAME" | |
134 | h2xs \- convert .h C header files to Perl extensions | |
135 | .SH "SYNOPSIS" | |
136 | .IX Header "SYNOPSIS" | |
137 | \&\fBh2xs\fR [\fB\s-1OPTIONS\s0\fR ...] [headerfile ... [extra_libraries]] | |
138 | .PP | |
139 | \&\fBh2xs\fR \fB\-h\fR|\fB\-?\fR|\fB\-\-help\fR | |
140 | .SH "DESCRIPTION" | |
141 | .IX Header "DESCRIPTION" | |
142 | \&\fIh2xs\fR builds a Perl extension from C header files. The extension | |
143 | will include functions which can be used to retrieve the value of any | |
144 | #define statement which was in the C header files. | |
145 | .PP | |
146 | The \fImodule_name\fR will be used for the name of the extension. If | |
147 | module_name is not supplied then the name of the first header file | |
148 | will be used, with the first character capitalized. | |
149 | .PP | |
150 | If the extension might need extra libraries, they should be included | |
151 | here. The extension Makefile.PL will take care of checking whether | |
152 | the libraries actually exist and how they should be loaded. The extra | |
153 | libraries should be specified in the form \-lm \-lposix, etc, just as on | |
154 | the cc command line. By default, the Makefile.PL will search through | |
155 | the library path determined by Configure. That path can be augmented | |
156 | by including arguments of the form \fB\-L/another/library/path\fR in the | |
157 | extra-libraries argument. | |
158 | .SH "OPTIONS" | |
159 | .IX Header "OPTIONS" | |
160 | .IP "\fB\-A\fR, \fB\-\-omit\-autoload\fR" 5 | |
161 | .IX Item "-A, --omit-autoload" | |
162 | Omit all autoload facilities. This is the same as \fB\-c\fR but also | |
163 | removes the \f(CW\*(C`use\ AutoLoader\*(C'\fR statement from the .pm file. | |
164 | .IP "\fB\-B\fR, \fB\-\-beta\-version\fR" 5 | |
165 | .IX Item "-B, --beta-version" | |
166 | Use an alpha/beta style version number. Causes version number to | |
167 | be \*(L"0.00_01\*(R" unless \fB\-v\fR is specified. | |
168 | .IP "\fB\-C\fR, \fB\-\-omit\-changes\fR" 5 | |
169 | .IX Item "-C, --omit-changes" | |
170 | Omits creation of the \fIChanges\fR file, and adds a \s-1HISTORY\s0 section to | |
171 | the \s-1POD\s0 template. | |
172 | .IP "\fB\-F\fR, \fB\-\-cpp\-flags\fR=\fIaddflags\fR" 5 | |
173 | .IX Item "-F, --cpp-flags=addflags" | |
174 | Additional flags to specify to C preprocessor when scanning header for | |
175 | function declarations. Writes these options in the generated \fIMakefile.PL\fR | |
176 | too. | |
177 | .IP "\fB\-M\fR, \fB\-\-func\-mask\fR=\fIregular expression\fR" 5 | |
178 | .IX Item "-M, --func-mask=regular expression" | |
179 | selects functions/macros to process. | |
180 | .IP "\fB\-O\fR, \fB\-\-overwrite\-ok\fR" 5 | |
181 | .IX Item "-O, --overwrite-ok" | |
182 | Allows a pre-existing extension directory to be overwritten. | |
183 | .IP "\fB\-P\fR, \fB\-\-omit\-pod\fR" 5 | |
184 | .IX Item "-P, --omit-pod" | |
185 | Omit the autogenerated stub \s-1POD\s0 section. | |
186 | .IP "\fB\-X\fR, \fB\-\-omit\-XS\fR" 5 | |
187 | .IX Item "-X, --omit-XS" | |
188 | Omit the \s-1XS\s0 portion. Used to generate templates for a module which is not | |
189 | XS\-based. \f(CW\*(C`\-c\*(C'\fR and \f(CW\*(C`\-f\*(C'\fR are implicitly enabled. | |
190 | .IP "\fB\-a\fR, \fB\-\-gen\-accessors\fR" 5 | |
191 | .IX Item "-a, --gen-accessors" | |
192 | Generate an accessor method for each element of structs and unions. The | |
193 | generated methods are named after the element name; will return the current | |
194 | value of the element if called without additional arguments; and will set | |
195 | the element to the supplied value (and return the new value) if called with | |
196 | an additional argument. Embedded structures and unions are returned as a | |
197 | pointer rather than the complete structure, to facilitate chained calls. | |
198 | .Sp | |
199 | These methods all apply to the Ptr type for the structure; additionally | |
200 | two methods are constructed for the structure type itself, \f(CW\*(C`_to_ptr\*(C'\fR | |
201 | which returns a Ptr type pointing to the same structure, and a \f(CW\*(C`new\*(C'\fR | |
202 | method to construct and return a new structure, initialised to zeroes. | |
203 | .IP "\fB\-b\fR, \fB\-\-compat\-version\fR=\fIversion\fR" 5 | |
204 | .IX Item "-b, --compat-version=version" | |
205 | Generates a .pm file which is backwards compatible with the specified | |
206 | perl version. | |
207 | .Sp | |
208 | For versions < 5.6.0, the changes are. | |
209 | \- no use of 'our' (uses 'use vars' instead) | |
210 | \- no 'use warnings' | |
211 | .Sp | |
212 | Specifying a compatibility version higher than the version of perl you | |
213 | are using to run h2xs will have no effect. If unspecified h2xs will default | |
214 | to compatibility with the version of perl you are using to run h2xs. | |
215 | .IP "\fB\-c\fR, \fB\-\-omit\-constant\fR" 5 | |
216 | .IX Item "-c, --omit-constant" | |
217 | Omit \f(CW\*(C`constant()\*(C'\fR from the .xs file and corresponding specialised | |
218 | \&\f(CW\*(C`AUTOLOAD\*(C'\fR from the .pm file. | |
219 | .IP "\fB\-d\fR, \fB\-\-debugging\fR" 5 | |
220 | .IX Item "-d, --debugging" | |
221 | Turn on debugging messages. | |
222 | .IP "\fB\-f\fR, \fB\-\-force\fR" 5 | |
223 | .IX Item "-f, --force" | |
224 | Allows an extension to be created for a header even if that header is | |
225 | not found in standard include directories. | |
226 | .IP "\fB\-g\fR, \fB\-\-global\fR" 5 | |
227 | .IX Item "-g, --global" | |
228 | Include code for safely storing static data in the .xs file. | |
229 | Extensions that do no make use of static data can ignore this option. | |
230 | .IP "\fB\-h\fR, \fB\-?\fR, \fB\-\-help\fR" 5 | |
231 | .IX Item "-h, -?, --help" | |
232 | Print the usage, help and version for this h2xs and exit. | |
233 | .IP "\fB\-k\fR, \fB\-\-omit\-const\-func\fR" 5 | |
234 | .IX Item "-k, --omit-const-func" | |
235 | For function arguments declared as \f(CW\*(C`const\*(C'\fR, omit the const attribute in the | |
236 | generated \s-1XS\s0 code. | |
237 | .IP "\fB\-m\fR, \fB\-\-gen\-tied\-var\fR" 5 | |
238 | .IX Item "-m, --gen-tied-var" | |
239 | \&\fBExperimental\fR: for each variable declared in the header file(s), declare | |
240 | a perl variable of the same name magically tied to the C variable. | |
241 | .IP "\fB\-n\fR, \fB\-\-name\fR=\fImodule_name\fR" 5 | |
242 | .IX Item "-n, --name=module_name" | |
243 | Specifies a name to be used for the extension, e.g., \-n\ \s-1RPC::DCE\s0 | |
244 | .IP "\fB\-o\fR, \fB\-\-opaque\-re\fR=\fIregular expression\fR" 5 | |
245 | .IX Item "-o, --opaque-re=regular expression" | |
246 | Use \*(L"opaque\*(R" data type for the C types matched by the regular | |
247 | expression, even if these types are \f(CW\*(C`typedef\*(C'\fR\-equivalent to types | |
248 | from typemaps. Should not be used without \fB\-x\fR. | |
249 | .Sp | |
250 | This may be useful since, say, types which are \f(CW\*(C`typedef\*(C'\fR\-equivalent | |
251 | to integers may represent OS-related handles, and one may want to work | |
252 | with these handles in OO\-way, as in \f(CW\*(C`$handle\->do_something()\*(C'\fR. | |
253 | Use \f(CW\*(C`\-o .\*(C'\fR if you want to handle all the \f(CW\*(C`typedef\*(C'\fRed types as opaque | |
254 | types. | |
255 | .Sp | |
256 | The type-to-match is whitewashed (except for commas, which have no | |
257 | whitespace before them, and multiple \f(CW\*(C`*\*(C'\fR which have no whitespace | |
258 | between them). | |
259 | .IP "\fB\-p\fR, \fB\-\-remove\-prefix\fR=\fIprefix\fR" 5 | |
260 | .IX Item "-p, --remove-prefix=prefix" | |
261 | Specify a prefix which should be removed from the Perl function names, | |
262 | e.g., \-p\ sec_rgy_ This sets up the \s-1XS\s0 \fB\s-1PREFIX\s0\fR keyword and removes | |
263 | the prefix from functions that are autoloaded via the \f(CW\*(C`constant()\*(C'\fR | |
264 | mechanism. | |
265 | .IP "\fB\-s\fR, \fB\-\-const\-subs\fR=\fIsub1,sub2\fR" 5 | |
266 | .IX Item "-s, --const-subs=sub1,sub2" | |
267 | Create a perl subroutine for the specified macros rather than autoload | |
268 | with the \fIconstant()\fR subroutine. These macros are assumed to have a | |
269 | return type of \fBchar *\fR, e.g., | |
270 | \&\-s\ sec_rgy_wildcard_name,sec_rgy_wildcard_sid. | |
271 | .IP "\fB\-t\fR, \fB\-\-default\-type\fR=\fItype\fR" 5 | |
272 | .IX Item "-t, --default-type=type" | |
273 | Specify the internal type that the \fIconstant()\fR mechanism uses for macros. | |
274 | The default is \s-1IV\s0 (signed integer). Currently all macros found during the | |
275 | header scanning process will be assumed to have this type. Future versions | |
276 | of \f(CW\*(C`h2xs\*(C'\fR may gain the ability to make educated guesses. | |
277 | .IP "\fB\-\-use\-new\-tests\fR" 5 | |
278 | .IX Item "--use-new-tests" | |
279 | When \fB\-\-compat\-version\fR (\fB\-b\fR) is present the generated tests will use | |
280 | \&\f(CW\*(C`Test::More\*(C'\fR rather than \f(CW\*(C`Test\*(C'\fR which is the default for versions before | |
281 | 5.7.2 . \f(CW\*(C`Test::More\*(C'\fR will be added to \s-1PREREQ_PM\s0 in the generated | |
282 | \&\f(CW\*(C`Makefile.PL\*(C'\fR. | |
283 | .IP "\fB\-\-use\-old\-tests\fR" 5 | |
284 | .IX Item "--use-old-tests" | |
285 | Will force the generation of test code that uses the older \f(CW\*(C`Test\*(C'\fR module. | |
286 | .IP "\fB\-\-skip\-exporter\fR" 5 | |
287 | .IX Item "--skip-exporter" | |
288 | Do not use \f(CW\*(C`Exporter\*(C'\fR and/or export any symbol. | |
289 | .IP "\fB\-\-skip\-ppport\fR" 5 | |
290 | .IX Item "--skip-ppport" | |
291 | Do not use \f(CW\*(C`Devel::PPPort\*(C'\fR: no portability to older version. | |
292 | .IP "\fB\-\-skip\-autoloader\fR" 5 | |
293 | .IX Item "--skip-autoloader" | |
294 | Do not use the module \f(CW\*(C`AutoLoader\*(C'\fR; but keep the \fIconstant()\fR function | |
295 | and \f(CW\*(C`sub AUTOLOAD\*(C'\fR for constants. | |
296 | .IP "\fB\-\-skip\-strict\fR" 5 | |
297 | .IX Item "--skip-strict" | |
298 | Do not use the pragma \f(CW\*(C`strict\*(C'\fR. | |
299 | .IP "\fB\-\-skip\-warnings\fR" 5 | |
300 | .IX Item "--skip-warnings" | |
301 | Do not use the pragma \f(CW\*(C`warnings\*(C'\fR. | |
302 | .IP "\fB\-v\fR, \fB\-\-version\fR=\fIversion\fR" 5 | |
303 | .IX Item "-v, --version=version" | |
304 | Specify a version number for this extension. This version number is added | |
305 | to the templates. The default is 0.01, or 0.00_01 if \f(CW\*(C`\-B\*(C'\fR is specified. | |
306 | The version specified should be numeric. | |
307 | .IP "\fB\-x\fR, \fB\-\-autogen\-xsubs\fR" 5 | |
308 | .IX Item "-x, --autogen-xsubs" | |
309 | Automatically generate XSUBs basing on function declarations in the | |
310 | header file. The package \f(CW\*(C`C::Scan\*(C'\fR should be installed. If this | |
311 | option is specified, the name of the header file may look like | |
312 | \&\f(CW\*(C`NAME1,NAME2\*(C'\fR. In this case \s-1NAME1\s0 is used instead of the specified | |
313 | string, but XSUBs are emitted only for the declarations included from | |
314 | file \s-1NAME2\s0. | |
315 | .Sp | |
316 | Note that some types of arguments/return\-values for functions may | |
317 | result in XSUB\-declarations/typemap\-entries which need | |
318 | hand\-editing. Such may be objects which cannot be converted from/to a | |
319 | pointer (like \f(CW\*(C`long long\*(C'\fR), pointers to functions, or arrays. See | |
320 | also the section on "\s-1LIMITATIONS\s0 of \fB\-x\fR". | |
321 | .SH "EXAMPLES" | |
322 | .IX Header "EXAMPLES" | |
323 | .Vb 2 | |
324 | \& # Default behavior, extension is Rusers | |
325 | \& h2xs rpcsvc/rusers | |
326 | .Ve | |
327 | .PP | |
328 | .Vb 2 | |
329 | \& # Same, but extension is RUSERS | |
330 | \& h2xs -n RUSERS rpcsvc/rusers | |
331 | .Ve | |
332 | .PP | |
333 | .Vb 2 | |
334 | \& # Extension is rpcsvc::rusers. Still finds <rpcsvc/rusers.h> | |
335 | \& h2xs rpcsvc::rusers | |
336 | .Ve | |
337 | .PP | |
338 | .Vb 2 | |
339 | \& # Extension is ONC::RPC. Still finds <rpcsvc/rusers.h> | |
340 | \& h2xs -n ONC::RPC rpcsvc/rusers | |
341 | .Ve | |
342 | .PP | |
343 | .Vb 2 | |
344 | \& # Without constant() or AUTOLOAD | |
345 | \& h2xs -c rpcsvc/rusers | |
346 | .Ve | |
347 | .PP | |
348 | .Vb 2 | |
349 | \& # Creates templates for an extension named RPC | |
350 | \& h2xs -cfn RPC | |
351 | .Ve | |
352 | .PP | |
353 | .Vb 2 | |
354 | \& # Extension is ONC::RPC. | |
355 | \& h2xs -cfn ONC::RPC | |
356 | .Ve | |
357 | .PP | |
358 | .Vb 3 | |
359 | \& # Makefile.PL will look for library -lrpc in | |
360 | \& # additional directory /opt/net/lib | |
361 | \& h2xs rpcsvc/rusers -L/opt/net/lib -lrpc | |
362 | .Ve | |
363 | .PP | |
364 | .Vb 3 | |
365 | \& # Extension is DCE::rgynbase | |
366 | \& # prefix "sec_rgy_" is dropped from perl function names | |
367 | \& h2xs -n DCE::rgynbase -p sec_rgy_ dce/rgynbase | |
368 | .Ve | |
369 | .PP | |
370 | .Vb 5 | |
371 | \& # Extension is DCE::rgynbase | |
372 | \& # prefix "sec_rgy_" is dropped from perl function names | |
373 | \& # subroutines are created for sec_rgy_wildcard_name and sec_rgy_wildcard_sid | |
374 | \& h2xs -n DCE::rgynbase -p sec_rgy_ \e | |
375 | \& -s sec_rgy_wildcard_name,sec_rgy_wildcard_sid dce/rgynbase | |
376 | .Ve | |
377 | .PP | |
378 | .Vb 7 | |
379 | \& # Make XS without defines in perl.h, but with function declarations | |
380 | \& # visible from perl.h. Name of the extension is perl1. | |
381 | \& # When scanning perl.h, define -DEXT=extern -DdEXT= -DINIT(x)= | |
382 | \& # Extra backslashes below because the string is passed to shell. | |
383 | \& # Note that a directory with perl header files would | |
384 | \& # be added automatically to include path. | |
385 | \& h2xs -xAn perl1 -F "-DEXT=extern -DdEXT= -DINIT\e(x\e)=" perl.h | |
386 | .Ve | |
387 | .PP | |
388 | .Vb 2 | |
389 | \& # Same with function declaration in proto.h as visible from perl.h. | |
390 | \& h2xs -xAn perl2 perl.h,proto.h | |
391 | .Ve | |
392 | .PP | |
393 | .Vb 2 | |
394 | \& # Same but select only functions which match /^av_/ | |
395 | \& h2xs -M '^av_' -xAn perl2 perl.h,proto.h | |
396 | .Ve | |
397 | .PP | |
398 | .Vb 2 | |
399 | \& # Same but treat SV* etc as "opaque" types | |
400 | \& h2xs -o '^[S]V \e*$' -M '^av_' -xAn perl2 perl.h,proto.h | |
401 | .Ve | |
402 | .Sh "Extension based on \fI.h\fP and \fI.c\fP files" | |
403 | .IX Subsection "Extension based on .h and .c files" | |
404 | Suppose that you have some C files implementing some functionality, | |
405 | and the corresponding header files. How to create an extension which | |
406 | makes this functionality accessable in Perl? The example below | |
407 | assumes that the header files are \fIinterface_simple.h\fR and | |
408 | \&\fIinterface_hairy.h\fR, and you want the perl module be named as | |
409 | \&\f(CW\*(C`Ext::Ension\*(C'\fR. If you need some preprocessor directives and/or | |
410 | linking with external libraries, see the flags \f(CW\*(C`\-F\*(C'\fR, \f(CW\*(C`\-L\*(C'\fR and \f(CW\*(C`\-l\*(C'\fR | |
411 | in \*(L"\s-1OPTIONS\s0\*(R". | |
412 | .IP "Find the directory name" 4 | |
413 | .IX Item "Find the directory name" | |
414 | Start with a dummy run of h2xs: | |
415 | .Sp | |
416 | .Vb 1 | |
417 | \& h2xs -Afn Ext::Ension | |
418 | .Ve | |
419 | .Sp | |
420 | The only purpose of this step is to create the needed directories, and | |
421 | let you know the names of these directories. From the output you can | |
422 | see that the directory for the extension is \fIExt/Ension\fR. | |
423 | .IP "Copy C files" 4 | |
424 | .IX Item "Copy C files" | |
425 | Copy your header files and C files to this directory \fIExt/Ension\fR. | |
426 | .IP "Create the extension" 4 | |
427 | .IX Item "Create the extension" | |
428 | Run h2xs, overwriting older autogenerated files: | |
429 | .Sp | |
430 | .Vb 1 | |
431 | \& h2xs -Oxan Ext::Ension interface_simple.h interface_hairy.h | |
432 | .Ve | |
433 | .Sp | |
434 | h2xs looks for header files \fIafter\fR changing to the extension | |
435 | directory, so it will find your header files \s-1OK\s0. | |
436 | .IP "Archive and test" 4 | |
437 | .IX Item "Archive and test" | |
438 | As usual, run | |
439 | .Sp | |
440 | .Vb 5 | |
441 | \& cd Ext/Ension | |
442 | \& perl Makefile.PL | |
443 | \& make dist | |
444 | \& make | |
445 | \& make test | |
446 | .Ve | |
447 | .IP "Hints" 4 | |
448 | .IX Item "Hints" | |
449 | It is important to do \f(CW\*(C`make dist\*(C'\fR as early as possible. This way you | |
450 | can easily \fImerge\fR\|(1) your changes to autogenerated files if you decide | |
451 | to edit your \f(CW\*(C`.h\*(C'\fR files and rerun h2xs. | |
452 | .Sp | |
453 | Do not forget to edit the documentation in the generated \fI.pm\fR file. | |
454 | .Sp | |
455 | Consider the autogenerated files as skeletons only, you may invent | |
456 | better interfaces than what h2xs could guess. | |
457 | .Sp | |
458 | Consider this section as a guideline only, some other options of h2xs | |
459 | may better suit your needs. | |
460 | .SH "ENVIRONMENT" | |
461 | .IX Header "ENVIRONMENT" | |
462 | No environment variables are used. | |
463 | .SH "AUTHOR" | |
464 | .IX Header "AUTHOR" | |
465 | Larry Wall and others | |
466 | .SH "SEE ALSO" | |
467 | .IX Header "SEE ALSO" | |
468 | perl, perlxstut, ExtUtils::MakeMaker, and AutoLoader. | |
469 | .SH "DIAGNOSTICS" | |
470 | .IX Header "DIAGNOSTICS" | |
471 | The usual warnings if it cannot read or write the files involved. | |
472 | .SH "LIMITATIONS of \fB\-x\fP" | |
473 | .IX Header "LIMITATIONS of -x" | |
474 | \&\fIh2xs\fR would not distinguish whether an argument to a C function | |
475 | which is of the form, say, \f(CW\*(C`int *\*(C'\fR, is an input, output, or | |
476 | input/output parameter. In particular, argument declarations of the | |
477 | form | |
478 | .PP | |
479 | .Vb 3 | |
480 | \& int | |
481 | \& foo(n) | |
482 | \& int *n | |
483 | .Ve | |
484 | .PP | |
485 | should be better rewritten as | |
486 | .PP | |
487 | .Vb 3 | |
488 | \& int | |
489 | \& foo(n) | |
490 | \& int &n | |
491 | .Ve | |
492 | .PP | |
493 | if \f(CW\*(C`n\*(C'\fR is an input parameter. | |
494 | .PP | |
495 | Additionally, \fIh2xs\fR has no facilities to intuit that a function | |
496 | .PP | |
497 | .Vb 4 | |
498 | \& int | |
499 | \& foo(addr,l) | |
500 | \& char *addr | |
501 | \& int l | |
502 | .Ve | |
503 | .PP | |
504 | takes a pair of address and length of data at this address, so it is better | |
505 | to rewrite this function as | |
506 | .PP | |
507 | .Vb 11 | |
508 | \& int | |
509 | \& foo(sv) | |
510 | \& SV *addr | |
511 | \& PREINIT: | |
512 | \& STRLEN len; | |
513 | \& char *s; | |
514 | \& CODE: | |
515 | \& s = SvPV(sv,len); | |
516 | \& RETVAL = foo(s, len); | |
517 | \& OUTPUT: | |
518 | \& RETVAL | |
519 | .Ve | |
520 | .PP | |
521 | or alternately | |
522 | .PP | |
523 | .Vb 5 | |
524 | \& static int | |
525 | \& my_foo(SV *sv) | |
526 | \& { | |
527 | \& STRLEN len; | |
528 | \& char *s = SvPV(sv,len); | |
529 | .Ve | |
530 | .PP | |
531 | .Vb 2 | |
532 | \& return foo(s, len); | |
533 | \& } | |
534 | .Ve | |
535 | .PP | |
536 | .Vb 1 | |
537 | \& MODULE = foo PACKAGE = foo PREFIX = my_ | |
538 | .Ve | |
539 | .PP | |
540 | .Vb 3 | |
541 | \& int | |
542 | \& foo(sv) | |
543 | \& SV *sv | |
544 | .Ve | |
545 | .PP | |
546 | See perlxs and perlxstut for additional details. |