This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
toke.c:incline: Avoid duplicate symbol lookup
[perl5.git] / README.os2
index e02c081..d356e35 100644 (file)
@@ -151,7 +151,7 @@ versions of EMX.
 
 =item *
 
-You need a separate perl executable F<perl__.exe> (see L<perl__.exe>)
+You need a separate perl executable F<perl__.exe> (see L</perl__.exe>)
 if you want to use PM code in your application (as Perl/Tk or OpenGL
 Perl modules do) without having a text-mode window present.
 
@@ -162,7 +162,7 @@ Using F<perl__.exe> avoids such a degradation.
 =item *
 
 There is no simple way to access WPS objects. The only way I know
-is via C<OS2::REXX> and C<SOM> extensions (see L<OS2::REXX>, L<Som>).
+is via C<OS2::REXX> and C<SOM> extensions (see L<OS2::REXX>, L<SOM>).
 However, we do not have access to
 convenience methods of Object-REXX. (Is it possible at all? I know
 of no Object-REXX API.)  The C<SOM> extension (currently in alpha-text)
@@ -186,7 +186,7 @@ Note that not all features of Perl are available under these
 environments. This depends on the features the I<extender> - most
 probably RSX - decided to implement.
 
-Cf. L<Prerequisites>.
+Cf. L</Prerequisites>.
 
 =head2 Prerequisites
 
@@ -196,7 +196,7 @@ Cf. L<Prerequisites>.
 
 EMX runtime is required (may be substituted by RSX). Note that
 it is possible to make F<perl_.exe> to run under DOS without any
-external support by binding F<emx.exe>/F<rsx.exe> to it, see L<emxbind>. Note
+external support by binding F<emx.exe>/F<rsx.exe> to it, see C<emxbind>. Note
 that under DOS for best results one should use RSX runtime, which
 has much more functions working (like C<fork>, C<popen> and so on). In
 fact RSX is required if there is no VCPI present. Note the
@@ -208,9 +208,8 @@ under earlier versions of EMX, but this is not tested.
 
 One can get different parts of EMX from, say
 
-  http://www.leo.org/pub/comp/os/os2/leo/gnu/emx+gcc/
-  http://powerusersbbs.com/pub/os2/dev/   [EMX+GCC Development]
-  http://hobbes.nmsu.edu/pub/os2/dev/emx/v0.9d/
+  ftp://crydee.sai.msu.ru/pub/comp/os/os2/leo/gnu/emx+gcc/
+  http://hobbes.nmsu.edu/h-browse.php?dir=/pub/os2/dev/emx/v0.9d/
 
 The runtime component should have the name F<emxrt.zip>.
 
@@ -235,9 +234,8 @@ can have Perl development environment under DOS.
 
 One can get RSX from, say
 
-  ftp://ftp.cdrom.com/pub/os2/emx09c/contrib
-  ftp://ftp.uni-bielefeld.de/pub/systems/msdos/misc
-  ftp://ftp.leo.org/pub/comp/os/os2/leo/devtools/emx+gcc/contrib
+  http://cd.textfiles.com/hobbesos29804/disk1/EMX09C/
+  ftp://crydee.sai.msu.ru/pub/comp/os/os2/leo/gnu/emx+gcc/contrib/
 
 Contact the author on C<rainer@mathematik.uni-bielefeld.de>.
 
@@ -266,7 +264,7 @@ either in the wired-in-during-compile locations (usually F<F:/bin>),
 or in configurable location (see L<"PERL_SH_DIR">).
 
 For best results use EMX pdksh. The standard binary (5.2.14 or later) runs
-under DOS (with L<RSX>) as well, see
+under DOS (with L</RSX>) as well, see
 
   http://www.ilyaz.org/software/os2/
 
@@ -317,7 +315,7 @@ or whatever method you prefer.
 There are also endless possibilities to use I<executable extensions> of
 4os2, I<associations> of WPS and so on... However, if you use
 *nixish shell (like F<sh.exe> supplied in the binary distribution),
-you need to follow the syntax specified in L<perlrun/"Switches">.
+you need to follow the syntax specified in L<perlrun/"Command Switches">.
 
 Note that B<-S> switch supports scripts with additional extensions 
 F<.cmd>, F<.btm>, F<.bat>, F<.pl> as well.
