Mac OS X: tweak once again the installation directories.
[p5sagit/p5-mst-13.2.git] / README.os2
CommitLineData
a56dbb1c 1If you read this file _as_is_, just ignore the funny characters you
2see. It is written in the POD format (see perlpod manpage) which is
3specially designed to be readable as is.
4
5=head1 NAME
6
72ea3524 7perlos2 - Perl under OS/2, DOS, Win0.3*, Win0.95 and WinNT.
a56dbb1c 8
9=head1 SYNOPSIS
10
11One can read this document in the following formats:
12
13 man perlos2
14 view perl perlos2
15 explorer perlos2.html
16 info perlos2
17
18to list some (not all may be available simultaneously), or it may
19be read I<as is>: either as F<README.os2>, or F<pod/perlos2.pod>.
20
72ea3524 21To read the F<.INF> version of documentation (B<very> recommended)
22outside of OS/2, one needs an IBM's reader (may be available on IBM
df3ef7a9 23ftp sites (?) (URL anyone?)) or shipped with PC DOS 7.0 and IBM's
24Visual Age C++ 3.5.
25
26A copy of a Win* viewer is contained in the "Just add OS/2 Warp" package
27
28 ftp://ftp.software.ibm.com/ps/products/os2/tools/jaow/jaow.zip
29
aa689395 30in F<?:\JUST_ADD\view.exe>. This gives one an access to EMX's
df3ef7a9 31F<.INF> docs as well (text form is available in F</emx/doc> in
25417810 32EMX's distribution). There is also a different viewer named xview.
72ea3524 33
25417810 34Note that if you have F<lynx.exe> or F<netscape.exe> installed, you can follow WWW links
d7678ab8 35from this document in F<.INF> format. If you have EMX docs installed
36correctly, you can follow library links (you need to have C<view emxbook>
37working by setting C<EMXBOOK> environment variable as it is described
38in EMX docs).
39
a56dbb1c 40=cut
41
25417810 42Contents (This may be a little bit obsolete)
a56dbb1c 43
df3ef7a9 44 perlos2 - Perl under OS/2, DOS, Win0.3*, Win0.95 and WinNT.
a56dbb1c 45
25417810 46 NAME
47 SYNOPSIS
48 DESCRIPTION
49 - Target
50 - Other OSes
51 - Prerequisites
52 - Starting Perl programs under OS/2 (and DOS and...)
53 - Starting OS/2 (and DOS) programs under Perl
54 Frequently asked questions
55 - "It does not work"
56 - I cannot run external programs
57 - I cannot embed perl into my program, or use perl.dll from my
58 - `` and pipe-open do not work under DOS.
59 - Cannot start find.exe "pattern" file
60 INSTALLATION
61 - Automatic binary installation
62 - Manual binary installation
63 - Warning
64 Accessing documentation
65 - OS/2 .INF file
66 - Plain text
67 - Manpages
68 - HTML
69 - GNU info files
70 - PDF files
71 - LaTeX docs
72 BUILD
73 - The short story
74 - Prerequisites
75 - Getting perl source
76 - Application of the patches
77 - Hand-editing
78 - Making
79 - Testing
80 - Installing the built perl
81 - a.out-style build
82 Build FAQ
83 - Some / became \ in pdksh.
84 - 'errno' - unresolved external
85 - Problems with tr or sed
86 - Some problem (forget which ;-)
87 - Library ... not found
88 - Segfault in make
89 - op/sprintf test failure
90 Specific (mis)features of OS/2 port
91 - setpriority, getpriority
92 - system()
93 - extproc on the first line
94 - Additional modules:
95 - Prebuilt methods:
96 - Prebuilt variables:
97 - Misfeatures
98 - Modifications
99 - Identifying DLLs
100 - Centralized management of resources
101 Perl flavors
102 - perl.exe
103 - perl_.exe
104 - perl__.exe
105 - perl___.exe
106 - Why strange names?
107 - Why dynamic linking?
108 - Why chimera build?
109 ENVIRONMENT
110 - PERLLIB_PREFIX
111 - PERL_BADLANG
112 - PERL_BADFREE
113 - PERL_SH_DIR
114 - USE_PERL_FLOCK
115 - TMP or TEMP
116 Evolution
117 - Text-mode filehandles
118 - Priorities
119 - DLL name mangling: pre 5.6.2
120 - DLL name mangling: 5.6.2 and beyond
121 - DLL forwarder generation
122 - Threading
123 - Calls to external programs
124 - Memory allocation
125 - Threads
126 BUGS
127 AUTHOR
128 SEE ALSO
abe67105 129
a56dbb1c 130=head1 DESCRIPTION
131
132=head2 Target
133
25417810 134The target is to make OS/2 one of the best supported platform for
72ea3524 135using/building/developing Perl and I<Perl applications>, as well as
aa689395 136make Perl the best language to use under OS/2. The secondary target is
137to try to make this work under DOS and Win* as well (but not B<too> hard).
a56dbb1c 138
139The current state is quite close to this target. Known limitations:
140
141=over 5
142
143=item *
144
25417810 145Some *nix programs use fork() a lot; with the mostly useful flavors of
146perl for OS/2 (there are several built simultaneously) this is
147supported; but some flavors do not support this (e.g., when Perl is
148called from inside REXX). Using fork() after
149I<use>ing dynamically loading extensions would not work with I<very> old
150versions of EMX.
a56dbb1c 151
152=item *
153
154You need a separate perl executable F<perl__.exe> (see L<perl__.exe>)
3998488b 155if you want to use PM code in your application (as Perl/Tk or OpenGL
156Perl modules do) without having a text-mode window present.
157
158While using the standard F<perl.exe> from a text-mode window is possible
159too, I have seen cases when this causes degradation of the system stability.
160Using F<perl__.exe> avoids such a degradation.
a56dbb1c 161
162=item *
163
aa689395 164There is no simple way to access WPS objects. The only way I know
25417810 165is via C<OS2::REXX> and C<SOM> extensions (see L<OS2::REXX>, L<Som>).
166However, we do not have access to
aa689395 167convenience methods of Object-REXX. (Is it possible at all? I know
3998488b 168of no Object-REXX API.) The C<SOM> extension (currently in alpha-text)
25417810 169may eventually remove this shortcoming; however, due to the fact that
170DII is not supported by the C<SOM> module, using C<SOM> is not as
171convenient as one would like it.
a56dbb1c 172
173=back
174
175Please keep this list up-to-date by informing me about other items.
176
177=head2 Other OSes
178
aa689395 179Since OS/2 port of perl uses a remarkable EMX environment, it can
3998488b 180run (and build extensions, and - possibly - be built itself) under any
a56dbb1c 181environment which can run EMX. The current list is DOS,
72ea3524 182DOS-inside-OS/2, Win0.3*, Win0.95 and WinNT. Out of many perl flavors,
a56dbb1c 183only one works, see L<"perl_.exe">.
184
185Note that not all features of Perl are available under these
186environments. This depends on the features the I<extender> - most
aa689395 187probably RSX - decided to implement.
a56dbb1c 188
189Cf. L<Prerequisites>.
190
191=head2 Prerequisites
192
193=over 6
194
aa689395 195=item EMX
a56dbb1c 196
aa689395 197EMX runtime is required (may be substituted by RSX). Note that
55497cff 198it is possible to make F<perl_.exe> to run under DOS without any
72ea3524 199external support by binding F<emx.exe>/F<rsx.exe> to it, see L<emxbind>. Note
aa689395 200that under DOS for best results one should use RSX runtime, which
55497cff 201has much more functions working (like C<fork>, C<popen> and so on). In
aa689395 202fact RSX is required if there is no VCPI present. Note the
25417810 203RSX requires DPMI. Many implementations of DPMI are known to be very
204buggy, beware!
a56dbb1c 205
884335e8 206Only the latest runtime is supported, currently C<0.9d fix 03>. Perl may run
aa689395 207under earlier versions of EMX, but this is not tested.
a56dbb1c 208
aa689395 209One can get different parts of EMX from, say
a56dbb1c 210
884335e8 211 http://www.leo.org/pub/comp/os/os2/leo/gnu/emx+gcc/
212 http://powerusersbbs.com/pub/os2/dev/ [EMX+GCC Development]
213 http://hobbes.nmsu.edu/pub/os2/dev/emx/v0.9d/
a56dbb1c 214
215The runtime component should have the name F<emxrt.zip>.
216
25417810 217B<NOTE>. When using F<emx.exe>/F<rsx.exe>, it is enough to have them on your path. One
72ea3524 218does not need to specify them explicitly (though this
219
220 emx perl_.exe -de 0
221
222will work as well.)
223
aa689395 224=item RSX
a56dbb1c 225
aa689395 226To run Perl on DPMI platforms one needs RSX runtime. This is
72ea3524 227needed under DOS-inside-OS/2, Win0.3*, Win0.95 and WinNT (see
aa689395 228L<"Other OSes">). RSX would not work with VCPI
229only, as EMX would, it requires DMPI.
55497cff 230
aa689395 231Having RSX and the latest F<sh.exe> one gets a fully functional
55497cff 232B<*nix>-ish environment under DOS, say, C<fork>, C<``> and
233pipe-C<open> work. In fact, MakeMaker works (for static build), so one
234can have Perl development environment under DOS.
a56dbb1c 235
aa689395 236One can get RSX from, say
a56dbb1c 237
d7678ab8 238 ftp://ftp.cdrom.com/pub/os2/emx09c/contrib
a56dbb1c 239 ftp://ftp.uni-bielefeld.de/pub/systems/msdos/misc
d7678ab8 240 ftp://ftp.leo.org/pub/comp/os/os2/leo/devtools/emx+gcc/contrib
a56dbb1c 241
242Contact the author on C<rainer@mathematik.uni-bielefeld.de>.
243
3998488b 244The latest F<sh.exe> with DOS hooks is available in
245
25417810 246 http://www.ilyaz.org/software/os2/
55497cff 247
3998488b 248as F<sh_dos.zip> or under similar names starting with C<sh>, C<pdksh> etc.
55497cff 249
aa689395 250=item HPFS
a56dbb1c 251
25417810 252Perl does not care about file systems, but the perl library contains
253many files with long names, so to install it intact one needs a file
254system which supports long file names.
a56dbb1c 255
256Note that if you do not plan to build the perl itself, it may be
aa689395 257possible to fool EMX to truncate file names. This is not supported,
258read EMX docs to see how to do it.
259
260=item pdksh
261
262To start external programs with complicated command lines (like with
263pipes in between, and/or quoting of arguments), Perl uses an external
3998488b 264shell. With EMX port such shell should be named F<sh.exe>, and located
aa689395 265either in the wired-in-during-compile locations (usually F<F:/bin>),
266or in configurable location (see L<"PERL_SH_DIR">).
267
3998488b 268For best results use EMX pdksh. The standard binary (5.2.14 or later) runs
269under DOS (with L<RSX>) as well, see
aa689395 270
25417810 271 http://www.ilyaz.org/software/os2/
a56dbb1c 272
273=back
274
aa689395 275=head2 Starting Perl programs under OS/2 (and DOS and...)
a56dbb1c 276
277Start your Perl program F<foo.pl> with arguments C<arg1 arg2 arg3> the
278same way as on any other platform, by
279
280 perl foo.pl arg1 arg2 arg3
281
282If you want to specify perl options C<-my_opts> to the perl itself (as
d1be9408 283opposed to your program), use
a56dbb1c 284
285 perl -my_opts foo.pl arg1 arg2 arg3
286
aa689395 287Alternately, if you use OS/2-ish shell, like CMD or 4os2, put
a56dbb1c 288the following at the start of your perl script:
289
aa689395 290 extproc perl -S -my_opts
a56dbb1c 291
292rename your program to F<foo.cmd>, and start it by typing
293
294 foo arg1 arg2 arg3
295
a56dbb1c 296Note that because of stupid OS/2 limitations the full path of the perl
297script is not available when you use C<extproc>, thus you are forced to
3998488b 298use C<-S> perl switch, and your script should be on the C<PATH>. As a plus
a56dbb1c 299side, if you know a full path to your script, you may still start it
300with
301
aa689395 302 perl ../../blah/foo.cmd arg1 arg2 arg3
a56dbb1c 303
aa689395 304(note that the argument C<-my_opts> is taken care of by the C<extproc> line
305in your script, see L<C<extproc> on the first line>).
a56dbb1c 306
307To understand what the above I<magic> does, read perl docs about C<-S>
aa689395 308switch - see L<perlrun>, and cmdref about C<extproc>:
a56dbb1c 309
310 view perl perlrun
311 man perlrun
312 view cmdref extproc
313 help extproc
314
315or whatever method you prefer.
316
72ea3524 317There are also endless possibilities to use I<executable extensions> of
aa689395 3184os2, I<associations> of WPS and so on... However, if you use
a56dbb1c 319*nixish shell (like F<sh.exe> supplied in the binary distribution),
72ea3524 320you need to follow the syntax specified in L<perlrun/"Switches">.
a56dbb1c 321
25417810 322Note that B<-S> switch supports scripts with additional extensions
d8c2d278 323F<.cmd>, F<.btm>, F<.bat>, F<.pl> as well.
324
aa689395 325=head2 Starting OS/2 (and DOS) programs under Perl
a56dbb1c 326
327This is what system() (see L<perlfunc/system>), C<``> (see
328L<perlop/"I/O Operators">), and I<open pipe> (see L<perlfunc/open>)
329are for. (Avoid exec() (see L<perlfunc/exec>) unless you know what you
330do).
331
332Note however that to use some of these operators you need to have a
aa689395 333sh-syntax shell installed (see L<"Pdksh">,
a56dbb1c 334L<"Frequently asked questions">), and perl should be able to find it
335(see L<"PERL_SH_DIR">).
336
2c2e0e8c 337The cases when the shell is used are:
338
339=over
340
341=item 1
342
343One-argument system() (see L<perlfunc/system>), exec() (see L<perlfunc/exec>)
344with redirection or shell meta-characters;
345
346=item 2
347
348Pipe-open (see L<perlfunc/open>) with the command which contains redirection
349or shell meta-characters;
350
351=item 3
352
353Backticks C<``> (see L<perlop/"I/O Operators">) with the command which contains
354redirection or shell meta-characters;
355
356=item 4
357
358If the executable called by system()/exec()/pipe-open()/C<``> is a script
359with the "magic" C<#!> line or C<extproc> line which specifies shell;
360
361=item 5
362
363If the executable called by system()/exec()/pipe-open()/C<``> is a script
364without "magic" line, and C<$ENV{EXECSHELL}> is set to shell;
365
366=item 6
367
368If the executable called by system()/exec()/pipe-open()/C<``> is not
25417810 369found (is not this remark obsolete?);
2c2e0e8c 370
371=item 7
372
25417810 373For globbing (see L<perlfunc/glob>, L<perlop/"I/O Operators">)
374(obsolete? Perl uses builtin globbing nowadays...).
2c2e0e8c 375
376=back
377
378For the sake of speed for a common case, in the above algorithms
379backslashes in the command name are not considered as shell metacharacters.
380
381Perl starts scripts which begin with cookies
382C<extproc> or C<#!> directly, without an intervention of shell. Perl uses the
383same algorithm to find the executable as F<pdksh>: if the path
25417810 384on C<#!> line does not work, and contains C</>, then the directory
385part of the executable is ignored, and the executable
2c2e0e8c 386is searched in F<.> and on C<PATH>. To find arguments for these scripts
387Perl uses a different algorithm than F<pdksh>: up to 3 arguments are
388recognized, and trailing whitespace is stripped.
389
390If a script
391does not contain such a cooky, then to avoid calling F<sh.exe>, Perl uses
392the same algorithm as F<pdksh>: if C<$ENV{EXECSHELL}> is set, the
393script is given as the first argument to this command, if not set, then
394C<$ENV{COMSPEC} /c> is used (or a hardwired guess if C<$ENV{COMSPEC}> is
395not set).
491527d0 396
25417810 397When starting scripts directly, Perl uses exactly the same algorithm as for
491527d0 398the search of script given by B<-S> command-line option: it will look in
399the current directory, then on components of C<$ENV{PATH}> using the
400following order of appended extensions: no extension, F<.cmd>, F<.btm>,
401F<.bat>, F<.pl>.
402
403Note that Perl will start to look for scripts only if OS/2 cannot start the
404specified application, thus C<system 'blah'> will not look for a script if
25417810 405there is an executable file F<blah.exe> I<anywhere> on C<PATH>. In
406other words, C<PATH> is essentially searched twice: once by the OS for
407an executable, then by Perl for scripts.
491527d0 408
409Note also that executable files on OS/2 can have an arbitrary extension,
410but F<.exe> will be automatically appended if no dot is present in the name.
d1be9408 411The workaround is as simple as that: since F<blah.> and F<blah> denote the
25417810 412same file (at list on FAT and HPFS file systems), to start an executable residing in file F<n:/bin/blah> (no
3998488b 413extension) give an argument C<n:/bin/blah.> (dot appended) to system().
491527d0 414
25417810 415Perl will start PM programs from VIO (=text-mode) Perl process in a
416separate PM session;
3998488b 417the opposite is not true: when you start a non-PM program from a PM
25417810 418Perl process, Perl would not run it in a separate session. If a separate
3998488b 419session is desired, either ensure
420that shell will be used, as in C<system 'cmd /c myprog'>, or start it using
491527d0 421optional arguments to system() documented in C<OS2::Process> module. This
3998488b 422is considered to be a feature.
a56dbb1c 423
424=head1 Frequently asked questions
425
3998488b 426=head2 "It does not work"
427
428Perl binary distributions come with a F<testperl.cmd> script which tries
429to detect common problems with misconfigured installations. There is a
430pretty large chance it will discover which step of the installation you
431managed to goof. C<;-)>
432
72ea3524 433=head2 I cannot run external programs
a56dbb1c 434
55497cff 435=over 4
436
13a2d996 437=item *
55497cff 438
a56dbb1c 439Did you run your programs with C<-w> switch? See
aa689395 440L<Starting OS/2 (and DOS) programs under Perl>.
a56dbb1c 441
13a2d996 442=item *
55497cff 443
444Do you try to run I<internal> shell commands, like C<`copy a b`>
445(internal for F<cmd.exe>), or C<`glob a*b`> (internal for ksh)? You
72ea3524 446need to specify your shell explicitly, like C<`cmd /c copy a b`>,
55497cff 447since Perl cannot deduce which commands are internal to your shell.
448
449=back
450
a56dbb1c 451=head2 I cannot embed perl into my program, or use F<perl.dll> from my
452program.
453
454=over 4
455
aa689395 456=item Is your program EMX-compiled with C<-Zmt -Zcrtdll>?
a56dbb1c 457
25417810 458Well, nowadays Perl DLL should be usable from a differently compiled
459program too... If you can run Perl code from REXX scripts (see
460L<OS2::REXX>), then there are some other aspect of interaction which
461are overlooked by the current hackish code to support
462differently-compiled principal programs.
463
464If everything else fails, you need to build a stand-alone DLL for
465perl. Contact me, I did it once. Sockets would not work, as a lot of
466other stuff.
a56dbb1c 467
aa689395 468=item Did you use L<ExtUtils::Embed>?
a56dbb1c 469
25417810 470Some time ago I had reports it does not work. Nowadays it is checked
471in the Perl test suite, so grep F<./t> subdirectory of the build tree
472(as well as F<*.t> files in the F<./lib> subdirectory) to find how it
473should be done "correctly".
a56dbb1c 474
475=back
476
55497cff 477=head2 C<``> and pipe-C<open> do not work under DOS.
478
72ea3524 479This may a variant of just L<"I cannot run external programs">, or a
aa689395 480deeper problem. Basically: you I<need> RSX (see L<"Prerequisites">)
72ea3524 481for these commands to work, and you may need a port of F<sh.exe> which
55497cff 482understands command arguments. One of such ports is listed in
aa689395 483L<"Prerequisites"> under RSX. Do not forget to set variable
484C<L<"PERL_SH_DIR">> as well.
485
486DPMI is required for RSX.
487
488=head2 Cannot start C<find.exe "pattern" file>
55497cff 489
25417810 490The whole idea of the "standard C API to start applications" is that
491the forms C<foo> and C<"foo"> of program arguments are completely
492interchangable. F<find> breaks this paradigm;
493
494 find "pattern" file
495 find pattern file
496
497are not equivalent; F<find> cannot be started directly using the above
498API. One needs a way to surround the doublequotes in some other
499quoting construction, necessarily having an extra non-Unixish shell in
500between.
501
aa689395 502Use one of
503
504 system 'cmd', '/c', 'find "pattern" file';
505 `cmd /c 'find "pattern" file'`
506
507This would start F<find.exe> via F<cmd.exe> via C<sh.exe> via
508C<perl.exe>, but this is a price to pay if you want to use
25417810 509non-conforming program.
55497cff 510
a56dbb1c 511=head1 INSTALLATION
512
513=head2 Automatic binary installation
514
3998488b 515The most convenient way of installing a binary distribution of perl is via perl installer
a56dbb1c 516F<install.exe>. Just follow the instructions, and 99% of the
517installation blues would go away.
518
519Note however, that you need to have F<unzip.exe> on your path, and
aa689395 520EMX environment I<running>. The latter means that if you just
521installed EMX, and made all the needed changes to F<Config.sys>,
522you may need to reboot in between. Check EMX runtime by running
a56dbb1c 523
524 emxrev
525
25417810 526Binary installer also creates a folder on your desktop with some useful
527objects. If you need to change some aspects of the work of the binary
528installer, feel free to edit the file F<Perl.pkg>. This may be useful
529e.g., if you need to run the installer many times and do not want to
530make many interactive changes in the GUI.
a56dbb1c 531
532B<Things not taken care of by automatic binary installation:>
533
534=over 15
535
536=item C<PERL_BADLANG>
537
538may be needed if you change your codepage I<after> perl installation,
aa689395 539and the new value is not supported by EMX. See L<"PERL_BADLANG">.
a56dbb1c 540
541=item C<PERL_BADFREE>
542
543see L<"PERL_BADFREE">.
544
545=item F<Config.pm>
546
547This file resides somewhere deep in the location you installed your
548perl library, find it out by
549
550 perl -MConfig -le "print $INC{'Config.pm'}"
551
552While most important values in this file I<are> updated by the binary
553installer, some of them may need to be hand-edited. I know no such
25417810 554data, please keep me informed if you find one. Moreover, manual
555changes to the installed version may need to be accompanied by an edit
556of this file.
a56dbb1c 557
558=back
559
aa689395 560B<NOTE>. Because of a typo the binary installer of 5.00305
561would install a variable C<PERL_SHPATH> into F<Config.sys>. Please
562remove this variable and put C<L<PERL_SH_DIR>> instead.
563
a56dbb1c 564=head2 Manual binary installation
565
72ea3524 566As of version 5.00305, OS/2 perl binary distribution comes split
a56dbb1c 567into 11 components. Unfortunately, to enable configurable binary
aa689395 568installation, the file paths in the zip files are not absolute, but
a56dbb1c 569relative to some directory.
570
571Note that the extraction with the stored paths is still necessary
aa689395 572(default with unzip, specify C<-d> to pkunzip). However, you
a56dbb1c 573need to know where to extract the files. You need also to manually
574change entries in F<Config.sys> to reflect where did you put the
72ea3524 575files. Note that if you have some primitive unzipper (like
25417810 576C<pkunzip>), you may get a lot of warnings/errors during
72ea3524 577unzipping. Upgrade to C<(w)unzip>.
a56dbb1c 578
579Below is the sample of what to do to reproduce the configuration on my
25417810 580machine. In F<VIEW.EXE> you can press C<Ctrl-Insert> now, and
581cut-and-paste from the resulting file - created in the directory you
582started F<VIEW.EXE> from.
583
584For each component, we mention environment variables related to each
585installation directory. Either choose directories to match your
586values of the variables, or create/append-to variables to take into
587account the directories.
a56dbb1c 588
589=over 3
590
591=item Perl VIO and PM executables (dynamically linked)
592
593 unzip perl_exc.zip *.exe *.ico -d f:/emx.add/bin
594 unzip perl_exc.zip *.dll -d f:/emx.add/dll
595
aa689395 596(have the directories with C<*.exe> on PATH, and C<*.dll> on
597LIBPATH);
a56dbb1c 598
599=item Perl_ VIO executable (statically linked)
600
601 unzip perl_aou.zip -d f:/emx.add/bin
602
aa689395 603(have the directory on PATH);
a56dbb1c 604
605=item Executables for Perl utilities
606
607 unzip perl_utl.zip -d f:/emx.add/bin
608
aa689395 609(have the directory on PATH);
a56dbb1c 610
611=item Main Perl library
612
613 unzip perl_mlb.zip -d f:/perllib/lib
614
3998488b 615If this directory is exactly the same as the prefix which was compiled
616into F<perl.exe>, you do not need to change
617anything. However, for perl to find the library if you use a different
618path, you need to
a56dbb1c 619C<set PERLLIB_PREFIX> in F<Config.sys>, see L<"PERLLIB_PREFIX">.
620
621=item Additional Perl modules
622
3998488b 623 unzip perl_ste.zip -d f:/perllib/lib/site_perl/5.8.3/
a56dbb1c 624
3998488b 625Same remark as above applies. Additionally, if this directory is not
626one of directories on @INC (and @INC is influenced by C<PERLLIB_PREFIX>), you
627need to put this
a56dbb1c 628directory and subdirectory F<./os2> in C<PERLLIB> or C<PERL5LIB>
629variable. Do not use C<PERL5LIB> unless you have it set already. See
3998488b 630L<perl/"ENVIRONMENT">.
a56dbb1c 631
25417810 632B<[Check whether this extraction directory is still applicable with
633the new directory structure layout!]>
634
a56dbb1c 635=item Tools to compile Perl modules
636
637 unzip perl_blb.zip -d f:/perllib/lib
638
3998488b 639Same remark as for F<perl_ste.zip>.
a56dbb1c 640
641=item Manpages for Perl and utilities
642
643 unzip perl_man.zip -d f:/perllib/man
644
645This directory should better be on C<MANPATH>. You need to have a
25417810 646working F<man> to access these files.
a56dbb1c 647
648=item Manpages for Perl modules
649
650 unzip perl_mam.zip -d f:/perllib/man
651
652This directory should better be on C<MANPATH>. You need to have a
aa689395 653working man to access these files.
a56dbb1c 654
655=item Source for Perl documentation
656
657 unzip perl_pod.zip -d f:/perllib/lib
658
3998488b 659This is used by the C<perldoc> program (see L<perldoc>), and may be used to
aa689395 660generate HTML documentation usable by WWW browsers, and
a56dbb1c 661documentation in zillions of other formats: C<info>, C<LaTeX>,
25417810 662C<Acrobat>, C<FrameMaker> and so on. [Use programs such as
663F<pod2latex> etc.]
a56dbb1c 664
aa689395 665=item Perl manual in F<.INF> format
a56dbb1c 666
667 unzip perl_inf.zip -d d:/os2/book
668
669This directory should better be on C<BOOKSHELF>.
670
671=item Pdksh
672
673 unzip perl_sh.zip -d f:/bin
674
72ea3524 675This is used by perl to run external commands which explicitly
a56dbb1c 676require shell, like the commands using I<redirection> and I<shell
677metacharacters>. It is also used instead of explicit F</bin/sh>.
678
679Set C<PERL_SH_DIR> (see L<"PERL_SH_DIR">) if you move F<sh.exe> from
680the above location.
681
25417810 682B<Note.> It may be possible to use some other sh-compatible shell (untested).
a56dbb1c 683
684=back
685
686After you installed the components you needed and updated the
687F<Config.sys> correspondingly, you need to hand-edit
688F<Config.pm>. This file resides somewhere deep in the location you
689installed your perl library, find it out by
690
691 perl -MConfig -le "print $INC{'Config.pm'}"
692
693You need to correct all the entries which look like file paths (they
694currently start with C<f:/>).
695
696=head2 B<Warning>
697
698The automatic and manual perl installation leave precompiled paths
699inside perl executables. While these paths are overwriteable (see
25417810 700L<"PERLLIB_PREFIX">, L<"PERL_SH_DIR">), some people may prefer
a56dbb1c 701binary editing of paths inside the executables/DLLs.
702
703=head1 Accessing documentation
704
705Depending on how you built/installed perl you may have (otherwise
706identical) Perl documentation in the following formats:
707
708=head2 OS/2 F<.INF> file
709
aa689395 710Most probably the most convenient form. Under OS/2 view it as
a56dbb1c 711
712 view perl
713 view perl perlfunc
714 view perl less
715 view perl ExtUtils::MakeMaker
716
717(currently the last two may hit a wrong location, but this may improve
aa689395 718soon). Under Win* see L<"SYNOPSIS">.
a56dbb1c 719
720If you want to build the docs yourself, and have I<OS/2 toolkit>, run
721
722 pod2ipf > perl.ipf
723
724in F</perllib/lib/pod> directory, then
725
726 ipfc /inf perl.ipf
727
728(Expect a lot of errors during the both steps.) Now move it on your
729BOOKSHELF path.
730
731=head2 Plain text
732
733If you have perl documentation in the source form, perl utilities
aa689395 734installed, and GNU groff installed, you may use
a56dbb1c 735
736 perldoc perlfunc
737 perldoc less
738 perldoc ExtUtils::MakeMaker
739
72ea3524 740to access the perl documentation in the text form (note that you may get
a56dbb1c 741better results using perl manpages).
742
743Alternately, try running pod2text on F<.pod> files.
744
745=head2 Manpages
746
25417810 747If you have F<man> installed on your system, and you installed perl
a56dbb1c 748manpages, use something like this:
5243f9ae 749
5243f9ae 750 man perlfunc
751 man 3 less
752 man ExtUtils.MakeMaker
5243f9ae 753
a56dbb1c 754to access documentation for different components of Perl. Start with
755
756 man perl
757
758Note that dot (F<.>) is used as a package separator for documentation
759for packages, and as usual, sometimes you need to give the section - C<3>
760above - to avoid shadowing by the I<less(1) manpage>.
761
762Make sure that the directory B<above> the directory with manpages is
763on our C<MANPATH>, like this
764
765 set MANPATH=c:/man;f:/perllib/man
766
3998488b 767for Perl manpages in C<f:/perllib/man/man1/> etc.
768
aa689395 769=head2 HTML
a56dbb1c 770
771If you have some WWW browser available, installed the Perl
772documentation in the source form, and Perl utilities, you can build
aa689395 773HTML docs. Cd to directory with F<.pod> files, and do like this
a56dbb1c 774
775 cd f:/perllib/lib/pod
5243f9ae 776 pod2html
5243f9ae 777
a56dbb1c 778After this you can direct your browser the file F<perl.html> in this
779directory, and go ahead with reading docs, like this:
5243f9ae 780
a56dbb1c 781 explore file:///f:/perllib/lib/pod/perl.html
5243f9ae 782
aa689395 783Alternatively you may be able to get these docs prebuilt from CPAN.
5243f9ae 784
aa689395 785=head2 GNU C<info> files
bb14ff96 786
aa689395 787Users of Emacs would appreciate it very much, especially with
25417810 788C<CPerl> mode loaded. You need to get latest C<pod2texi> from C<CPAN>,
789or, alternately, the prebuilt info pages.
615d1a09 790
5cb3728c 791=head2 F<PDF> files
a56dbb1c 792
25417810 793for C<Acrobat> are available on CPAN (may be for slightly older version of
a56dbb1c 794perl).
795
796=head2 C<LaTeX> docs
797
798can be constructed using C<pod2latex>.
799
800=head1 BUILD
801
802Here we discuss how to build Perl under OS/2. There is an alternative
25417810 803(but maybe older) view on L<http://www.shadow.net/~troc/os2perl.html>.
a56dbb1c 804
3998488b 805=head2 The short story
806
807Assume that you are a seasoned porter, so are sure that all the necessary
808tools are already present on your system, and you know how to get the Perl
809source distribution. Untar it, change to the extract directory, and
810
811 gnupatch -p0 < os2\diff.configure
812 sh Configure -des -D prefix=f:/perllib
813 make
814 make test
815 make install
816 make aout_test
817 make aout_install
818
819This puts the executables in f:/perllib/bin. Manually move them to the
25417810 820C<PATH>, manually move the built F<perl*.dll> to C<LIBPATH> (here for
821Perl DLL F<*> is a not-very-meaningful hex checksum), and run
3998488b 822
823 make installcmd INSTALLCMDDIR=d:/ir/on/path
824
25417810 825Assuming that the C<man>-files were put on an appropriate location,
826this completes the installation of minimal Perl system. (The binary
827distribution contains also a lot of additional modules, and the
828documentation in INF format.)
829
3998488b 830What follows is a detailed guide through these steps.
831
a56dbb1c 832=head2 Prerequisites
833
aa689395 834You need to have the latest EMX development environment, the full
835GNU tool suite (gawk renamed to awk, and GNU F<find.exe>
a56dbb1c 836earlier on path than the OS/2 F<find.exe>, same with F<sort.exe>, to
837check use
838
839 find --version
840 sort --version
841
842). You need the latest version of F<pdksh> installed as F<sh.exe>.
843
2c2e0e8c 844Check that you have B<BSD> libraries and headers installed, and -
845optionally - Berkeley DB headers and libraries, and crypt.
846
25417810 847Possible locations to get the files:
a56dbb1c 848
d7678ab8 849 ftp://hobbes.nmsu.edu/os2/unix/
a56dbb1c 850 ftp://ftp.cdrom.com/pub/os2/unix/
851 ftp://ftp.cdrom.com/pub/os2/dev32/
d7678ab8 852 ftp://ftp.cdrom.com/pub/os2/emx09c/
a56dbb1c 853
eb447b86 854It is reported that the following archives contain enough utils to
3998488b 855build perl: F<gnufutil.zip>, F<gnusutil.zip>, F<gnututil.zip>, F<gnused.zip>,
25417810 856F<gnupatch.zip>, F<gnuawk.zip>, F<gnumake.zip>, F<gnugrep.zip>, F<bsddev.zip> and
3998488b 857F<ksh527rt.zip> (or a later version). Note that all these utilities are
858known to be available from LEO:
eb447b86 859
860 ftp://ftp.leo.org/pub/comp/os/os2/leo/gnu
a56dbb1c 861
25417810 862Note also that the F<db.lib> and F<db.a> from the EMX distribution
863are not suitable for multi-threaded compile (even single-threaded
864flavor of Perl uses multi-threaded C RTL, for
865compatibility with XFree86-OS/2). Get a corrected one from
866
867 http://www.ilyaz.org/software/os2/db_mt.zip
868
3998488b 869If you have I<exactly the same version of Perl> installed already,
870make sure that no copies or perl are currently running. Later steps
871of the build may fail since an older version of F<perl.dll> loaded into
a56dbb1c 872memory may be found.
873
874Also make sure that you have F</tmp> directory on the current drive,
875and F<.> directory in your C<LIBPATH>. One may try to correct the
876latter condition by
877
25417810 878 set BEGINLIBPATH .\.
a56dbb1c 879
25417810 880if you use something like F<CMD.EXE> or latest versions of
881F<4os2.exe>. (Setting BEGINLIBPATH to just C<.> is ignored by the
882OS/2 kernel.)
a56dbb1c 883
aa689395 884Make sure your gcc is good for C<-Zomf> linking: run C<omflibs>
a56dbb1c 885script in F</emx/lib> directory.
886
aa689395 887Check that you have link386 installed. It comes standard with OS/2,
a56dbb1c 888but may be not installed due to customization. If typing
889
890 link386
891
892shows you do not have it, do I<Selective install>, and choose C<Link
72ea3524 893object modules> in I<Optional system utilities/More>. If you get into
3998488b 894link386 prompts, press C<Ctrl-C> to exit.
a56dbb1c 895
896=head2 Getting perl source
897
72ea3524 898You need to fetch the latest perl source (including developers
a56dbb1c 899releases). With some probability it is located in
900
468f45d5 901 http://www.cpan.org/src/5.0
902 http://www.cpan.org/src/5.0/unsupported
a56dbb1c 903
904If not, you may need to dig in the indices to find it in the directory
905of the current maintainer.
906
72ea3524 907Quick cycle of developers release may break the OS/2 build time to
a56dbb1c 908time, looking into
909
6c8d78fb 910 http://www.cpan.org/ports/os2/
a56dbb1c 911
912may indicate the latest release which was publicly released by the
913maintainer. Note that the release may include some additional patches
914to apply to the current source of perl.
915
916Extract it like this
917
918 tar vzxf perl5.00409.tar.gz
919
920You may see a message about errors while extracting F<Configure>. This is
921because there is a conflict with a similarly-named file F<configure>.
922
a56dbb1c 923Change to the directory of extraction.
924
925=head2 Application of the patches
926
10fb174d 927You need to apply the patches in F<./os2/diff.*> like this:
a56dbb1c 928
df3ef7a9 929 gnupatch -p0 < os2\diff.configure
a56dbb1c 930
931You may also need to apply the patches supplied with the binary
25417810 932distribution of perl. It also makes sense to look on the
933perl5-porters mailing list for the latest OS/2-related patches (see
934L<http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/>). Such
935patches usually contain strings C</os2/> and C<patch>, so it makes
936sense looking for these strings.
a56dbb1c 937
938=head2 Hand-editing
939
940You may look into the file F<./hints/os2.sh> and correct anything
941wrong you find there. I do not expect it is needed anywhere.
615d1a09 942
a56dbb1c 943=head2 Making
615d1a09 944
a56dbb1c 945 sh Configure -des -D prefix=f:/perllib
615d1a09 946
aa689395 947C<prefix> means: where to install the resulting perl library. Giving
a56dbb1c 948correct prefix you may avoid the need to specify C<PERLLIB_PREFIX>,
949see L<"PERLLIB_PREFIX">.
5243f9ae 950
a56dbb1c 951I<Ignore the message about missing C<ln>, and about C<-c> option to
3998488b 952tr>. The latter is most probably already fixed, if you see it and can trace
953where the latter spurious warning comes from, please inform me.
615d1a09 954
a56dbb1c 955Now
5243f9ae 956
a56dbb1c 957 make
5243f9ae 958
a56dbb1c 959At some moment the built may die, reporting a I<version mismatch> or
3998488b 960I<unable to run F<perl>>. This means that you do not have F<.> in
961your LIBPATH, so F<perl.exe> cannot find the needed F<perl67B2.dll> (treat
962these hex digits as line noise). After this is fixed the build
963should finish without a lot of fuss.
615d1a09 964
a56dbb1c 965=head2 Testing
966
967Now run
968
969 make test
970
25417810 971All tests should succeed (with some of them skipped). If you have the
972same version of Perl installed, it is crucial that you have C<.> early
973in your LIBPATH (or in BEGINLIBPATH), otherwise your tests will most
974probably test the wrong version of Perl.
a56dbb1c 975
ec40c0cd 976Some tests may generate extra messages similar to
a56dbb1c 977
ec40c0cd 978=over 4
a56dbb1c 979
ec40c0cd 980=item A lot of C<bad free>
a56dbb1c 981
3998488b 982in database tests related to Berkeley DB. I<This should be fixed already.>
983If it persists, you may disable this warnings, see L<"PERL_BADFREE">.
72ea3524 984
ec40c0cd 985=item Process terminated by SIGTERM/SIGINT
72ea3524 986
ec40c0cd 987This is a standard message issued by OS/2 applications. *nix
3998488b 988applications die in silence. It is considered to be a feature. One can
ec40c0cd 989easily disable this by appropriate sighandlers.
a56dbb1c 990
ec40c0cd 991However the test engine bleeds these message to screen in unexpected
992moments. Two messages of this kind I<should> be present during
993testing.
a56dbb1c 994
ec40c0cd 995=back
a56dbb1c 996
ec40c0cd 997To get finer test reports, call
998
999 perl t/harness
1000
1001The report with F<io/pipe.t> failing may look like this:
a56dbb1c 1002
ec40c0cd 1003 Failed Test Status Wstat Total Fail Failed List of failed
1004 ------------------------------------------------------------
1005 io/pipe.t 12 1 8.33% 9
1006 7 tests skipped, plus 56 subtests skipped.
1007 Failed 1/195 test scripts, 99.49% okay. 1/6542 subtests failed, 99.98% okay.
1008
1009The reasons for most important skipped tests are:
1010
1011=over 8
a56dbb1c 1012
ec40c0cd 1013=item F<op/fs.t>
a56dbb1c 1014
a7665c5e 1015=over 4
1016
a56dbb1c 1017=item 18
1018
ec40c0cd 1019Checks C<atime> and C<mtime> of C<stat()> - unfortunately, HPFS
1020provides only 2sec time granularity (for compatibility with FAT?).
a56dbb1c 1021
1022=item 25
1023
1024Checks C<truncate()> on a filehandle just opened for write - I do not
1025know why this should or should not work.
1026
1027=back
1028
a56dbb1c 1029=item F<op/stat.t>
1030
1031Checks C<stat()>. Tests:
1032
1033=over 4
1034
a56dbb1c 1035=item 4
1036
ec40c0cd 1037Checks C<atime> and C<mtime> of C<stat()> - unfortunately, HPFS
1038provides only 2sec time granularity (for compatibility with FAT?).
a56dbb1c 1039
1040=back
1041
a56dbb1c 1042=back
615d1a09 1043
a56dbb1c 1044=head2 Installing the built perl
615d1a09 1045
25417810 1046If you haven't yet moved C<perl*.dll> onto LIBPATH, do it now.
491527d0 1047
a56dbb1c 1048Run
615d1a09 1049
a56dbb1c 1050 make install
615d1a09 1051
a56dbb1c 1052It would put the generated files into needed locations. Manually put
1053F<perl.exe>, F<perl__.exe> and F<perl___.exe> to a location on your
aa689395 1054PATH, F<perl.dll> to a location on your LIBPATH.
615d1a09 1055
a56dbb1c 1056Run
615d1a09 1057
3998488b 1058 make installcmd INSTALLCMDDIR=d:/ir/on/path
615d1a09 1059
a56dbb1c 1060to convert perl utilities to F<.cmd> files and put them on
aa689395 1061PATH. You need to put F<.EXE>-utilities on path manually. They are
a56dbb1c 1062installed in C<$prefix/bin>, here C<$prefix> is what you gave to
1063F<Configure>, see L<Making>.
1064
25417810 1065If you use C<man>, either move the installed F<*/man/> directories to
1066your C<MANPATH>, or modify C<MANPATH> to match the location. (One
1067could have avoided this by providing a correct C<manpath> option to
1068F<./Configure>, or editing F<./config.sh> between configuring and
1069making steps.)
1070
a56dbb1c 1071=head2 C<a.out>-style build
1072
1073Proceed as above, but make F<perl_.exe> (see L<"perl_.exe">) by
1074
1075 make perl_
1076
1077test and install by
1078
1079 make aout_test
1080 make aout_install
1081
aa689395 1082Manually put F<perl_.exe> to a location on your PATH.
a56dbb1c 1083
a56dbb1c 1084B<Note.> The build process for C<perl_> I<does not know> about all the
1085dependencies, so you should make sure that anything is up-to-date,
1086say, by doing
1087
3998488b 1088 make perl_dll
a56dbb1c 1089
1090first.
1091
1092=head1 Build FAQ
1093
1094=head2 Some C</> became C<\> in pdksh.
1095
1096You have a very old pdksh. See L<Prerequisites>.
1097
1098=head2 C<'errno'> - unresolved external
1099
1100You do not have MT-safe F<db.lib>. See L<Prerequisites>.
1101
2c2e0e8c 1102=head2 Problems with tr or sed
a56dbb1c 1103
2c2e0e8c 1104reported with very old version of tr and sed.
a56dbb1c 1105
1106=head2 Some problem (forget which ;-)
1107
aa689395 1108You have an older version of F<perl.dll> on your LIBPATH, which
a56dbb1c 1109broke the build of extensions.
1110
1111=head2 Library ... not found
1112
1113You did not run C<omflibs>. See L<Prerequisites>.
1114
1115=head2 Segfault in make
1116
aa689395 1117You use an old version of GNU make. See L<Prerequisites>.
a56dbb1c 1118
884335e8 1119=head2 op/sprintf test failure
1120
1121This can result from a bug in emx sprintf which was fixed in 0.9d fix 03.
1122
a56dbb1c 1123=head1 Specific (mis)features of OS/2 port
1124
1125=head2 C<setpriority>, C<getpriority>
1126
1127Note that these functions are compatible with *nix, not with the older
1128ports of '94 - 95. The priorities are absolute, go from 32 to -95,
72ea3524 1129lower is quicker. 0 is the default priority.
a56dbb1c 1130
d88df687 1131B<WARNING>. Calling C<getpriority> on a non-existing process could lock
1132the system before Warp3 fixpak22. Starting with Warp3, Perl will use
1133a workaround: it aborts getpriority() if the process is not present.
1134This is not possible on older versions C<2.*>, and has a race
1135condition anyway.
3998488b 1136
a56dbb1c 1137=head2 C<system()>
1138
1139Multi-argument form of C<system()> allows an additional numeric
1140argument. The meaning of this argument is described in
1141L<OS2::Process>.
1142
3998488b 1143When finding a program to run, Perl first asks the OS to look for executables
d88df687 1144on C<PATH> (OS/2 adds extension F<.exe> if no extension is present).
1145If not found, it looks for a script with possible extensions
3998488b 1146added in this order: no extension, F<.cmd>, F<.btm>,
1147F<.bat>, F<.pl>. If found, Perl checks the start of the file for magic
1148strings C<"#!"> and C<"extproc ">. If found, Perl uses the rest of the
1149first line as the beginning of the command line to run this script. The
1150only mangling done to the first line is extraction of arguments (currently
1151up to 3), and ignoring of the path-part of the "interpreter" name if it can't
1152be found using the full path.
1153
1154E.g., C<system 'foo', 'bar', 'baz'> may lead Perl to finding
1155F<C:/emx/bin/foo.cmd> with the first line being
1156
1157 extproc /bin/bash -x -c
1158
d88df687 1159If F</bin/bash.exe> is not found, then Perl looks for an executable F<bash.exe> on
3998488b 1160C<PATH>. If found in F<C:/emx.add/bin/bash.exe>, then the above system() is
1161translated to
1162
1163 system qw(C:/emx.add/bin/bash.exe -x -c C:/emx/bin/foo.cmd bar baz)
1164
1165One additional translation is performed: instead of F</bin/sh> Perl uses
1166the hardwired-or-customized shell (see C<L<"PERL_SH_DIR">>).
1167
1168The above search for "interpreter" is recursive: if F<bash> executable is not
1169found, but F<bash.btm> is found, Perl will investigate its first line etc.
1170The only hardwired limit on the recursion depth is implicit: there is a limit
11714 on the number of additional arguments inserted before the actual arguments
1172given to system(). In particular, if no additional arguments are specified
1173on the "magic" first lines, then the limit on the depth is 4.
1174
25417810 1175If Perl finds that the found executable is of PM type when the
1176current session is not, it will start the new process in a separate session of
3998488b 1177necessary type. Call via C<OS2::Process> to disable this magic.
1178
d88df687 1179B<WARNING>. Due to the described logic, you need to explicitly
1180specify F<.com> extension if needed. Moreover, if the executable
1181F<perl5.6.1> is requested, Perl will not look for F<perl5.6.1.exe>.
1182[This may change in the future.]
1183
aa689395 1184=head2 C<extproc> on the first line
1185
3998488b 1186If the first chars of a Perl script are C<"extproc ">, this line is treated
aa689395 1187as C<#!>-line, thus all the switches on this line are processed (twice
3998488b 1188if script was started via cmd.exe). See L<perlrun/DESCRIPTION>.
aa689395 1189
a56dbb1c 1190=head2 Additional modules:
615d1a09 1191
3998488b 1192L<OS2::Process>, L<OS2::DLL>, L<OS2::REXX>, L<OS2::PrfDB>, L<OS2::ExtAttr>. These
2c2e0e8c 1193modules provide access to additional numeric argument for C<system>
3998488b 1194and to the information about the running process,
1195to DLLs having functions with REXX signature and to the REXX runtime, to
a56dbb1c 1196OS/2 databases in the F<.INI> format, and to Extended Attributes.
615d1a09 1197
72ea3524 1198Two additional extensions by Andreas Kaiser, C<OS2::UPM>, and
3998488b 1199C<OS2::FTP>, are included into C<ILYAZ> directory, mirrored on CPAN.
25417810 1200Other OS/2-related extensions are available too.
615d1a09 1201
a56dbb1c 1202=head2 Prebuilt methods:
615d1a09 1203
a56dbb1c 1204=over 4
615d1a09 1205
a56dbb1c 1206=item C<File::Copy::syscopy>
615d1a09 1207
d7678ab8 1208used by C<File::Copy::copy>, see L<File::Copy>.
615d1a09 1209
a56dbb1c 1210=item C<DynaLoader::mod2fname>
615d1a09 1211
72ea3524 1212used by C<DynaLoader> for DLL name mangling.
615d1a09 1213
a56dbb1c 1214=item C<Cwd::current_drive()>
615d1a09 1215
a56dbb1c 1216Self explanatory.
615d1a09 1217
a56dbb1c 1218=item C<Cwd::sys_chdir(name)>
615d1a09 1219
a56dbb1c 1220leaves drive as it is.
615d1a09 1221
a56dbb1c 1222=item C<Cwd::change_drive(name)>
615d1a09 1223
3998488b 1224chanes the "current" drive.
615d1a09 1225
a56dbb1c 1226=item C<Cwd::sys_is_absolute(name)>
615d1a09 1227
a56dbb1c 1228means has drive letter and is_rooted.
615d1a09 1229
a56dbb1c 1230=item C<Cwd::sys_is_rooted(name)>
615d1a09 1231
a56dbb1c 1232means has leading C<[/\\]> (maybe after a drive-letter:).
615d1a09 1233
a56dbb1c 1234=item C<Cwd::sys_is_relative(name)>
615d1a09 1235
a56dbb1c 1236means changes with current dir.
615d1a09 1237
a56dbb1c 1238=item C<Cwd::sys_cwd(name)>
615d1a09 1239
aa689395 1240Interface to cwd from EMX. Used by C<Cwd::cwd>.
615d1a09 1241
a56dbb1c 1242=item C<Cwd::sys_abspath(name, dir)>
615d1a09 1243
a56dbb1c 1244Really really odious function to implement. Returns absolute name of
1245file which would have C<name> if CWD were C<dir>. C<Dir> defaults to the
1246current dir.
615d1a09 1247
6d0f518e 1248=item C<Cwd::extLibpath([type])>
615d1a09 1249
a56dbb1c 1250Get current value of extended library search path. If C<type> is
25417810 1251present and positive, works with C<END_LIBPATH>, if negative, works
1252with C<LIBPATHSTRICT>, otherwise with C<BEGIN_LIBPATH>.
615d1a09 1253
a56dbb1c 1254=item C<Cwd::extLibpath_set( path [, type ] )>
615d1a09 1255
a56dbb1c 1256Set current value of extended library search path. If C<type> is
25417810 1257present and positive, works with <END_LIBPATH>, if negative, works
1258with C<LIBPATHSTRICT>, otherwise with C<BEGIN_LIBPATH>.
615d1a09 1259
3998488b 1260=item C<OS2::Error(do_harderror,do_exception)>
1261
1262Returns C<undef> if it was not called yet, otherwise bit 1 is
1263set if on the previous call do_harderror was enabled, bit
d1be9408 12642 is set if on previous call do_exception was enabled.
3998488b 1265
1266This function enables/disables error popups associated with
1267hardware errors (Disk not ready etc.) and software exceptions.
1268
1269I know of no way to find out the state of popups I<before> the first call
1270to this function.
1271
1272=item C<OS2::Errors2Drive(drive)>
1273
1274Returns C<undef> if it was not called yet, otherwise return false if errors
1275were not requested to be written to a hard drive, or the drive letter if
1276this was requested.
1277
1278This function may redirect error popups associated with hardware errors
1279(Disk not ready etc.) and software exceptions to the file POPUPLOG.OS2 at
1280the root directory of the specified drive. Overrides OS2::Error() specified
1281by individual programs. Given argument undef will disable redirection.
1282
1283Has global effect, persists after the application exits.
1284
1285I know of no way to find out the state of redirection of popups to the disk
1286I<before> the first call to this function.
1287
1288=item OS2::SysInfo()
1289
1290Returns a hash with system information. The keys of the hash are
1291
1292 MAX_PATH_LENGTH, MAX_TEXT_SESSIONS, MAX_PM_SESSIONS,
1293 MAX_VDM_SESSIONS, BOOT_DRIVE, DYN_PRI_VARIATION,
1294 MAX_WAIT, MIN_SLICE, MAX_SLICE, PAGE_SIZE,
1295 VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION,
1296 MS_COUNT, TIME_LOW, TIME_HIGH, TOTPHYSMEM, TOTRESMEM,
1297 TOTAVAILMEM, MAXPRMEM, MAXSHMEM, TIMER_INTERVAL,
1298 MAX_COMP_LENGTH, FOREGROUND_FS_SESSION,
1299 FOREGROUND_PROCESS
1300
1301=item OS2::BootDrive()
1302
1303Returns a letter without colon.
1304
1305=item C<OS2::MorphPM(serve)>, C<OS2::UnMorphPM(serve)>
1306
1307Transforms the current application into a PM application and back.
1308The argument true means that a real message loop is going to be served.
1309OS2::MorphPM() returns the PM message queue handle as an integer.
1310
1311See L<"Centralized management of resources"> for additional details.
1312
1313=item C<OS2::Serve_Messages(force)>
1314
1315Fake on-demand retrieval of outstanding PM messages. If C<force> is false,
1316will not dispatch messages if a real message loop is known to
1317be present. Returns number of messages retrieved.
1318
1319Dies with "QUITing..." if WM_QUIT message is obtained.
1320
1321=item C<OS2::Process_Messages(force [, cnt])>
1322
1323Retrieval of PM messages until window creation/destruction.
1324If C<force> is false, will not dispatch messages if a real message loop
1325is known to be present.
1326
1327Returns change in number of windows. If C<cnt> is given,
1328it is incremented by the number of messages retrieved.
1329
1330Dies with "QUITing..." if WM_QUIT message is obtained.
1331
1332=item C<OS2::_control87(new,mask)>
1333
1334the same as L<_control87(3)> of EMX. Takes integers as arguments, returns
1335the previous coprocessor control word as an integer. Only bits in C<new> which
1336are present in C<mask> are changed in the control word.
1337
1338=item OS2::get_control87()
1339
1340gets the coprocessor control word as an integer.
1341
1342=item C<OS2::set_control87_em(new=MCW_EM,mask=MCW_EM)>
1343
1344The variant of OS2::_control87() with default values good for
1345handling exception mask: if no C<mask>, uses exception mask part of C<new>
1346only. If no C<new>, disables all the floating point exceptions.
1347
1348See L<"Misfeatures"> for details.
1349
25417810 1350=item C<OS2::DLLname([how [, \&xsub]])>
1351
1352Gives the information about the Perl DLL or the DLL containing the C
1353function bound to by C<&xsub>. The meaning of C<how> is: default (2):
1354full name; 0: handle; 1: module name.
1355
a56dbb1c 1356=back
615d1a09 1357
a56dbb1c 1358(Note that some of these may be moved to different libraries -
1359eventually).
615d1a09 1360
615d1a09 1361
3998488b 1362=head2 Prebuilt variables:
1363
1364=over 4
1365
1366=item $OS2::emx_rev
1367
25417810 1368numeric value is the same as _emx_rev of EMX, a string value the same
1369as _emx_vprt (similar to C<0.9c>).
3998488b 1370
1371=item $OS2::emx_env
1372
1373same as _emx_env of EMX, a number similar to 0x8001.
1374
1375=item $OS2::os_ver
1376
1377a number C<OS_MAJOR + 0.001 * OS_MINOR>.
1378
25417810 1379=item $OS2::is_aout
1380
1381true if the Perl library was compiled in AOUT format.
1382
1383=item $OS2::can_fork
1384
1385true if the current executable is an AOUT EMX executable, so Perl can
1386fork. Do not use this, use the portable check for
1387$Config::Config{dfork}.
1388
1389=item $OS2::nsyserror
1390
1391This variable (default is 1) controls whether to enforce the contents
1392of $^E to start with C<SYS0003>-like id. If set to 0, then the string
1393value of $^E is what is available from the OS/2 message file. (Some
1394messages in this file have an C<SYS0003>-like id prepended, some not.)
1395
3998488b 1396=back
1397
a56dbb1c 1398=head2 Misfeatures
615d1a09 1399
a56dbb1c 1400=over 4
615d1a09 1401
13a2d996 1402=item *
615d1a09 1403
367f3c24 1404Since L<flock(3)> is present in EMX, but is not functional, it is
1405emulated by perl. To disable the emulations, set environment variable
1406C<USE_PERL_FLOCK=0>.
1407
13a2d996 1408=item *
367f3c24 1409
1410Here is the list of things which may be "broken" on
55497cff 1411EMX (from EMX docs):
1412
13a2d996 1413=over 4
d7678ab8 1414
1415=item *
1416
1417The functions L<recvmsg(3)>, L<sendmsg(3)>, and L<socketpair(3)> are not
1418implemented.
1419
1420=item *
1421
1422L<sock_init(3)> is not required and not implemented.
1423
1424=item *
1425
367f3c24 1426L<flock(3)> is not yet implemented (dummy function). (Perl has a workaround.)
d7678ab8 1427
1428=item *
1429
1430L<kill(3)>: Special treatment of PID=0, PID=1 and PID=-1 is not implemented.
1431
1432=item *
1433
1434L<waitpid(3)>:
1435
55497cff 1436 WUNTRACED
1437 Not implemented.
1438 waitpid() is not implemented for negative values of PID.
1439
d7678ab8 1440=back
1441
55497cff 1442Note that C<kill -9> does not work with the current version of EMX.
615d1a09 1443
13a2d996 1444=item *
615d1a09 1445
25417810 1446See L<"Text-mode filehandles">.
615d1a09 1447
3998488b 1448=item *
1449
1450Unix-domain sockets on OS/2 live in a pseudo-file-system C</sockets/...>.
1451To avoid a failure to create a socket with a name of a different form,
1452C<"/socket/"> is prepended to the socket name (unless it starts with this
1453already).
1454
1455This may lead to problems later in case the socket is accessed via the
1456"usual" file-system calls using the "initial" name.
1457
1458=item *
1459
1460Apparently, IBM used a compiler (for some period of time around '95?) which
1461changes FP mask right and left. This is not I<that> bad for IBM's
1462programs, but the same compiler was used for DLLs which are used with
1463general-purpose applications. When these DLLs are used, the state of
1464floating-point flags in the application is not predictable.
1465
1466What is much worse, some DLLs change the floating point flags when in
1467_DLLInitTerm() (e.g., F<TCP32IP>). This means that even if you do not I<call>
1468any function in the DLL, just the act of loading this DLL will reset your
1469flags. What is worse, the same compiler was used to compile some HOOK DLLs.
1470Given that HOOK dlls are executed in the context of I<all> the applications
1471in the system, this means a complete unpredictablity of floating point
1472flags on systems using such HOOK DLLs. E.g., F<GAMESRVR.DLL> of B<DIVE>
1473origin changes the floating point flags on each write to the TTY of a VIO
1474(windowed text-mode) applications.
1475
1476Some other (not completely debugged) situations when FP flags change include
1477some video drivers (?), and some operations related to creation of the windows.
1478People who code B<OpenGL> may have more experience on this.
1479
1480Perl is generally used in the situation when all the floating-point
1481exceptions are ignored, as is the default under EMX. If they are not ignored,
1482some benign Perl programs would get a C<SIGFPE> and would die a horrible death.
1483
1484To circumvent this, Perl uses two hacks. They help against I<one> type of
1485damage only: FP flags changed when loading a DLL.
1486
25417810 1487One of the hacks is to disable floating point exceptions on Perl startup (as
3998488b 1488is the default with EMX). This helps only with compile-time-linked DLLs
1489changing the flags before main() had a chance to be called.
1490
1491The other hack is to restore FP flags after a call to dlopen(). This helps
1492against similar damage done by DLLs _DLLInitTerm() at runtime. Currently
1493no way to switch these hacks off is provided.
1494
a56dbb1c 1495=back
615d1a09 1496
55497cff 1497=head2 Modifications
1498
1499Perl modifies some standard C library calls in the following ways:
1500
1501=over 9
1502
1503=item C<popen>
1504
72ea3524 1505C<my_popen> uses F<sh.exe> if shell is required, cf. L<"PERL_SH_DIR">.
55497cff 1506
1507=item C<tmpnam>
1508
1509is created using C<TMP> or C<TEMP> environment variable, via
1510C<tempnam>.
1511
1512=item C<tmpfile>
1513
72ea3524 1514If the current directory is not writable, file is created using modified
55497cff 1515C<tmpnam>, so there may be a race condition.
1516
1517=item C<ctermid>
1518
1519a dummy implementation.
1520
1521=item C<stat>
1522
1523C<os2_stat> special-cases F</dev/tty> and F</dev/con>.
1524
3998488b 1525=item C<mkdir>, C<rmdir>
1526
1527these EMX functions do not work if the path contains a trailing C</>.
1528Perl contains a workaround for this.
1529
367f3c24 1530=item C<flock>
1531
1532Since L<flock(3)> is present in EMX, but is not functional, it is
1533emulated by perl. To disable the emulations, set environment variable
1534C<USE_PERL_FLOCK=0>.
1535
55497cff 1536=back
1537
3998488b 1538=head2 Identifying DLLs
1539
1540All the DLLs built with the current versions of Perl have ID strings
1541identifying the name of the extension, its version, and the version
1542of Perl required for this DLL. Run C<bldlevel DLL-name> to find this
1543info.
1544
1545=head2 Centralized management of resources
1546
1547Since to call certain OS/2 API one needs to have a correctly initialized
1548C<Win> subsystem, OS/2-specific extensions may require getting C<HAB>s and
1549C<HMQ>s. If an extension would do it on its own, another extension could
1550fail to initialize.
1551
1552Perl provides a centralized management of these resources:
1553
1554=over
1555
1556=item C<HAB>
1557
1558To get the HAB, the extension should call C<hab = perl_hab_GET()> in C. After
1559this call is performed, C<hab> may be accessed as C<Perl_hab>. There is
1560no need to release the HAB after it is used.
1561
1562If by some reasons F<perl.h> cannot be included, use
1563
1564 extern int Perl_hab_GET(void);
1565
1566instead.
1567
1568=item C<HMQ>
1569
1570There are two cases:
1571
1572=over
1573
1574=item *
1575
1576the extension needs an C<HMQ> only because some API will not work otherwise.
1577Use C<serve = 0> below.
1578
1579=item *
1580
1581the extension needs an C<HMQ> since it wants to engage in a PM event loop.
1582Use C<serve = 1> below.
1583
1584=back
1585
1586To get an C<HMQ>, the extension should call C<hmq = perl_hmq_GET(serve)> in C.
1587After this call is performed, C<hmq> may be accessed as C<Perl_hmq>.
1588
1589To signal to Perl that HMQ is not needed any more, call
1590C<perl_hmq_UNSET(serve)>. Perl process will automatically morph/unmorph itself
1591into/from a PM process if HMQ is needed/not-needed. Perl will automatically
1592enable/disable C<WM_QUIT> message during shutdown if the message queue is
1593served/not-served.
1594
1595B<NOTE>. If during a shutdown there is a message queue which did not disable
1596WM_QUIT, and which did not process the received WM_QUIT message, the
1597shutdown will be automatically cancelled. Do not call C<perl_hmq_GET(1)>
1598unless you are going to process messages on an orderly basis.
1599
25417810 1600=item * Treating errors reported by OS/2 API
1601
1602There are two principal conventions (it is useful to call them C<Dos*>
1603and C<Win*> - though this part of the function signature is not always
1604determined by the name of the API) of reporting the error conditions
1605of OS/2 API. Most of C<Dos*> APIs report the error code as the result
1606of the call (so 0 means success, and there are many types of errors).
1607Most of C<Win*> API report success/fail via the result being
1608C<TRUE>/C<FALSE>; to find the reason for the failure one should call
1609WinGetLastError() API.
1610
1611Some C<Win*> entry points also overload a "meaningful" return value
1612with the error indicator; having a 0 return value indicates an error.
1613Yet some other C<Win*> entry points overload things even more, and 0
1614return value may mean a successful call returning a valid value 0, as
1615well as an error condition; in the case of a 0 return value one should
1616call WinGetLastError() API to distinguish a successful call from a
1617failing one.
1618
1619By convention, all the calls to OS/2 API should indicate their
1620failures by resetting $^E. All the Perl-accessible functions which
1621call OS/2 API may be broken into two classes: some die()s when an API
1622error is encountered, the other report the error via a false return
1623value (of course, this does not concern Perl-accessible functions
1624which I<expect> a failure of the OS/2 API call, having some workarounds
1625coded).
1626
1627Obviously, in the situation of the last type of the signature of an OS/2
1628API, it is must more convenient for the users if the failure is
1629indicated by die()ing: one does not need to check $^E to know that
1630something went wrong. If, however, this solution is not desirable by
1631some reason, the code in question should reset $^E to 0 before making
1632this OS/2 API call, so that the caller of this Perl-accessible
1633function has a chance to distinguish a success-but-0-return value from
1634a failure. (One may return undef as an alternative way of reporting
1635an error.)
1636
1637The macros to simplify this type of error propagation are
1638
1639=over
1640
1641=item C<CheckOSError(expr)>
1642
1643Returns true on error, sets $^E. Expects expr() be a call of
1644C<Dos*>-style API.
1645
1646=item C<CheckWinError(expr)>
1647
1648Returns true on error, sets $^E. Expects expr() be a call of
1649C<Win*>-style API.
1650
1651=item C<SaveWinError(expr)>
1652
1653Returns C<expr>, sets $^E from WinGetLastError() if C<expr> is false.
1654
1655=item C<SaveCroakWinError(expr,die,name1,name2)>
1656
1657Returns C<expr>, sets $^E from WinGetLastError() if C<expr> is false,
1658and die()s if C<die> and $^E are true. The message to die is the
1659concatenated strings C<name1> and C<name2>, separated by C<": "> from
1660the contents of $^E.
1661
1662=item C<WinError_2_Perl_rc>
1663
1664Sets C<Perl_rc> to the return value of WinGetLastError().
1665
1666=item C<FillWinError>
1667
1668Sets C<Perl_rc> to the return value of WinGetLastError(), and sets $^E
1669to the corresponding value.
1670
1671=item C<FillOSError(rc)>
1672
1673Sets C<Perl_rc> to C<rc>, and sets $^E to the corresponding value.
1674
1675=back
1676
1677=item * Loading DLLs and ordinals in DLLs
1678
1679Some DLLs are only present in some versions of OS/2, or in some
1680configurations of OS/2. Some exported entry points are present only
1681in DLLs shipped with some versions of OS/2. If these DLLs and entry
1682points were linked directly for a Perl executable/DLL or from a Perl
1683extensions, this binary would work only with the specified
1684versions/setups. Even if these entry points were not needed, the
1685I<load> of the executable (or DLL) would fail.
1686
1687For example, many newer useful APIs are not present in OS/2 v2; many
1688PM-related APIs require DLLs not available on floppy-boot setup.
1689
1690To make these calls fail I<only when the calls are executed>, one
1691should call these API via a dynamic linking API. There is a subsystem
1692in Perl to simplify such type of calls. A large number of entry
1693points available for such linking is provided (see C<entries_ordinals>
1694- and also C<PMWIN_entries> - in F<os2ish.h>). These ordinals can be
1695accessed via the APIs:
1696
1697 CallORD(), DeclFuncByORD(), DeclVoidFuncByORD(),
1698 DeclOSFuncByORD(), DeclWinFuncByORD(), AssignFuncPByORD(),
1699 DeclWinFuncByORD_CACHE(), DeclWinFuncByORD_CACHE_survive(),
1700 DeclWinFuncByORD_CACHE_resetError_survive(),
1701 DeclWinFunc_CACHE(), DeclWinFunc_CACHE_resetError(),
1702 DeclWinFunc_CACHE_survive(), DeclWinFunc_CACHE_resetError_survive()
1703
1704See the header files and the C code in the supplied OS/2-related
1705modules for the details on usage of these functions.
1706
1707Some of these functions also combine dynaloading semantic with the
1708error-propagation semantic discussed above.
d6fd60d6 1709
3998488b 1710=back
1711
a56dbb1c 1712=head1 Perl flavors
615d1a09 1713
72ea3524 1714Because of idiosyncrasies of OS/2 one cannot have all the eggs in the
aa689395 1715same basket (though EMX environment tries hard to overcome this
a56dbb1c 1716limitations, so the situation may somehow improve). There are 4
1717executables for Perl provided by the distribution:
615d1a09 1718
a56dbb1c 1719=head2 F<perl.exe>
615d1a09 1720
a56dbb1c 1721The main workhorse. This is a chimera executable: it is compiled as an
1722C<a.out>-style executable, but is linked with C<omf>-style dynamic
aa689395 1723library F<perl.dll>, and with dynamic CRT DLL. This executable is a
1724VIO application.
a56dbb1c 1725
3998488b 1726It can load perl dynamic extensions, and it can fork().
a56dbb1c 1727
1728B<Note.> Keep in mind that fork() is needed to open a pipe to yourself.
1729
1730=head2 F<perl_.exe>
1731
3998488b 1732This is a statically linked C<a.out>-style executable. It cannot
1733load dynamic Perl extensions. The executable supplied in binary
1734distributions has a lot of extensions prebuilt, thus the above restriction is
1735important only if you use custom-built extensions. This executable is a VIO
a56dbb1c 1736application.
1737
3998488b 1738I<This is the only executable with does not require OS/2.> The
a56dbb1c 1739friends locked into C<M$> world would appreciate the fact that this
72ea3524 1740executable runs under DOS, Win0.3*, Win0.95 and WinNT with an
a56dbb1c 1741appropriate extender. See L<"Other OSes">.
1742
1743=head2 F<perl__.exe>
1744
aa689395 1745This is the same executable as F<perl___.exe>, but it is a PM
a56dbb1c 1746application.
1747
3998488b 1748B<Note.> Usually (unless explicitly redirected during the startup)
1749STDIN, STDERR, and STDOUT of a PM
1750application are redirected to F<nul>. However, it is possible to I<see>
a56dbb1c 1751them if you start C<perl__.exe> from a PM program which emulates a
aa689395 1752console window, like I<Shell mode> of Emacs or EPM. Thus it I<is
a56dbb1c 1753possible> to use Perl debugger (see L<perldebug>) to debug your PM
3998488b 1754application (but beware of the message loop lockups - this will not
1755work if you have a message queue to serve, unless you hook the serving
1756into the getc() function of the debugger).
a56dbb1c 1757
3998488b 1758Another way to see the output of a PM program is to run it as
1759
1760 pm_prog args 2>&1 | cat -
1761
1762with a shell I<different> from F<cmd.exe>, so that it does not create
1763a link between a VIO session and the session of C<pm_porg>. (Such a link
1764closes the VIO window.) E.g., this works with F<sh.exe> - or with Perl!
1765
1766 open P, 'pm_prog args 2>&1 |' or die;
1767 print while <P>;
1768
1769The flavor F<perl__.exe> is required if you want to start your program without
1770a VIO window present, but not C<detach>ed (run C<help detach> for more info).
1771Very useful for extensions which use PM, like C<Perl/Tk> or C<OpenGL>.
a56dbb1c 1772
25417810 1773Note also that the differences between PM and VIO executables are only
1774in the I<default> behaviour. One can start I<any> executable in
1775I<any> kind of session by using the arguments C</fs>, C</pm> or
1776C</win> switches of the command C<start> (of F<CMD.EXE> or a similar
1777shell). Alternatively, one can use the numeric first argument of the
1778C<system> Perl function (see L<C<OS2::Process>>).
1779
a56dbb1c 1780=head2 F<perl___.exe>
1781
1782This is an C<omf>-style executable which is dynamically linked to
aa689395 1783F<perl.dll> and CRT DLL. I know no advantages of this executable
a56dbb1c 1784over C<perl.exe>, but it cannot fork() at all. Well, one advantage is
1785that the build process is not so convoluted as with C<perl.exe>.
1786
aa689395 1787It is a VIO application.
a56dbb1c 1788
1789=head2 Why strange names?
1790
1791Since Perl processes the C<#!>-line (cf.
1792L<perlrun/DESCRIPTION>, L<perlrun/Switches>,
1793L<perldiag/"Not a perl script">,
1794L<perldiag/"No Perl script found in input">), it should know when a
1795program I<is a Perl>. There is some naming convention which allows
1796Perl to distinguish correct lines from wrong ones. The above names are
72ea3524 1797almost the only names allowed by this convention which do not contain
a56dbb1c 1798digits (which have absolutely different semantics).
1799
1800=head2 Why dynamic linking?
1801
1802Well, having several executables dynamically linked to the same huge
1803library has its advantages, but this would not substantiate the
3998488b 1804additional work to make it compile. The reason is the complicated-to-developers
1805but very quick and convenient-to-users "hard" dynamic linking used by OS/2.
1806
1807There are two distinctive features of the dyna-linking model of OS/2:
25417810 1808first, all the references to external functions are resolved at the compile time;
1809second, there is no runtime fixup of the DLLs after they are loaded into memory.
3998488b 1810The first feature is an enormous advantage over other models: it avoids
1811conflicts when several DLLs used by an application export entries with
1812the same name. In such cases "other" models of dyna-linking just choose
1813between these two entry points using some random criterion - with predictable
1814disasters as results. But it is the second feature which requires the build
1815of F<perl.dll>.
a56dbb1c 1816
72ea3524 1817The address tables of DLLs are patched only once, when they are
3998488b 1818loaded. The addresses of the entry points into DLLs are guaranteed to be
1819the same for all the programs which use the same DLL. This removes the
1820runtime fixup - once DLL is loaded, its code is read-only.
a56dbb1c 1821
3998488b 1822While this allows some (significant?) performance advantages, this makes life
1823much harder for developers, since the above scheme makes it impossible
1824for a DLL to be "linked" to a symbol in the F<.EXE> file. Indeed, this
1825would need a DLL to have different relocations tables for the
1826(different) executables which use this DLL.
1827
1828However, a dynamically loaded Perl extension is forced to use some symbols
1829from the perl
1830executable, e.g., to know how to find the arguments to the functions:
1831the arguments live on the perl
1832internal evaluation stack. The solution is to put the main code of
1833the interpreter into a DLL, and make the F<.EXE> file which just loads
1834this DLL into memory and supplies command-arguments. The extension DLL
1835cannot link to symbols in F<.EXE>, but it has no problem linking
1836to symbols in the F<.DLL>.
a56dbb1c 1837
72ea3524 1838This I<greatly> increases the load time for the application (as well as
3998488b 1839complexity of the compilation). Since interpreter is in a DLL,
1840the C RTL is basically forced to reside in a DLL as well (otherwise
1841extensions would not be able to use CRT). There are some advantages if
1842you use different flavors of perl, such as running F<perl.exe> and
1843F<perl__.exe> simultaneously: they share the memory of F<perl.dll>.
1844
1845B<NOTE>. There is one additional effect which makes DLLs more wasteful:
1846DLLs are loaded in the shared memory region, which is a scarse resource
1847given the 512M barrier of the "standard" OS/2 virtual memory. The code of
1848F<.EXE> files is also shared by all the processes which use the particular
1849F<.EXE>, but they are "shared in the private address space of the process";
1850this is possible because the address at which different sections
1851of the F<.EXE> file are loaded is decided at compile-time, thus all the
1852processes have these sections loaded at same addresses, and no fixup
1853of internal links inside the F<.EXE> is needed.
1854
d1be9408 1855Since DLLs may be loaded at run time, to have the same mechanism for DLLs
3998488b 1856one needs to have the address range of I<any of the loaded> DLLs in the
1857system to be available I<in all the processes> which did not load a particular
1858DLL yet. This is why the DLLs are mapped to the shared memory region.
a56dbb1c 1859
1860=head2 Why chimera build?
1861
aa689395 1862Current EMX environment does not allow DLLs compiled using Unixish
3998488b 1863C<a.out> format to export symbols for data (or at least some types of
1864data). This forces C<omf>-style compile of F<perl.dll>.
a56dbb1c 1865
aa689395 1866Current EMX environment does not allow F<.EXE> files compiled in
a56dbb1c 1867C<omf> format to fork(). fork() is needed for exactly three Perl
1868operations:
1869
1870=over 4
1871
3998488b 1872=item *
a56dbb1c 1873
3998488b 1874explicit fork() in the script,
a56dbb1c 1875
3998488b 1876=item *
a56dbb1c 1877
3998488b 1878C<open FH, "|-">
1879
1880=item *
a56dbb1c 1881
3998488b 1882C<open FH, "-|">, in other words, opening pipes to itself.
a56dbb1c 1883
1884=back
1885
3998488b 1886While these operations are not questions of life and death, they are
1887needed for a lot of
1888useful scripts. This forces C<a.out>-style compile of
a56dbb1c 1889F<perl.exe>.
1890
1891
1892=head1 ENVIRONMENT
1893
aa689395 1894Here we list environment variables with are either OS/2- and DOS- and
1895Win*-specific, or are more important under OS/2 than under other OSes.
a56dbb1c 1896
1897=head2 C<PERLLIB_PREFIX>
1898
aa689395 1899Specific for EMX port. Should have the form
a56dbb1c 1900
1901 path1;path2
1902
1903or
1904
1905 path1 path2
1906
1907If the beginning of some prebuilt path matches F<path1>, it is
1908substituted with F<path2>.
1909
1910Should be used if the perl library is moved from the default
1911location in preference to C<PERL(5)LIB>, since this would not leave wrong
3998488b 1912entries in @INC. For example, if the compiled version of perl looks for @INC
eb447b86 1913in F<f:/perllib/lib>, and you want to install the library in
1914F<h:/opt/gnu>, do
1915
1916 set PERLLIB_PREFIX=f:/perllib/lib;h:/opt/gnu
a56dbb1c 1917
3998488b 1918This will cause Perl with the prebuilt @INC of
1919
1920 f:/perllib/lib/5.00553/os2
1921 f:/perllib/lib/5.00553
1922 f:/perllib/lib/site_perl/5.00553/os2
1923 f:/perllib/lib/site_perl/5.00553
1924 .
1925
1926to use the following @INC:
1927
1928 h:/opt/gnu/5.00553/os2
1929 h:/opt/gnu/5.00553
1930 h:/opt/gnu/site_perl/5.00553/os2
1931 h:/opt/gnu/site_perl/5.00553
1932 .
1933
a56dbb1c 1934=head2 C<PERL_BADLANG>
1935
3998488b 1936If 0, perl ignores setlocale() failing. May be useful with some
a56dbb1c 1937strange I<locale>s.
1938
1939=head2 C<PERL_BADFREE>
1940
3998488b 1941If 0, perl would not warn of in case of unwarranted free(). With older
1942perls this might be
1943useful in conjunction with the module DB_File, which was buggy when
1944dynamically linked and OMF-built.
1945
1946Should not be set with newer Perls, since this may hide some I<real> problems.
a56dbb1c 1947
1948=head2 C<PERL_SH_DIR>
1949
aa689395 1950Specific for EMX port. Gives the directory part of the location for
a56dbb1c 1951F<sh.exe>.
1952
367f3c24 1953=head2 C<USE_PERL_FLOCK>
1954
1955Specific for EMX port. Since L<flock(3)> is present in EMX, but is not
1956functional, it is emulated by perl. To disable the emulations, set
1957environment variable C<USE_PERL_FLOCK=0>.
1958
a56dbb1c 1959=head2 C<TMP> or C<TEMP>
1960
3998488b 1961Specific for EMX port. Used as storage place for temporary files.
a56dbb1c 1962
1963=head1 Evolution
1964
1965Here we list major changes which could make you by surprise.
1966
25417810 1967=head2 Text-mode filehandles
1968
1969Starting from version 5.8, Perl uses a builtin translation layer for
1970text-mode files. This replaces the efficient well-tested EMX layer by
1971some code which should be best characterized as a "quick hack".
1972
1973In addition to possible bugs and an inability to follow changes to the
1974translation policy with off/on switches of TERMIO translation, this
1975introduces a serious incompatible change: before sysread() on
1976text-mode filehandles would go through the translation layer, now it
1977would not.
1978
a56dbb1c 1979=head2 Priorities
1980
1981C<setpriority> and C<getpriority> are not compatible with earlier
1982ports by Andreas Kaiser. See C<"setpriority, getpriority">.
1983
d88df687 1984=head2 DLL name mangling: pre 5.6.2
a56dbb1c 1985
1986With the release 5.003_01 the dynamically loadable libraries
3998488b 1987should be rebuilt when a different version of Perl is compiled. In particular,
1988DLLs (including F<perl.dll>) are now created with the names
a56dbb1c 1989which contain a checksum, thus allowing workaround for OS/2 scheme of
1990caching DLLs.
1991
3998488b 1992It may be possible to code a simple workaround which would
1993
1994=over
1995
1996=item *
1997
1998find the old DLLs looking through the old @INC;
1999
2000=item *
2001
2002mangle the names according to the scheme of new perl and copy the DLLs to
2003these names;
2004
2005=item *
2006
2007edit the internal C<LX> tables of DLL to reflect the change of the name
2008(probably not needed for Perl extension DLLs, since the internally coded names
2009are not used for "specific" DLLs, they used only for "global" DLLs).
2010
2011=item *
2012
2013edit the internal C<IMPORT> tables and change the name of the "old"
2014F<perl????.dll> to the "new" F<perl????.dll>.
2015
2016=back
2017
354a27bf 2018=head2 DLL name mangling: 5.6.2 and beyond
d88df687 2019
2020In fact mangling of I<extension> DLLs was done due to misunderstanding
2021of the OS/2 dynaloading model. OS/2 (effectively) maintains two
2022different tables of loaded DLL:
2023
2024=over
2025
2026=item Global DLLs
2027
2028those loaded by the base name from C<LIBPATH>; including those
2029associated at link time;
2030
2031=item specific DLLs
2032
2033loaded by the full name.
2034
2035=back
2036
2037When resolving a request for a global DLL, the table of already-loaded
2038specific DLLs is (effectively) ignored; moreover, specific DLLs are
2039I<always> loaded from the prescribed path.
2040
2041There is/was a minor twist which makes this scheme fragile: what to do
2042with DLLs loaded from
2043
2044=over
2045
2046=item C<BEGINLIBPATH> and C<ENDLIBPATH>
2047
2048(which depend on the process)
2049
2050=item F<.> from C<LIBPATH>
2051
2052which I<effectively> depends on the process (although C<LIBPATH> is the
2053same for all the processes).
2054
2055=back
2056
2057Unless C<LIBPATHSTRICT> is set to C<T> (and the kernel is after
20582000/09/01), such DLLs are considered to be global. When loading a
2059global DLL it is first looked in the table of already-loaded global
2060DLLs. Because of this the fact that one executable loaded a DLL from
2061C<BEGINLIBPATH> and C<ENDLIBPATH>, or F<.> from C<LIBPATH> may affect
2062I<which> DLL is loaded when I<another> executable requests a DLL with
2063the same name. I<This> is the reason for version-specific mangling of
2064the DLL name for perl DLL.
2065
2066Since the Perl extension DLLs are always loaded with the full path,
2067there is no need to mangle their names in a version-specific ways:
2068their directory already reflects the corresponding version of perl,
2069and @INC takes into account binary compatibility with older version.
2070Starting from C<5.6.2> the name mangling scheme is fixed to be the
2071same as for Perl 5.005_53 (same as in a popular binary release). Thus
2072new Perls will be able to I<resolve the names> of old extension DLLs
2073if @INC allows finding their directories.
2074
210b36aa 2075However, this still does not guarantee that these DLL may be loaded.
d88df687 2076The reason is the mangling of the name of the I<Perl DLL>. And since
2077the extension DLLs link with the Perl DLL, extension DLLs for older
2078versions would load an older Perl DLL, and would most probably
2079segfault (since the data in this DLL is not properly initialized).
2080
2081There is a partial workaround (which can be made complete with newer
2082OS/2 kernels): create a forwarder DLL with the same name as the DLL of
2083the older version of Perl, which forwards the entry points to the
2084newer Perl's DLL. Make this DLL accessible on (say) the C<BEGINLIBPATH> of
2085the new Perl executable. When the new executable accesses old Perl's
2086extension DLLs, they would request the old Perl's DLL by name, get the
2087forwarder instead, so effectively will link with the currently running
2088(new) Perl DLL.
2089
2090This may break in two ways:
2091
2092=over
2093
2094=item *
2095
2096Old perl executable is started when a new executable is running has
2097loaded an extension compiled for the old executable (ouph!). In this
2098case the old executable will get a forwarder DLL instead of the old
2099perl DLL, so would link with the new perl DLL. While not directly
210b36aa 2100fatal, it will behave the same as new executable. This beats the whole
d88df687 2101purpose of explicitly starting an old executable.
2102
2103=item *
2104
2105A new executable loads an extension compiled for the old executable
2106when an old perl executable is running. In this case the extension
2107will not pick up the forwarder - with fatal results.
2108
2109=back
2110
2111With support for C<LIBPATHSTRICT> this may be circumvented - unless
2112one of DLLs is started from F<.> from C<LIBPATH> (I do not know
2113whether C<LIBPATHSTRICT> affects this case).
2114
2115B<REMARK>. Unless newer kernels allow F<.> in C<BEGINLIBPATH> (older
25417810 2116do not), this mess cannot be completely cleaned. (It turns out that
2117as of the beginning of 2002, F<.> is not allowed, but F<.\.> is - and
2118it has the same effect.)
d88df687 2119
2120
2121B<REMARK>. C<LIBPATHSTRICT>, C<BEGINLIBPATH> and C<ENDLIBPATH> are
2122not environment variables, although F<cmd.exe> emulates them on C<SET
2123...> lines. From Perl they may be accessed by L<Cwd::extLibpath> and
2124L<Cwd::extLibpath_set>.
2125
2126=head2 DLL forwarder generation
2127
2128Assume that the old DLL is named F<perlE0AC.dll> (as is one for
21295.005_53), and the new version is 5.6.1. Create a file
2130F<perl5shim.def-leader> with
2131
2132 LIBRARY 'perlE0AC' INITINSTANCE TERMINSTANCE
2133 DESCRIPTION '@#perl5-porters@perl.org:5.006001#@ Perl module for 5.00553 -> Perl 5.6.1 forwarder'
2134 CODE LOADONCALL
2135 DATA LOADONCALL NONSHARED MULTIPLE
2136 EXPORTS
2137
2138modifying the versions/names as needed. Run
2139
2140 perl -wnle "next if 0../EXPORTS/; print qq( \"$1\") if /\"(\w+)\"/" perl5.def >lst
2141
2142in the Perl build directory (to make the DLL smaller replace perl5.def
2143with the definition file for the older version of Perl if present).
2144
2145 cat perl5shim.def-leader lst >perl5shim.def
2146 gcc -Zomf -Zdll -o perlE0AC.dll perl5shim.def -s -llibperl
2147
2148(ignore multiple C<warning L4085>).
2149
a56dbb1c 2150=head2 Threading
2151
3998488b 2152As of release 5.003_01 perl is linked to multithreaded C RTL
2153DLL. If perl itself is not compiled multithread-enabled, so will not be perl's
a56dbb1c 2154malloc(). However, extensions may use multiple thread on their own
2155risk.
2156
3998488b 2157This was needed to compile C<Perl/Tk> for XFree86-OS/2 out-of-the-box, and
2158link with DLLs for other useful libraries, which typically are compiled
2159with C<-Zmt -Zcrtdll>.
a56dbb1c 2160
2161=head2 Calls to external programs
2162
2163Due to a popular demand the perl external program calling has been
72ea3524 2164changed wrt Andreas Kaiser's port. I<If> perl needs to call an
a56dbb1c 2165external program I<via shell>, the F<f:/bin/sh.exe> will be called, or
2166whatever is the override, see L<"PERL_SH_DIR">.
2167
2168Thus means that you need to get some copy of a F<sh.exe> as well (I
3998488b 2169use one from pdksh). The path F<F:/bin> above is set up automatically during
a56dbb1c 2170the build to a correct value on the builder machine, but is
2171overridable at runtime,
2172
2173B<Reasons:> a consensus on C<perl5-porters> was that perl should use
2174one non-overridable shell per platform. The obvious choices for OS/2
2175are F<cmd.exe> and F<sh.exe>. Having perl build itself would be impossible
3998488b 2176with F<cmd.exe> as a shell, thus I picked up C<sh.exe>. This assures almost
aa689395 2177100% compatibility with the scripts coming from *nix. As an added benefit
2178this works as well under DOS if you use DOS-enabled port of pdksh
2179(see L<"Prerequisites">).
a56dbb1c 2180
aa689395 2181B<Disadvantages:> currently F<sh.exe> of pdksh calls external programs
a56dbb1c 2182via fork()/exec(), and there is I<no> functioning exec() on
3998488b 2183OS/2. exec() is emulated by EMX by an asynchronous call while the caller
72ea3524 2184waits for child completion (to pretend that the C<pid> did not change). This
a56dbb1c 2185means that 1 I<extra> copy of F<sh.exe> is made active via fork()/exec(),
2186which may lead to some resources taken from the system (even if we do
2187not count extra work needed for fork()ing).
2188
72ea3524 2189Note that this a lesser issue now when we do not spawn F<sh.exe>
2190unless needed (metachars found).
2191
2192One can always start F<cmd.exe> explicitly via
a56dbb1c 2193
2194 system 'cmd', '/c', 'mycmd', 'arg1', 'arg2', ...
2195
72ea3524 2196If you need to use F<cmd.exe>, and do not want to hand-edit thousands of your
a56dbb1c 2197scripts, the long-term solution proposed on p5-p is to have a directive
2198
2199 use OS2::Cmd;
2200
2201which will override system(), exec(), C<``>, and
2202C<open(,'...|')>. With current perl you may override only system(),
2203readpipe() - the explicit version of C<``>, and maybe exec(). The code
2204will substitute the one-argument call to system() by
2205C<CORE::system('cmd.exe', '/c', shift)>.
2206
2207If you have some working code for C<OS2::Cmd>, please send it to me,
2208I will include it into distribution. I have no need for such a module, so
2209cannot test it.
2210
2c2e0e8c 2211For the details of the current situation with calling external programs,
3998488b 2212see L<Starting OS/2 (and DOS) programs under Perl>. Set us mention a couple
2213of features:
2c2e0e8c 2214
13a2d996 2215=over 4
2c2e0e8c 2216
13a2d996 2217=item *
2c2e0e8c 2218
3998488b 2219External scripts may be called by their basename. Perl will try the same
2220extensions as when processing B<-S> command-line switch.
2221
2222=item *
2223
2224External scripts starting with C<#!> or C<extproc > will be executed directly,
2225without calling the shell, by calling the program specified on the rest of
2226the first line.
2c2e0e8c 2227
2228=back
2229
df3ef7a9 2230=head2 Memory allocation
2231
2232Perl uses its own malloc() under OS/2 - interpreters are usually malloc-bound
ec40c0cd 2233for speed, but perl is not, since its malloc is lightning-fast.
4375e838 2234Perl-memory-usage-tuned benchmarks show that Perl's malloc is 5 times quicker
2235than EMX one. I do not have convincing data about memory footprint, but
3998488b 2236a (pretty random) benchmark showed that Perl's one is 5% better.
df3ef7a9 2237
2238Combination of perl's malloc() and rigid DLL name resolution creates
2239a special problem with library functions which expect their return value to
2240be free()d by system's free(). To facilitate extensions which need to call
2241such functions, system memory-allocation functions are still available with
2242the prefix C<emx_> added. (Currently only DLL perl has this, it should
2243propagate to F<perl_.exe> shortly.)
2244
ec40c0cd 2245=head2 Threads
2246
2247One can build perl with thread support enabled by providing C<-D usethreads>
2248option to F<Configure>. Currently OS/2 support of threads is very
2249preliminary.
2250
2251Most notable problems:
2252
13a2d996 2253=over 4
ec40c0cd 2254
2255=item C<COND_WAIT>
2256
25417810 2257may have a race condition (but probably does not due to edge-triggered
2258nature of OS/2 Event semaphores). (Needs a reimplementation (in terms of chaining
2259waiting threads, with the linked list stored in per-thread structure?)?)
ec40c0cd 2260
2261=item F<os2.c>
2262
2263has a couple of static variables used in OS/2-specific functions. (Need to be
2264moved to per-thread structure, or serialized?)
2265
2266=back
2267
2268Note that these problems should not discourage experimenting, since they
2269have a low probability of affecting small programs.
2270
d88df687 2271=head1 BUGS
2272
2273This description was not updated since 5.6.1, see F<os2/Changes> for
2274more info.
2275
a56dbb1c 2276=cut
2277
2278OS/2 extensions
2279~~~~~~~~~~~~~~~
72ea3524 2280I include 3 extensions by Andreas Kaiser, OS2::REXX, OS2::UPM, and OS2::FTP,
a56dbb1c 2281into my ftp directory, mirrored on CPAN. I made
2282some minor changes needed to compile them by standard tools. I cannot
2283test UPM and FTP, so I will appreciate your feedback. Other extensions
2284there are OS2::ExtAttr, OS2::PrfDB for tied access to EAs and .INI
2285files - and maybe some other extensions at the time you read it.
2286
2287Note that OS2 perl defines 2 pseudo-extension functions
aa689395 2288OS2::Copy::copy and DynaLoader::mod2fname (many more now, see
2289L<Prebuilt methods>).
a56dbb1c 2290
2291The -R switch of older perl is deprecated. If you need to call a REXX code
2292which needs access to variables, include the call into a REXX compartment
2293created by
2294 REXX_call {...block...};
2295
2296Two new functions are supported by REXX code,
2297 REXX_eval 'string';
2298 REXX_eval_with 'string', REXX_function_name => \&perl_sub_reference;
2299
2300If you have some other extensions you want to share, send the code to
2301me. At least two are available: tied access to EA's, and tied access
2302to system databases.
615d1a09 2303
a56dbb1c 2304=head1 AUTHOR
615d1a09 2305
25417810 2306Ilya Zakharevich, cpan@ilyaz.org
615d1a09 2307
a56dbb1c 2308=head1 SEE ALSO
615d1a09 2309
a56dbb1c 2310perl(1).
615d1a09 2311
a56dbb1c 2312=cut
615d1a09 2313