b0468310254c685f72307f7f91180e29461d69c1
[p5sagit/p5-mst-13.2.git] / Porting / pumpkin.pod
1 =head1 NAME
2
3 Pumpkin - Notes on handling the Perl Patch Pumpkin
4
5 =head1 SYNOPSIS
6
7 There is no simple synopsis, yet.
8
9 =head1 DESCRIPTION
10
11 This document attempts to begin to describe some of the
12 considerations involved in patching and maintaining perl.
13
14 This document is still under construction, and still subject to
15 significant changes.  Still, I hope parts of it will be useful,
16 so I'm releasing it even though it's not done.
17
18 For the most part, it's a collection of anecdotal information that
19 already assumes some familiarity with the Perl sources.  I really need
20 an introductory section that describes the organization of the sources
21 and all the various auxiliary files that are part of the distribution.
22
23 =head1 Where Do I Get Perl Sources and Related Material?
24
25 The Comprehensive Perl Archive Network (or CPAN) is the place to go.
26 There are many mirrors, but the easiest thing to use is probably
27 http://www.perl.com/CPAN/README.html , which automatically points you to a
28 mirror site "close" to you.
29
30 =head2 Perl5-porters mailing list
31
32 The mailing list perl5-porters@perl.org
33 is the main group working with the development of perl.  If you're
34 interested in all the latest developments, you should definitely
35 subscribe.  The list is high volume, but generally has a
36 fairly low noise level.
37
38 Subscribe by sending the message (in the body of your letter)
39
40         subscribe perl5-porters
41
42 to perl5-porters-request@perl.org .
43
44 Archives of the list are held at:
45
46     http://www.rosat.mpe-garching.mpg.de/mailing-lists/perl-porters/
47
48 =head1 How are Perl Releases Numbered?
49
50 Perl version numbers are floating point numbers, such as 5.004.
51 (Observations about the imprecision of floating point numbers for
52 representing reality probably have more relevance than you might
53 imagine :-) The major version number is 5 and the '004' is the
54 patchlevel.  (Questions such as whether or not '004' is really a minor
55 version number can safely be ignored.:)
56
57 The version number is available as the magic variable $],
58 and can be used in comparisons, e.g.
59
60         print "You've got an old perl\n" if $] < 5.002;
61
62 You can also require particular version (or later) with
63
64         use 5.002;
65
66 At some point in the future, we may need to decide what to call the
67 next big revision.  In the .package file used by metaconfig to
68 generate Configure, there are two variables that might be relevant:
69 $baserev=5.0 and $package=perl5.   At various times, I have suggested
70 we might change them to $baserev=5.1 and $package=perl5.1 if want
71 to signify a fairly major update.  Or, we might want to jump to perl6.
72 Let's worry about that problem when we get there.
73
74 =head2 Subversions
75
76 In addition, there may be "developer" sub-versions available.  These
77 are not official releases.  They may contain unstable experimental
78 features, and are subject to rapid change.  Such developer
79 sub-versions are numbered with sub-version numbers.  For example,
80 version 5.003_04 is the 4'th developer version built on top of
81 5.003.  It might include the _01, _02, and _03 changes, but it
82 also might not.  Sub-versions are allowed to be subversive. (But see
83 the next section for recent changes.)
84
85 These sub-versions can also be used as floating point numbers, so
86 you can do things such as
87
88         print "You've got an unstable perl\n" if $] == 5.00303;
89
90 You can also require particular version (or later) with
91
92         use 5.003_03;    # the "_" is optional
93
94 Sub-versions produced by the members of perl5-porters are usually
95 available on CPAN in the F<src/5.0/unsupported> directory.
96
97 =head2 Maintenance and Development Subversions
98
99 As an experiment, starting with version 5.004, subversions _01 through
100 _49 will be reserved for bug-fix maintenance releases, and subversions
101 _50 through _99 will be available for unstable development versions.
102
103 The separate bug-fix track is being established to allow us an easy
104 way to distribute important bug fixes without waiting for the
105 developers to untangle all the other problems in the current
106 developer's release.
107
108 Trial releases of bug-fix maintenance releases are announced on
109 perl5-porters. Trial releases use the new subversion number (to avoid
110 testers installing it over the previous release) and include a 'local
111 patch' entry in patchlevel.h.
112
113 Watch for announcements of maintenance subversions in
114 comp.lang.perl.announce.
115
116 =head2 Why such a complicated scheme?
117
118 Two reasons, really.  At least.
119
120 First, we need some way to identify and release collections of patches
121 that are known to have new features that need testing and exploration.  The
122 subversion scheme does that nicely while fitting into the
123 C<use 5.004;> mold.
124
125 Second, since most of the folks who help maintain perl do so on a
126 free-time voluntary basis, perl development does not proceed at a
127 precise pace, though it always seems to be moving ahead quickly.
128 We needed some way to pass around the "patch pumpkin" to allow
129 different people chances to work on different aspects of the
130 distribution without getting in each other's way.  It wouldn't be
131 constructive to have multiple people working on incompatible
132 implementations of the same idea.  Instead what was needed was
133 some kind of "baton" or "token" to pass around so everyone knew
134 whose turn was next.
135
136 =head2 Why is it called the patch pumpkin?
137
138 Chip Salzenberg gets credit for that, with a nod to his cow orker,
139 David Croy.  We had passed around various names (baton, token, hot
140 potato) but none caught on.  Then, Chip asked:
141
142 [begin quote]
143
144    Who has the patch pumpkin?
145
146 To explain:  David Croy once told me once that at a previous job,
147 there was one tape drive and multiple systems that used it for backups.
148 But instead of some high-tech exclusion software, they used a low-tech
149 method to prevent multiple simultaneous backups: a stuffed pumpkin.
150 No one was allowed to make backups unless they had the "backup pumpkin".
151
152 [end quote]
153
154 The name has stuck.
155
156 =head1 Philosophical Issues in Patching Perl
157
158 There are no absolute rules, but there are some general guidelines I
159 have tried to follow as I apply patches to the perl sources.
160 (This section is still under construction.)
161
162 =head2 Solve problems as generally as possible
163
164 Never implement a specific restricted solution to a problem when you
165 can solve the same problem in a more general, flexible way.
166
167 For example, for dynamic loading to work on some SVR4 systems, we had
168 to build a shared libperl.so library.  In order to build "FAT" binaries
169 on NeXT 4.0 systems, we had to build a special libperl library.  Rather
170 than continuing to build a contorted nest of special cases, I
171 generalized the process of building libperl so that NeXT and SVR4 users
172 could still get their work done, but others could build a shared
173 libperl if they wanted to as well.
174
175 =head2 Seek consensus on major changes
176
177 If you are making big changes, don't do it in secret.  Discuss the
178 ideas in advance on perl5-porters.
179
180 =head2 Keep the documentation up-to-date
181
182 If your changes may affect how users use perl, then check to be sure
183 that the documentation is in sync with your changes.  Be sure to
184 check all the files F<pod/*.pod> and also the F<INSTALL> document.
185
186 Consider writing the appropriate documentation first and then
187 implementing your change to correspond to the documentation.
188
189 =head2 Avoid machine-specific #ifdef's
190
191 To the extent reasonable, try to avoid machine-specific #ifdef's in
192 the sources.  Instead, use feature-specific #ifdef's.  The reason is
193 that the machine-specific #ifdef's may not be valid across major
194 releases of the operating system.  Further, the feature-specific tests
195 may help out folks on another platform who have the same problem.
196
197 =head2 Allow for lots of testing
198
199 We should never release a main version without testing it as a
200 subversion first.
201
202 =head2 Test popular applications and modules.
203
204 We should never release a main version without testing whether or not
205 it breaks various popular modules and applications.  A partial list of
206 such things would include majordomo, metaconfig, apache, Tk, CGI,
207 libnet, and libwww, to name just a few.  Of course it's quite possible
208 that some of those things will be just plain broken and need to be fixed,
209 but, in general, we ought to try to avoid breaking widely-installed
210 things.
211
212 =head2 Automate generation of derivative files
213
214 The F<embed.h>, F<keywords.h>, F<opcode.h>, and F<perltoc.pod> files
215 are all automatically generated by perl scripts.  In general, don't
216 patch these directly; patch the data files instead.
217
218 F<Configure> and F<config_h.SH> are also automatically generated by
219 B<metaconfig>.  In general, you should patch the metaconfig units
220 instead of patching these files directly.  However, very minor changes to
221 F<Configure> may be made in between major sync-ups with the metaconfig
222 units, which tends to be complicated operations.  But be careful, this
223 can quickly spiral out of control.  Running metaconfig is not really
224 hard.
225
226 Finally, the sample files in the F<Porting/> subdirectory are
227 generated automatically by the script F<U/mksample> included 
228 with the metaconfig units.  See L<"run metaconfig"> below for
229 information on obtaining the metaconfig units.
230
231 =head1 How to Make a Distribution
232
233 There really ought to be a 'make dist' target, but there isn't.
234 The 'dist' suite of tools also contains a number of tools that I haven't
235 learned how to use yet.  Some of them may make this all a bit easier.
236
237 Here are the steps I go through to prepare a patch & distribution.
238
239 Lots of it could doubtless be automated but isn't.  The Porting/makerel
240 (make release) perl script does now help automate some parts of it.
241
242 =head2 Announce your intentions
243
244 First, you should volunteer out loud to take the patch pumpkin.  It's
245 generally counter-productive to have multiple people working in secret
246 on the same thing.
247
248 At the same time, announce what you plan to do with the patch pumpkin,
249 to allow folks a chance to object or suggest alternatives, or do it for
250 you.  Naturally, the patch pumpkin holder ought to incorporate various
251 bug fixes and documentation improvements that are posted while he or
252 she has the pumpkin, but there might also be larger issues at stake.
253
254 One of the precepts of the subversion idea is that we shouldn't give
255 the patch pumpkin to anyone unless we have some idea what he or she
256 is going to do with it.
257
258 =head2 refresh pod/perltoc.pod
259
260 Presumably, you have done a full C<make> in your working source
261 directory.  Before you C<make spotless> (if you do), and if you have
262 changed any documentation in any module or pod file, change to the
263 F<pod> directory and run C<make toc>.
264
265 =head2 run installhtml to check the validity of the pod files
266
267 =head2 update patchlevel.h
268
269 Don't be shy about using the subversion number, even for a relatively
270 modest patch.  We've never even come close to using all 99 subversions,
271 and it's better to have a distinctive number for your patch.  If you
272 need feedback on your patch, go ahead and issue it and promise to
273 incorporate that feedback quickly (e.g. within 1 week) and send out a
274 second patch.
275
276 =head2 run metaconfig
277
278 If you need to make changes to Configure or config_h.SH, it may be best to
279 change the appropriate metaconfig units instead, and regenerate Configure.
280
281         metaconfig -m
282
283 will regenerate Configure and config_h.SH.  More information on
284 obtaining and running metaconfig is in the F<U/README> file that comes
285 with Perl's metaconfig units.  Perl's metaconfig units should be
286 available the same place you found this file.  On CPAN, look under my
287 directory F<authors/id/ANDYD/> for a file such as 
288 F<mc_units-5.004_70-01.tar.gz>.
289 That file should be unpacked in your main perl source directory.  It
290 contains the files needed to run B<metaconfig> to reproduce Perl's
291 Configure script.  (Those units are for 5.004_70.  There may have been
292 changes since then; please contact me if you want more recent
293 versions, and I will try to point you in the right direction.)
294
295 Alternatively, do consider if the F<*ish.h> files might be a better
296 place for your changes.
297
298 =head2 MANIFEST
299
300 Make sure the MANIFEST is up-to-date.  You can use dist's B<manicheck>
301 program for this.  You can also use
302
303     perl -w -MExtUtils::Manifest=fullcheck -e fullcheck
304
305 Both commands will also list extra files in the directory that are not
306 listed in MANIFEST.
307
308 The MANIFEST is normally sorted.
309
310 If you are using metaconfig to regenerate Configure, then you should note
311 that metaconfig actually uses MANIFEST.new, so you want to be sure
312 MANIFEST.new is up-to-date too.  I haven't found the MANIFEST/MANIFEST.new
313 distinction particularly useful, but that's probably because I still haven't
314 learned how to use the full suite of tools in the dist distribution.
315
316 =head2 Check permissions
317
318 All the tests in the t/ directory ought to be executable.  The
319 main makefile used to do a 'chmod t/*/*.t', but that resulted in
320 a self-modifying distribution--something some users would strongly
321 prefer to avoid.  Probably, the F<t/TEST> script should check for this
322 and do the chmod if needed, but it doesn't currently.
323
324 In all, the following files should probably be executable:
325
326     Configure
327     configpm
328     configure.gnu
329     embed.pl
330     installperl
331     installman
332     keywords.pl
333     myconfig
334     opcode.pl
335     perly.fixer
336     t/TEST
337     t/*/*.t
338     *.SH
339     vms/ext/Stdio/test.pl
340     vms/ext/filespec.t
341     x2p/*.SH
342
343 Other things ought to be readable, at least :-).
344
345 Probably, the permissions for the files could be encoded in MANIFEST
346 somehow, but I'm reluctant to change MANIFEST itself because that
347 could break old scripts that use MANIFEST.
348
349 I seem to recall that some SVR3 systems kept some sort of file that listed
350 permissions for system files; something like that might be appropriate.
351
352 =head2 Run Configure
353
354 This will build a config.sh and config.h.  You can skip this if you haven't
355 changed Configure or config_h.SH at all.  I use the following command
356
357     sh Configure -Dprefix=/opt/perl -Doptimize=-O -Dusethreads \
358         -Dcf_by='yourname' \
359         -Dcf_email='yourname@yourhost.yourplace.com' \
360         -Dperladmin='yourname@yourhost.yourplace.com' \
361         -Dmydomain='.yourplace.com' \
362         -Dmyhostname='yourhost' \
363         -des
364
365 =head2 Update Porting/config.sh and Porting/config_H
366
367 [XXX 
368 This section needs revision.  We're currently working on easing
369 the task of keeping the vms, win32, and plan9 config.sh info
370 up-to-date.  The plan is to use keep up-to-date 'canned' config.sh
371 files in the appropriate subdirectories and then generate 'canned'
372 config.h files for vms, win32, etc. from the generic config.sh file.
373 This is to ease maintenance.  When Configure gets updated, the parts
374 sometimes get scrambled around, and the changes in config_H can
375 sometimes be very hard to follow.  config.sh, on the other hand, can
376 safely be sorted, so it's easy to track (typically very small) changes
377 to config.sh and then propoagate them to a canned 'config.h' by any
378 number of means, including a perl script in win32/ or carrying 
379 config.sh and config_h.SH to a Unix system and running sh
380 config_h.SH.)
381 XXX]
382
383 The Porting/config.sh and Porting/config_H files are provided to
384 help those folks who can't run Configure.  It is important to keep
385 them up-to-date.  If you have changed config_h.SH, those changes must
386 be reflected in config_H as well.  (The name config_H was chosen to
387 distinguish the file from config.h even on case-insensitive file systems.)
388 Simply edit the existing config_H file; keep the first few explanatory
389 lines and then copy your new config.h below.
390
391 It may also be necessary to update vms/config.vms and
392 plan9/config.plan9, though you should be quite careful in doing so if
393 you are not familiar with those systems.  You might want to issue your
394 patch with a promise to quickly issue a follow-up that handles those
395 directories.
396
397 =head2 make run_byacc
398
399 If you have byacc-1.8.2 (available from CPAN), and if there have been
400 changes to F<perly.y>, you can regenerate the F<perly.c> file.  The
401 run_byacc makefile target does this by running byacc and then applying
402 some patches so that byacc dynamically allocates space, rather than
403 having fixed limits.  This patch is handled by the F<perly.fixer>
404 script.  Depending on the nature of the changes to F<perly.y>, you may
405 or may not have to hand-edit the patch to apply correctly.  If you do,
406 you should include the edited patch in the new distribution.  If you
407 have byacc-1.9, the patch won't apply cleanly.  Changes to the printf
408 output statements mean the patch won't apply cleanly.  Long ago I
409 started to fix F<perly.fixer> to detect this, but I never completed the
410 task.
411
412 Some additional notes from Larry on this:
413
414 Don't forget to regenerate perly.c.diff.
415
416     byacc -d perly.y
417     mv y.tab.c perly.c
418     patch perly.c <perly.c.diff
419     # manually apply any failed hunks
420     diff -c2 perly.c.orig perly.c >perly.c.diff
421
422 One chunk of lines that often fails begins with
423
424     #line 29 "perly.y"
425
426 and ends one line before
427
428     #define YYERRCODE 256
429
430 This only happens when you add or remove a token type.  I suppose this
431 could be automated, but it doesn't happen very often nowadays.
432
433 Larry
434
435 =head2 make regen_headers
436
437 The F<embed.h>, F<keywords.h>, and F<opcode.h> files are all automatically
438 generated by perl scripts.  Since the user isn't guaranteed to have a
439 working perl, we can't require the user to generate them.  Hence you have
440 to, if you're making a distribution.
441
442 I used to include rules like the following in the makefile:
443
444     # The following three header files are generated automatically
445     # The correct versions should be already supplied with the perl kit,
446     # in case you don't have perl or 'sh' available.
447     # The - is to ignore error return codes in case you have the source
448     # installed read-only or you don't have perl yet.
449     keywords.h: keywords.pl
450             @echo "Don't worry if this fails."
451             - perl keywords.pl
452
453
454 However, I got B<lots> of mail consisting of people worrying because the
455 command failed.  I eventually decided that I would save myself time
456 and effort by manually running C<make regen_headers> myself rather
457 than answering all the questions and complaints about the failing
458 command.
459
460 =head2 global.sym, interp.sym and perlio.sym
461
462 Make sure these files are up-to-date.  Read the comments in these
463 files and in perl_exp.SH to see what to do.
464
465 =head2 Binary compatibility
466
467 If you do change F<global.sym> or F<interp.sym>, think carefully about
468 what you are doing.  To the extent reasonable, we'd like to maintain
469 souce and binary compatibility with older releases of perl.  That way,
470 extensions built under one version of perl will continue to work with
471 new versions of perl.
472
473 Of course, some incompatible changes may well be necessary.  I'm just
474 suggesting that we not make any such changes without thinking carefully
475 about them first.  If possible, we should provide
476 backwards-compatibility stubs.  There's a lot of XS code out there.
477 Let's not force people to keep changing it.
478
479 =head2 Changes
480
481 Be sure to update the F<Changes> file.  Try to include both an overall
482 summary as well as detailed descriptions of the changes.  Your
483 audience will include other developers and users, so describe
484 user-visible changes (if any) in terms they will understand, not in
485 code like "initialize foo variable in bar function".
486
487 There are differing opinions on whether the detailed descriptions
488 ought to go in the Changes file or whether they ought to be available
489 separately in the patch file (or both).  There is no disagreement that
490 detailed descriptions ought to be easily available somewhere.
491
492 =head2 Todo
493
494 The F<Todo> file contains a roughly-catgorized unordered list of
495 aspects of Perl that could use enhancement, features that could be
496 added, areas that could be cleaned up, and so on.  During your term as
497 pumpkin-holder, you will probably address some of these issues, and
498 perhaps identify others which, while you decide not to address them
499 this time around, may be tackled in the future.  Update the file
500 reflect the situation as it stands when you hand over the pumpkin.
501
502 You might like, early in your pumpkin-holding career, to see if you
503 can find champions for partiticular issues on the to-do list: an issue
504 owned is an issue more likely to be resolved.
505
506 There are also some more porting-specific L<Todo> items later in this
507 file.
508
509 =head2 OS/2-specific updates
510
511 In the os2 directory is F<diff.configure>, a set of OS/2-specific
512 diffs against B<Configure>.  If you make changes to Configure, you may
513 want to consider regenerating this diff file to save trouble for the
514 OS/2 maintainer.
515
516 You can also consider the OS/2 diffs as reminders of portability
517 things that need to be fixed in Configure.
518
519 =head2 VMS-specific updates
520
521 If you have changed F<perly.y>, then you may want to update
522 F<vms/perly_{h,c}.vms> by running C<perl vms/vms_yfix.pl>.
523
524 The Perl version number appears in several places under F<vms>.
525 It is courteous to update these versions.  For example, if you are
526 making 5.004_42, replace "5.00441" with "5.00442".
527
528 =head2 Making the new distribution
529
530 Suppose, for example, that you want to make version 5.004_08.  Then you can
531 do something like the following
532
533         mkdir ../perl5.004_08
534         awk '{print $1}' MANIFEST | cpio -pdm ../perl5.004_08
535         cd ../
536         tar cf perl5.004_08.tar perl5.004_08
537         gzip --best perl5.004_08.tar
538
539 These steps, with extra checks, are automated by the Porting/makerel
540 script.
541
542 =head2 Making a new patch
543
544 I find the F<makepatch> utility quite handy for making patches.
545 You can obtain it from any CPAN archive under
546 http://www.perl.com/CPAN/authors/Johan_Vromans/ .  There are a couple
547 of differences between my version and the standard one. I have mine do
548 a
549
550         # Print a reassuring "End of Patch" note so people won't
551         # wonder if their mailer truncated patches.
552         print "\n\nEnd of Patch.\n";
553
554 at the end.  That's because I used to get questions from people asking
555 if their mail was truncated.
556
557 It also writes Index: lines which include the new directory prefix
558 (change Index: print, approx line 294 or 310 depending on the version,
559 to read:  print PATCH ("Index: $newdir$new\n");).  That helps patches
560 work with more POSIX conformant patch programs.
561
562 Here's how I generate a new patch.  I'll use the hypothetical
563 5.004_07 to 5.004_08 patch as an example.
564
565         # unpack perl5.004_07/
566         gzip -d -c perl5.004_07.tar.gz | tar -xof -
567         # unpack perl5.004_08/
568         gzip -d -c perl5.004_08.tar.gz | tar -xof -
569         makepatch perl5.004_07 perl5.004_08 > perl5.004_08.pat
570
571 Makepatch will automatically generate appropriate B<rm> commands to remove
572 deleted files.  Unfortunately, it will not correctly set permissions
573 for newly created files, so you may have to do so manually.  For example,
574 patch 5.003_04 created a new test F<t/op/gv.t> which needs to be executable,
575 so at the top of the patch, I inserted the following lines:
576
577         # Make a new test
578         touch t/op/gv.t
579         chmod +x t/opt/gv.t
580
581 Now, of course, my patch is now wrong because makepatch didn't know I
582 was going to do that command, and it patched against /dev/null.
583
584 So, what I do is sort out all such shell commands that need to be in the
585 patch (including possible mv-ing of files, if needed) and put that in the
586 shell commands at the top of the patch.  Next, I delete all the patch parts
587 of perl5.004_08.pat, leaving just the shell commands.  Then, I do the
588 following:
589
590         cd perl5.004_07
591         sh ../perl5.004_08.pat
592         cd ..
593         makepatch perl5.004_07 perl5.004_08 >> perl5.004_08.pat
594
595 (Note the append to preserve my shell commands.)
596 Now, my patch will line up with what the end users are going to do.
597
598 =head2 Testing your patch
599
600 It seems obvious, but be sure to test your patch.  That is, verify that
601 it produces exactly the same thing as your full distribution.
602
603         rm -rf perl5.004_07
604         gzip -d -c perl5.004_07.tar.gz | tar -xf -
605         cd perl5.004_07
606         sh ../perl5.004_08.pat
607         patch -p1 -N < ../perl5.004_08.pat
608         cd ..
609         gdiff -r perl5.004_07 perl5.004_08
610
611 where B<gdiff> is GNU diff.  Other diff's may also do recursive checking.
612
613 =head2 More testing
614
615 Again, it's obvious, but you should test your new version as widely as you
616 can.  You can be sure you'll hear about it quickly if your version doesn't
617 work on both ANSI and pre-ANSI compilers, and on common systems such as
618 SunOS 4.1.[34], Solaris, and Linux.
619
620 If your changes include conditional code, try to test the different
621 branches as thoroughly as you can.  For example, if your system
622 supports dynamic loading, you can also test static loading with
623
624         sh Configure -Uusedl
625
626 You can also hand-tweak your config.h to try out different #ifdef
627 branches.
628
629 =head1 Common Gotcha's
630
631 =over 4
632
633 =item #elif
634
635 The '#elif' preprocessor directive is not understood on all systems.
636 Specifically, I know that Pyramids don't understand it.  Thus instead of the
637 simple
638
639         #if defined(I_FOO)
640         #  include <foo.h>
641         #elif defined(I_BAR)
642         #  include <bar.h>
643         #else
644         #  include <fubar.h>
645         #endif
646
647 You have to do the more Byzantine
648
649         #if defined(I_FOO)
650         #  include <foo.h>
651         #else
652         #  if defined(I_BAR)
653         #    include <bar.h>
654         #  else
655         #    include <fubar.h>
656         #  endif
657         #endif
658
659 Incidentally, whitespace between the leading '#' and the preprocessor
660 command is not guaranteed, but is very portable and you may use it freely.
661 I think it makes things a bit more readable, especially once things get
662 rather deeply nested.  I also think that things should almost never get
663 too deeply nested,  so it ought to be a moot point :-)
664
665 =item Probably Prefer POSIX
666
667 It's often the case that you'll need to choose whether to do
668 something the BSD-ish way or the POSIX-ish way.  It's usually not
669 a big problem when the two systems use different names for similar
670 functions, such as memcmp() and bcmp().  The perl.h header file
671 handles these by appropriate #defines, selecting the POSIX mem*()
672 functions if available, but falling back on the b*() functions, if
673 need be.
674
675 More serious is the case where some brilliant person decided to
676 use the same function name but give it a different meaning or
677 calling sequence :-).  getpgrp() and setpgrp() come to mind.
678 These are a real problem on systems that aim for conformance to
679 one standard (e.g. POSIX), but still try to support the other way
680 of doing things (e.g. BSD).  My general advice (still not really
681 implemented in the source) is to do something like the following.
682 Suppose there are two alternative versions, fooPOSIX() and
683 fooBSD().
684
685     #ifdef HAS_FOOPOSIX
686         /* use fooPOSIX(); */
687     #else
688     #  ifdef HAS_FOOBSD
689         /* try to emulate fooPOSIX() with fooBSD();
690            perhaps with the following:  */
691     #    define fooPOSIX fooBSD
692     #  else
693     #  /* Uh, oh.  We have to supply our own. */
694     #    define fooPOSIX Perl_fooPOSIX
695     #  endif
696     #endif
697
698 =item Think positively
699
700 If you need to add an #ifdef test, it is usually easier to follow if you
701 think positively, e.g.
702
703         #ifdef HAS_NEATO_FEATURE
704             /* use neato feature */
705         #else
706             /* use some fallback mechanism */
707         #endif
708
709 rather than the more impenetrable
710
711         #ifndef MISSING_NEATO_FEATURE
712             /* Not missing it, so we must have it, so use it */
713         #else
714             /* Are missing it, so fall back on something else. */
715         #endif
716
717 Of course for this toy example, there's not much difference.  But when
718 the #ifdef's start spanning a couple of screen fulls, and the #else's
719 are marked something like
720
721         #else /* !MISSING_NEATO_FEATURE */
722
723 I find it easy to get lost.
724
725 =item Providing Missing Functions -- Problem
726
727 Not all systems have all the neat functions you might want or need, so
728 you might decide to be helpful and provide an emulation.  This is
729 sound in theory and very kind of you, but please be careful about what
730 you name the function.  Let me use the C<pause()> function as an
731 illustration.
732
733 Perl5.003 has the following in F<perl.h>
734
735     #ifndef HAS_PAUSE
736     #define pause() sleep((32767<<16)+32767)
737     #endif
738
739 Configure sets HAS_PAUSE if the system has the pause() function, so
740 this #define only kicks in if the pause() function is missing.
741 Nice idea, right?
742
743 Unfortunately, some systems apparently have a prototype for pause()
744 in F<unistd.h>, but don't actually have the function in the library.
745 (Or maybe they do have it in a library we're not using.)
746
747 Thus, the compiler sees something like
748
749     extern int pause(void);
750     /* . . . */
751     #define pause() sleep((32767<<16)+32767)
752
753 and dies with an error message.  (Some compilers don't mind this;
754 others apparently do.)
755
756 To work around this, 5.003_03 and later have the following in perl.h:
757
758     /* Some unistd.h's give a prototype for pause() even though
759        HAS_PAUSE ends up undefined.  This causes the #define
760        below to be rejected by the compiler.  Sigh.
761     */
762     #ifdef HAS_PAUSE
763     #  define Pause     pause
764     #else
765     #  define Pause() sleep((32767<<16)+32767)
766     #endif
767
768 This works.
769
770 The curious reader may wonder why I didn't do the following in
771 F<util.c> instead:
772
773     #ifndef HAS_PAUSE
774     void pause()
775     {
776     sleep((32767<<16)+32767);
777     }
778     #endif
779
780 That is, since the function is missing, just provide it.
781 Then things would probably be been alright, it would seem.
782
783 Well, almost.  It could be made to work.  The problem arises from the
784 conflicting needs of dynamic loading and namespace protection.
785
786 For dynamic loading to work on AIX (and VMS) we need to provide a list
787 of symbols to be exported.  This is done by the script F<perl_exp.SH>,
788 which reads F<global.sym> and F<interp.sym>.  Thus, the C<pause>
789 symbol would have to be added to F<global.sym>  So far, so good.
790
791 On the other hand, one of the goals of Perl5 is to make it easy to
792 either extend or embed perl and link it with other libraries.  This
793 means we have to be careful to keep the visible namespace "clean".
794 That is, we don't want perl's global variables to conflict with
795 those in the other application library.  Although this work is still
796 in progress, the way it is currently done is via the F<embed.h> file.
797 This file is built from the F<global.sym> and F<interp.sym> files,
798 since those files already list the globally visible symbols.  If we
799 had added C<pause> to global.sym, then F<embed.h> would contain the
800 line
801
802     #define pause       Perl_pause
803
804 and calls to C<pause> in the perl sources would now point to
805 C<Perl_pause>.  Now, when B<ld> is run to build the F<perl> executable,
806 it will go looking for C<perl_pause>, which probably won't exist in any
807 of the standard libraries.  Thus the build of perl will fail.
808
809 Those systems where C<HAS_PAUSE> is not defined would be ok, however,
810 since they would get a C<Perl_pause> function in util.c.  The rest of
811 the world would be in trouble.
812
813 And yes, this scenario has happened.  On SCO, the function C<chsize>
814 is available.  (I think it's in F<-lx>, the Xenix compatibility
815 library.)  Since the perl4 days (and possibly before), Perl has
816 included a C<chsize> function that gets called something akin to
817
818     #ifndef HAS_CHSIZE
819     I32 chsize(fd, length)
820     /*  . . . */
821     #endif
822
823 When 5.003 added
824
825     #define chsize      Perl_chsize
826
827 to F<embed.h>, the compile started failing on SCO systems.
828
829 The "fix" is to give the function a different name.  The one
830 implemented in 5.003_05 isn't optimal, but here's what was done:
831
832     #ifdef HAS_CHSIZE
833     # ifdef my_chsize  /* Probably #defined to Perl_my_chsize in embed.h */
834     #   undef my_chsize
835     # endif
836     # define my_chsize chsize
837     #endif
838
839 My explanatory comment in patch 5.003_05 said:
840
841      Undef and then re-define my_chsize from Perl_my_chsize to
842      just plain chsize if this system HAS_CHSIZE.  This probably only
843      applies to SCO.  This shows the perils of having internal
844      functions with the same name as external library functions :-).
845
846 Now, we can safely put C<my_chsize> in F<global.sym>, export it, and
847 hide it with F<embed.h>.
848
849 To be consistent with what I did for C<pause>, I probably should have
850 called the new function C<Chsize>, rather than C<my_chsize>.
851 However, the perl sources are quite inconsistent on this (Consider
852 New, Mymalloc, and Myremalloc, to name just a few.)
853
854 There is a problem with this fix, however, in that C<Perl_chsize>
855 was available as a F<libperl.a> library function in 5.003, but it
856 isn't available any more (as of 5.003_07).  This means that we've
857 broken binary compatibility.  This is not good.
858
859 =item Providing missing functions -- some ideas
860
861 We currently don't have a standard way of handling such missing
862 function names.  Right now, I'm effectively thinking aloud about a
863 solution.  Some day, I'll try to formally propose a solution.
864
865 Part of the problem is that we want to have some functions listed as
866 exported but not have their names mangled by embed.h or possibly
867 conflict with names in standard system headers.  We actually already
868 have such a list at the end of F<perl_exp.SH> (though that list is
869 out-of-date):
870
871     # extra globals not included above.
872     cat <<END >> perl.exp
873     perl_init_ext
874     perl_init_fold
875     perl_init_i18nl14n
876     perl_alloc
877     perl_construct
878     perl_destruct
879     perl_free
880     perl_parse
881     perl_run
882     perl_get_sv
883     perl_get_av
884     perl_get_hv
885     perl_get_cv
886     perl_call_argv
887     perl_call_pv
888     perl_call_method
889     perl_call_sv
890     perl_requirepv
891     safecalloc
892     safemalloc
893     saferealloc
894     safefree
895
896 This still needs much thought, but I'm inclined to think that one
897 possible solution is to prefix all such functions with C<perl_> in the
898 source and list them along with the other C<perl_*> functions in
899 F<perl_exp.SH>.
900
901 Thus, for C<chsize>, we'd do something like the following:
902
903     /* in perl.h */
904     #ifdef HAS_CHSIZE
905     #  define perl_chsize chsize
906     #endif
907
908 then in some file (e.g. F<util.c> or F<doio.c>) do
909
910     #ifndef HAS_CHSIZE
911     I32 perl_chsize(fd, length)
912     /* implement the function here . . . */
913     #endif
914
915 Alternatively, we could just always use C<chsize> everywhere and move
916 C<chsize> from F<global.sym> to the end of F<perl_exp.SH>.  That would
917 probably be fine as long as our C<chsize> function agreed with all the
918 C<chsize> function prototypes in the various systems we'll be using.
919 As long as the prototypes in actual use don't vary that much, this is
920 probably a good alternative.  (As a counter-example, note how Configure
921 and perl have to go through hoops to find and use get Malloc_t and
922 Free_t for C<malloc> and C<free>.)
923
924 At the moment, this latter option is what I tend to prefer.
925
926 =item All the world's a VAX
927
928 Sorry, showing my age:-).  Still, all the world is not BSD 4.[34],
929 SVR4, or POSIX.  Be aware that SVR3-derived systems are still quite
930 common (do you have any idea how many systems run SCO?)  If you don't
931 have a bunch of v7 manuals handy, the metaconfig units (by default
932 installed in F</usr/local/lib/dist/U>) are a good resource to look at
933 for portability.
934
935 =back
936
937 =head1 Miscellaneous Topics
938
939 =head2 Autoconf
940
941 Why does perl use a metaconfig-generated Configure script instead of an
942 autoconf-generated configure script?
943
944 Metaconfig and autoconf are two tools with very similar purposes.
945 Metaconfig is actually the older of the two, and was originally written
946 by Larry Wall, while autoconf is probably now used in a wider variety of
947 packages.  The autoconf info file discusses the history of autoconf and
948 how it came to be.  The curious reader is referred there for further
949 information.
950
951 Overall, both tools are quite good, I think, and the choice of which one
952 to use could be argued either way.  In March, 1994, when I was just
953 starting to work on Configure support for Perl5, I considered both
954 autoconf and metaconfig, and eventually decided to use metaconfig for the
955 following reasons:
956
957 =over 4
958
959 =item Compatibility with Perl4
960
961 Perl4 used metaconfig, so many of the #ifdef's were already set up for
962 metaconfig.  Of course metaconfig had evolved some since Perl4's days,
963 but not so much that it posed any serious problems.
964
965 =item Metaconfig worked for me
966
967 My system at the time was Interactive 2.2, a SVR3.2/386 derivative that
968 also had some POSIX support.  Metaconfig-generated Configure scripts
969 worked fine for me on that system.  On the other hand, autoconf-generated
970 scripts usually didn't.  (They did come quite close, though, in some
971 cases.)  At the time, I actually fetched a large number of GNU packages
972 and checked.  Not a single one configured and compiled correctly
973 out-of-the-box with the system's cc compiler.
974
975 =item Configure can be interactive
976
977 With both autoconf and metaconfig, if the script works, everything is
978 fine.  However, one of my main problems with autoconf-generated scripts
979 was that if it guessed wrong about something, it could be B<very> hard to
980 go back and fix it.  For example, autoconf always insisted on passing the
981 -Xp flag to cc (to turn on POSIX behavior), even when that wasn't what I
982 wanted or needed for that package.  There was no way short of editing the
983 configure script to turn this off.  You couldn't just edit the resulting
984 Makefile at the end because the -Xp flag influenced a number of other
985 configure tests.
986
987 Metaconfig's Configure scripts, on the other hand, can be interactive.
988 Thus if Configure is guessing things incorrectly, you can go back and fix
989 them.  This isn't as important now as it was when we were actively
990 developing Configure support for new features such as dynamic loading,
991 but it's still useful occasionally.
992
993 =item GPL
994
995 At the time, autoconf-generated scripts were covered under the GNU Public
996 License, and hence weren't suitable for inclusion with Perl, which has a
997 different licensing policy.  (Autoconf's licensing has since changed.)
998
999 =item Modularity
1000
1001 Metaconfig builds up Configure from a collection of discrete pieces
1002 called "units".  You can override the standard behavior by supplying your
1003 own unit.  With autoconf, you have to patch the standard files instead.
1004 I find the metaconfig "unit" method easier to work with.  Others
1005 may find metaconfig's units clumsy to work with.
1006
1007 =back
1008
1009 =head2 @INC search order
1010
1011 By default, the list of perl library directories in @INC is the
1012 following:
1013
1014     $archlib
1015     $privlib
1016     $sitearch
1017     $sitelib
1018
1019 Specifically, on my Solaris/x86 system, I run
1020 B<sh Configure -Dprefix=/opt/perl> and I have the following
1021 directories:
1022
1023     /opt/perl/lib/i86pc-solaris/5.00307
1024     /opt/perl/lib
1025     /opt/perl/lib/site_perl/i86pc-solaris
1026     /opt/perl/lib/site_perl
1027
1028 That is, perl's directories come first, followed by the site-specific
1029 directories.
1030
1031 The site libraries come second to support the usage of extensions
1032 across perl versions.  Read the relevant section in F<INSTALL> for
1033 more information.  If we ever make $sitearch version-specific, this
1034 topic could be revisited.
1035
1036 =head2 Why isn't there a directory to override Perl's library?
1037
1038 Mainly because no one's gotten around to making one.  Note that
1039 "making one"  involves changing perl.c, Configure, config_h.SH (and
1040 associated files, see above), and I<documenting> it all in the
1041 INSTALL file.
1042
1043 Apparently, most folks who want to override one of the standard library
1044 files simply do it by overwriting the standard library files.
1045
1046 =head2 APPLLIB
1047
1048 In the perl.c sources, you'll find an undocumented APPLLIB_EXP
1049 variable, sort of like PRIVLIB_EXP and ARCHLIB_EXP (which are
1050 documented in config_h.SH).  Here's what APPLLIB_EXP is for, from
1051 a mail message from Larry:
1052
1053     The main intent of APPLLIB_EXP is for folks who want to send out a
1054     version of Perl embedded in their product.  They would set the symbol
1055     to be the name of the library containing the files needed to run or to
1056     support their particular application.  This works at the "override"
1057     level to make sure they get their own versions of any library code that
1058     they absolutely must have configuration control over.
1059
1060     As such, I don't see any conflict with a sysadmin using it for a
1061     override-ish sort of thing, when installing a generic Perl.  It should
1062     probably have been named something to do with overriding though.  Since
1063     it's undocumented we could still change it...  :-)
1064
1065 Given that it's already there, you can use it to override
1066 distribution modules.  If you do
1067
1068         sh Configure -Dccflags='-DAPPLLIB_EXP=/my/override'
1069
1070 then perl.c will put /my/override ahead of ARCHLIB and PRIVLIB.
1071
1072 =head2 Shared libperl.so location
1073
1074 Why isn't the shared libperl.so installed in /usr/lib/ along
1075 with "all the other" shared libraries?  Instead, it is installed
1076 in $archlib, which is typically something like
1077
1078         /usr/local/lib/perl5/archname/5.00404
1079
1080 and is architecture- and version-specific.
1081
1082 The basic reason why a shared libperl.so gets put in $archlib is so that
1083 you can have more than one version of perl on the system at the same time,
1084 and have each refer to its own libperl.so.
1085
1086 Three examples might help.  All of these work now; none would work if you
1087 put libperl.so in /usr/lib.
1088
1089 =over
1090
1091 =item 1.
1092
1093 Suppose you want to have both threaded and non-threaded perl versions
1094 around.  Configure will name both perl libraries "libperl.so" (so that
1095 you can link to them with -lperl).  The perl binaries tell them apart
1096 by having looking in the appropriate $archlib directories.
1097
1098 =item 2.
1099
1100 Suppose you have perl5.004_04 installed and you want to try to compile
1101 it again, perhaps with different options or after applying a patch.
1102 If you already have libperl.so installed in /usr/lib/, then it may be
1103 either difficult or impossible to get ld.so to find the new libperl.so
1104 that you're trying to build.  If, instead, libperl.so is tucked away in
1105 $archlib, then you can always just change $archlib in the current perl
1106 you're trying to build so that ld.so won't find your old libperl.so.
1107 (The INSTALL file suggests you do this when building a debugging perl.)
1108
1109 =item 3.
1110
1111 The shared perl library is not a "well-behaved" shared library with
1112 proper major and minor version numbers, so you can't necessarily
1113 have perl5.004_04 and perl5.004_05 installed simultaneously.  Suppose
1114 perl5.004_04 were to install /usr/lib/libperl.so.4.4, and perl5.004_05
1115 were to install /usr/lib/libperl.so.4.5.  Now, when you try to run
1116 perl5.004_04, ld.so might try to load libperl.so.4.5, since it has
1117 the right "major version" number.  If this works at all, it almost
1118 certainly defeats the reason for keeping perl5.004_04 around.  Worse,
1119 with development subversions, you certaily can't guarantee that
1120 libperl.so.4.4 and libperl.so.4.55 will be compatible.
1121
1122 Anyway, all this leads to quite obscure failures that are sure to drive
1123 casual users crazy.  Even experienced users will get confused :-).  Upon
1124 reflection, I'd say leave libperl.so in $archlib.
1125
1126 =back
1127
1128 =head1 Upload Your Work to CPAN
1129
1130 You can upload your work to CPAN if you have a CPAN id.  Check out
1131 http://www.perl.com/CPAN/modules/04pause.html for information on
1132 _PAUSE_, the Perl Author's Upload Server.
1133
1134 I typically upload both the patch file, e.g. F<perl5.004_08.pat.gz>
1135 and the full tar file, e.g. F<perl5.004_08.tar.gz>.
1136
1137 If you want your patch to appear in the F<src/5.0/unsupported>
1138 directory on CPAN, send e-mail to the CPAN master librarian.  (Check
1139 out http://www.perl.com/CPAN/CPAN.html ).
1140
1141 =head1 Help Save the World
1142
1143 You should definitely announce your patch on the perl5-porters list.
1144 You should also consider announcing your patch on
1145 comp.lang.perl.announce, though you should make it quite clear that a
1146 subversion is not a production release, and be prepared to deal with
1147 people who will not read your disclaimer.
1148
1149 =head1 Todo
1150
1151 Here, in no particular order, are some Configure and build-related
1152 items that merit consideration.  This list isn't exhaustive, it's just
1153 what I came up with off the top of my head.
1154
1155 =head2 Good ideas waiting for round tuits
1156
1157 =over 4
1158
1159 =item installprefix
1160
1161 I think we ought to support
1162
1163     Configure -Dinstallprefix=/blah/blah
1164
1165 Currently, we support B<-Dprefix=/blah/blah>, but the changing the install
1166 location has to be handled by something like the F<config.over> trick
1167 described in F<INSTALL>.  AFS users also are treated specially.
1168 We should probably duplicate the metaconfig prefix stuff for an
1169 install prefix.
1170
1171 =item Configure -Dsrc=/blah/blah
1172
1173 We should be able to emulate B<configure --srcdir>.  Tom Tromey
1174 tromey@creche.cygnus.com has submitted some patches to
1175 the dist-users mailing list along these lines.  They have been folded
1176 back into the main distribution, but various parts of the perl
1177 Configure/build/install process still assume src='.'.
1178
1179 =item Hint file fixes
1180
1181 Various hint files work around Configure problems.  We ought to fix
1182 Configure so that most of them aren't needed.
1183
1184 =item Hint file information
1185
1186 Some of the hint file information (particularly dynamic loading stuff)
1187 ought to be fed back into the main metaconfig distribution.
1188
1189 =item Catch GNU Libc "Stub" functions
1190
1191 Some functions (such as lchown()) are present in libc, but are
1192 unimplmented.  That is, they always fail and set errno=ENOSYS.
1193
1194 Thomas Bushnell provided the following sample code and the explanation
1195 that follows:
1196
1197     /* System header to define __stub macros and hopefully few prototypes,
1198         which can conflict with char FOO(); below.  */
1199     #include <assert.h>
1200     /* Override any gcc2 internal prototype to avoid an error.  */
1201     /* We use char because int might match the return type of a gcc2
1202         builtin and then its argument prototype would still apply.  */
1203     char FOO();
1204
1205     int main() {
1206
1207     /* The GNU C library defines this for functions which it implements
1208         to always fail with ENOSYS.  Some functions are actually named
1209         something starting with __ and the normal name is an alias.  */
1210     #if defined (__stub_FOO) || defined (__stub___FOO)
1211     choke me
1212     #else
1213     FOO();
1214     #endif
1215
1216     ; return 0; }
1217
1218 The choice of <assert.h> is essentially arbitrary.  The GNU libc
1219 macros are found in <gnu/stubs.h>.  You can include that file instead
1220 of <assert.h> (which itself includes <gnu/stubs.h>) if you test for
1221 its existence first.  <assert.h> is assumed to exist on every system,
1222 which is why it's used here.  Any GNU libc header file will include
1223 the stubs macros.  If either __stub_NAME or __stub___NAME is defined,
1224 then the function doesn't actually exist.  Tests using <assert.h> work
1225 on every system around.
1226
1227 The declaration of FOO is there to override builtin prototypes for
1228 ANSI C functions.
1229
1230 =back
1231
1232 =head2 Probably good ideas waiting for round tuits
1233
1234 =over 4
1235
1236 =item GNU configure --options
1237
1238 I've received sensible suggestions for --exec_prefix and other
1239 GNU configure --options.  It's not always obvious exactly what is
1240 intended, but this merits investigation.
1241
1242 =item make clean
1243
1244 Currently, B<make clean> isn't all that useful, though
1245 B<make realclean> and B<make distclean> are.  This needs a bit of
1246 thought and documentation before it gets cleaned up.
1247
1248 =item Try gcc if cc fails
1249
1250 Currently, we just give up.
1251
1252 =item bypassing safe*alloc wrappers
1253
1254 On some systems, it may be safe to call the system malloc directly
1255 without going through the util.c safe* layers.  (Such systems would
1256 accept free(0), for example.)  This might be a time-saver for systems
1257 that already have a good malloc.  (Recent Linux libc's apparently have
1258 a nice malloc that is well-tuned for the system.)
1259
1260 =back
1261
1262 =head2 Vague possibilities
1263
1264 =over 4
1265
1266 =item MacPerl
1267
1268 Get some of the Macintosh stuff folded back into the main distribution.
1269
1270 =item gconvert replacement
1271
1272 Maybe include a replacement function that doesn't lose data in rare
1273 cases of coercion between string and numerical values.
1274
1275 =item Improve makedepend
1276
1277 The current makedepend process is clunky and annoyingly slow, but it
1278 works for most folks.  Alas, it assumes that there is a filename
1279 $firstmakefile that the B<make> command will try to use before it uses
1280 F<Makefile>.  Such may not be the case for all B<make> commands,
1281 particularly those on non-Unix systems.
1282
1283 Probably some variant of the BSD F<.depend> file will be useful.
1284 We ought to check how other packages do this, if they do it at all.
1285 We could probably pre-generate the dependencies (with the exception of
1286 malloc.o, which could probably be determined at F<Makefile.SH>
1287 extraction time.
1288
1289 =item GNU Makefile standard targets
1290
1291 GNU software generally has standardized Makefile targets.  Unless we
1292 have good reason to do otherwise, I see no reason not to support them.
1293
1294 =item File locking
1295
1296 Somehow, straighten out, document, and implement lockf(), flock(),
1297 and/or fcntl() file locking.  It's a mess.
1298
1299 =back
1300
1301 =head1 AUTHORS
1302
1303 Original author:  Andy Dougherty doughera@lafcol.lafayette.edu .
1304 Additions by Chip Salzenberg chip@perl.com and 
1305 Tim Bunce Tim.Bunce@ig.co.uk .
1306
1307 All opinions expressed herein are those of the authorZ<>(s).
1308
1309 =head1 LAST MODIFIED
1310
1311 $Id: pumpkin.pod,v 1.19 1998/07/06 20:48:55 doughera Released $