Commit | Line | Data |
a0d0e21e |
1 | package ExtUtils::MakeMaker; |
2 | |
42793c05 |
3 | $Version = 3.6; # Last edited 19th Dec 1994 by Tim Bunce |
a0d0e21e |
4 | |
5 | use Config; |
42793c05 |
6 | use Carp; |
7 | use Cwd; |
8 | |
a0d0e21e |
9 | require Exporter; |
10 | @ISA = qw(Exporter); |
42793c05 |
11 | @EXPORT = qw(&WriteMakefile &mkbootstrap $Verbose &writeMakefile); |
12 | @EXPORT_OK = qw($Version %att %skip %Recognized_Att_Keys @MM_Sections %MM_Sections); |
a0d0e21e |
13 | |
42793c05 |
14 | $Is_VMS = $Config{'osname'} eq 'VMS'; |
15 | require ExtUtils::MM_VMS if $Is_VMS; |
a0d0e21e |
16 | |
42793c05 |
17 | use strict qw(refs); |
a0d0e21e |
18 | |
42793c05 |
19 | $Version = $Version;# avoid typo warning |
a0d0e21e |
20 | $Verbose = 0; |
a0d0e21e |
21 | $^W=1; |
22 | |
23 | |
42793c05 |
24 | =head1 NAME |
a0d0e21e |
25 | |
42793c05 |
26 | ExtUtils::MakeMaker - create an extension Makefile |
a0d0e21e |
27 | |
42793c05 |
28 | =head1 SYNOPSIS |
a0d0e21e |
29 | |
42793c05 |
30 | use ExtUtils::MakeMaker; |
31 | WriteMakefile( ATTRIBUTE => VALUE [, ...] ); |
a0d0e21e |
32 | |
42793c05 |
33 | =head1 DESCRIPTION |
34 | |
35 | This utility is designed to write a Makefile for an extension module |
36 | from a Makefile.PL. It is based on the Makefile.SH model provided by |
37 | Andy Dougherty and the perl5-porters. |
38 | |
39 | It splits the task of generating the Makefile into several subroutines |
40 | that can be individually overridden. Each subroutine returns the text |
41 | it wishes to have written to the Makefile. |
42 | |
43 | =head2 Default Makefile Behaviour |
44 | |
45 | This section (not yet written) will describe how a default Makefile will behave. |
46 | |
47 | =head2 Determination of Perl Library and Installation Locations |
48 | |
49 | MakeMaker needs to know, or to guess, where certain things are located. |
50 | Especially INST_LIB, INST_ARCHLIB, PERL_LIB, PERL_ARCHLIB and PERL_SRC. |
51 | |
52 | Because installperl does not currently install header files (etc) into |
53 | the library the Perl source code must be available when building |
54 | extensions. Currently MakeMaker will default PERL_LIB and PERL_ARCHLIB |
55 | to PERL_SRC/lib. Later, once installperl does install header files |
56 | (etc) into the library, PERL_*LIB will only default to PERL_SRC/lib if |
57 | the extension is in PERL_SRC/ext/* (e.g., a standard extension). |
58 | Otherwise PERL_*LIB and PERL_SRC will default to the public library |
59 | locations. |
60 | |
61 | INST_LIB and INST_ARCHLIB default to PERL_LIB and PERL_ARCHLIB. |
62 | |
63 | =head2 Useful Default Makefile Macros |
64 | |
65 | FULLEXT = Pathname for extension directory (eg DBD/Oracle). |
66 | |
67 | BASEEXT = Basename part of FULLEXT. May be just equal FULLEXT. |
68 | |
69 | ROOTEXT = Directory part of FULLEXT with leading slash (eg /DBD) |
70 | |
71 | PERL_LIB |
72 | |
73 | PERL_ARCHLIB |
74 | |
75 | INST_LIB |
76 | |
77 | INST_ARCHLIB |
78 | |
79 | INST_LIBDIR = $(INST_LIB)$(ROOTEXT) (and INST_ARCHLIBDIR) |
80 | |
81 | INST_AUTODIR = $(INST_LIB)/auto/$(FULLEXT) (and INST_ARCHAUTODIR) |
82 | |
83 | =head2 Customizing The Generated Makefile |
84 | |
85 | If the Makefile generated does not fit your purpose you can change it |
86 | using the mechanisms described below. |
87 | |
88 | =head2 Using Attributes (and Parameters) |
89 | |
90 | The following attributes can be specified as arguments to WriteMakefile() |
91 | or as NAME=VALUE pairs on the command line: |
92 | |
93 | (not yet complete) |
94 | |
95 | =head2 Overriding MakeMaker Methods |
96 | |
97 | If you cannot achieve the desired Makefile behaviour by specifying |
98 | attributes you may define private subroutines in the Makefile.PL. |
99 | Each subroutines returns the text it wishes to have written to |
100 | the Makefile. To override a section of the Makefile you can |
101 | either say: |
102 | |
103 | sub MY::c_o { "new literal text" } |
104 | |
105 | or you can edit the default by saying something like: |
106 | |
107 | sub MY::c_o { $_=MM->c_o; s/old text/new text/; $_ } |
a0d0e21e |
108 | |
42793c05 |
109 | If you still need a different solution, try to develop another |
110 | subroutine, that fits your needs and submit the diffs to |
111 | perl5-porters@isu.edu or comp.lang.perl as appropriate. |
112 | |
113 | |
114 | =head1 AUTHORS |
115 | |
116 | Andy Dougherty <doughera@lafcol.lafayette.edu>, Andreas Koenig |
117 | <k@franz.ww.TU-Berlin.DE>, Tim Bunce <Tim.Bunce@ig.co.uk> |
118 | |
119 | =head1 MODIFICATION HISTORY |
120 | |
121 | v1, August 1994; by Andreas Koenig. |
122 | |
123 | Initial version. Based on Andy Dougherty's Makefile.SH work. |
124 | |
125 | v2, September 1994; by Tim Bunce. |
126 | |
127 | Use inheritance to implement overriding. Methods return text so |
128 | derived methods can edit it before it's output. mkbootstrap() now |
129 | executes the *_BS file in the DynaLoader package and automatically adds |
130 | dl_findfile() if required. More support for nested modules. |
131 | |
132 | v3.0, October/November 1994; by Tim Bunce. |
133 | |
134 | Major reorganisation. Fixed perl binary locating code. Replaced single |
135 | $(TOP) with $(PERL_SRC), $(PERL_LIB) and $(INST_LIB). Restructured |
136 | code. Consolidated and/or eliminated several attributes and added |
137 | argument name checking. Added initial pod documentation. Made generated |
138 | Makefile easier to read. Added generic mechanism for passing parameters |
139 | to specific sections of the Makefile. Merged in Andreas's perl version |
140 | of Andy's extliblist. |
141 | |
142 | v3.1 November 11th 1994 by Tim Bunce |
143 | |
144 | Fixed AIX dynamic loading problem for nested modules. Fixed perl |
145 | extliblist to give paths not names for libs so that cross-check works. |
146 | Converted the .xs to .c translation to a suffix rule. Added a .xs.o |
147 | rule for dumb makes. Added very useful PM, XS and DIR attributes. Used |
148 | new attributes to make other sections smarter (especially clean and |
149 | realclean). Make clean no longer deletes Makefile so that a later make |
150 | realclean can still work. Fixed all known problems. Write temporary |
151 | Makefile as Makefile.new and rename once complete. |
152 | |
153 | v3.2 November 18th 1994 By Tim Bunce |
154 | |
155 | Fixed typos, added makefile section (split out of a flattened |
156 | perldepend section). Added subdirectories to test section. Added -lm |
157 | fix for NeXT in extliblist. Added clean of *~ files. Tidied up clean |
158 | and realclean sections to produce fewer lines. Major revision to the |
159 | const_loadlibs comments for EXTRALIBS, LDLOADLIBS and BSLOADLIBS. |
160 | Added LINKTYPE=\$(LINKTYPE) to subdirectory make invocations. |
161 | Write temporary Makefile as MakeMaker.tmp. Write temporary xsubpp |
162 | output files as xstmp.c instead of tmp. Now installs multiple PM files. |
163 | Improved parsing of NAME=VALUE args. $(BOOTSTRAP) is now a dependency |
164 | of $(INST_DYNAMIC). Improved init of PERL_LIB, INST_LIB and PERL_SRC. |
165 | Reinstated $(TOP) for transition period. Removed CONFIG_SH attribute |
166 | (no longer used). Put INST_PM back and include .pm and .pl files in |
167 | current and lib directory. Allow OBJECT to contain newlines. ROOTEXT |
168 | now has leading slash. Added INST_LIBDIR (containing ROOTEXT) and |
169 | renamed AUTOEXT to INST_AUTO. Assorted other cosmetic changes. |
170 | All known problems fixed. |
171 | |
172 | v3.3 November 27th 1994 By Andreas Koenig |
173 | |
174 | Bug fixes submitted by Michael Peppler and Wayne Scott. Changed the |
175 | order how @libpath is constructed in C<new_extliblist()>. Improved |
176 | pod-structure. Relative paths in C<-L> switches to LIBS are turned into |
177 | absolute ones now. Included VMS support thanks to submissions by |
178 | Charles Bailey. Added warnings for switches other than C<-L> or C<-l> |
179 | in new_extliblist() and if a library is not found at all. Changed |
180 | dependency distclean:clean to distclean:realclean. Added dependency |
181 | all->config. ext.libs is now written without duplicates and empty |
182 | lines. As old_extliblist() and new_extliblist() do not produce the |
183 | same anymore, the default becomes new_extliblist(), though the warning |
184 | remains, whenever they differ. The use of cflags is accompanied by a |
185 | replacement: there will be a warning when the two routines lead to |
186 | different results, but still the output of cflags will be used. |
187 | Cosmetic changes (Capitalize globals, uncapitalize others, insert a |
188 | C<:> as default for $postop). Added some verbosity. |
189 | |
190 | v3.4 December 7th 1994 By Andreas Koenig and Tim Bunce |
191 | |
192 | Introduced ARCH_LIB and required other perl files to be patched. |
193 | |
194 | v3.5 December 15th 1994 By Tim Bunce |
195 | |
196 | Based primarily on v3.3. Replaced ARCH_LIB with INST_ARCHLIB, which |
197 | defaults to INST_LIB, because the rest of perl assumes that ./lib |
198 | includes architecture dependent files. Ideally an ./archlib should |
199 | exist, that would be more consistent and simplify installperl. |
200 | Added linkext and $(INST_PM) dependencies to all: target. The linkext |
201 | target (and subroutine) exists solely to depend on $(LINKTYPE). Any |
202 | Makefile.PLs using LINKTYPE => '...' where '...' is not 'static' or |
203 | 'dynamic' should be changed to use 'linkext' => { LINKTYPE => '...' }. |
204 | |
205 | Automatic determination of PERL_* and INST_* has been revised. The |
206 | INST_* macros have INST_ARCH* and INST_*DIR variants. The ARCH variants |
207 | point to the architecture specific directory and the *DIR variants |
208 | include the module specific subdirectory path. So INST_AUTO is now |
209 | INST_AUTODIR and an INST_ARCHAUTODIR has also been defined. |
210 | |
211 | An AUTOSPLITFILE tool macro has been defined which will AutoSplit any |
212 | named file into any named auto directory. This replaces AUTOSPLITLIB. |
213 | MKPATH now accepts multiple paths. The paths INST_LIBDIR, |
214 | INST_ARCHLIBDIR, INST_AUTODIR and INST_ARCHAUTODIR are made by the |
215 | config: target. A new ext.libs mechanism has been added. installpm has |
216 | been split and now calls installpm_x per file. A section attribute |
217 | mechanism has been added and skip cross-checking has been moved into a |
218 | skipcheck function. MakeMaker now uses Cwd and File::Basename modules. |
219 | |
220 | v3.6 December 15th 1994 By Tim Bunce |
221 | |
222 | Added C and H attributes and corresponding macros. These default to the |
223 | list of *.c and *.h files in the directory. C also includes *.c file |
224 | names corresponding to any *.xs files in the directory. ARMAYBE should |
225 | now be specified as an attribute of the dynamic_lib section. The installpm |
226 | section now accepts a SPLITLIB attribute. This defaults to '$(INST_LIB)'. |
227 | Improved automatic setting of INST_ARCHLIB. Newlines in OBJECT now translate |
228 | into <space><backslash><newline><tab> for better formatting. Improved |
229 | descriptive comments for EXTRALIBS, LDLOADLIBS and BSLOADLIBS. Bootstrap |
230 | files are now always installed - (after a small patch) the DynaLoader will |
231 | only read a non-empty bootstrap file. Subdirectory dependencies have |
232 | been improved. The .c files produced from .xs files now depend on |
233 | XSUBPPDEPS (the typemaps). |
234 | |
235 | |
236 | =head1 NOTES |
237 | |
238 | MakeMaker development work still to be done: |
239 | |
240 | Needs more complete documentation. |
241 | |
242 | Replace use of cflags with %Config (taking note of hints etc) |
243 | |
244 | Move xsubpp and typemap into lib/ExtUtils/... |
245 | |
246 | The ext.libs file mechanism will need to be revised to allow a |
247 | make-a-perl [list-of-static-extensions] script to work. |
248 | |
249 | Eventually eliminate use of $(PERL_SRC). This must wait until |
250 | MakeMaker is the standard and Larry makes the required changes |
251 | elsewhere. |
252 | |
253 | Add method to take a list of files and wrap it in a Makefile |
254 | compatible way (<space><backslash><newline><tab>). |
255 | |
256 | =cut |
257 | |
258 | |
259 | # Setup dummy package: |
260 | # MY exists for overriding methods to be defined within |
261 | unshift(@MY::ISA, qw(MM)); |
262 | |
263 | # Dummy package MM inherits actual methods from OS-specific |
264 | # default packages. We use this intermediate package so |
265 | # MY->func() can call MM->func() and get the proper |
266 | # default routine without having to know under what OS |
267 | # it's running. |
268 | unshift(@MM::ISA, $Is_VMS ? qw(ExtUtils::MM_VMS MM_Unix) : qw(MM_Unix)); |
269 | |
270 | $Attrib_Help = <<'END'; |
271 | NAME: Perl module name for this extension (DBD::Oracle) |
272 | This defaults to the directory name. |
273 | |
274 | DISTNAME: Your name for distributing the package (by tar file) |
275 | This defaults to NAME above. |
276 | |
277 | VERSION: Your version number for distributing the package. |
278 | This defaults to 0.1. |
279 | |
280 | INST_LIB: Perl library directory to install the module into. |
281 | INST_ARCHLIB: Perl architecture-dependent library to install into |
282 | (defaults to INST_LIB) |
283 | |
284 | PERL_LIB: Directory containing the Perl library to use. |
285 | PERL_SRC: Directory containing the Perl source code |
286 | (use of this should be avoided, it may be removed later) |
287 | |
288 | INC: Include file dirs eg: '-I/usr/5include -I/path/to/inc' |
289 | DEFINE: something like "-DHAVE_UNISTD_H" |
290 | OBJECT: List of object files, defaults to '$(BASEEXT).o', |
291 | but can be a long string containing all object files, |
292 | e.g. "tkpBind.o tkpButton.o tkpCanvas.o" |
293 | MYEXTLIB: If the extension links to a library that it builds |
294 | set this to the name of the library (see SDBM_File) |
295 | |
296 | LIBS: An anonymous array of alternative library specifications |
297 | to be searched for (in order) until at least one library |
298 | is found. |
299 | 'LIBS' => [ "-lgdbm", "-ldbm -lfoo", "-L/path -ldbm.nfs" ] |
300 | Mind, that any element of the array contains a complete |
301 | set of arguments for the ld command. So do not specify |
302 | 'LIBS' => ["-ltcl", "-ltk", "-lX11" ], #wrong |
303 | See ODBM_File/Makefile.PL for an example, where an |
304 | array is needed. If you specify a scalar as in |
305 | 'LIBS' => "-ltcl -ltk -lX11" |
306 | MakeMaker will turn it into an array with one element. |
307 | |
308 | LDTARGET: defaults to "$(OBJECT)" and is used in the ld command |
309 | (some machines need additional switches for bigger projects) |
310 | |
311 | DIR: Ref to array of subdirectories containing Makefile.PLs |
312 | e.g. [ 'sdbm' ] in ext/SDBM_File |
313 | |
314 | PM: Hashref of .pm files and *.pl files to be installed. |
315 | e.g. { 'name_of_file.pm' => '$(INST_LIBDIR)/install_as.pm' } |
316 | By default this will include *.pm and *.pl. If a lib directory |
317 | exists and is not listed in DIR (above) then any *.pm and |
318 | *.pl files it contains will also be included by default. |
319 | |
320 | XS: Hashref of .xs files. MakeMaker will default this. |
321 | e.g. { 'name_of_file.xs' => 'name_of_file.c' } |
322 | The .c files will automatically be included in the list |
323 | of files deleted by a make clean. |
324 | |
325 | C: Ref to array of *.c file names. Initialised from a directory scan |
326 | and the values portion of the XS attribute hash. This is not |
327 | currently used by MakeMaker but may be handy in Makefile.PLs. |
328 | |
329 | H: Ref to array of *.h file names. Similar to C: above. |
330 | |
331 | LINKTYPE: =>'static' or 'dynamic' (default unless usedl=undef in config.sh) |
332 | Should only be used to force static linking (also see linkext below). |
333 | |
334 | CONFIG: =>[qw(archname manext)] defines ARCHNAME & MANEXT from config.sh |
335 | SKIP: =>[qw(name1 name2)] skip (do not write) sections of the Makefile |
336 | |
337 | PERL: |
338 | FULLPERL: |
339 | |
340 | Additional lowercase attributes can be used to pass parameters to the |
341 | methods which implement that part of the Makefile. These are not |
342 | normally required: |
343 | |
344 | installpm: {SPLITLIB => '$(INST_LIB)' (default) or '$(INST_ARCHLIB)'} |
345 | linkext: {LINKTYPE => 'static', 'dynamic' or ''} |
346 | dynamic_lib {ARMAYBE => 'ar', OTHERLDFLAGS => '...'} |
347 | clean: {FILES => "*.xyz foo"} |
348 | realclean: {FILES => '$(INST_AUTODIR)/*.xyz'} |
349 | distclean: {TARNAME=>'MyTarFile', TARFLAGS=>'cvfF', COMPRESS=>'gzip'} |
350 | tool_autosplit: {MAXLEN => 8} |
351 | END |
352 | |
353 | @MM_Sections_spec = ( |
354 | 'post_initialize' => {}, |
355 | 'constants' => {}, |
356 | 'const_config' => {}, |
357 | 'const_loadlibs' => {}, |
358 | 'const_cccmd' => {}, |
359 | 'tool_autosplit' => {}, |
360 | 'tool_xsubpp' => {}, |
361 | 'tools_other' => {}, |
362 | 'post_constants' => {}, |
363 | 'c_o' => {}, |
364 | 'xs_c' => {}, |
365 | 'xs_o' => {}, |
366 | 'top_targets' => {}, |
367 | 'linkext' => {}, |
368 | 'dynamic' => {}, |
369 | 'dynamic_bs' => {}, |
370 | 'dynamic_lib' => {}, |
371 | 'static' => {}, |
372 | 'static_lib' => {}, |
373 | 'installpm' => {}, |
374 | 'subdirs' => {}, |
375 | 'clean' => {}, |
376 | 'realclean' => {}, |
377 | 'distclean' => {}, |
378 | 'test' => {}, |
379 | 'install' => {}, |
380 | 'force' => {}, |
381 | 'perldepend' => {}, |
382 | 'makefile' => {}, |
383 | 'postamble' => {}, |
384 | ); |
385 | %MM_Sections = @MM_Sections_spec; # looses section ordering |
386 | @MM_Sections = grep(!ref, @MM_Sections_spec); # keeps order |
387 | |
388 | %Recognized_Att_Keys = %MM_Sections; # All sections are valid keys. |
389 | foreach(split(/\n/,$Attrib_Help)){ |
390 | chomp; |
391 | next unless m/^\s*(\w+):\s*(.*)/; |
392 | $Recognized_Att_Keys{$1} = $2; |
393 | print "Attribute '$1' => '$2'\n" if ($Verbose >= 2); |
394 | } |
395 | |
396 | %att = (); |
397 | %skip = (); |
398 | |
399 | sub skipcheck{ |
400 | my($section) = @_; |
401 | return 'skipped' if $skip{$section}; |
402 | return ''; |
403 | } |
404 | |
405 | |
406 | sub WriteMakefile { |
a0d0e21e |
407 | %att = @_; |
408 | local($\)="\n"; |
409 | |
a0d0e21e |
410 | print STDOUT "MakeMaker" if $Verbose; |
a0d0e21e |
411 | |
42793c05 |
412 | parse_args(\%att, @ARGV); |
413 | my(%initial_att) = %att; # record initial attributes |
a0d0e21e |
414 | |
42793c05 |
415 | MY->initialize(@ARGV); |
a0d0e21e |
416 | |
42793c05 |
417 | print STDOUT "Writing Makefile for $att{NAME}"; |
a0d0e21e |
418 | |
42793c05 |
419 | unlink("Makefile", "MakeMaker.tmp", $Is_VMS ? 'Descrip.MMS' : ''); |
420 | open MAKE, ">MakeMaker.tmp" or die "Unable to open MakeMaker.tmp: $!"; |
421 | select MAKE; $|=1; select STDOUT; |
a0d0e21e |
422 | |
42793c05 |
423 | print MAKE "# This Makefile is for the $att{NAME} extension to perl.\n#"; |
424 | print MAKE "# It was generated automatically by MakeMaker from the contents"; |
425 | print MAKE "# of Makefile.PL. Don't edit this file, edit Makefile.PL instead."; |
426 | print MAKE "#\n# ANY CHANGES MADE HERE WILL BE LOST! \n#"; |
427 | print MAKE "# MakeMaker Parameters: "; |
428 | foreach $key (sort keys %initial_att){ |
429 | my($v) = neatvalue($initial_att{$key}); |
430 | $v =~ tr/\n/ /s; |
431 | print MAKE "# $key => $v"; |
432 | } |
a0d0e21e |
433 | |
42793c05 |
434 | # build hash for SKIP to make testing easy |
435 | %skip = map( ($_,1), @{$att{'SKIP'} || []}); |
436 | |
437 | foreach $section ( @MM_Sections ){ |
438 | print "Processing Makefile '$section' section" if ($Verbose >= 2); |
439 | my($skipit) = skipcheck($section); |
440 | if ($skipit){ |
441 | print MAKE "\n# --- MakeMaker $section section $skipit."; |
442 | } else { |
443 | my(%a) = %{$att{$section} || {}}; |
444 | print MAKE "\n# --- MakeMaker $section section:"; |
445 | print MAKE "# ",%a if ($Verbose >= 2); |
446 | print(MAKE MY->nicetext(MY->$section( %a ))); |
447 | } |
448 | } |
a0d0e21e |
449 | |
42793c05 |
450 | if ($Verbose){ |
451 | print MAKE "\n# Full list of MakeMaker attribute values:"; |
452 | foreach $key (sort keys %att){ |
453 | my($v) = neatvalue($att{$key}); |
454 | $v =~ tr/\n/ /s; |
455 | print MAKE "# $key => $v"; |
456 | } |
457 | } |
a0d0e21e |
458 | |
42793c05 |
459 | print MAKE "\n# End."; |
a0d0e21e |
460 | close MAKE; |
42793c05 |
461 | my($finalname) = $Is_VMS ? "Descrip.MMS" : "Makefile"; |
462 | rename("MakeMaker.tmp", $finalname); |
463 | |
464 | chmod 0644, $finalname; |
465 | system("$Config{'eunicefix'} $finalname") unless $Config{'eunicefix'} eq ":"; |
a0d0e21e |
466 | |
467 | 1; |
468 | } |
469 | |
470 | |
471 | sub mkbootstrap{ |
42793c05 |
472 | parse_args(\%att, @ARGV); |
473 | MY->mkbootstrap(@_); |
a0d0e21e |
474 | } |
475 | |
476 | |
42793c05 |
477 | sub parse_args{ |
478 | my($attr, @args) = @_; |
479 | foreach (@args){ |
480 | next unless m/(.*?)=(.*)/; |
481 | $$attr{$1} = $2; |
482 | } |
483 | # catch old-style 'potential_libs' and inform user how to 'upgrade' |
484 | if (defined $$attr{'potential_libs'}){ |
485 | my($msg)="'potential_libs' => '$$attr{potential_libs}' should be"; |
486 | if ($$attr{'potential_libs'}){ |
487 | print STDERR "$msg changed to:\n\t'LIBS' => ['$$attr{potential_libs}']\n"; |
488 | } else { |
489 | print STDERR "$msg deleted.\n"; |
490 | } |
491 | $$attr{LIBS} = [$$attr{'potential_libs'}]; |
492 | delete $$attr{'potential_libs'}; |
493 | } |
494 | # catch old-style 'ARMAYBE' and inform user how to 'upgrade' |
495 | if (defined $$attr{'ARMAYBE'}){ |
496 | my($armaybe) = $$attr{'ARMAYBE'}; |
497 | print STDERR "ARMAYBE => '$armaybe' should be changed to:\n", |
498 | "\t'dynamic_lib' => {ARMAYBE => '$armaybe'}\n"; |
499 | my(%dl) = %{$$attr{'dynamic_lib'} || {}}; |
500 | $$attr{'dynamic_lib'} = { %dl, ARMAYBE => $armaybe}; |
501 | delete $$attr{'ARMAYBE'}; |
502 | } |
503 | foreach(sort keys %{$attr}){ |
504 | print STDOUT " $_ => ".neatvalue($$attr{$_}) if ($Verbose); |
505 | warn "'$_' is not a known MakeMaker parameter name.\n" |
506 | unless exists $Recognized_Att_Keys{$_}; |
507 | } |
a0d0e21e |
508 | } |
509 | |
510 | |
42793c05 |
511 | sub neatvalue{ |
512 | my($v) = @_; |
513 | my($t) = ref $v; |
514 | return "'$v'" unless $t; |
515 | return "[ ".join(', ',map("'$_'",@$v))." ]" if ($t eq 'ARRAY'); |
516 | return "$v" unless $t eq 'HASH'; |
517 | my(@m, $key, $val); |
518 | push(@m,"$key=>".neatvalue($val)) while (($key,$val) = each %$v); |
519 | return "{ ".join(', ',@m)." }"; |
520 | } |
521 | |
522 | |
523 | # ------ Define the MakeMaker default methods in package MM_Unix ------ |
a0d0e21e |
524 | |
42793c05 |
525 | package MM_Unix; |
a0d0e21e |
526 | |
527 | use Config; |
42793c05 |
528 | use Cwd; |
529 | use File::Basename; |
a0d0e21e |
530 | require Exporter; |
531 | |
42793c05 |
532 | Exporter::import('ExtUtils::MakeMaker', |
533 | qw(%att %skip %Recognized_Att_Keys $Verbose)); |
a0d0e21e |
534 | |
42793c05 |
535 | # These attributes cannot be overridden externally |
536 | @Other_Att_Keys{qw(EXTRALIBS BSLOADLIBS LDLOADLIBS)} = (1) x 3; |
a0d0e21e |
537 | |
42793c05 |
538 | if ($Is_VMS = $Config{'osname'} eq 'VMS') { |
539 | require File::VMSspec; |
540 | import File::VMSspec 'vmsify'; |
a0d0e21e |
541 | } |
542 | |
543 | |
544 | sub initialize { |
42793c05 |
545 | # Find out directory name. This may contain the extension name. |
546 | my($pwd) = fastcwd(); # from Cwd.pm |
547 | |
548 | # --- Initialize PERL_LIB, INST_LIB, PERL_SRC |
549 | |
550 | # *Real* information: where did we get these two from? ... |
551 | $inc_config_dir = dirname($INC{'Config.pm'}); |
552 | $inc_carp_dir = dirname($INC{'Carp.pm'}); |
553 | |
554 | # Typically PERL_* and INST_* will be identical but that need |
555 | # not be the case (e.g., installing into project libraries etc). |
556 | |
557 | # Perl Macro: With source No source |
558 | # PERL_LIB ../../lib /usr/local/lib/perl5 |
559 | # PERL_ARCHLIB ../../lib /usr/local/lib/perl5/sun4-sunos |
560 | # PERL_SRC ../.. (undecided) |
561 | |
562 | # INST Macro: Locally Publically |
563 | # INST_LIB ../../lib /usr/local/lib/perl5 |
564 | # INST_ARCHLIB ../../lib /usr/local/lib/perl5/sun4-sunos |
a0d0e21e |
565 | |
42793c05 |
566 | # This code will need to be reworked to deal with having no perl |
567 | # source. PERL_LIB should become the primary focus. |
568 | |
569 | unless ($att{PERL_SRC}){ |
a0d0e21e |
570 | foreach(qw(../.. ../../.. ../../../..)){ |
42793c05 |
571 | ($att{PERL_SRC}=$_, last) if -f "$_/config.sh"; |
a0d0e21e |
572 | } |
a0d0e21e |
573 | } |
42793c05 |
574 | unless ($att{PERL_SRC}){ |
575 | # Later versions will not die here. |
576 | die "Unable to locate perl source. Try setting PERL_SRC.\n"; |
577 | # we should also consider $ENV{PERL5LIB} here |
578 | $att{PERL_LIB} = $Config{'privlib'} unless $att{PERL_LIB}; |
579 | $att{PERL_ARCHLIB} = $Config{'archlib'} unless $att{PERL_ARCHLIB}; |
580 | } else { |
581 | $att{PERL_LIB} = "$att{PERL_SRC}/lib" unless $att{PERL_LIB}; |
582 | $att{PERL_ARCHLIB} = $att{PERL_LIB}; |
583 | } |
584 | |
585 | # INST_LIB typically pre-set if building an extension after |
586 | # perl has been built and installed. Setting INST_LIB allows |
587 | # You to build directly into privlib and avoid installperl. |
588 | $att{INST_LIB} = $att{PERL_LIB} unless $att{INST_LIB}; |
589 | |
590 | # Try to work out what INST_ARCHLIB should be if not set: |
591 | unless ($att{INST_ARCHLIB}){ |
592 | my(%archmap) = ( |
593 | $att{PERL_LIB} => $att{PERL_ARCHLIB}, |
594 | $Config{'privlib'} => $Config{'archlib'}, |
595 | $Config{'installprivlib'} => $Config{'installarchlib'}, |
596 | $inc_carp_dir => $inc_config_dir, |
597 | ); |
598 | $att{INST_ARCHLIB} = $archmap{$att{INST_LIB}}; |
599 | die "Unable to determine INST_ARCHLIB. Please define it explicitly.\n" |
600 | unless $att{INST_ARCHLIB}; |
601 | } |
602 | |
603 | # make a few simple checks |
604 | die "PERL_LIB ($att{PERL_LIB}) is not a perl library directory" |
605 | unless (-f "$att{PERL_LIB}/Exporter.pm"); |
606 | |
607 | # --- Initialize Module Name and Paths |
a0d0e21e |
608 | |
42793c05 |
609 | # NAME = The perl module name for this extension (eg DBD::Oracle). |
610 | # FULLEXT = Pathname for extension directory (eg DBD/Oracle). |
a0d0e21e |
611 | # BASEEXT = Basename part of FULLEXT. May be just equal FULLEXT. |
42793c05 |
612 | # ROOTEXT = Directory part of FULLEXT with leading /. |
613 | unless($att{NAME}){ # we have to guess our name |
614 | my($name) = $pwd; |
615 | if ($Is_VMS) { |
616 | $name =~ s:.*?([^.\]]+)\]:$1: unless ($name =~ s:.*[.\[]ext\.::); |
617 | ($att{NAME}=$name) =~ s#[.\]]#::#g; |
618 | } else { |
619 | $name =~ s:.*/:: unless ($name =~ s:^.*/ext/::); |
620 | ($att{NAME} =$name) =~ s#/#::#g; |
621 | } |
622 | } |
623 | ($att{FULLEXT} =$att{NAME}) =~ s#::#/#g ; #eg. BSD/Foo/Socket |
624 | ($att{BASEEXT} =$att{NAME}) =~ s#.*::##; #eg. Socket |
625 | ($att{ROOTEXT} =$att{FULLEXT}) =~ s#/?\Q$att{BASEEXT}\E$## ; # eg. /BSD/Foo |
626 | $att{ROOTEXT} = "/$att{ROOTEXT}" if $att{ROOTEXT}; |
627 | $att{ROOTEXT} = "" if $Is_VMS; |
628 | |
629 | ($att{DISTNAME}=$att{NAME}) =~ s#(::)#-#g; |
630 | $att{VERSION} = "0.1" unless $att{VERSION}; |
631 | |
632 | |
633 | # --- Initialize Perl Binary Locations |
634 | |
635 | # Find Perl 5. The only contract here is that both 'PERL' and 'FULLPERL' |
a0d0e21e |
636 | # will be working versions of perl 5. |
42793c05 |
637 | $att{'PERL'} = MY->find_perl(5.0, [ qw(perl5 perl miniperl) ], |
638 | [ $att{PERL_SRC}, split(":", $ENV{PATH}), $Config{'bin'} ], 0 ) |
639 | unless ($att{'PERL'} && -x $att{'PERL'}); |
a0d0e21e |
640 | |
42793c05 |
641 | # Define 'FULLPERL' to be a non-miniperl (used in test: target) |
642 | ($att{'FULLPERL'} = $att{'PERL'}) =~ s/miniperl/perl/ |
643 | unless ($att{'FULLPERL'} && -x $att{'FULLPERL'}); |
a0d0e21e |
644 | |
42793c05 |
645 | if ($Is_VMS) { |
646 | ($att{'PERL'} = 'MCR ' . vmsify($att{'PERL'})) =~ s:.*/::; |
647 | ($att{'FULLPERL'} = 'MCR ' . vmsify($att{'FULLPERL'})) =~ s:.*/::; |
648 | } |
649 | |
650 | # --- Initialize File and Directory Lists (.xs .pm etc) |
651 | |
652 | { |
653 | my($name, %dir, %xs, %pm, %c, %h, %ignore); |
654 | $ignore{'test.pl'} = 1; |
655 | $ignore{'makefile.pl'} = 1 if $Is_VMS; |
656 | foreach $name (lsdir(".")){ |
657 | next if ($name =~ /^\./ or $ignore{$name}); |
658 | if (-d $name){ |
659 | $dir{$name} = $name if (-f "$name/Makefile.PL"); |
660 | }elsif ($name =~ /\.xs$/){ |
661 | my($c); ($c = $name) =~ s/\.xs$/.c/; |
662 | $xs{$name} = $c; |
663 | $c{$c} = 1; |
664 | }elsif ($name =~ /\.c$/){ |
665 | $c{$name} = 1; |
666 | }elsif ($name =~ /\.h$/){ |
667 | $h{$name} = 1; |
668 | }elsif ($name =~ /\.p[ml]$/){ |
669 | $pm{$name} = "\$(INST_LIBDIR)/$name"; |
670 | } |
671 | } |
672 | |
673 | # If we have a ./lib dir that does NOT contain a Makefile.PL |
674 | # then add in any .pm and .pl files in that directory. |
675 | # This makes it easy and tidy to ship a number of perl files. |
676 | if (-d "lib" and !$dir{'lib'}){ |
677 | foreach $name (lsdir("lib")){ |
678 | next unless ($name =~ /\.p[ml]$/); |
679 | $pm{"lib/$name"} = "\$(INST_LIBDIR)/$name"; |
680 | } |
681 | } |
682 | |
683 | $att{DIR} = [sort keys %dir] unless $att{DIRS}; |
684 | $att{XS} = \%xs unless $att{XS}; |
685 | $att{PM} = \%pm unless $att{PM}; |
686 | $att{C} = [sort keys %c] unless $att{C}; |
687 | $att{H} = [sort keys %h] unless $att{H}; |
688 | } |
689 | |
690 | # --- Initialize Other Attributes |
691 | |
692 | for $key (keys(%Recognized_Att_Keys), keys(%Other_Att_Keys)){ |
a0d0e21e |
693 | # avoid warnings for uninitialized vars |
42793c05 |
694 | next if exists $att{$key}; |
695 | $att{$key} = ""; |
a0d0e21e |
696 | } |
697 | |
42793c05 |
698 | # Compute EXTRALIBS, BSLOADLIBS and LDLOADLIBS from $att{'LIBS'} |
699 | # Lets look at $att{LIBS} carefully: It may be an anon array, a string or |
700 | # undefined. In any case we turn it into an anon array: |
701 | $att{LIBS}=[] unless $att{LIBS}; |
702 | $att{LIBS}=[$att{LIBS}] if ref \$att{LIBS} eq SCALAR; |
703 | foreach ( @{$att{'LIBS'}} ){ |
704 | s/^\s*(.*\S)\s*$/$1/; # remove leading and trailing whitespace |
705 | my(@libs) = MY->extliblist($_); |
706 | if ($libs[0] or $libs[1] or $libs[2]){ |
707 | @att{EXTRALIBS, BSLOADLIBS, LDLOADLIBS} = @libs; |
708 | last; |
709 | } |
710 | } |
a0d0e21e |
711 | |
42793c05 |
712 | warn "CONFIG must be an array ref\n" |
713 | if ($att{CONFIG} and ref $att{CONFIG} ne 'ARRAY'); |
714 | $att{CONFIG} = [] unless (ref $att{CONFIG}); |
715 | push(@{$att{CONFIG}}, |
716 | qw( cc libc ldflags lddlflags ccdlflags cccdlflags |
717 | ranlib so dlext dlsrc installprivlib installarchlib |
718 | )); |
719 | push(@{$att{CONFIG}}, 'shellflags') if $Config{'shellflags'}; |
720 | |
721 | if ($Is_VMS) { |
722 | # This will not make other Makefile.PLs portable. Any Makefile.PL |
723 | # which says OBJECT => "foo.o bar.o" will fail on VMS. It might |
724 | # be better to fix the c_o section to produce .o files. |
725 | $att{OBJECT} = '$(BASEEXT).obj' unless $att{OBJECT}; |
726 | $att{OBJECT} =~ s/[^,\s]\s+/, /g; |
727 | $att{OBJECT} =~ s/\n+/, /g; |
728 | } else { |
729 | $att{OBJECT} = '$(BASEEXT).o' unless $att{OBJECT}; |
730 | $att{OBJECT} =~ s/\n+/ \\\n\t/g; |
a0d0e21e |
731 | } |
42793c05 |
732 | $att{BOOTDEP} = (-f "$att{BASEEXT}_BS") ? "$att{BASEEXT}_BS" : ""; |
733 | $att{LDTARGET} = '$(OBJECT)' unless $att{LDTARGET}; |
734 | $att{LINKTYPE} = ($Config{'usedl'}) ? 'dynamic' : 'static' |
735 | unless $att{LINKTYPE}; |
736 | |
a0d0e21e |
737 | } |
738 | |
739 | |
42793c05 |
740 | sub lsdir{ |
741 | local(*DIR, @ls); |
742 | opendir(DIR, $_[0] || ".") or die "opendir: $!"; |
743 | @ls = readdir(DIR); |
744 | closedir(DIR); |
745 | @ls; |
746 | } |
747 | |
748 | |
749 | sub find_perl{ |
750 | my($self, $ver, $names, $dirs, $trace) = @_; |
751 | my($name, $dir); |
752 | print "Looking for perl $ver by these names: @$names, in these dirs: @$dirs\n" |
753 | if ($trace); |
754 | foreach $dir (@$dirs){ |
755 | foreach $name (@$names){ |
756 | print "checking $dir/$name\n" if ($trace >= 2); |
757 | if ($Is_VMS) { |
758 | $name .= ".exe" unless -x "$dir/$name"; |
759 | } |
760 | next unless -x "$dir/$name"; |
761 | print "executing $dir/$name\n" if ($trace); |
762 | my($out); |
763 | if ($Is_VMS) { |
764 | my($vmscmd) = 'MCR ' . vmsify("$dir/$name"); |
765 | $out = `$vmscmd -e "require $ver; print ""VER_OK\n"""`; |
766 | } else { |
767 | $out = `$dir/$name -e 'require $ver; print "VER_OK\n" ' 2>&1`; |
768 | } |
769 | return "$dir/$name" if $out =~ /VER_OK/; |
a0d0e21e |
770 | } |
771 | } |
42793c05 |
772 | warn "Unable to find a perl $ver (by these names: @$names, in these dirs: @$dirs)\n"; |
773 | 0; # false and not empty |
a0d0e21e |
774 | } |
775 | |
776 | |
777 | sub post_initialize{ |
778 | ""; |
779 | } |
780 | |
781 | |
782 | sub constants { |
783 | my(@m); |
784 | |
a0d0e21e |
785 | push @m, " |
42793c05 |
786 | NAME = $att{NAME} |
a0d0e21e |
787 | DISTNAME = $att{DISTNAME} |
788 | VERSION = $att{VERSION} |
789 | |
42793c05 |
790 | # In which library should we install this extension? |
791 | # This is typically the same as PERL_LIB. |
792 | # (also see INST_LIBDIR and relationship to ROOTEXT) |
793 | INST_LIB = $att{INST_LIB} |
794 | INST_ARCHLIB = $att{INST_ARCHLIB} |
795 | |
796 | # Perl library to use when building the extension |
797 | PERL_LIB = $att{PERL_LIB} |
798 | PERL_ARCHLIB = $att{PERL_ARCHLIB} |
799 | |
800 | # Where is the perl source code located? (Eventually we should |
801 | # be able to build extensions without requiring the perl source |
802 | # but that's a way off yet). |
803 | PERL_SRC = $att{PERL_SRC} |
804 | # Perl header files (will eventually be under PERL_LIB) |
805 | PERL_INC = $att{PERL_SRC} |
806 | # Perl binaries |
807 | PERL = $att{'PERL'} |
808 | FULLPERL = $att{'FULLPERL'} |
809 | |
810 | # FULLEXT = Pathname for extension directory (eg DBD/Oracle). |
811 | # BASEEXT = Basename part of FULLEXT. May be just equal FULLEXT. |
812 | # ROOTEXT = Directory part of FULLEXT with leading slash (eg /DBD) |
813 | FULLEXT = $att{FULLEXT} |
814 | BASEEXT = $att{BASEEXT} |
815 | ROOTEXT = $att{ROOTEXT} |
816 | |
817 | # These will be removed later. Use PERL_SRC and BASEEXT instead. |
818 | TOP = \$(PERL_SRC) |
819 | EXT = CHANGE_EXT_TO_BASEEXT |
820 | |
a0d0e21e |
821 | INC = $att{INC} |
822 | DEFINE = $att{DEFINE} |
823 | OBJECT = $att{OBJECT} |
824 | LDTARGET = $att{LDTARGET} |
a0d0e21e |
825 | LINKTYPE = $att{LINKTYPE} |
a0d0e21e |
826 | |
42793c05 |
827 | # Source code: |
828 | XS= ".join(" \\\n\t", sort keys %{$att{XS}})." |
829 | C = ".join(" \\\n\t", @{$att{C}})." |
830 | H = ".join(" \\\n\t", @{$att{H}})." |
a0d0e21e |
831 | |
42793c05 |
832 | .SUFFIXES: .xs |
a0d0e21e |
833 | |
42793c05 |
834 | .PRECIOUS: Makefile |
835 | |
836 | .PHONY: all config static dynamic test |
837 | |
838 | # This extension may link to it's own library (see SDBM_File) |
839 | MYEXTLIB = $att{MYEXTLIB} |
840 | |
841 | # Where is the Config.pm that we are using/depend on |
842 | CONFIGDEP = \$(PERL_ARCHLIB)/Config.pm |
a0d0e21e |
843 | "; |
844 | |
845 | push @m, ' |
846 | # Where to put things: |
42793c05 |
847 | INST_LIBDIR = $(INST_LIB)$(ROOTEXT) |
848 | INST_ARCHLIBDIR = $(INST_ARCHLIB)$(ROOTEXT) |
849 | |
850 | INST_AUTODIR = $(INST_LIB)/auto/$(FULLEXT) |
851 | INST_ARCHAUTODIR = $(INST_ARCHLIB)/auto/$(FULLEXT) |
852 | |
853 | INST_BOOT = $(INST_ARCHAUTODIR)/$(BASEEXT).bs |
854 | INST_DYNAMIC = $(INST_ARCHAUTODIR)/$(BASEEXT).$(DLEXT) |
855 | INST_STATIC = $(BASEEXT).a |
856 | INST_PM = '.join(" \\\n\t", sort values %{$att{PM}}).' |
857 | '; |
858 | |
859 | join('',@m); |
860 | } |
861 | |
862 | |
863 | sub const_cccmd{ |
864 | # This is implemented in the |
865 | # same manner as extliblist, e.g., do both and compare results during |
866 | # the transition period. |
867 | my($cc,$ccflags,$optimize,$large,$split)=@Config{qw(cc ccflags optimize large split)}; |
868 | my($prog); |
869 | chop(my($old) = `cd $att{PERL_SRC}; sh $Config{'shellflags'} ./cflags $att{BASEEXT}.c`); |
870 | # Why is this written this way ? |
871 | if ($prog = $Config{"$att{BASEEXT}_cflags"}) { |
872 | my(@o)=`cc=\"$cc\" |
873 | ccflags=\"$ccflags\" |
874 | optimize=\"$optimize\" |
875 | large=\"$large\" |
876 | split=\"$split\" |
877 | eval '$prog' |
878 | echo cc=\$cc |
879 | echo ccflags=\$ccflags |
880 | echo optimize=\$optimize |
881 | echo large=\$large |
882 | echo split=\$split |
883 | `; |
884 | my(%cflags); |
885 | foreach $line (@o){ |
886 | chomp $line; |
887 | if ($line =~ /(.*?)\s*=\s*(.*)\s*$/){ |
888 | $cflags{$1} = $2; |
889 | print STDERR " $1 = $2" if $Verbose; |
890 | } |
891 | } |
892 | ($cc,$ccflags,$optimize,$large,$split)=@cflags{qw(cc ccflags optimize large split)}; |
893 | } |
894 | |
895 | my($new) = "$cc -c $ccflags $optimize $large $split"; |
896 | if ($new ne $old) { |
897 | warn "Warning (non-fatal): cflags evaluation in MakeMaker differs from shell output\n" |
898 | ." package: $att{NAME}\n" |
899 | ." old: $old\n" |
900 | ." new: $new\n" |
901 | ." Using 'old' set.\n" |
902 | ."Please notify perl5-porters\@isu.edu\n"; |
903 | } |
904 | my($cccmd)=$old; |
905 | "CCCMD = $cccmd\n"; |
906 | } |
907 | |
908 | |
909 | # --- Constants Sections --- |
910 | |
911 | sub const_config{ |
912 | my(@m,$m); |
913 | push(@m,"\n# These definitions are from config.sh (via $INC{'Config.pm'})\n"); |
914 | my(%once_only); |
915 | foreach $m (@{$att{'CONFIG'}}){ |
916 | next if $once_only{$m}; |
917 | warn "CONFIG key '$m' does not exist in Config.pm\n" |
918 | unless exists $Config{$m}; |
919 | push @m, "\U$m\E = $Config{$m}\n"; |
920 | $once_only{$m} = 1; |
921 | } |
922 | join('', @m); |
923 | } |
924 | |
925 | |
926 | sub const_loadlibs{ |
927 | " |
928 | # $att{NAME} might depend on some other libraries: |
929 | # (These comments may need revising:) |
930 | # |
931 | # Dependent libraries can be linked in one of three ways: |
932 | # |
933 | # 1. (For static extensions) by the ld command when the perl binary |
934 | # is linked with the extension library. See EXTRALIBS below. |
935 | # |
936 | # 2. (For dynamic extensions) by the ld command when the shared |
937 | # object is built/linked. See LDLOADLIBS below. |
938 | # |
939 | # 3. (For dynamic extensions) by the DynaLoader when the shared |
940 | # object is loaded. See BSLOADLIBS below. |
941 | # |
942 | # EXTRALIBS = List of libraries that need to be linked with when |
943 | # linking a perl binary which includes this extension |
944 | # Only those libraries that actually exist are included. |
945 | # These are written to a file and used when linking perl. |
946 | # |
947 | # LDLOADLIBS = List of those libraries which can or must be linked into |
948 | # the shared library when created using ld. These may be |
949 | # static or dynamic libraries. |
950 | # |
951 | # BSLOADLIBS = List of those libraries that are needed but can be |
952 | # linked in dynamically at run time on this platform. |
953 | # SunOS/Solaris does not need this because ld records |
954 | # the information (from LDLOADLIBS) into the object file. |
955 | # This list is used to create a .bs (bootstrap) file. |
956 | # The bootstrap file is installed only if it's not empty. |
957 | # |
958 | EXTRALIBS = $att{'EXTRALIBS'} |
959 | LDLOADLIBS = $att{'LDLOADLIBS'} |
960 | BSLOADLIBS = $att{'BSLOADLIBS'} |
a0d0e21e |
961 | "; |
42793c05 |
962 | } |
a0d0e21e |
963 | |
a0d0e21e |
964 | |
42793c05 |
965 | # --- Tool Sections --- |
a0d0e21e |
966 | |
42793c05 |
967 | sub tool_autosplit{ |
968 | my($self, %attribs) = @_; |
969 | my($asl) = ""; |
970 | $asl = "\$AutoSplit::Maxlen=$attribs{MAXLEN};" if $attribs{MAXLEN}; |
971 | q{ |
972 | AUTOSPLITLIB = $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) -e 'use AutoSplit; chdir("$(INST_LIB)/..") or die $$!; $$AutoSplit::Maxlen=}.$asl.q{; autosplit_lib_modules(@ARGV) ;' |
a0d0e21e |
973 | |
42793c05 |
974 | # Usage: $(AUTOSPLITFILE) FileToSplit AutoDirToSplitInto |
975 | AUTOSPLITFILE = $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) -e 'use AutoSplit;}.$asl.q{ AutoSplit::autosplit_file($$ARGV[0], $$ARGV[1], 0, 1, 1) ;' |
976 | }; |
977 | } |
a0d0e21e |
978 | |
a0d0e21e |
979 | |
42793c05 |
980 | sub tool_xsubpp{ |
981 | my(@tmdeps) = ('$(PERL_SRC)/ext/typemap'); |
982 | push(@tmdeps, "typemap") if -f "typemap"; |
983 | my(@tmargs) = map("-typemap $_", @tmdeps); |
984 | " |
985 | XSUBPP = \$(PERL_SRC)/ext/xsubpp |
986 | XSUBPPDEPS = @tmdeps |
987 | XSUBPPARGS = @tmargs |
988 | "; |
989 | }; |
a0d0e21e |
990 | |
a0d0e21e |
991 | |
42793c05 |
992 | sub tools_other{ |
993 | q{ |
994 | SHELL = /bin/sh |
995 | |
996 | # The following is a portable way to say mkdir -p |
997 | MKPATH = $(PERL) -wle '$$"="/"; foreach $$p (@ARGV){ my(@p); foreach(split(/\//,$$p)){ push(@p,$$_); next if -d "@p/"; print "mkdir @p"; mkdir("@p",0777)||die $$! }} exit 0;' |
998 | }; |
a0d0e21e |
999 | } |
1000 | |
1001 | |
1002 | sub post_constants{ |
1003 | ""; |
1004 | } |
1005 | |
1006 | |
42793c05 |
1007 | # --- Translation Sections --- |
a0d0e21e |
1008 | |
42793c05 |
1009 | sub c_o { |
1010 | ' |
1011 | .c.o: |
1012 | $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) $(INC) $*.c |
1013 | '; |
a0d0e21e |
1014 | } |
1015 | |
42793c05 |
1016 | sub xs_c { |
1017 | ' |
1018 | .xs.c: |
1019 | $(PERL) $(XSUBPP) $(XSUBPPARGS) $*.xs >xstmp.c && mv xstmp.c $@ |
1020 | '; |
1021 | } |
a0d0e21e |
1022 | |
42793c05 |
1023 | sub xs_o { # many makes are too dumb to use xs_c then c_o |
a0d0e21e |
1024 | ' |
42793c05 |
1025 | .xs.o: |
1026 | $(PERL) $(XSUBPP) $(XSUBPPARGS) $*.xs >xstmp.c && mv xstmp.c $*.c |
1027 | $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) $(INC) $*.c |
a0d0e21e |
1028 | '; |
1029 | } |
1030 | |
1031 | |
42793c05 |
1032 | # --- Target Sections --- |
1033 | |
1034 | sub top_targets{ |
a0d0e21e |
1035 | ' |
42793c05 |
1036 | all :: config linkext $(INST_PM) |
1037 | |
1038 | config :: Makefile |
1039 | @$(MKPATH) $(INST_LIBDIR) $(INST_ARCHLIBDIR) |
1040 | @$(MKPATH) $(INST_AUTODIR) $(INST_ARCHAUTODIR) |
1041 | |
1042 | install :: all |
a0d0e21e |
1043 | '; |
1044 | } |
1045 | |
42793c05 |
1046 | sub linkext { |
1047 | my($self, %attribs) = @_; |
1048 | # LINKTYPE => static or dynamic |
1049 | my($linktype) = $attribs{LINKTYPE} || '$(LINKTYPE)'; |
1050 | " |
1051 | linkext :: $linktype |
1052 | "; |
1053 | } |
1054 | |
1055 | |
1056 | # --- Dynamic Loading Sections --- |
a0d0e21e |
1057 | |
1058 | sub dynamic { |
1059 | ' |
42793c05 |
1060 | # $(INST_PM) has been moved to the all: target. |
1061 | # It remains here for awhile to allow for old usage: "make dynamic" |
1062 | dynamic :: $(INST_DYNAMIC) $(INST_BOOT) $(INST_PM) |
1063 | '; |
1064 | } |
a0d0e21e |
1065 | |
42793c05 |
1066 | sub dynamic_bs { |
1067 | my($self, %attribs) = @_; |
1068 | ' |
1069 | BOOTSTRAP = '."$att{BASEEXT}.bs".' |
a0d0e21e |
1070 | |
42793c05 |
1071 | # As MakeMaker mkbootstrap might not write a file (if none is required) |
1072 | # we use touch to prevent make continually trying to remake it. |
1073 | # The DynaLoader only reads a non-empty file. |
1074 | $(BOOTSTRAP): '.$att{BOOTDEP}.' $(CONFIGDEP) |
1075 | $(PERL) -I$(PERL_LIB) -e \'use ExtUtils::MakeMaker; &mkbootstrap("$(BSLOADLIBS)");\' INST_LIB=$(INST_LIB) PERL_SRC=$(PERL_SRC) NAME=$(NAME) |
1076 | @touch $(BOOTSTRAP) |
a0d0e21e |
1077 | |
1078 | $(INST_BOOT): $(BOOTSTRAP) |
42793c05 |
1079 | @rm -f $(INST_BOOT) |
1080 | cp $(BOOTSTRAP) $(INST_BOOT) |
a0d0e21e |
1081 | '; |
1082 | } |
1083 | |
42793c05 |
1084 | sub dynamic_lib { |
1085 | my($self, %attribs) = @_; |
1086 | my($otherldflags) = $attribs{OTHERLDFLAGS} || ""; |
1087 | my($armaybe) = $attribs{ARMAYBE} || $att{ARMAYBE} || ":"; |
a0d0e21e |
1088 | ' |
42793c05 |
1089 | ARMAYBE = '.$armaybe.' |
1090 | OTHERLDFLAGS = '.$otherldflags.' |
a0d0e21e |
1091 | |
42793c05 |
1092 | $(INST_DYNAMIC): $(OBJECT) $(MYEXTLIB) $(BOOTSTRAP) |
1093 | @$(MKPATH) $(INST_AUTODIR) |
1094 | $(ARMAYBE) cr $(BASEEXT).a $(OBJECT) |
1095 | ld $(LDDLFLAGS) -o $@ $(LDTARGET) $(OTHERLDFLAGS) $(MYEXTLIB) $(LDLOADLIBS) |
a0d0e21e |
1096 | '; |
1097 | } |
1098 | |
1099 | |
42793c05 |
1100 | # --- Static Loading Sections --- |
1101 | |
1102 | sub static { |
a0d0e21e |
1103 | ' |
42793c05 |
1104 | # $(INST_PM) has been moved to the all: target. |
1105 | # It remains here for awhile to allow for old usage: "make static" |
1106 | static :: $(INST_STATIC) $(INST_PM) |
a0d0e21e |
1107 | '; |
1108 | } |
1109 | |
42793c05 |
1110 | sub static_lib{ |
1111 | my(@m); |
1112 | push(@m, <<'END'); |
1113 | $(INST_STATIC): $(OBJECT) $(MYEXTLIB) |
1114 | END |
1115 | # If this extension has it's own library (eg SDBM_File) |
1116 | # then copy that to $(INST_STATIC) and add $(OBJECT) into it. |
1117 | push(@m, ' cp $(MYEXTLIB) $@'."\n") if $att{MYEXTLIB}; |
1118 | |
1119 | push(@m, <<'END'); |
1120 | ar cr $@ $(OBJECT) && $(RANLIB) $@ |
1121 | @: Old mechanism - still needed: |
1122 | echo $(EXTRALIBS) >> $(PERL_SRC)/ext.libs |
1123 | @: New mechanism - not yet used: |
1124 | echo $(EXTRALIBS) > $(INST_ARCHAUTODIR)/extralibs.ld |
1125 | cp $@ $(INST_ARCHAUTODIR)/ |
1126 | END |
1127 | join('', "\n",@m); |
1128 | } |
1129 | |
a0d0e21e |
1130 | |
1131 | sub installpm { |
42793c05 |
1132 | my($self, %attribs) = @_; |
1133 | # By default .pm files are split into the architecture independent |
1134 | # library. This is a good thing. If a specific module requires that |
1135 | # it's .pm files are split into the architecture specific library |
1136 | # then it should use: installpm => {SPLITLIB=>'$(INST_ARCHLIB)'} |
1137 | # Note that installperl currently interferes with this (Config.pm) |
1138 | # User can disable split by saying: installpm => {SPLITLIB=>''} |
1139 | my($splitlib) = '$(INST_LIB)'; # NOT arch specific by default |
1140 | $splitlib = $attribs{SPLITLIB} if exists $attribs{SPLITLIB}; |
1141 | my(@m, $dist); |
1142 | foreach $dist (sort keys %{$att{PM}}){ |
1143 | my($inst) = $att{PM}->{$dist}; |
1144 | push(@m, "\n# installpm: $dist => $inst, splitlib=$splitlib\n"); |
1145 | push(@m, MY->installpm_x($dist, $inst, $splitlib)); |
1146 | push(@m, "\n"); |
1147 | } |
1148 | join('', @m); |
a0d0e21e |
1149 | } |
1150 | |
42793c05 |
1151 | sub installpm_x { # called by installpm per file |
1152 | my($self, $dist, $inst, $splitlib) = @_; |
1153 | my($instdir) = $inst =~ m|(.*)/|; |
1154 | my(@m); |
1155 | push(@m," |
1156 | $inst: $dist |
1157 | ".' @rm -f $@ |
1158 | @$(MKPATH) '.$instdir.' |
1159 | cp $? $@ |
1160 | '); |
1161 | push(@m, "\t\$(AUTOSPLITFILE) \$@ $splitlib/auto\n") |
1162 | if ($splitlib and $inst =~ m/\.pm$/); |
1163 | join('', @m); |
1164 | } |
a0d0e21e |
1165 | |
42793c05 |
1166 | |
1167 | # --- Sub-directory Sections --- |
1168 | |
1169 | sub subdirs { |
1170 | my(@m); |
1171 | # This method provides a mechanism to automatically deal with |
1172 | # subdirectories containing further Makefile.PL scripts. |
1173 | # It calls the subdir_x() method for each subdirectory. |
1174 | foreach(<*/Makefile.PL>){ |
1175 | s:/Makefile\.PL$:: ; |
1176 | print "Including $_ subdirectory" if ($Verbose); |
1177 | push(@m, MY->subdir_x($_)); |
1178 | } |
1179 | if (@m){ |
1180 | unshift(@m, " |
1181 | # The default clean, realclean and test targets in this Makefile |
1182 | # have automatically been given entries for each subdir. |
1183 | |
1184 | all :: subdirs |
1185 | "); |
1186 | } else { |
1187 | push(@m, "\n# none") |
1188 | } |
1189 | join('',@m); |
1190 | } |
1191 | |
1192 | sub runsubdirpl{ # Experimental! See subdir_x section |
1193 | my($self,$subdir) = @_; |
1194 | chdir($subdir) or die "chdir($subdir): $!"; |
1195 | require "Makefile.PL"; |
a0d0e21e |
1196 | } |
1197 | |
42793c05 |
1198 | sub subdir_x { |
1199 | my($self, $subdir) = @_; |
1200 | my(@m); |
1201 | # The intention is that the calling Makefile.PL should define the |
1202 | # $(SUBDIR_MAKEFILE_PL_ARGS) make macro to contain whatever |
1203 | # information needs to be passed down to the other Makefile.PL scripts. |
1204 | # If this does not suit your needs you'll need to write your own |
1205 | # MY::subdir_x() method to override this one. |
1206 | qq{ |
1207 | config :: $subdir/Makefile |
1208 | cd $subdir ; \$(MAKE) config LINKTYPE=\$(LINKTYPE) |
1209 | |
1210 | $subdir/Makefile: $subdir/Makefile.PL \$(CONFIGDEP) |
1211 | }.' @echo "Rebuilding $@ ..." |
1212 | $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) \\ |
1213 | -e "use ExtUtils::MakeMaker; MM->runsubdirpl(qw('.$subdir.'))" \\ |
1214 | $(SUBDIR_MAKEFILE_PL_ARGS) |
1215 | @echo "Rebuild of $@ complete." |
1216 | '.qq{ |
1217 | |
1218 | subdirs :: |
1219 | cd $subdir ; \$(MAKE) all LINKTYPE=\$(LINKTYPE) |
1220 | |
1221 | }; |
1222 | } |
1223 | |
1224 | |
1225 | # --- Cleanup and Distribution Sections --- |
1226 | |
1227 | sub clean { |
1228 | my($self, %attribs) = @_; |
1229 | my(@m); |
1230 | push(@m, ' |
1231 | # Delete temporary files but do not touch installed files. We don\'t delete |
1232 | # the Makefile here so a later make realclean still has a makefile to use. |
1233 | |
1234 | clean :: |
1235 | '); |
1236 | # clean subdirectories first |
1237 | push(@m, map("\t-cd $_ && test -f Makefile && \$(MAKE) clean\n",@{$att{DIR}})); |
1238 | push(@m, " rm -f *~ t/*~ *.o *.a mon.out core so_locations \$(BOOTSTRAP) \$(BASEEXT).bso\n"); |
1239 | my(@otherfiles); |
1240 | # Automatically delete the .c files generated from *.xs files: |
1241 | push(@otherfiles, values %{$att{XS}}); |
1242 | push(@otherfiles, $attribs{FILES}) if $attribs{FILES}; |
1243 | push(@m, " rm -rf @otherfiles\n") if @otherfiles; |
1244 | push(@m, " $attribs{POSTOP}\n") if $attribs{POSTOP}; |
1245 | join("", @m); |
1246 | } |
a0d0e21e |
1247 | |
1248 | sub realclean { |
42793c05 |
1249 | my($self, %attribs) = @_; |
1250 | my(@m); |
1251 | push(@m,' |
1252 | # Delete temporary files (via clean) and also delete installed files |
1253 | realclean purge :: clean |
1254 | '); |
1255 | # clean subdirectories first |
1256 | push(@m, map("\t-cd $_ && test -f Makefile && \$(MAKE) realclean\n",@{$att{DIR}})); |
1257 | push(@m, ' rm -f Makefile $(INST_DYNAMIC) $(INST_STATIC) $(INST_BOOT) $(INST_PM)'."\n"); |
1258 | push(@m, ' rm -rf $(INST_AUTODIR) $(INST_ARCHAUTODIR)'."\n"); |
1259 | my(@otherfiles); |
1260 | push(@otherfiles, $attribs{FILES}) if $attribs{FILES}; |
1261 | push(@m, " rm -rf @otherfiles\n") if @otherfiles; |
1262 | push(@m, " $attribs{POSTOP}\n") if $attribs{POSTOP}; |
1263 | join("", @m); |
1264 | } |
a0d0e21e |
1265 | |
42793c05 |
1266 | |
1267 | sub distclean { |
1268 | my($self, %attribs) = @_; |
1269 | # VERSION should be sanitised before use as a file name |
1270 | my($tarname) = $attribs{TARNAME} || '$(DISTNAME)-$(VERSION)'; |
1271 | my($tarflags) = $attribs{TARFLAGS} || 'cvf'; |
1272 | my($compress) = $attribs{COMPRESS} || 'compress'; # eg gzip |
1273 | my($preop) = $attribs{PREOP} || '@:'; # e.g., update MANIFEST |
1274 | my($postop) = $attribs{POSTOP} || '@:'; |
1275 | my($mkfiles) = join(' ', map("$_/Makefile", ".", @{$att{DIR}})); |
1276 | " |
1277 | distclean: clean |
1278 | $preop |
1279 | rm -f $mkfiles |
1280 | cd ..; tar $tarflags $tarname.tar \$(BASEEXT) |
1281 | cd ..; $compress $tarname.tar |
1282 | $postop |
1283 | "; |
a0d0e21e |
1284 | } |
1285 | |
1286 | |
42793c05 |
1287 | # --- Test and Installation Sections --- |
1288 | |
a0d0e21e |
1289 | sub test { |
42793c05 |
1290 | my($self, %attribs) = @_; |
1291 | my($tests) = $attribs{TESTS} || (-d "t" ? "t/*.t" : ""); |
1292 | my(@m); |
1293 | push(@m," |
1294 | test :: all |
1295 | "); |
1296 | push(@m, <<"END") if $tests; |
1297 | \$(FULLPERL) -I\$(PERL_ARCHLIB) -I\$(PERL_LIB) -e 'use Test::Harness; runtests \@ARGV;' $tests |
1298 | END |
1299 | push(@m, <<'END') if -f "test.pl"; |
1300 | $(FULLPERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) test.pl |
1301 | END |
1302 | push(@m, map("\tcd $_ && test -f Makefile && \$(MAKE) test LINKTYPE=\$(LINKTYPE)\n",@{$att{DIR}})); |
1303 | push(@m, "\t\@echo 'No tests defined for \$(NAME) extension.'\n") unless @m > 1; |
1304 | join("", @m); |
a0d0e21e |
1305 | } |
1306 | |
1307 | |
1308 | sub install { |
1309 | ' |
42793c05 |
1310 | install :: all |
1311 | # install is not defined. Makefile, by default, builds the extension |
1312 | # directly into $(INST_LIB) so "installing" does not make much sense. |
1313 | # If INST_LIB is in the perl source tree then installperl will install |
1314 | # the extension when it installs perl. |
a0d0e21e |
1315 | '; |
1316 | } |
1317 | |
1318 | |
42793c05 |
1319 | sub force { |
1320 | '# Phony target to force checking subdirectories. |
1321 | FORCE: |
a0d0e21e |
1322 | '; |
1323 | } |
1324 | |
1325 | |
1326 | sub perldepend { |
42793c05 |
1327 | my(@m); |
1328 | push(@m,' |
1329 | PERL_HDRS = $(PERL_INC)/EXTERN.h $(PERL_INC)/INTERN.h \ |
1330 | $(PERL_INC)/XSUB.h $(PERL_INC)/av.h $(PERL_INC)/cop.h \ |
1331 | $(PERL_INC)/cv.h $(PERL_INC)/dosish.h $(PERL_INC)/embed.h \ |
1332 | $(PERL_INC)/form.h $(PERL_INC)/gv.h $(PERL_INC)/handy.h \ |
1333 | $(PERL_INC)/hv.h $(PERL_INC)/keywords.h $(PERL_INC)/mg.h \ |
1334 | $(PERL_INC)/op.h $(PERL_INC)/opcode.h $(PERL_INC)/patchlevel.h \ |
1335 | $(PERL_INC)/perl.h $(PERL_INC)/perly.h $(PERL_INC)/pp.h \ |
1336 | $(PERL_INC)/proto.h $(PERL_INC)/regcomp.h $(PERL_INC)/regexp.h \ |
1337 | $(PERL_INC)/scope.h $(PERL_INC)/sv.h $(PERL_INC)/unixish.h \ |
1338 | $(PERL_INC)/util.h |
1339 | |
1340 | $(OBJECT) : $(PERL_HDRS) |
1341 | '); |
1342 | # Don't output this if PERL_SRC not available: |
1343 | push(@m,' |
1344 | $(PERL_INC)/config.h: $(PERL_SRC)/config.sh; cd $(PERL_SRC); /bin/sh config_h.SH |
1345 | $(PERL_INC)/embed.h: $(PERL_SRC)/config.sh; cd $(PERL_SRC); /bin/sh embed_h.SH |
1346 | '); |
1347 | # This needs a better home: |
1348 | push(@m, join(" ", values %{$att{XS}})." : \$(XSUBPPDEPS)\n") |
1349 | if %{$att{XS}}; |
1350 | join("\n",@m); |
1351 | } |
1352 | |
1353 | |
1354 | sub makefile { |
1355 | # We do not know what target was originally specified so we |
1356 | # must force a manual rerun to be sure. But as it would only |
1357 | # happen very rarely it is not a significant problem. |
a0d0e21e |
1358 | ' |
1359 | $(OBJECT) : Makefile |
42793c05 |
1360 | |
1361 | Makefile: Makefile.PL $(CONFIGDEP) |
1362 | $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) Makefile.PL |
1363 | @echo "Now you must rerun make."; false |
a0d0e21e |
1364 | '; |
1365 | } |
1366 | |
1367 | |
1368 | sub postamble{ |
1369 | ""; |
1370 | } |
1371 | |
1372 | |
42793c05 |
1373 | # --- Determine libraries to use and how to use them --- |
1374 | |
1375 | sub extliblist{ |
1376 | my($self, $libs) = @_; |
1377 | return ("", "", "") unless $libs; |
1378 | print STDERR "Potential libraries are '$libs':" if $Verbose; |
1379 | my(@old) = MY->old_extliblist($libs); |
1380 | my(@new) = MY->new_extliblist($libs); |
1381 | |
1382 | my($oldlibs) = join(" : ",@old); |
1383 | my($newlibs) = join(" : ",@new); |
1384 | warn "Warning (non-fatal): $att{NAME} extliblist consistency check failed:\n". |
1385 | " old: $oldlibs\n". |
1386 | " new: $newlibs\n". |
1387 | "Using 'new' set. Please notify perl5-porters\@isu.edu.\n" |
1388 | if "$newlibs" ne "$oldlibs"; |
1389 | @new; |
a0d0e21e |
1390 | } |
1391 | |
1392 | |
42793c05 |
1393 | sub old_extliblist { |
1394 | my($self, $potential_libs)=@_; |
1395 | return ("", "", "") unless $potential_libs; |
1396 | |
1397 | my(%attrib, @w); |
1398 | # Now run ext/util/extliblist to discover what *libs definitions |
1399 | # are required for the needs of $potential_libs |
1400 | $ENV{'potential_libs'} = $potential_libs; |
1401 | my(@o)=`. $att{PERL_SRC}/config.sh |
1402 | . $att{PERL_SRC}/ext/util/extliblist; |
1403 | echo EXTRALIBS=\$extralibs |
1404 | echo BSLOADLIBS=\$dynaloadlibs |
1405 | echo LDLOADLIBS=\$statloadlibs |
1406 | `; |
1407 | foreach $line (@o){ |
1408 | chomp $line; |
1409 | if ($line =~ /(.*)\s*=\s*(.*)\s*$/){ |
1410 | $attrib{$1} = $2; |
1411 | print STDERR " $1 = $2" if $Verbose; |
1412 | }else{ |
1413 | push(@w, $line); |
1414 | } |
1415 | } |
1416 | print STDERR "Messages from extliblist:\n", join("\n",@w,'') |
1417 | if @w ; |
1418 | @attrib{qw(EXTRALIBS BSLOADLIBS LDLOADLIBS)}; |
1419 | } |
1420 | |
1421 | |
1422 | sub new_extliblist { |
1423 | my($self, $potential_libs)=@_; |
1424 | return ("", "", "") unless $potential_libs; |
1425 | |
1426 | my($so) = $Config{'so'}; |
1427 | my($libs) = $Config{'libs'}; |
1428 | |
1429 | # compute $extralibs, $bsloadlibs and $ldloadlibs from |
1430 | # $potential_libs |
1431 | # this is a rewrite of Andy Dougherty's extliblist in perl |
1432 | # its home is in <distribution>/ext/util |
1433 | |
1434 | my(@searchpath); # from "-L/path" entries in $potential_libs |
1435 | my(@libpath) = split " ", $Config{'libpth'}; |
1436 | my(@ldloadlibs); |
1437 | my(@bsloadlibs); |
1438 | my(@extralibs); |
1439 | my($fullname); |
1440 | my($pwd) = fastcwd(); # from Cwd.pm |
1441 | |
1442 | foreach $thislib (split ' ', $potential_libs){ |
1443 | |
1444 | # Handle possible linker path arguments. |
1445 | if ($thislib =~ s/^(-[LR])//){ # save path flag type |
1446 | my($ptype) = $1; |
1447 | unless (-d $thislib){ |
1448 | warn "$ptype$thislib ignored, directory does not exist\n" |
1449 | if $Verbose; |
1450 | next; |
1451 | } |
1452 | if ($thislib !~ m|^/|) { |
1453 | warn "Warning: $ptype$thislib changed to $ptype$pwd/$thislib\n"; |
1454 | $thislib = "$pwd/$thislib"; |
1455 | } |
1456 | push(@searchpath, $thislib); |
1457 | push(@extralibs, "$ptype$thislib"); |
1458 | push(@ldloadlibs, "$ptype$thislib"); |
1459 | next; |
1460 | } |
1461 | |
1462 | # Handle possible library arguments. |
1463 | unless ($thislib =~ s/^-l//){ |
1464 | warn "Unrecognized argument in LIBS ignored: '$thislib'\n"; |
1465 | next; |
1466 | } |
1467 | |
1468 | my($found_lib)=0; |
1469 | foreach $thispth (@searchpath, @libpath){ |
1470 | |
1471 | if (@fullname=<${thispth}/lib${thislib}.${so}.[0-9]*>){ |
1472 | $fullname=$fullname[-1]; #ATTN: 10 looses against 9! |
1473 | } elsif (-f ($fullname="$thispth/lib$thislib.$so")){ |
1474 | } elsif (-f ($fullname="$thispth/lib${thislib}_s.a")){ |
1475 | } elsif (-f ($fullname="$thispth/lib$thislib.a")){ |
1476 | } elsif (-f ($fullname="$thispth/Slib$thislib.a")){ |
1477 | } else { |
1478 | warn "$thislib not found in $thispth\n" if $Verbose; |
1479 | next; |
1480 | } |
1481 | warn "'-l$thislib' found at $fullname\n" if $Verbose; |
1482 | $found_lib++; |
1483 | |
1484 | # Now update library lists |
1485 | |
1486 | # what do we know about this library... |
1487 | my $is_dyna = ($fullname !~ /\.a$/); |
1488 | my $in_perl = ($libs =~ /\B-l${thislib}\b|\B-l${thislib}_s\b/s); |
1489 | |
1490 | # Do not add it into the list if it is already linked in |
1491 | # with the main perl executable. |
1492 | # We have to special-case the NeXT, because all the math is also in libsys_s |
1493 | unless ( $in_perl || ($Config{'osname'} eq 'next' && $thislib eq 'm') ){ |
1494 | push(@extralibs, "-l$thislib"); |
1495 | } |
1496 | |
1497 | |
1498 | # We might be able to load this archive file dynamically |
1499 | if ( $Config{'dlsrc'} =~ /dl_next|dl_dld/){ |
1500 | # We push -l$thislib instead of $fullname because |
1501 | # it avoids hardwiring a fixed path into the .bs file. |
1502 | # mkbootstrap will automatically add dl_findfile() to |
1503 | # the .bs file if it sees a name in the -l format. |
1504 | # USE THIS LATER: push(@bsloadlibs, "-l$thislib"); # " $fullname"; |
1505 | # USE THIS while checking results against old_extliblist |
1506 | push(@bsloadlibs, "$fullname"); |
1507 | } else { |
1508 | if ($is_dyna){ |
1509 | # For SunOS4, do not add in this shared library if |
1510 | # it is already linked in the main perl executable |
1511 | push(@ldloadlibs, "-l$thislib") |
1512 | unless ($in_perl and $Config{'osname'} eq 'sunos'); |
1513 | } else { |
1514 | push(@ldloadlibs, "-l$thislib"); |
1515 | } |
1516 | } |
1517 | last; # found one here so don't bother looking further |
1518 | } |
1519 | warn "Warning (non-fatal): No library found for -l$thislib\n" unless $found_lib>0; |
1520 | } |
1521 | ("@extralibs", "@bsloadlibs", "@ldloadlibs"); |
1522 | } |
1523 | |
1524 | |
1525 | # --- Write a DynaLoader bootstrap file if required |
a0d0e21e |
1526 | |
1527 | sub mkbootstrap { |
a0d0e21e |
1528 | |
42793c05 |
1529 | =head1 NAME |
1530 | |
1531 | mkbootstrap |
1532 | |
1533 | =head1 DESCRIPTION |
1534 | |
1535 | Make a bootstrap file for use by this system's DynaLoader. |
1536 | It typically gets called from an extension Makefile. |
1537 | |
1538 | There is no .bs file supplied with the extension. Instead a _BS file |
1539 | which has code for the special cases, like posix for berkeley db on the |
1540 | NeXT. |
1541 | |
1542 | This file will get parsed, and produce a maybe empty |
1543 | @DynaLoader::dl_resolve_using array for the current architecture. |
1544 | That will be extended by $BSLOADLIBS, which was computed by Andy's |
1545 | extliblist script. If this array still is empty, we do nothing, else |
1546 | we write a .bs file with an @DynaLoader::dl_resolve_using array, but |
1547 | without any C<if>s, because there is no longer a need to deal with |
1548 | special cases. |
1549 | |
1550 | The _BS file can put some code into the generated .bs file by placing |
1551 | it in $bscode. This is a handy 'escape' mechanism that may prove |
1552 | useful in complex situations. |
1553 | |
1554 | If @DynaLoader::dl_resolve_using contains C<-L*> or C<-l*> entries then |
1555 | mkbootstrap will automatically add a dl_findfile() call to the |
1556 | generated .bs file. |
1557 | |
1558 | =head1 AUTHORS |
1559 | |
1560 | Andreas Koenig <k@otto.ww.TU-Berlin.DE>, Tim Bunce |
1561 | <Tim.Bunce@ig.co.uk>, Andy Dougherty <doughera@lafcol.lafayette.edu> |
1562 | |
1563 | =cut |
1564 | |
1565 | my($self, @bsloadlibs)=@_; |
1566 | |
1567 | @bsloadlibs = grep($_, @bsloadlibs); # strip empty libs |
1568 | |
1569 | print STDERR " bsloadlibs=@bsloadlibs\n" if $Verbose; |
1570 | |
1571 | # We need DynaLoader here because we and/or the *_BS file may |
1572 | # call dl_findfile(). We don't say `use' here because when |
1573 | # first building perl extensions the DynaLoader will not have |
1574 | # been built when MakeMaker gets first used. |
1575 | require DynaLoader; |
1576 | import DynaLoader; |
1577 | |
1578 | initialize(@ARGV) unless defined $att{'BASEEXT'}; |
a0d0e21e |
1579 | |
1580 | rename "$att{BASEEXT}.bs", "$att{BASEEXT}.bso"; |
1581 | |
1582 | if (-f "$att{BASEEXT}_BS"){ |
1583 | $_ = "$att{BASEEXT}_BS"; |
1584 | package DynaLoader; # execute code as if in DynaLoader |
1585 | local($osname, $dlsrc) = (); # avoid warnings |
42793c05 |
1586 | ($osname, $dlsrc) = @Config::Config{qw(osname dlsrc)}; |
a0d0e21e |
1587 | $bscode = ""; |
1588 | unshift @INC, "."; |
1589 | require $_; |
42793c05 |
1590 | shift @INC; |
a0d0e21e |
1591 | } |
1592 | |
1593 | if ($Config{'dlsrc'} =~ /^dl_dld/){ |
1594 | package DynaLoader; |
1595 | push(@dl_resolve_using, dl_findfile('-lc')); |
1596 | } |
1597 | |
42793c05 |
1598 | my(@all) = (@bsloadlibs, @DynaLoader::dl_resolve_using); |
a0d0e21e |
1599 | my($method) = ''; |
1600 | if (@all){ |
1601 | open BS, ">$att{BASEEXT}.bs" |
1602 | or die "Unable to open $att{BASEEXT}.bs: $!"; |
1603 | print STDOUT "Writing $att{BASEEXT}.bs\n"; |
1604 | print STDOUT " containing: @all" if $Verbose; |
1605 | print BS "# $att{BASEEXT} DynaLoader bootstrap file for $Config{'osname'} architecture.\n"; |
1606 | print BS "# Do not edit this file, changes will be lost.\n"; |
1607 | print BS "# This file was automatically generated by the\n"; |
1608 | print BS "# mkbootstrap routine in ExtUtils/MakeMaker.pm.\n"; |
1609 | print BS "\@DynaLoader::dl_resolve_using = "; |
42793c05 |
1610 | # If @all contains names in the form -lxxx or -Lxxx then it's asking for |
1611 | # runtime library location so we automatically add a call to dl_findfile() |
1612 | if (" @all" =~ m/ -[lLR]/){ |
a0d0e21e |
1613 | print BS " dl_findfile(qw(\n @all\n ));\n"; |
1614 | }else{ |
1615 | print BS " qw(@all);\n"; |
1616 | } |
1617 | # write extra code if *_BS says so |
1618 | print BS $DynaLoader::bscode if $DynaLoader::bscode; |
42793c05 |
1619 | print BS "\n1;\n"; |
a0d0e21e |
1620 | close BS; |
1621 | } |
1622 | |
42793c05 |
1623 | # special handling for systems which needs a list of all global |
1624 | # symbols exported by a modules to be dynamically linked. |
a0d0e21e |
1625 | if ($Config{'dlsrc'} =~ /^dl_aix/){ |
42793c05 |
1626 | my($bootfunc); |
1627 | ($bootfunc = $att{NAME}) =~ s/\W/_/g; |
1628 | open EXP, ">$att{BASEEXT}.exp"; |
1629 | print EXP "#!\nboot_$bootfunc\n"; |
1630 | close EXP; |
a0d0e21e |
1631 | } |
1632 | } |
1633 | |
42793c05 |
1634 | |
1635 | # --- Output postprocessing section --- |
1636 | #nicetext is included to make VMS support easier |
1637 | sub nicetext { # Just return the input - no action needed |
1638 | my($self,$text) = @_; |
1639 | $text; |
1640 | } |
1641 | |
1642 | # the following keeps AutoSplit happy |
a0d0e21e |
1643 | package ExtUtils::MakeMaker; |
1644 | 1; |
1645 | |
1646 | __END__ |
42793c05 |
1647 | |