Debian Codegraph @

README

raw
1 NAME
2 Module::Build::WithXSpp - XS++ enhanced flavour of Module::Build
3
4 SYNOPSIS
5 In Build.PL:
6
7 use strict;
8 use warnings;
9 use 5.006001;
10
11 use Module::Build::WithXSpp;
12
13 my $build = Module::Build::WithXSpp->new(
14 # normal Module::Build arguments...
15 # optional: mix in some extra C typemaps:
16 extra_typemap_modules => {
17 'ExtUtils::Typemaps::ObjectMap' => '0',
18 },
19 );
20 $build->create_build_script;
21
22 DESCRIPTION
23 This subclass of Module::Build adds some tools and processes to make it
24 easier to use for wrapping C++ using XS++ (ExtUtils::XSpp).
25
26 There are a few minor differences from using "Module::Build" for an
27 ordinary XS module and a few conventions that you should be aware of as
28 an XS++ module author. They are documented in the "FEATURES AND
29 CONVENTIONS" section below. But if you can't be bothered to read all
30 that, you may choose skip it and blindly follow the advice in "JUMP
31 START FOR THE IMPATIENT".
32
33 An example of a full distribution based on this build tool can be found
34 in the ExtUtils::XSpp distribution under examples/XSpp-Example. Using
35 that example as the basis for your "Module::Build::WithXSpp"-based
36 distribution is probably a good idea.
37
38 FEATURES AND CONVENTIONS
39 XS files
40 By default, "Module::Build::WithXSpp" will automatically generate a main
41 XS file for your module which includes all XS++ files and does the
42 correct incantations to support C++.
43
44 If "Module::Build::WithXSpp" detects any XS files in your module, it
45 will skip the generation of this default file and assume that you wrote
46 a custom main XS file. If that is not what you want, and wish to simply
47 include plain XS code, then you should put the XS in a verbatim block of
48 an .xsp file. In case you need to use the plain-C part of an XS file for
49 "#include" directives and other code, then put your code into a header
50 file and "#include" it from an .xsp file:
51
52 In src/mystuff.h:
53
54 #include <something>
55 using namespace some::thing;
56
57 In xsp/MyClass.xsp
58
59 #include "mystuff.h"
60
61 %{
62 ... verbatim XS here ...
63 %}
64
65 Note that there is no guarantee about the order in which the XS++ files
66 are picked up.
67
68 Build directory
69 When building your XS++ based extension, a temporary build directory
70 buildtmp is created for the byproducts. It is automatically cleaned up
71 by "./Build clean".
72
73 Source directories
74 A Perl module distribution typically has the module ".pm" files in its
75 lib subdirectory. In a "Module::Build::WithXSpp" based distribution,
76 there are two more such conventions about source directories:
77
78 If any C++ source files are present in the src directory, they will be
79 compiled to object files and linked automatically.
80
81 Any ".xs", ".xsp", and ".xspt" files in an xs or xsp subdirectory will
82 be automatically picked up and included by the build system.
83
84 For backwards compatibility, files of the above types are also
85 recognized in lib.
86
87 Typemaps
88 In XS++, there are two types of typemaps: The ordinary XS typemaps which
89 conventionally put in a file called typemap, and XS++ typemaps.
90
91 The ordinary XS typemaps will be found in the main directory, under lib,
92 and in the XS directories (xs and xsp). They are required to carry the
93 ".map" extension or to be called typemap. You may use multiple .map
94 files if the entries do not collide. They will be merged at build time
95 into a complete typemap file in the temporary build directory.
96
97 The "extra_typemap_modules" option is the prefered way to do XS
98 typemapping. It works like any other "Module::Build" argument that
99 declares dependencies except that it loads the listed modules at build
100 time and includes their typemaps into the build.
101
102 The XS++ typemaps are required to carry the ".xspt" extension or (for
103 backwards compatibility) to be called "typemap.xsp".
104
105 Detecting the C++ compiler
106 "Module::Build::WithXSpp" uses ExtUtils::CppGuess to detect a C++
107 compiler on your system that is compatible with the C compiler that was
108 used to compile your perl binary. It sets some additional
109 compiler/linker options.
110
111 This is known to work on GCC (Linux, MacOS, Windows, and ?) as well as
112 the MS VC toolchain. Patches to enable other compilers are very welcome.
113
114 Automatic dependencies
115 "Module::Build::WithXSpp" automatically adds several dependencies (on
116 the currently running versions) to your distribution. You can disable
117 this by setting "auto_configure_requires => 0" in Build.PL.
118
119 These are at configure time: "Module::Build", "Module::Build::WithXSpp"
120 itself, and "ExtUtils::CppGuess". Additionally there will be a
121 build-time dependency on "ExtUtils::XSpp".
122
123 You do not have to set these dependencies yourself unless you need to
124 set the required versions manually.
125
126 Include files
127 Unfortunately, including the perl headers produces quite some pollution
128 and redefinition of common symbols. Therefore, it may be necessary to
129 include some of your headers before including the perl headers.
130 Specifically, this is the case for MSVC compilers and the standard
131 library headers.
132
133 Therefore, if you care about that platform in the least, you should use
134 the "early_includes" option when creating a "Module::Build::WithXSpp"
135 object to list headers to include before the perl headers. If such a
136 supplied header file starts with a double quote, "#include "..."" is
137 used, otherwise "#include <...>" is the default. Example:
138
139 Module::Build::WithXSpp->new(
140 early_includes => [qw(
141 "mylocalheader.h"
142 <mysystemheader.h>
143 )]
144 )
145
146 JUMP START FOR THE IMPATIENT
147 There are as many ways to start a new CPAN distribution as there are
148 CPAN distributions. Choose your favourite (I just do "h2xs -An
149 My::Module"), then apply a few changes to your setup:
150
151 * Obliterate any Makefile.PL.
152
153 This is what your Build.PL should look like:
154
155 use strict;
156 use warnings;
157 use 5.006001;
158 use Module::Build::WithXSpp;
159
160 my $build = Module::Build::WithXSpp->new(
161 module_name => 'My::Module',
162 license => 'perl',
163 dist_author => q{John Doe <john_does_mail_address>},
164 dist_version_from => 'lib/My/Module.pm',
165 build_requires => { 'Test::More' => 0, },
166 extra_typemap_modules => {
167 'ExtUtils::Typemaps::ObjectMap' => '0',
168 # ...
169 },
170 );
171 $build->create_build_script;
172
173 If you need to link against some library "libfoo", add this to the
174 options:
175
176 extra_linker_flags => [qw(-lfoo)],
177
178 There is "extra_compiler_flags", too, if you need it.
179
180 * You create two folders in the main distribution folder: src and xsp.
181
182 * You put any C++ code that you want to build and include in the module
183 into src/. All the typical C(++) file extensions are recognized and
184 will be compiled to object files and linked into the module. And
185 headers in that folder will be accessible for "#include <myheader.h>".
186
187 For good measure, move a copy of ppport.h to that directory. See
188 Devel::PPPort.
189
190 * You do not write normal XS files. Instead, you write XS++ and put it
191 into the xsp/ folder in files with the ".xsp" extension. Do not worry,
192 you can include verbatim XS blocks in XS++. For details on XS++, see
193 ExtUtils::XSpp.
194
195 * If you need to do any XS type mapping, put your typemaps into a .map
196 file in the "xsp" directory. Alternatively, search CPAN for an
197 appropriate typemap module (cf. ExtUtils::Typemaps::Default for an
198 explanation). XS++ typemaps belong into .xspt files in the same
199 directory.
200
201 * In this scheme, lib/ only contains Perl module files (and POD). If you
202 started from a pure-Perl distribution, don't forget to add these magic
203 two lines to your main module:
204
205 require XSLoader;
206 XSLoader::load('My::Module', $VERSION);
207
208 SEE ALSO
209 Module::Build upon which this module is based.
210
211 ExtUtils::XSpp implements XS++. The "ExtUtils::XSpp" distribution
212 contains an examples directory with a usage example of this module.
213
214 ExtUtils::Typemaps implements progammatic modification (merging) of C/XS
215 typemaps. "ExtUtils::Typemaps" was renamed from "ExtUtils::Typemap"
216 since the original name conflicted with the core typemap file on
217 case-insensitive file systems.
218
219 ExtUtils::Typemaps::Default explains the concept of having typemaps
220 shipped as modules.
221
222 ExtUtils::Typemaps::ObjectMap is such a typemap module and probably very
223 useful for any XS++ module.
224
225 ExtUtils::Typemaps::STL::String implements simple typemapping for STL
226 "std::string"s.
227
228 AUTHOR
229 Steffen Mueller <[email protected]>
230
231 With input and bug fixes from:
232
233 Mattia Barbon
234
235 Shmuel Fomberg
236
237 COPYRIGHT AND LICENSE
238 Copyright 2010, 2011 Steffen Mueller.
239
240 This program is free software; you can redistribute it and/or modify it
241 under the same terms as Perl itself.
242
243 POD ERRORS
244 Hey! The above document had some coding errors, which are explained
245 below:
246
247 Around line 717:
248 You forgot a '=back' before '=head1'
249