summaryrefslogtreecommitdiff
path: root/lib/ExtUtils/MakeMaker/FAQ.pod
blob: 6d7ba70202eaa99d1519ede66a3ebbf9617e4670 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
package ExtUtils::MakeMaker::FAQ;

our $VERSION = '0.02';

1;
__END__

=head1 NAME

ExtUtils::MakeMaker::FAQ - Frequently Asked Questions About MakeMaker

=head1 DESCRIPTION

FAQs, tricks and tips for C<ExtUtils::MakeMaker>.

=head2 Philosophy and History

=over 4

=item Why not just use <insert other build config tool here>?

Why did MakeMaker reinvent the build configuration wheel?  Why not
just use autoconf or automake or ppm or Ant or ...

There are many reasons, but the major one is cross-platform
compatibility.

Perl is one of the most ported pieces of software ever.  It works on
operating systems I've never even heard of (see perlport for details).
It needs a build tool that can work on all those platforms and with
any wacky C compilers they might have.

No such build tool existed at the time and I only know of one now
(Module::Build).


=item What's Module::Build and how does it relate to MakeMaker?

Module::Build is a project by Ken Williams to supplant MakeMaker.
Its primary advantages are:

=over 8

=item * pure perl.  no make, no shell commands

=item * easier to customize

=item * cleaner internals

=item * less cruft

=back

Module::Build is the official heir apparent to MakeMaker and we
encourage people to work on M::B rather than spending time improving
MakeMaker.

=back

=head2 XS

=over 4

=item How do I make two or more XS files coexist in the same directory?

Sometimes you need to have two and more XS files in the same package.
One way to go is to put them into separate directories, but sometimes
this is not the most suitable solution. The following technique allows
you to put two (and more) XS files in the same directory.

Let's assume that we have a package C<Cool::Foo>, which includes
C<Cool::Foo> and C<Cool::Bar> modules each having a separate XS
file. First we use the following I<Makefile.PL>:

  use ExtUtils::MakeMaker;

  WriteMakefile(
      NAME		=> 'Cool::Foo',
      VERSION_FROM	=> 'Foo.pm',
      OBJECT              => q/$(O_FILES)/,
      # ... other attrs ...
  );

Notice the C<OBJECT> attribute. MakeMaker generates the following
variables in I<Makefile>:

  # Handy lists of source code files:
  XS_FILES= Bar.xs \
  	Foo.xs
  C_FILES = Bar.c \
  	Foo.c
  O_FILES = Bar.o \
  	Foo.o

Therefore we can use the C<O_FILES> variable to tell MakeMaker to use
these objects into the shared library.

That's pretty much it. Now write I<Foo.pm> and I<Foo.xs>, I<Bar.pm>
and I<Bar.xs>, where I<Foo.pm> bootstraps the shared library and
I<Bar.pm> simply loading I<Foo.pm>.

The only issue left is to how to bootstrap I<Bar.xs>. This is done
from I<Foo.xs>:

  MODULE = Cool::Foo PACKAGE = Cool::Foo

  BOOT:
  # boot the second XS file
  boot_Cool__Bar(aTHX_ cv);

If you have more than two files, this is the place where you should
boot extra XS files from.

The following four files sum up all the details discussed so far.

  Foo.pm:
  -------
  package Cool::Foo;

  require DynaLoader;

  our @ISA = qw(DynaLoader);
  our $VERSION = '0.01';
  bootstrap Cool::Foo $VERSION;

  1;

  Bar.pm:
  -------
  package Cool::Bar;

  use Cool::Foo; # bootstraps Bar.xs

  1;

  Foo.xs:
  -------
  #include "EXTERN.h"
  #include "perl.h"
  #include "XSUB.h"

  MODULE = Cool::Foo  PACKAGE = Cool::Foo

  BOOT:
  # boot the second XS file
  boot_Cool__Bar(aTHX_ cv);

  MODULE = Cool::Foo  PACKAGE = Cool::Foo  PREFIX = cool_foo_

  void
  cool_foo_perl_rules()

      CODE:
      fprintf(stderr, "Cool::Foo says: Perl Rules\n");

  Bar.xs:
  -------
  #include "EXTERN.h"
  #include "perl.h"
  #include "XSUB.h"

  MODULE = Cool::Bar  PACKAGE = Cool::Bar PREFIX = cool_bar_

  void
  cool_bar_perl_rules()

      CODE:
      fprintf(stderr, "Cool::Bar says: Perl Rules\n");

And of course a very basic test:

  test.pl:
  --------
  use Test;
  BEGIN { plan tests => 1 };
  use Cool::Foo;
  use Cool::Bar;
  Cool::Foo::perl_rules();
  Cool::Bar::perl_rules();
  ok 1;

This tip has been brought to you by Nick Ing-Simmons and Stas Bekman.

=back

=head1 PATCHING

If you have a question you'd like to see added to the FAQ (whether or
not you have the answer) please send it to makemaker@perl.org.

=head1 AUTHOR

The denizens of makemaker@perl.org.

=head1 SEE ALSO

L<ExtUtils::MakeMaker>

=cut