@@ -406,11 +404,12 @@ there is an executable file F<blah.exe> I<anywhere> on C<PATH>.  In
 other words, C<PATH> is essentially searched twice: once by the OS for
 an executable, then by Perl for scripts.
 
-Note also that executable files on OS/2 can have an arbitrary extension, 
-but F<.exe> will be automatically appended if no dot is present in the name.  
-The workaround is as simple as that:  since F<blah.> and F<blah> denote the 
-same file (at list on FAT and HPFS file systems), to start an executable residing in file F<n:/bin/blah> (no 
-extension) give an argument C<n:/bin/blah.> (dot appended) to system().
+Note also that executable files on OS/2 can have an arbitrary extension, but
+F<.exe> will be automatically appended if no dot is present in the name.  The
+workaround is as simple as that:  since F<blah.> and F<blah> denote the same
+file (at list on FAT and HPFS file systems), to start an executable residing in
+file F<n:/bin/blah> (no extension) give an argument C<n:/bin/blah.> (dot
+appended) to system().
 
 Perl will start PM programs from VIO (=text-mode) Perl process in a
 separate PM session;
@@ -437,7 +436,7 @@ managed to goof.  C<;-)>
 =item *
 
 Did you run your programs with C<-w> switch? See 
-L<Starting OS/2 (and DOS) programs under Perl>.
+L<Starting OSE<sol>2 (and DOS) programs under Perl>.
 
 =item *
 
@@ -477,10 +476,10 @@ should be done "correctly".
 =head2 C<``> and pipe-C<open> do not work under DOS.
 
 This may a variant of just L<"I cannot run external programs">, or a
-deeper problem. Basically: you I<need> RSX (see L<"Prerequisites">)
+deeper problem. Basically: you I<need> RSX (see L</Prerequisites>)
 for these commands to work, and you may need a port of F<sh.exe> which
 understands command arguments. One of such ports is listed in
-L<"Prerequisites"> under RSX. Do not forget to set variable
+L</Prerequisites> under RSX. Do not forget to set variable
 C<L<"PERL_SH_DIR">> as well.
 
 DPMI is required for RSX.
@@ -489,7 +488,7 @@ DPMI is required for RSX.
 
 The whole idea of the "standard C API to start applications" is that
 the forms C<foo> and C<"foo"> of program arguments are completely
-interchangable.  F<find> breaks this paradigm;
+interchangeable.  F<find> breaks this paradigm;
 
   find "pattern" file
   find pattern file
@@ -559,7 +558,7 @@ of this file.
 
 B<NOTE>. Because of a typo the binary installer of 5.00305
 would install a variable C<PERL_SHPATH> into F<Config.sys>. Please
-remove this variable and put C<L<PERL_SH_DIR>> instead.
+remove this variable and put C<L</PERL_SH_DIR>> instead.
 
 =head2 Manual binary installation
 
@@ -620,7 +619,7 @@ C<set PERLLIB_PREFIX> in F<Config.sys>, see L<"PERLLIB_PREFIX">.
 
 =item Additional Perl modules
 
-  unzip perl_ste.zip -d f:/perllib/lib/site_perl/5.8.3/
+  unzip perl_ste.zip -d f:/perllib/lib/site_perl/5.19.3/
 
 Same remark as above applies.  Additionally, if this directory is not
 one of directories on @INC (and @INC is influenced by C<PERLLIB_PREFIX>), you
@@ -799,8 +798,7 @@ can be constructed using C<pod2latex>.
 
 =head1 BUILD
 
-Here we discuss how to build Perl under OS/2. There is an alternative
-(but maybe older) view on L<http://www.shadow.net/~troc/os2perl.html>.
+Here we discuss how to build Perl under OS/2.
 
 =head2 The short story
 
@@ -846,10 +844,11 @@ optionally - Berkeley DB headers and libraries, and crypt.
 
 Possible locations to get the files:
 
-  ftp://hobbes.nmsu.edu/os2/unix/
-  ftp://ftp.cdrom.com/pub/os2/unix/
-  ftp://ftp.cdrom.com/pub/os2/dev32/
-  ftp://ftp.cdrom.com/pub/os2/emx09c/
+
+  ftp://ftp.uni-heidelberg.de/pub/os2/unix/
+  http://hobbes.nmsu.edu/h-browse.php?dir=/pub/os2
+  http://cd.textfiles.com/hobbesos29804/disk1/DEV32/
+  http://cd.textfiles.com/hobbesos29804/disk1/EMX09C/
 
 It is reported that the following archives contain enough utils to
 build perl: F<gnufutil.zip>, F<gnusutil.zip>, F<gnututil.zip>, F<gnused.zip>,
@@ -857,7 +856,7 @@ F<gnupatch.zip>, F<gnuawk.zip>, F<gnumake.zip>, F<gnugrep.zip>, F<bsddev.zip> an
 F<ksh527rt.zip> (or a later version).  Note that all these utilities are
 known to be available from LEO:
 
-  ftp://ftp.leo.org/pub/comp/os/os2/leo/gnu
+  ftp://crydee.sai.msu.ru/pub/comp/os/os2/leo/gnu/
 
 Note also that the F<db.lib> and F<db.a> from the EMX distribution
 are not suitable for multi-threaded compile (even single-threaded
@@ -869,7 +868,10 @@ compatibility with XFree86-OS/2). Get a corrected one from
 If you have I<exactly the same version of Perl> installed already,
 make sure that no copies or perl are currently running.  Later steps
 of the build may fail since an older version of F<perl.dll> loaded into
-memory may be found. 
+memory may be found.  Running C<make test> becomes meaningless, since
+the test are checking a previous build of perl (this situation is detected
+and reported by F<lib/os2_base.t> test).  Do not forget to unset
+C<PERL_EMXLOAD_SEC> in environment.
 
 Also make sure that you have F</tmp> directory on the current drive,
 and F<.> directory in your C<LIBPATH>. One may try to correct the
@@ -898,8 +900,8 @@ link386 prompts, press C<Ctrl-C> to exit.
 You need to fetch the latest perl source (including developers
 releases). With some probability it is located in 
 
-  http://www.cpan.org/src/5.0
-  http://www.cpan.org/src/5.0/unsupported
+  http://www.cpan.org/src/
+  http://www.cpan.org/src/unsupported
 
 If not, you may need to dig in the indices to find it in the directory
 of the current maintainer.
@@ -907,7 +909,7 @@ of the current maintainer.
 Quick cycle of developers release may break the OS/2 build time to
 time, looking into 
 
-  http://www.cpan.org/ports/os2/ilyaz/
+  http://www.cpan.org/ports/os2/
 
 may indicate the latest release which was publicly released by the
 maintainer. Note that the release may include some additional patches
@@ -1060,7 +1062,7 @@ Run
 to convert perl utilities to F<.cmd> files and put them on
 PATH. You need to put F<.EXE>-utilities on path manually. They are
 installed in C<$prefix/bin>, here C<$prefix> is what you gave to
-F<Configure>, see L<Making>.
+F<Configure>, see L</Making>.
 
 If you use C<man>, either move the installed F<*/man/> directories to
 your C<MANPATH>, or modify C<MANPATH> to match the location.  (One
@@ -1089,15 +1091,443 @@ say, by doing
 
 first.
 
+=head1 Building a binary distribution
+
+[This section provides a short overview only...]
+
+Building should proceed differently depending on whether the version of perl
+you install is already present and used on your system, or is a new version
+not yet used.  The description below assumes that the version is new, so
+installing its DLLs and F<.pm> files will not disrupt the operation of your
+system even if some intermediate steps are not yet fully working.
+
+The other cases require a little bit more convoluted procedures.  Below I
+suppose that the current version of Perl is C<5.8.2>, so the executables are
+named accordingly.
+
+=over
+
+=item 1.
+
+Fully build and test the Perl distribution.  Make sure that no tests are
+failing with C<test> and C<aout_test> targets; fix the bugs in Perl and
+the Perl test suite detected by these tests.  Make sure that C<all_test>
+make target runs as clean as possible.  Check that F<os2/perlrexx.cmd>
+runs fine.
+
+=item 2.
+
+Fully install Perl, including C<installcmd> target.  Copy the generated DLLs
+to C<LIBPATH>; copy the numbered Perl executables (as in F<perl5.8.2.exe>)
+to C<PATH>; copy C<perl_.exe> to C<PATH> as C<perl_5.8.2.exe>.  Think whether
+you need backward-compatibility DLLs.  In most cases you do not need to install
+them yet; but sometime this may simplify the following steps.
+
+=item 3.
+
+Make sure that C<CPAN.pm> can download files from CPAN.  If not, you may need
+to manually install C<Net::FTP>.
+
+=item 4.
+
+Install the bundle C<Bundle::OS2_default>
+
+  perl5.8.2 -MCPAN -e "install Bundle::OS2_default" < nul |& tee 00cpan_i_1
+
+This may take a couple of hours on 1GHz processor (when run the first time).
+And this should not be necessarily a smooth procedure.  Some modules may not
+specify required dependencies, so one may need to repeat this procedure several
+times until the results stabilize.
+
+  perl5.8.2 -MCPAN -e "install Bundle::OS2_default" < nul |& tee 00cpan_i_2
+  perl5.8.2 -MCPAN -e "install Bundle::OS2_default" < nul |& tee 00cpan_i_3
+
+Even after they stabilize, some tests may fail.
+
+Fix as many discovered bugs as possible.  Document all the bugs which are not
+fixed, and all the failures with unknown reasons.  Inspect the produced logs
+F<00cpan_i_1> to find suspiciously skipped tests, and other fishy events.
+
+Keep in mind that I<installation> of some modules may fail too: for example,
+the DLLs to update may be already loaded by F<CPAN.pm>.  Inspect the C<install>
+logs (in the example above F<00cpan_i_1> etc) for errors, and install things
+manually, as in
+
+  cd $CPANHOME/.cpan/build/Digest-MD5-2.31
+  make install
+
+Some distributions may fail some tests, but you may want to install them
+anyway (as above, or via C<force install> command of C<CPAN.pm> shell-mode).
+
+Since this procedure may take quite a long time to complete, it makes sense
+to "freeze" your CPAN configuration by disabling periodic updates of the
+local copy of CPAN index: set C<index_expire> to some big value (I use 365),
+then save the settings
+
+  CPAN> o conf index_expire 365
+  CPAN> o conf commit
+
+Reset back to the default value C<1> when you are finished.
+
+=item 5.
+
+When satisfied with the results, rerun the C<installcmd> target.  Now you
+can copy C<perl5.8.2.exe> to C<perl.exe>, and install the other OMF-build
+executables: C<perl__.exe> etc.  They are ready to be used.
+
+=item 6.
+
+Change to the C<./pod> directory of the build tree, download the Perl logo
+F<CamelGrayBig.BMP>, and run
+
+  ( perl2ipf > perl.ipf ) |& tee 00ipf
+  ipfc /INF perl.ipf |& tee 00inf
+
+This produces the Perl docs online book C<perl.INF>.  Install in on
+C<BOOKSHELF> path.
+
+=item 7.
+
+Now is the time to build statically linked executable F<perl_.exe> which
+includes newly-installed via C<Bundle::OS2_default> modules.  Doing testing
+via C<CPAN.pm> is going to be painfully slow, since it statically links
+a new executable per XS extension.
+
+Here is a possible workaround: create a toplevel F<Makefile.PL> in
+F<$CPANHOME/.cpan/build/> with contents being (compare with L<Making
+executables with a custom collection of statically loaded extensions>)
+
+  use ExtUtils::MakeMaker;
+  WriteMakefile NAME => 'dummy';
+
+execute this as
+
+  perl_5.8.2.exe Makefile.PL <nul |& tee 00aout_c1
+  make -k all test <nul |& 00aout_t1
+
+Again, this procedure should not be absolutely smooth.  Some C<Makefile.PL>'s
+in subdirectories may be buggy, and would not run as "child" scripts.  The
+interdependency of modules can strike you; however, since non-XS modules
+are already installed, the prerequisites of most modules have a very good
+chance to be present.
+
+If you discover some glitches, move directories of problematic modules to a
+different location; if these modules are non-XS modules, you may just ignore
+them - they are already installed; the remaining, XS, modules you need to
+install manually one by one.
+
+After each such removal you need to rerun the C<Makefile.PL>/C<make> process;
+usually this procedure converges soon.  (But be sure to convert all the
+necessary external C libraries from F<.lib> format to F<.a> format: run one of
+
+  emxaout foo.lib
+  emximp -o foo.a foo.lib
+
+whichever is appropriate.)  Also, make sure that the DLLs for external
+libraries are usable with with executables compiled without C<-Zmtd> options.
+
+When you are sure that only a few subdirectories
+lead to failures, you may want to add C<-j4> option to C<make> to speed up
+skipping subdirectories with already finished build.
+
+When you are satisfied with the results of tests, install the build C libraries
+for extensions:
+
+  make install |& tee 00aout_i
+
+Now you can rename the file F<./perl.exe> generated during the last phase
+to F<perl_5.8.2.exe>; place it on C<PATH>; if there is an inter-dependency
+between some XS modules, you may need to repeat the C<test>/C<install> loop
+with this new executable and some excluded modules - until the procedure
+converges.
+
+Now you have all the necessary F<.a> libraries for these Perl modules in the
+places where Perl builder can find it.  Use the perl builder: change to an
+empty directory, create a "dummy" F<Makefile.PL> again, and run
+
+  perl_5.8.2.exe Makefile.PL |& tee 00c
+  make perl                 |& tee 00p
+
+This should create an executable F<./perl.exe> with all the statically loaded
+extensions built in.  Compare the generated F<perlmain.c> files to make sure
+that during the iterations the number of loaded extensions only increases.
+Rename F<./perl.exe> to F<perl_5.8.2.exe> on C<PATH>.
+
+When it converges, you got a functional variant of F<perl_5.8.2.exe>; copy it
+to C<perl_.exe>.  You are done with generation of the local Perl installation.
+
+=item 8.
+
+Make sure that the installed modules are actually installed in the location
+of the new Perl, and are not inherited from entries of @INC given for
+inheritance from the older versions of Perl: set C<PERLLIB_582_PREFIX> to
+redirect the new version of Perl to a new location, and copy the installed
+files to this new location.  Redo the tests to make sure that the versions of
+modules inherited from older versions of Perl are not needed.
+
+Actually, the log output of L<pod2ipf(1)> during the step 6 gives a very detailed
+info about which modules are loaded from which place; so you may use it as
+an additional verification tool.
+
+Check that some temporary files did not make into the perl install tree.
+Run something like this
+
+  pfind . -f "!(/\.(pm|pl|ix|al|h|a|lib|txt|pod|imp|bs|dll|ld|bs|inc|xbm|yml|cgi|uu|e2x|skip|packlist|eg|cfg|html|pub|enc|all|ini|po|pot)$/i or /^\w+$/") | less
+
+in the install tree (both top one and F<sitelib> one).
+
+Compress all the DLLs with F<lxlite>.  The tiny F<.exe> can be compressed with
+C</c:max> (the bug only appears when there is a fixup in the last 6 bytes of a
+page (?); since the tiny executables are much smaller than a page, the bug
+will not hit).  Do not compress C<perl_.exe> - it would not work under DOS.
+
+=item 9.
+
+Now you can generate the binary distribution.  This is done by running the
+test of the CPAN distribution C<OS2::SoftInstaller>.  Tune up the file
+F<test.pl> to suit the layout of current version of Perl first.  Do not
+forget to pack the necessary external DLLs accordingly.  Include the
+description of the bugs and test suite failures you could not fix.  Include
+the small-stack versions of Perl executables from Perl build directory.
+
+Include F<perl5.def> so that people can relink the perl DLL preserving
+the binary compatibility, or can create compatibility DLLs.  Include the diff
+files (C<diff -pu old new>) of fixes you did so that people can rebuild your
+version.  Include F<perl5.map> so that one can use remote debugging.
+
+=item 10.
+
+Share what you did with the other people.  Relax.  Enjoy fruits of your work.
+
+=item 11.
+
+Brace yourself for thanks, bug reports, hate mail and spam coming as result
+of the previous step.  No good deed should remain unpunished!
+
+=back
+
+=head1 Building custom F<.EXE> files
+
+The Perl executables can be easily rebuilt at any moment.  Moreover, one can
+use the I<embedding> interface (see L<perlembed>) to make very customized
+executables.
+
+=head2 Making executables with a custom collection of statically loaded extensions
+
+It is a little bit easier to do so while I<decreasing> the list of statically
+loaded extensions.  We discuss this case only here.
+
+=over
+
+=item 1.
+
+Change to an empty directory, and create a placeholder <Makefile.PL>:
+
+  use ExtUtils::MakeMaker;
+  WriteMakefile NAME => 'dummy';
+
+=item 2.
+
+Run it with the flavor of Perl (F<perl.exe> or F<perl_.exe>) you want to
+rebuild.
+
+  perl_ Makefile.PL
+
+=item 3.
+
+Ask it to create new Perl executable:
+
+  make perl
+
+(you may need to manually add C<PERLTYPE=-DPERL_CORE> to this commandline on
+some versions of Perl; the symptom is that the command-line globbing does not
+work from OS/2 shells with the newly-compiled executable; check with
+
+  .\perl.exe -wle "print for @ARGV" *
+
+).
+
+=item 4.
+
+The previous step created F<perlmain.c> which contains a list of newXS() calls
+near the end.  Removing unnecessary calls, and rerunning
+
+  make perl
+
+will produce a customized executable.
+
+=back
+
+=head2 Making executables with a custom search-paths
+
+The default perl executable is flexible enough to support most usages.
+However, one may want something yet more flexible; for example, one may want
+to find Perl DLL relatively to the location of the EXE file; or one may want
+to ignore the environment when setting the Perl-library search patch, etc.
+
+If you fill comfortable with I<embedding> interface (see L<perlembed>), such
+things are easy to do repeating the steps outlined in L<Making
+executables with a custom collection of statically loaded extensions>, and
+doing more comprehensive edits to main() of F<perlmain.c>.  The people with
+little desire to understand Perl can just rename main(), and do necessary
+modification in a custom main() which calls the renamed function in appropriate
+time.
+
+However, there is a third way: perl DLL exports the main() function and several
+callbacks to customize the search path.  Below is a complete example of a
+"Perl loader" which
+
+=over
+
+=item 1.
+
+Looks for Perl DLL in the directory C<$exedir/../dll>;
+
+=item 2.
+
+Prepends the above directory to C<BEGINLIBPATH>;
+
+=item 3.
+
+Fails if the Perl DLL found via C<BEGINLIBPATH> is different from what was
+loaded on step 1; e.g., another process could have loaded it from C<LIBPATH>
+or from a different value of C<BEGINLIBPATH>.  In these cases one needs to
+modify the setting of the system so that this other process either does not
+run, or loads the DLL from C<BEGINLIBPATH> with C<LIBPATHSTRICT=T> (available
+with kernels after September 2000).
+
+=item 4.
+
+Loads Perl library from C<$exedir/../dll/lib/>.
+
+=item 5.
+
+Uses Bourne shell from C<$exedir/../dll/sh/ksh.exe>.
+
+=back
+
+For best results compile the C file below with the same options as the Perl
+DLL.  However, a lot of functionality will work even if the executable is not
+an EMX applications, e.g., if compiled with
+
+  gcc -Wall -DDOSISH -DOS2=1 -O2 -s -Zomf -Zsys perl-starter.c \
+    -DPERL_DLL_BASENAME=\"perl312F\" -Zstack 8192 -Zlinker /PM:VIO
+
+Here is the sample C file:
+
+  #define INCL_DOS
+  #define INCL_NOPM
+  /* These are needed for compile if os2.h includes os2tk.h, not os2emx.h */
+  #define INCL_DOSPROCESS
+  #include <os2.h>
+
+  #include "EXTERN.h"
+  #define PERL_IN_MINIPERLMAIN_C
+  #include "perl.h"
+
+  static char *me;
+  HMODULE handle;
+
+  static void
+  die_with(char *msg1, char *msg2, char *msg3, char *msg4)
+  {
+     ULONG c;
+     char *s = " error: ";
+
+     DosWrite(2, me, strlen(me), &c);
+     DosWrite(2, s, strlen(s), &c);
+     DosWrite(2, msg1, strlen(msg1), &c);
+     DosWrite(2, msg2, strlen(msg2), &c);
+     DosWrite(2, msg3, strlen(msg3), &c);
+     DosWrite(2, msg4, strlen(msg4), &c);
+     DosWrite(2, "\r\n", 2, &c);
+     exit(255);
+  }
+
+  typedef ULONG (*fill_extLibpath_t)(int type, char *pre, char *post, int replace, char *msg);
+  typedef int (*main_t)(int type, char *argv[], char *env[]);
+  typedef int (*handler_t)(void* data, int which);
+
+  #ifndef PERL_DLL_BASENAME
+  #  define PERL_DLL_BASENAME "perl"
+  #endif
+
+  static HMODULE
+  load_perl_dll(char *basename)
+  {
+      char buf[300], fail[260];
+      STRLEN l, dirl;
+      fill_extLibpath_t f;
+      ULONG rc_fullname;
+      HMODULE handle, handle1;
+
+      if (_execname(buf, sizeof(buf) - 13) != 0)
+          die_with("Can't find full path: ", strerror(errno), "", "");
+      /* XXXX Fill 'me' with new value */
+      l = strlen(buf);
+      while (l && buf[l-1] != '/' && buf[l-1] != '\\')
+          l--;
+      dirl = l - 1;
+      strcpy(buf + l, basename);
+      l += strlen(basename);
+      strcpy(buf + l, ".dll");
+      if ( (rc_fullname = DosLoadModule(fail, sizeof fail, buf, &handle)) != 0
+           && DosLoadModule(fail, sizeof fail, basename, &handle) != 0 )
+          die_with("Can't load DLL ", buf, "", "");
+      if (rc_fullname)
+          return handle;               /* was loaded with short name; all is fine */
+      if (DosQueryProcAddr(handle, 0, "fill_extLibpath", (PFN*)&f))
+          die_with(buf, ": DLL exports no symbol ", "fill_extLibpath", "");
+      buf[dirl] = 0;
+      if (f(0 /*BEGINLIBPATH*/, buf /* prepend */, NULL /* append */,
+            0 /* keep old value */, me))
+          die_with(me, ": prepending BEGINLIBPATH", "", "");
+      if (DosLoadModule(fail, sizeof fail, basename, &handle1) != 0)
+          die_with(me, ": finding perl DLL again via BEGINLIBPATH", "", "");
+      buf[dirl] = '\\';     
+      if (handle1 != handle) {
+          if (DosQueryModuleName(handle1, sizeof(fail), fail))
+              strcpy(fail, "???");
+          die_with(buf, ":\n\tperl DLL via BEGINLIBPATH is different: \n\t",
+                   fail,
+                   "\n\tYou may need to manipulate global BEGINLIBPATH and LIBPATHSTRICT"
+                   "\n\tso that the other copy is loaded via BEGINLIBPATH.");
+      }
+      return handle;
+  }
+
+  int
+  main(int argc, char **argv, char **env)
+  {
+      main_t f;
+      handler_t h;
+
+      me = argv[0];
+      /**/
+      handle = load_perl_dll(PERL_DLL_BASENAME);
+
+      if (DosQueryProcAddr(handle, 0, "Perl_OS2_handler_install", (PFN*)&h))
+          die_with(PERL_DLL_BASENAME, ": DLL exports no symbol ", "Perl_OS2_handler_install", "");
+      if ( !h((void *)"~installprefix", Perlos2_handler_perllib_from)
+           || !h((void *)"~dll", Perlos2_handler_perllib_to)
+           || !h((void *)"~dll/sh/ksh.exe", Perlos2_handler_perl_sh) )
+          die_with(PERL_DLL_BASENAME, ": Can't install @INC manglers", "", "");
+
+      if (DosQueryProcAddr(handle, 0, "dll_perlmain", (PFN*)&f))
+          die_with(PERL_DLL_BASENAME, ": DLL exports no symbol ", "dll_perlmain", "");
+      return f(argc, argv, env);
+  }
+
+
 =head1 Build FAQ
 
 =head2 Some C</> became C<\> in pdksh.
 
-You have a very old pdksh. See L<Prerequisites>.
+You have a very old pdksh. See L</Prerequisites>.
 
 =head2 C<'errno'> - unresolved external
 
-You do not have MT-safe F<db.lib>. See L<Prerequisites>.
+You do not have MT-safe F<db.lib>. See L</Prerequisites>.
 
 =head2 Problems with tr or sed
 
@@ -1110,11 +1540,11 @@ broke the build of extensions.
 
 =head2 Library ... not found
 
-You did not run C<omflibs>. See L<Prerequisites>.
+You did not run C<omflibs>. See L</Prerequisites>.
 
 =head2 Segfault in make
 
-You use an old version of GNU make. See L<Prerequisites>.
+You use an old version of GNU make. See L</Prerequisites>.
 
 =head2 op/sprintf test failure
 
@@ -1221,7 +1651,7 @@ leaves drive as it is.
 
 =item  C<Cwd::change_drive(name)>
 
-chanes the "current" drive.
+changes the "current" drive.
 
 =item  C<Cwd::sys_is_absolute(name)>
 
@@ -1468,7 +1898,7 @@ _DLLInitTerm() (e.g., F<TCP32IP>).  This means that even if you do not I<call>
 any function in the DLL, just the act of loading this DLL will reset your
 flags.  What is worse, the same compiler was used to compile some HOOK DLLs.
 Given that HOOK dlls are executed in the context of I<all> the applications
-in the system, this means a complete unpredictablity of floating point
+in the system, this means a complete unpredictability of floating point
 flags on systems using such HOOK DLLs.  E.g., F<GAMESRVR.DLL> of B<DIVE>
 origin changes the floating point flags on each write to the TTY of a VIO
 (windowed text-mode) applications.
@@ -1597,7 +2027,7 @@ WM_QUIT, and which did not process the received WM_QUIT message, the
 shutdown will be automatically cancelled.  Do not call C<perl_hmq_GET(1)>
 unless you are going to process messages on an orderly basis.
 
-=item Treating errors reported by OS/2 API
+=item Treating errors reported by OS/2 API
 
 There are two principal conventions (it is useful to call them C<Dos*>
 and C<Win*> - though this part of the function signature is not always
@@ -1674,7 +2104,7 @@ Sets C<Perl_rc> to C<rc>, and sets $^E to the corresponding value.
 
 =back
 
-=item Loading DLLs and ordinals in DLLs
+=item Loading DLLs and ordinals in DLLs
 
 Some DLLs are only present in some versions of OS/2, or in some
 configurations of OS/2.  Some exported entry points are present only
@@ -1775,7 +2205,7 @@ in the I<default> behaviour.  One can start I<any> executable in
 I<any> kind of session by using the arguments C</fs>, C</pm> or
 C</win> switches of the command C<start> (of F<CMD.EXE> or a similar
 shell).  Alternatively, one can use the numeric first argument of the
-C<system> Perl function (see L<C<OS2::Process>>).
+C<system> Perl function (see L<OS2::Process>).
 
 =head2 F<perl___.exe>
 
@@ -1789,8 +2219,7 @@ It is a VIO application.
 =head2 Why strange names?
 
 Since Perl processes the C<#!>-line (cf. 
-L<perlrun/DESCRIPTION>, L<perlrun/Switches>,
-L<perldiag/"Not a perl script">, 
+L<perlrun/DESCRIPTION>, L<perlrun/Command Switches>,
 L<perldiag/"No Perl script found in input">), it should know when a
 program I<is a Perl>. There is some naming convention which allows
 Perl to distinguish correct lines from wrong ones. The above names are
@@ -2120,8 +2549,9 @@ it has the same effect.)
 
 B<REMARK>.  C<LIBPATHSTRICT>, C<BEGINLIBPATH> and C<ENDLIBPATH> are
 not environment variables, although F<cmd.exe> emulates them on C<SET
-...> lines.  From Perl they may be accessed by L<Cwd::extLibpath> and
-L<Cwd::extLibpath_set>.
+...> lines.  From Perl they may be accessed by
+L<Cwd::extLibpath|/Cwd::extLibpath([type])> and
+L<Cwd::extLibpath_set|/Cwd::extLibpath_set( path [, type ] )>.
 
 =head2 DLL forwarder generation
 
@@ -2176,7 +2606,7 @@ are F<cmd.exe> and F<sh.exe>. Having perl build itself would be impossible
 with F<cmd.exe> as a shell, thus I picked up C<sh.exe>. This assures almost
 100% compatibility with the scripts coming from *nix. As an added benefit 
 this works as well under DOS if you use DOS-enabled port of pdksh 
-(see L<"Prerequisites">).
+(see L</Prerequisites>).
 
 B<Disadvantages:> currently F<sh.exe> of pdksh calls external programs
 via fork()/exec(), and there is I<no> functioning exec() on
@@ -2209,7 +2639,7 @@ I will include it into distribution. I have no need for such a module, so
 cannot test it.
 
 For the details of the current situation with calling external programs,
-see L<Starting OS/2 (and DOS) programs under Perl>.  Set us mention a couple
+see L<Starting OSE<sol>2 (and DOS) programs under Perl>.  Set us mention a couple
 of features:
 
 =over 4
@@ -2270,8 +2700,8 @@ have a low probability of affecting small programs.
 
 =head1 BUGS
 
-This description was not updated since 5.6.1, see F<os2/Changes> for
-more info.
+This description is not updated often (since 5.6.1?), see F<./os2/Changes>
+for more info.
 
 =cut