Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1942 lines
62 KiB

  1. If you read this file _as_is_, just ignore the funny characters you
  2. see. It is written in the POD format (see perlpod manpage) which is
  3. specially designed to be readable as is.
  4. =head1 NAME
  5. perlos2 - Perl under OS/2, DOS, Win0.3*, Win0.95 and WinNT.
  6. =head1 SYNOPSIS
  7. One can read this document in the following formats:
  8. man perlos2
  9. view perl perlos2
  10. explorer perlos2.html
  11. info perlos2
  12. to list some (not all may be available simultaneously), or it may
  13. be read I<as is>: either as F<README.os2>, or F<pod/perlos2.pod>.
  14. To read the F<.INF> version of documentation (B<very> recommended)
  15. outside of OS/2, one needs an IBM's reader (may be available on IBM
  16. ftp sites (?) (URL anyone?)) or shipped with PC DOS 7.0 and IBM's
  17. Visual Age C++ 3.5.
  18. A copy of a Win* viewer is contained in the "Just add OS/2 Warp" package
  19. ftp://ftp.software.ibm.com/ps/products/os2/tools/jaow/jaow.zip
  20. in F<?:\JUST_ADD\view.exe>. This gives one an access to EMX's
  21. F<.INF> docs as well (text form is available in F</emx/doc> in
  22. EMX's distribution).
  23. Note that if you have F<lynx.exe> installed, you can follow WWW links
  24. from this document in F<.INF> format. If you have EMX docs installed
  25. correctly, you can follow library links (you need to have C<view emxbook>
  26. working by setting C<EMXBOOK> environment variable as it is described
  27. in EMX docs).
  28. =cut
  29. Contents
  30. perlos2 - Perl under OS/2, DOS, Win0.3*, Win0.95 and WinNT.
  31. NAME
  32. SYNOPSIS
  33. DESCRIPTION
  34. - Target
  35. - Other OSes
  36. - Prerequisites
  37. - Starting Perl programs under OS/2 (and DOS and...)
  38. - Starting OS/2 (and DOS) programs under Perl
  39. Frequently asked questions
  40. - I cannot run external programs
  41. - I cannot embed perl into my program, or use perl.dll from my program.
  42. - `` and pipe-open do not work under DOS.
  43. - Cannot start find.exe "pattern" file
  44. INSTALLATION
  45. - Automatic binary installation
  46. - Manual binary installation
  47. - Warning
  48. Accessing documentation
  49. - OS/2 .INF file
  50. - Plain text
  51. - Manpages
  52. - HTML
  53. - GNU info files
  54. - .PDF files
  55. - LaTeX docs
  56. BUILD
  57. - Prerequisites
  58. - Getting perl source
  59. - Application of the patches
  60. - Hand-editing
  61. - Making
  62. - Testing
  63. - Installing the built perl
  64. - a.out-style build
  65. Build FAQ
  66. - Some / became \ in pdksh.
  67. - 'errno' - unresolved external
  68. - Problems with tr
  69. - Some problem (forget which ;-)
  70. - Library ... not found
  71. - Segfault in make
  72. Specific (mis)features of EMX port
  73. - setpriority, getpriority
  74. - system()
  75. - extproc on the first line
  76. - Additional modules:
  77. - Prebuilt methods:
  78. - Misfeatures
  79. - Modifications
  80. Perl flavors
  81. - perl.exe
  82. - perl_.exe
  83. - perl__.exe
  84. - perl___.exe
  85. - Why strange names?
  86. - Why dynamic linking?
  87. - Why chimera build?
  88. ENVIRONMENT
  89. - PERLLIB_PREFIX
  90. - PERL_BADLANG
  91. - PERL_BADFREE
  92. - PERL_SH_DIR
  93. - TMP or TEMP
  94. Evolution
  95. - Priorities
  96. - DLL name mangling
  97. - Threading
  98. - Calls to external programs
  99. - Memory allocation
  100. - Threads
  101. AUTHOR
  102. SEE ALSO
  103. =head1 DESCRIPTION
  104. =head2 Target
  105. The target is to make OS/2 the best supported platform for
  106. using/building/developing Perl and I<Perl applications>, as well as
  107. make Perl the best language to use under OS/2. The secondary target is
  108. to try to make this work under DOS and Win* as well (but not B<too> hard).
  109. The current state is quite close to this target. Known limitations:
  110. =over 5
  111. =item *
  112. Some *nix programs use fork() a lot; with the mostly useful flavors of perl
  113. for OS/2 (there are several built simultaneously) this is supported;
  114. some flavors do not. Using fork() after I<use>ing dynamically loading
  115. extensions would not work with very old versions of EMX.
  116. =item *
  117. You need a separate perl executable F<perl__.exe> (see L<perl__.exe>)
  118. if you want to use PM code in your application (as Perl/Tk or OpenGL
  119. Perl modules do) without having a text-mode window present.
  120. While using the standard F<perl.exe> from a text-mode window is possible
  121. too, I have seen cases when this causes degradation of the system stability.
  122. Using F<perl__.exe> avoids such a degradation.
  123. =item *
  124. There is no simple way to access WPS objects. The only way I know
  125. is via C<OS2::REXX> extension (see L<OS2::REXX>), and we do not have access to
  126. convenience methods of Object-REXX. (Is it possible at all? I know
  127. of no Object-REXX API.) The C<SOM> extension (currently in alpha-text)
  128. may eventually remove this shortcoming.
  129. =back
  130. Please keep this list up-to-date by informing me about other items.
  131. =head2 Other OSes
  132. Since OS/2 port of perl uses a remarkable EMX environment, it can
  133. run (and build extensions, and - possibly - be built itself) under any
  134. environment which can run EMX. The current list is DOS,
  135. DOS-inside-OS/2, Win0.3*, Win0.95 and WinNT. Out of many perl flavors,
  136. only one works, see L<"perl_.exe">.
  137. Note that not all features of Perl are available under these
  138. environments. This depends on the features the I<extender> - most
  139. probably RSX - decided to implement.
  140. Cf. L<Prerequisites>.
  141. =head2 Prerequisites
  142. =over 6
  143. =item EMX
  144. EMX runtime is required (may be substituted by RSX). Note that
  145. it is possible to make F<perl_.exe> to run under DOS without any
  146. external support by binding F<emx.exe>/F<rsx.exe> to it, see L<emxbind>. Note
  147. that under DOS for best results one should use RSX runtime, which
  148. has much more functions working (like C<fork>, C<popen> and so on). In
  149. fact RSX is required if there is no VCPI present. Note the
  150. RSX requires DPMI.
  151. Only the latest runtime is supported, currently C<0.9d fix 03>. Perl may run
  152. under earlier versions of EMX, but this is not tested.
  153. One can get different parts of EMX from, say
  154. http://www.leo.org/pub/comp/os/os2/leo/gnu/emx+gcc/
  155. http://powerusersbbs.com/pub/os2/dev/ [EMX+GCC Development]
  156. http://hobbes.nmsu.edu/pub/os2/dev/emx/v0.9d/
  157. The runtime component should have the name F<emxrt.zip>.
  158. B<NOTE>. It is enough to have F<emx.exe>/F<rsx.exe> on your path. One
  159. does not need to specify them explicitly (though this
  160. emx perl_.exe -de 0
  161. will work as well.)
  162. =item RSX
  163. To run Perl on DPMI platforms one needs RSX runtime. This is
  164. needed under DOS-inside-OS/2, Win0.3*, Win0.95 and WinNT (see
  165. L<"Other OSes">). RSX would not work with VCPI
  166. only, as EMX would, it requires DMPI.
  167. Having RSX and the latest F<sh.exe> one gets a fully functional
  168. B<*nix>-ish environment under DOS, say, C<fork>, C<``> and
  169. pipe-C<open> work. In fact, MakeMaker works (for static build), so one
  170. can have Perl development environment under DOS.
  171. One can get RSX from, say
  172. ftp://ftp.cdrom.com/pub/os2/emx09c/contrib
  173. ftp://ftp.uni-bielefeld.de/pub/systems/msdos/misc
  174. ftp://ftp.leo.org/pub/comp/os/os2/leo/devtools/emx+gcc/contrib
  175. Contact the author on C<[email protected]>.
  176. The latest F<sh.exe> with DOS hooks is available in
  177. ftp://ftp.math.ohio-state.edu/pub/users/ilya/os2/
  178. as F<sh_dos.zip> or under similar names starting with C<sh>, C<pdksh> etc.
  179. =item HPFS
  180. Perl does not care about file systems, but to install the whole perl
  181. library intact one needs a file system which supports long file names.
  182. Note that if you do not plan to build the perl itself, it may be
  183. possible to fool EMX to truncate file names. This is not supported,
  184. read EMX docs to see how to do it.
  185. =item pdksh
  186. To start external programs with complicated command lines (like with
  187. pipes in between, and/or quoting of arguments), Perl uses an external
  188. shell. With EMX port such shell should be named F<sh.exe>, and located
  189. either in the wired-in-during-compile locations (usually F<F:/bin>),
  190. or in configurable location (see L<"PERL_SH_DIR">).
  191. For best results use EMX pdksh. The standard binary (5.2.14 or later) runs
  192. under DOS (with L<RSX>) as well, see
  193. ftp://ftp.math.ohio-state.edu/pub/users/ilya/os2/
  194. =back
  195. =head2 Starting Perl programs under OS/2 (and DOS and...)
  196. Start your Perl program F<foo.pl> with arguments C<arg1 arg2 arg3> the
  197. same way as on any other platform, by
  198. perl foo.pl arg1 arg2 arg3
  199. If you want to specify perl options C<-my_opts> to the perl itself (as
  200. opposed to to your program), use
  201. perl -my_opts foo.pl arg1 arg2 arg3
  202. Alternately, if you use OS/2-ish shell, like CMD or 4os2, put
  203. the following at the start of your perl script:
  204. extproc perl -S -my_opts
  205. rename your program to F<foo.cmd>, and start it by typing
  206. foo arg1 arg2 arg3
  207. Note that because of stupid OS/2 limitations the full path of the perl
  208. script is not available when you use C<extproc>, thus you are forced to
  209. use C<-S> perl switch, and your script should be on the C<PATH>. As a plus
  210. side, if you know a full path to your script, you may still start it
  211. with
  212. perl ../../blah/foo.cmd arg1 arg2 arg3
  213. (note that the argument C<-my_opts> is taken care of by the C<extproc> line
  214. in your script, see L<C<extproc> on the first line>).
  215. To understand what the above I<magic> does, read perl docs about C<-S>
  216. switch - see L<perlrun>, and cmdref about C<extproc>:
  217. view perl perlrun
  218. man perlrun
  219. view cmdref extproc
  220. help extproc
  221. or whatever method you prefer.
  222. There are also endless possibilities to use I<executable extensions> of
  223. 4os2, I<associations> of WPS and so on... However, if you use
  224. *nixish shell (like F<sh.exe> supplied in the binary distribution),
  225. you need to follow the syntax specified in L<perlrun/"Switches">.
  226. Note that B<-S> switch enables a search with additional extensions
  227. F<.cmd>, F<.btm>, F<.bat>, F<.pl> as well.
  228. =head2 Starting OS/2 (and DOS) programs under Perl
  229. This is what system() (see L<perlfunc/system>), C<``> (see
  230. L<perlop/"I/O Operators">), and I<open pipe> (see L<perlfunc/open>)
  231. are for. (Avoid exec() (see L<perlfunc/exec>) unless you know what you
  232. do).
  233. Note however that to use some of these operators you need to have a
  234. sh-syntax shell installed (see L<"Pdksh">,
  235. L<"Frequently asked questions">), and perl should be able to find it
  236. (see L<"PERL_SH_DIR">).
  237. The cases when the shell is used are:
  238. =over
  239. =item 1
  240. One-argument system() (see L<perlfunc/system>), exec() (see L<perlfunc/exec>)
  241. with redirection or shell meta-characters;
  242. =item 2
  243. Pipe-open (see L<perlfunc/open>) with the command which contains redirection
  244. or shell meta-characters;
  245. =item 3
  246. Backticks C<``> (see L<perlop/"I/O Operators">) with the command which contains
  247. redirection or shell meta-characters;
  248. =item 4
  249. If the executable called by system()/exec()/pipe-open()/C<``> is a script
  250. with the "magic" C<#!> line or C<extproc> line which specifies shell;
  251. =item 5
  252. If the executable called by system()/exec()/pipe-open()/C<``> is a script
  253. without "magic" line, and C<$ENV{EXECSHELL}> is set to shell;
  254. =item 6
  255. If the executable called by system()/exec()/pipe-open()/C<``> is not
  256. found;
  257. =item 7
  258. For globbing (see L<perlfunc/glob>, L<perlop/"I/O Operators">).
  259. =back
  260. For the sake of speed for a common case, in the above algorithms
  261. backslashes in the command name are not considered as shell metacharacters.
  262. Perl starts scripts which begin with cookies
  263. C<extproc> or C<#!> directly, without an intervention of shell. Perl uses the
  264. same algorithm to find the executable as F<pdksh>: if the path
  265. on C<#!> line does not work, and contains C</>, then the executable
  266. is searched in F<.> and on C<PATH>. To find arguments for these scripts
  267. Perl uses a different algorithm than F<pdksh>: up to 3 arguments are
  268. recognized, and trailing whitespace is stripped.
  269. If a script
  270. does not contain such a cooky, then to avoid calling F<sh.exe>, Perl uses
  271. the same algorithm as F<pdksh>: if C<$ENV{EXECSHELL}> is set, the
  272. script is given as the first argument to this command, if not set, then
  273. C<$ENV{COMSPEC} /c> is used (or a hardwired guess if C<$ENV{COMSPEC}> is
  274. not set).
  275. If starting scripts directly, Perl will use exactly the same algorithm as for
  276. the search of script given by B<-S> command-line option: it will look in
  277. the current directory, then on components of C<$ENV{PATH}> using the
  278. following order of appended extensions: no extension, F<.cmd>, F<.btm>,
  279. F<.bat>, F<.pl>.
  280. Note that Perl will start to look for scripts only if OS/2 cannot start the
  281. specified application, thus C<system 'blah'> will not look for a script if
  282. there is an executable file F<blah.exe> I<anywhere> on C<PATH>.
  283. Note also that executable files on OS/2 can have an arbitrary extension,
  284. but F<.exe> will be automatically appended if no dot is present in the name.
  285. The workaround as as simple as that: since F<blah.> and F<blah> denote the
  286. same file, to start an executable residing in file F<n:/bin/blah> (no
  287. extension) give an argument C<n:/bin/blah.> (dot appended) to system().
  288. Perl will correctly start PM programs from VIO (=text-mode) Perl process;
  289. the opposite is not true: when you start a non-PM program from a PM
  290. Perl process, it would not run it in a separate session. If a separate
  291. session is desired, either ensure
  292. that shell will be used, as in C<system 'cmd /c myprog'>, or start it using
  293. optional arguments to system() documented in C<OS2::Process> module. This
  294. is considered to be a feature.
  295. =head1 Frequently asked questions
  296. =head2 "It does not work"
  297. Perl binary distributions come with a F<testperl.cmd> script which tries
  298. to detect common problems with misconfigured installations. There is a
  299. pretty large chance it will discover which step of the installation you
  300. managed to goof. C<;-)>
  301. =head2 I cannot run external programs
  302. =over 4
  303. =item *
  304. Did you run your programs with C<-w> switch? See
  305. L<Starting OS/2 (and DOS) programs under Perl>.
  306. =item *
  307. Do you try to run I<internal> shell commands, like C<`copy a b`>
  308. (internal for F<cmd.exe>), or C<`glob a*b`> (internal for ksh)? You
  309. need to specify your shell explicitly, like C<`cmd /c copy a b`>,
  310. since Perl cannot deduce which commands are internal to your shell.
  311. =back
  312. =head2 I cannot embed perl into my program, or use F<perl.dll> from my
  313. program.
  314. =over 4
  315. =item Is your program EMX-compiled with C<-Zmt -Zcrtdll>?
  316. If not, you need to build a stand-alone DLL for perl. Contact me, I
  317. did it once. Sockets would not work, as a lot of other stuff.
  318. =item Did you use L<ExtUtils::Embed>?
  319. I had reports it does not work. Somebody would need to fix it.
  320. =back
  321. =head2 C<``> and pipe-C<open> do not work under DOS.
  322. This may a variant of just L<"I cannot run external programs">, or a
  323. deeper problem. Basically: you I<need> RSX (see L<"Prerequisites">)
  324. for these commands to work, and you may need a port of F<sh.exe> which
  325. understands command arguments. One of such ports is listed in
  326. L<"Prerequisites"> under RSX. Do not forget to set variable
  327. C<L<"PERL_SH_DIR">> as well.
  328. DPMI is required for RSX.
  329. =head2 Cannot start C<find.exe "pattern" file>
  330. Use one of
  331. system 'cmd', '/c', 'find "pattern" file';
  332. `cmd /c 'find "pattern" file'`
  333. This would start F<find.exe> via F<cmd.exe> via C<sh.exe> via
  334. C<perl.exe>, but this is a price to pay if you want to use
  335. non-conforming program. In fact F<find.exe> cannot be started at all
  336. using C library API only. Otherwise the following command-lines would be
  337. equivalent:
  338. find "pattern" file
  339. find pattern file
  340. =head1 INSTALLATION
  341. =head2 Automatic binary installation
  342. The most convenient way of installing a binary distribution of perl is via perl installer
  343. F<install.exe>. Just follow the instructions, and 99% of the
  344. installation blues would go away.
  345. Note however, that you need to have F<unzip.exe> on your path, and
  346. EMX environment I<running>. The latter means that if you just
  347. installed EMX, and made all the needed changes to F<Config.sys>,
  348. you may need to reboot in between. Check EMX runtime by running
  349. emxrev
  350. A folder is created on your desktop which contains some useful
  351. objects.
  352. B<Things not taken care of by automatic binary installation:>
  353. =over 15
  354. =item C<PERL_BADLANG>
  355. may be needed if you change your codepage I<after> perl installation,
  356. and the new value is not supported by EMX. See L<"PERL_BADLANG">.
  357. =item C<PERL_BADFREE>
  358. see L<"PERL_BADFREE">.
  359. =item F<Config.pm>
  360. This file resides somewhere deep in the location you installed your
  361. perl library, find it out by
  362. perl -MConfig -le "print $INC{'Config.pm'}"
  363. While most important values in this file I<are> updated by the binary
  364. installer, some of them may need to be hand-edited. I know no such
  365. data, please keep me informed if you find one.
  366. =back
  367. B<NOTE>. Because of a typo the binary installer of 5.00305
  368. would install a variable C<PERL_SHPATH> into F<Config.sys>. Please
  369. remove this variable and put C<L<PERL_SH_DIR>> instead.
  370. =head2 Manual binary installation
  371. As of version 5.00305, OS/2 perl binary distribution comes split
  372. into 11 components. Unfortunately, to enable configurable binary
  373. installation, the file paths in the zip files are not absolute, but
  374. relative to some directory.
  375. Note that the extraction with the stored paths is still necessary
  376. (default with unzip, specify C<-d> to pkunzip). However, you
  377. need to know where to extract the files. You need also to manually
  378. change entries in F<Config.sys> to reflect where did you put the
  379. files. Note that if you have some primitive unzipper (like
  380. pkunzip), you may get a lot of warnings/errors during
  381. unzipping. Upgrade to C<(w)unzip>.
  382. Below is the sample of what to do to reproduce the configuration on my
  383. machine:
  384. =over 3
  385. =item Perl VIO and PM executables (dynamically linked)
  386. unzip perl_exc.zip *.exe *.ico -d f:/emx.add/bin
  387. unzip perl_exc.zip *.dll -d f:/emx.add/dll
  388. (have the directories with C<*.exe> on PATH, and C<*.dll> on
  389. LIBPATH);
  390. =item Perl_ VIO executable (statically linked)
  391. unzip perl_aou.zip -d f:/emx.add/bin
  392. (have the directory on PATH);
  393. =item Executables for Perl utilities
  394. unzip perl_utl.zip -d f:/emx.add/bin
  395. (have the directory on PATH);
  396. =item Main Perl library
  397. unzip perl_mlb.zip -d f:/perllib/lib
  398. If this directory is exactly the same as the prefix which was compiled
  399. into F<perl.exe>, you do not need to change
  400. anything. However, for perl to find the library if you use a different
  401. path, you need to
  402. C<set PERLLIB_PREFIX> in F<Config.sys>, see L<"PERLLIB_PREFIX">.
  403. =item Additional Perl modules
  404. unzip perl_ste.zip -d f:/perllib/lib/site_perl/5.8.3/
  405. Same remark as above applies. Additionally, if this directory is not
  406. one of directories on @INC (and @INC is influenced by C<PERLLIB_PREFIX>), you
  407. need to put this
  408. directory and subdirectory F<./os2> in C<PERLLIB> or C<PERL5LIB>
  409. variable. Do not use C<PERL5LIB> unless you have it set already. See
  410. L<perl/"ENVIRONMENT">.
  411. =item Tools to compile Perl modules
  412. unzip perl_blb.zip -d f:/perllib/lib
  413. Same remark as for F<perl_ste.zip>.
  414. =item Manpages for Perl and utilities
  415. unzip perl_man.zip -d f:/perllib/man
  416. This directory should better be on C<MANPATH>. You need to have a
  417. working man to access these files.
  418. =item Manpages for Perl modules
  419. unzip perl_mam.zip -d f:/perllib/man
  420. This directory should better be on C<MANPATH>. You need to have a
  421. working man to access these files.
  422. =item Source for Perl documentation
  423. unzip perl_pod.zip -d f:/perllib/lib
  424. This is used by the C<perldoc> program (see L<perldoc>), and may be used to
  425. generate HTML documentation usable by WWW browsers, and
  426. documentation in zillions of other formats: C<info>, C<LaTeX>,
  427. C<Acrobat>, C<FrameMaker> and so on.
  428. =item Perl manual in F<.INF> format
  429. unzip perl_inf.zip -d d:/os2/book
  430. This directory should better be on C<BOOKSHELF>.
  431. =item Pdksh
  432. unzip perl_sh.zip -d f:/bin
  433. This is used by perl to run external commands which explicitly
  434. require shell, like the commands using I<redirection> and I<shell
  435. metacharacters>. It is also used instead of explicit F</bin/sh>.
  436. Set C<PERL_SH_DIR> (see L<"PERL_SH_DIR">) if you move F<sh.exe> from
  437. the above location.
  438. B<Note.> It may be possible to use some other sh-compatible shell
  439. (file globbing - if done via shell - may break).
  440. =back
  441. After you installed the components you needed and updated the
  442. F<Config.sys> correspondingly, you need to hand-edit
  443. F<Config.pm>. This file resides somewhere deep in the location you
  444. installed your perl library, find it out by
  445. perl -MConfig -le "print $INC{'Config.pm'}"
  446. You need to correct all the entries which look like file paths (they
  447. currently start with C<f:/>).
  448. =head2 B<Warning>
  449. The automatic and manual perl installation leave precompiled paths
  450. inside perl executables. While these paths are overwriteable (see
  451. L<"PERLLIB_PREFIX">, L<"PERL_SH_DIR">), one may get better results by
  452. binary editing of paths inside the executables/DLLs.
  453. =head1 Accessing documentation
  454. Depending on how you built/installed perl you may have (otherwise
  455. identical) Perl documentation in the following formats:
  456. =head2 OS/2 F<.INF> file
  457. Most probably the most convenient form. Under OS/2 view it as
  458. view perl
  459. view perl perlfunc
  460. view perl less
  461. view perl ExtUtils::MakeMaker
  462. (currently the last two may hit a wrong location, but this may improve
  463. soon). Under Win* see L<"SYNOPSIS">.
  464. If you want to build the docs yourself, and have I<OS/2 toolkit>, run
  465. pod2ipf > perl.ipf
  466. in F</perllib/lib/pod> directory, then
  467. ipfc /inf perl.ipf
  468. (Expect a lot of errors during the both steps.) Now move it on your
  469. BOOKSHELF path.
  470. =head2 Plain text
  471. If you have perl documentation in the source form, perl utilities
  472. installed, and GNU groff installed, you may use
  473. perldoc perlfunc
  474. perldoc less
  475. perldoc ExtUtils::MakeMaker
  476. to access the perl documentation in the text form (note that you may get
  477. better results using perl manpages).
  478. Alternately, try running pod2text on F<.pod> files.
  479. =head2 Manpages
  480. If you have man installed on your system, and you installed perl
  481. manpages, use something like this:
  482. man perlfunc
  483. man 3 less
  484. man ExtUtils.MakeMaker
  485. to access documentation for different components of Perl. Start with
  486. man perl
  487. Note that dot (F<.>) is used as a package separator for documentation
  488. for packages, and as usual, sometimes you need to give the section - C<3>
  489. above - to avoid shadowing by the I<less(1) manpage>.
  490. Make sure that the directory B<above> the directory with manpages is
  491. on our C<MANPATH>, like this
  492. set MANPATH=c:/man;f:/perllib/man
  493. for Perl manpages in C<f:/perllib/man/man1/> etc.
  494. =head2 HTML
  495. If you have some WWW browser available, installed the Perl
  496. documentation in the source form, and Perl utilities, you can build
  497. HTML docs. Cd to directory with F<.pod> files, and do like this
  498. cd f:/perllib/lib/pod
  499. pod2html
  500. After this you can direct your browser the file F<perl.html> in this
  501. directory, and go ahead with reading docs, like this:
  502. explore file:///f:/perllib/lib/pod/perl.html
  503. Alternatively you may be able to get these docs prebuilt from CPAN.
  504. =head2 GNU C<info> files
  505. Users of Emacs would appreciate it very much, especially with
  506. C<CPerl> mode loaded. You need to get latest C<pod2info> from C<CPAN>,
  507. or, alternately, prebuilt info pages.
  508. =head2 F<.PDF> files
  509. for C<Acrobat> are available on CPAN (for slightly old version of
  510. perl).
  511. =head2 C<LaTeX> docs
  512. can be constructed using C<pod2latex>.
  513. =head1 BUILD
  514. Here we discuss how to build Perl under OS/2. There is an alternative
  515. (but maybe older) view on http://www.shadow.net/~troc/os2perl.html
  516. =head2 The short story
  517. Assume that you are a seasoned porter, so are sure that all the necessary
  518. tools are already present on your system, and you know how to get the Perl
  519. source distribution. Untar it, change to the extract directory, and
  520. gnupatch -p0 < os2\diff.configure
  521. sh Configure -des -D prefix=f:/perllib
  522. make
  523. make test
  524. make install
  525. make aout_test
  526. make aout_install
  527. This puts the executables in f:/perllib/bin. Manually move them to the
  528. C<PATH>, manually move the built F<perl*.dll> to C<LIBPATH> (here F<*> is
  529. a not-very-meaningful hex checksum), and run
  530. make installcmd INSTALLCMDDIR=d:/ir/on/path
  531. What follows is a detailed guide through these steps.
  532. =head2 Prerequisites
  533. You need to have the latest EMX development environment, the full
  534. GNU tool suite (gawk renamed to awk, and GNU F<find.exe>
  535. earlier on path than the OS/2 F<find.exe>, same with F<sort.exe>, to
  536. check use
  537. find --version
  538. sort --version
  539. ). You need the latest version of F<pdksh> installed as F<sh.exe>.
  540. Check that you have B<BSD> libraries and headers installed, and -
  541. optionally - Berkeley DB headers and libraries, and crypt.
  542. Possible locations to get this from are
  543. ftp://hobbes.nmsu.edu/os2/unix/
  544. ftp://ftp.cdrom.com/pub/os2/unix/
  545. ftp://ftp.cdrom.com/pub/os2/dev32/
  546. ftp://ftp.cdrom.com/pub/os2/emx09c/
  547. It is reported that the following archives contain enough utils to
  548. build perl: F<gnufutil.zip>, F<gnusutil.zip>, F<gnututil.zip>, F<gnused.zip>,
  549. F<gnupatch.zip>, F<gnuawk.zip>, F<gnumake.zip>, F<bsddev.zip> and
  550. F<ksh527rt.zip> (or a later version). Note that all these utilities are
  551. known to be available from LEO:
  552. ftp://ftp.leo.org/pub/comp/os/os2/leo/gnu
  553. If you have I<exactly the same version of Perl> installed already,
  554. make sure that no copies or perl are currently running. Later steps
  555. of the build may fail since an older version of F<perl.dll> loaded into
  556. memory may be found.
  557. Also make sure that you have F</tmp> directory on the current drive,
  558. and F<.> directory in your C<LIBPATH>. One may try to correct the
  559. latter condition by
  560. set BEGINLIBPATH .
  561. if you use something like F<CMD.EXE> or latest versions of F<4os2.exe>.
  562. Make sure your gcc is good for C<-Zomf> linking: run C<omflibs>
  563. script in F</emx/lib> directory.
  564. Check that you have link386 installed. It comes standard with OS/2,
  565. but may be not installed due to customization. If typing
  566. link386
  567. shows you do not have it, do I<Selective install>, and choose C<Link
  568. object modules> in I<Optional system utilities/More>. If you get into
  569. link386 prompts, press C<Ctrl-C> to exit.
  570. =head2 Getting perl source
  571. You need to fetch the latest perl source (including developers
  572. releases). With some probability it is located in
  573. http://www.perl.com/CPAN/src/5.0
  574. http://www.perl.com/CPAN/src/5.0/unsupported
  575. If not, you may need to dig in the indices to find it in the directory
  576. of the current maintainer.
  577. Quick cycle of developers release may break the OS/2 build time to
  578. time, looking into
  579. http://www.perl.com/CPAN/ports/os2/ilyaz/
  580. may indicate the latest release which was publicly released by the
  581. maintainer. Note that the release may include some additional patches
  582. to apply to the current source of perl.
  583. Extract it like this
  584. tar vzxf perl5.00409.tar.gz
  585. You may see a message about errors while extracting F<Configure>. This is
  586. because there is a conflict with a similarly-named file F<configure>.
  587. Change to the directory of extraction.
  588. =head2 Application of the patches
  589. You need to apply the patches in F<./os2/diff.*> like this:
  590. gnupatch -p0 < os2\diff.configure
  591. You may also need to apply the patches supplied with the binary
  592. distribution of perl.
  593. Note also that the F<db.lib> and F<db.a> from the EMX distribution
  594. are not suitable for multi-threaded compile (even single-threaded
  595. flavor of Perl uses multi-threaded C RTL, for
  596. compatibility with XFree86-OS/2). Get a corrected one from
  597. ftp://ftp.math.ohio-state.edu/pub/users/ilya/os2/db_mt.zip
  598. =head2 Hand-editing
  599. You may look into the file F<./hints/os2.sh> and correct anything
  600. wrong you find there. I do not expect it is needed anywhere.
  601. =head2 Making
  602. sh Configure -des -D prefix=f:/perllib
  603. C<prefix> means: where to install the resulting perl library. Giving
  604. correct prefix you may avoid the need to specify C<PERLLIB_PREFIX>,
  605. see L<"PERLLIB_PREFIX">.
  606. I<Ignore the message about missing C<ln>, and about C<-c> option to
  607. tr>. The latter is most probably already fixed, if you see it and can trace
  608. where the latter spurious warning comes from, please inform me.
  609. Now
  610. make
  611. At some moment the built may die, reporting a I<version mismatch> or
  612. I<unable to run F<perl>>. This means that you do not have F<.> in
  613. your LIBPATH, so F<perl.exe> cannot find the needed F<perl67B2.dll> (treat
  614. these hex digits as line noise). After this is fixed the build
  615. should finish without a lot of fuss.
  616. =head2 Testing
  617. Now run
  618. make test
  619. All tests should succeed (with some of them skipped).
  620. Some tests may generate extra messages similar to
  621. =over 4
  622. =item A lot of C<bad free>
  623. in database tests related to Berkeley DB. I<This should be fixed already.>
  624. If it persists, you may disable this warnings, see L<"PERL_BADFREE">.
  625. =item Process terminated by SIGTERM/SIGINT
  626. This is a standard message issued by OS/2 applications. *nix
  627. applications die in silence. It is considered to be a feature. One can
  628. easily disable this by appropriate sighandlers.
  629. However the test engine bleeds these message to screen in unexpected
  630. moments. Two messages of this kind I<should> be present during
  631. testing.
  632. =back
  633. To get finer test reports, call
  634. perl t/harness
  635. The report with F<io/pipe.t> failing may look like this:
  636. Failed Test Status Wstat Total Fail Failed List of failed
  637. ------------------------------------------------------------
  638. io/pipe.t 12 1 8.33% 9
  639. 7 tests skipped, plus 56 subtests skipped.
  640. Failed 1/195 test scripts, 99.49% okay. 1/6542 subtests failed, 99.98% okay.
  641. The reasons for most important skipped tests are:
  642. =over 8
  643. =item F<op/fs.t>
  644. =over 4
  645. =item 18
  646. Checks C<atime> and C<mtime> of C<stat()> - unfortunately, HPFS
  647. provides only 2sec time granularity (for compatibility with FAT?).
  648. =item 25
  649. Checks C<truncate()> on a filehandle just opened for write - I do not
  650. know why this should or should not work.
  651. =back
  652. =item F<op/stat.t>
  653. Checks C<stat()>. Tests:
  654. =over 4
  655. =item 4
  656. Checks C<atime> and C<mtime> of C<stat()> - unfortunately, HPFS
  657. provides only 2sec time granularity (for compatibility with FAT?).
  658. =back
  659. =back
  660. =head2 Installing the built perl
  661. If you haven't yet moved perl.dll onto LIBPATH, do it now.
  662. Run
  663. make install
  664. It would put the generated files into needed locations. Manually put
  665. F<perl.exe>, F<perl__.exe> and F<perl___.exe> to a location on your
  666. PATH, F<perl.dll> to a location on your LIBPATH.
  667. Run
  668. make installcmd INSTALLCMDDIR=d:/ir/on/path
  669. to convert perl utilities to F<.cmd> files and put them on
  670. PATH. You need to put F<.EXE>-utilities on path manually. They are
  671. installed in C<$prefix/bin>, here C<$prefix> is what you gave to
  672. F<Configure>, see L<Making>.
  673. =head2 C<a.out>-style build
  674. Proceed as above, but make F<perl_.exe> (see L<"perl_.exe">) by
  675. make perl_
  676. test and install by
  677. make aout_test
  678. make aout_install
  679. Manually put F<perl_.exe> to a location on your PATH.
  680. B<Note.> The build process for C<perl_> I<does not know> about all the
  681. dependencies, so you should make sure that anything is up-to-date,
  682. say, by doing
  683. make perl_dll
  684. first.
  685. =head1 Build FAQ
  686. =head2 Some C</> became C<\> in pdksh.
  687. You have a very old pdksh. See L<Prerequisites>.
  688. =head2 C<'errno'> - unresolved external
  689. You do not have MT-safe F<db.lib>. See L<Prerequisites>.
  690. =head2 Problems with tr or sed
  691. reported with very old version of tr and sed.
  692. =head2 Some problem (forget which ;-)
  693. You have an older version of F<perl.dll> on your LIBPATH, which
  694. broke the build of extensions.
  695. =head2 Library ... not found
  696. You did not run C<omflibs>. See L<Prerequisites>.
  697. =head2 Segfault in make
  698. You use an old version of GNU make. See L<Prerequisites>.
  699. =head2 op/sprintf test failure
  700. This can result from a bug in emx sprintf which was fixed in 0.9d fix 03.
  701. =head1 Specific (mis)features of OS/2 port
  702. =head2 C<setpriority>, C<getpriority>
  703. Note that these functions are compatible with *nix, not with the older
  704. ports of '94 - 95. The priorities are absolute, go from 32 to -95,
  705. lower is quicker. 0 is the default priority.
  706. B<WARNING>. Calling C<getpriority> on a non-existing process can lock the
  707. system before Warp3 fixpak22.
  708. =head2 C<system()>
  709. Multi-argument form of C<system()> allows an additional numeric
  710. argument. The meaning of this argument is described in
  711. L<OS2::Process>.
  712. When finding a program to run, Perl first asks the OS to look for executables
  713. on C<PATH>. If not found, it looks for a script with possible extensions
  714. added in this order: no extension, F<.cmd>, F<.btm>,
  715. F<.bat>, F<.pl>. If found, Perl checks the start of the file for magic
  716. strings C<"#!"> and C<"extproc ">. If found, Perl uses the rest of the
  717. first line as the beginning of the command line to run this script. The
  718. only mangling done to the first line is extraction of arguments (currently
  719. up to 3), and ignoring of the path-part of the "interpreter" name if it can't
  720. be found using the full path.
  721. E.g., C<system 'foo', 'bar', 'baz'> may lead Perl to finding
  722. F<C:/emx/bin/foo.cmd> with the first line being
  723. extproc /bin/bash -x -c
  724. If F</bin/bash> is not found, and appending of executable extensions to
  725. F</bin/bash> does not help either, then Perl looks for an executable F<bash> on
  726. C<PATH>. If found in F<C:/emx.add/bin/bash.exe>, then the above system() is
  727. translated to
  728. system qw(C:/emx.add/bin/bash.exe -x -c C:/emx/bin/foo.cmd bar baz)
  729. One additional translation is performed: instead of F</bin/sh> Perl uses
  730. the hardwired-or-customized shell (see C<L<"PERL_SH_DIR">>).
  731. The above search for "interpreter" is recursive: if F<bash> executable is not
  732. found, but F<bash.btm> is found, Perl will investigate its first line etc.
  733. The only hardwired limit on the recursion depth is implicit: there is a limit
  734. 4 on the number of additional arguments inserted before the actual arguments
  735. given to system(). In particular, if no additional arguments are specified
  736. on the "magic" first lines, then the limit on the depth is 4.
  737. If Perl finds that the found executable is of different type than the
  738. current session, it will start the new process in a separate session of
  739. necessary type. Call via C<OS2::Process> to disable this magic.
  740. =head2 C<extproc> on the first line
  741. If the first chars of a Perl script are C<"extproc ">, this line is treated
  742. as C<#!>-line, thus all the switches on this line are processed (twice
  743. if script was started via cmd.exe). See L<perlrun/DESCRIPTION>.
  744. =head2 Additional modules:
  745. L<OS2::Process>, L<OS2::DLL>, L<OS2::REXX>, L<OS2::PrfDB>, L<OS2::ExtAttr>. These
  746. modules provide access to additional numeric argument for C<system>
  747. and to the information about the running process,
  748. to DLLs having functions with REXX signature and to the REXX runtime, to
  749. OS/2 databases in the F<.INI> format, and to Extended Attributes.
  750. Two additional extensions by Andreas Kaiser, C<OS2::UPM>, and
  751. C<OS2::FTP>, are included into C<ILYAZ> directory, mirrored on CPAN.
  752. =head2 Prebuilt methods:
  753. =over 4
  754. =item C<File::Copy::syscopy>
  755. used by C<File::Copy::copy>, see L<File::Copy>.
  756. =item C<DynaLoader::mod2fname>
  757. used by C<DynaLoader> for DLL name mangling.
  758. =item C<Cwd::current_drive()>
  759. Self explanatory.
  760. =item C<Cwd::sys_chdir(name)>
  761. leaves drive as it is.
  762. =item C<Cwd::change_drive(name)>
  763. chanes the "current" drive.
  764. =item C<Cwd::sys_is_absolute(name)>
  765. means has drive letter and is_rooted.
  766. =item C<Cwd::sys_is_rooted(name)>
  767. means has leading C<[/\\]> (maybe after a drive-letter:).
  768. =item C<Cwd::sys_is_relative(name)>
  769. means changes with current dir.
  770. =item C<Cwd::sys_cwd(name)>
  771. Interface to cwd from EMX. Used by C<Cwd::cwd>.
  772. =item C<Cwd::sys_abspath(name, dir)>
  773. Really really odious function to implement. Returns absolute name of
  774. file which would have C<name> if CWD were C<dir>. C<Dir> defaults to the
  775. current dir.
  776. =item C<Cwd::extLibpath([type])>
  777. Get current value of extended library search path. If C<type> is
  778. present and I<true>, works with END_LIBPATH, otherwise with
  779. C<BEGIN_LIBPATH>.
  780. =item C<Cwd::extLibpath_set( path [, type ] )>
  781. Set current value of extended library search path. If C<type> is
  782. present and I<true>, works with END_LIBPATH, otherwise with
  783. C<BEGIN_LIBPATH>.
  784. =item C<OS2::Error(do_harderror,do_exception)>
  785. Returns C<undef> if it was not called yet, otherwise bit 1 is
  786. set if on the previous call do_harderror was enabled, bit
  787. 2 is set if if on previous call do_exception was enabled.
  788. This function enables/disables error popups associated with
  789. hardware errors (Disk not ready etc.) and software exceptions.
  790. I know of no way to find out the state of popups I<before> the first call
  791. to this function.
  792. =item C<OS2::Errors2Drive(drive)>
  793. Returns C<undef> if it was not called yet, otherwise return false if errors
  794. were not requested to be written to a hard drive, or the drive letter if
  795. this was requested.
  796. This function may redirect error popups associated with hardware errors
  797. (Disk not ready etc.) and software exceptions to the file POPUPLOG.OS2 at
  798. the root directory of the specified drive. Overrides OS2::Error() specified
  799. by individual programs. Given argument undef will disable redirection.
  800. Has global effect, persists after the application exits.
  801. I know of no way to find out the state of redirection of popups to the disk
  802. I<before> the first call to this function.
  803. =item OS2::SysInfo()
  804. Returns a hash with system information. The keys of the hash are
  805. MAX_PATH_LENGTH, MAX_TEXT_SESSIONS, MAX_PM_SESSIONS,
  806. MAX_VDM_SESSIONS, BOOT_DRIVE, DYN_PRI_VARIATION,
  807. MAX_WAIT, MIN_SLICE, MAX_SLICE, PAGE_SIZE,
  808. VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION,
  809. MS_COUNT, TIME_LOW, TIME_HIGH, TOTPHYSMEM, TOTRESMEM,
  810. TOTAVAILMEM, MAXPRMEM, MAXSHMEM, TIMER_INTERVAL,
  811. MAX_COMP_LENGTH, FOREGROUND_FS_SESSION,
  812. FOREGROUND_PROCESS
  813. =item OS2::BootDrive()
  814. Returns a letter without colon.
  815. =item C<OS2::MorphPM(serve)>, C<OS2::UnMorphPM(serve)>
  816. Transforms the current application into a PM application and back.
  817. The argument true means that a real message loop is going to be served.
  818. OS2::MorphPM() returns the PM message queue handle as an integer.
  819. See L<"Centralized management of resources"> for additional details.
  820. =item C<OS2::Serve_Messages(force)>
  821. Fake on-demand retrieval of outstanding PM messages. If C<force> is false,
  822. will not dispatch messages if a real message loop is known to
  823. be present. Returns number of messages retrieved.
  824. Dies with "QUITing..." if WM_QUIT message is obtained.
  825. =item C<OS2::Process_Messages(force [, cnt])>
  826. Retrieval of PM messages until window creation/destruction.
  827. If C<force> is false, will not dispatch messages if a real message loop
  828. is known to be present.
  829. Returns change in number of windows. If C<cnt> is given,
  830. it is incremented by the number of messages retrieved.
  831. Dies with "QUITing..." if WM_QUIT message is obtained.
  832. =item C<OS2::_control87(new,mask)>
  833. the same as L<_control87(3)> of EMX. Takes integers as arguments, returns
  834. the previous coprocessor control word as an integer. Only bits in C<new> which
  835. are present in C<mask> are changed in the control word.
  836. =item OS2::get_control87()
  837. gets the coprocessor control word as an integer.
  838. =item C<OS2::set_control87_em(new=MCW_EM,mask=MCW_EM)>
  839. The variant of OS2::_control87() with default values good for
  840. handling exception mask: if no C<mask>, uses exception mask part of C<new>
  841. only. If no C<new>, disables all the floating point exceptions.
  842. See L<"Misfeatures"> for details.
  843. =back
  844. (Note that some of these may be moved to different libraries -
  845. eventually).
  846. =head2 Prebuilt variables:
  847. =over 4
  848. =item $OS2::emx_rev
  849. same as _emx_rev of EMX, a string similar to C<0.9c>.
  850. =item $OS2::emx_env
  851. same as _emx_env of EMX, a number similar to 0x8001.
  852. =item $OS2::os_ver
  853. a number C<OS_MAJOR + 0.001 * OS_MINOR>.
  854. =back
  855. =head2 Misfeatures
  856. =over 4
  857. =item *
  858. Since L<flock(3)> is present in EMX, but is not functional, it is
  859. emulated by perl. To disable the emulations, set environment variable
  860. C<USE_PERL_FLOCK=0>.
  861. =item *
  862. Here is the list of things which may be "broken" on
  863. EMX (from EMX docs):
  864. =over 4
  865. =item *
  866. The functions L<recvmsg(3)>, L<sendmsg(3)>, and L<socketpair(3)> are not
  867. implemented.
  868. =item *
  869. L<sock_init(3)> is not required and not implemented.
  870. =item *
  871. L<flock(3)> is not yet implemented (dummy function). (Perl has a workaround.)
  872. =item *
  873. L<kill(3)>: Special treatment of PID=0, PID=1 and PID=-1 is not implemented.
  874. =item *
  875. L<waitpid(3)>:
  876. WUNTRACED
  877. Not implemented.
  878. waitpid() is not implemented for negative values of PID.
  879. =back
  880. Note that C<kill -9> does not work with the current version of EMX.
  881. =item *
  882. Since F<sh.exe> is used for globing (see L<perlfunc/glob>), the bugs
  883. of F<sh.exe> plague perl as well.
  884. In particular, uppercase letters do not work in C<[...]>-patterns with
  885. the current pdksh.
  886. =item *
  887. Unix-domain sockets on OS/2 live in a pseudo-file-system C</sockets/...>.
  888. To avoid a failure to create a socket with a name of a different form,
  889. C<"/socket/"> is prepended to the socket name (unless it starts with this
  890. already).
  891. This may lead to problems later in case the socket is accessed via the
  892. "usual" file-system calls using the "initial" name.
  893. =item *
  894. Apparently, IBM used a compiler (for some period of time around '95?) which
  895. changes FP mask right and left. This is not I<that> bad for IBM's
  896. programs, but the same compiler was used for DLLs which are used with
  897. general-purpose applications. When these DLLs are used, the state of
  898. floating-point flags in the application is not predictable.
  899. What is much worse, some DLLs change the floating point flags when in
  900. _DLLInitTerm() (e.g., F<TCP32IP>). This means that even if you do not I<call>
  901. any function in the DLL, just the act of loading this DLL will reset your
  902. flags. What is worse, the same compiler was used to compile some HOOK DLLs.
  903. Given that HOOK dlls are executed in the context of I<all> the applications
  904. in the system, this means a complete unpredictablity of floating point
  905. flags on systems using such HOOK DLLs. E.g., F<GAMESRVR.DLL> of B<DIVE>
  906. origin changes the floating point flags on each write to the TTY of a VIO
  907. (windowed text-mode) applications.
  908. Some other (not completely debugged) situations when FP flags change include
  909. some video drivers (?), and some operations related to creation of the windows.
  910. People who code B<OpenGL> may have more experience on this.
  911. Perl is generally used in the situation when all the floating-point
  912. exceptions are ignored, as is the default under EMX. If they are not ignored,
  913. some benign Perl programs would get a C<SIGFPE> and would die a horrible death.
  914. To circumvent this, Perl uses two hacks. They help against I<one> type of
  915. damage only: FP flags changed when loading a DLL.
  916. One of the hacks is to disable floating point exceptions on startup (as
  917. is the default with EMX). This helps only with compile-time-linked DLLs
  918. changing the flags before main() had a chance to be called.
  919. The other hack is to restore FP flags after a call to dlopen(). This helps
  920. against similar damage done by DLLs _DLLInitTerm() at runtime. Currently
  921. no way to switch these hacks off is provided.
  922. =back
  923. =head2 Modifications
  924. Perl modifies some standard C library calls in the following ways:
  925. =over 9
  926. =item C<popen>
  927. C<my_popen> uses F<sh.exe> if shell is required, cf. L<"PERL_SH_DIR">.
  928. =item C<tmpnam>
  929. is created using C<TMP> or C<TEMP> environment variable, via
  930. C<tempnam>.
  931. =item C<tmpfile>
  932. If the current directory is not writable, file is created using modified
  933. C<tmpnam>, so there may be a race condition.
  934. =item C<ctermid>
  935. a dummy implementation.
  936. =item C<stat>
  937. C<os2_stat> special-cases F</dev/tty> and F</dev/con>.
  938. =item C<mkdir>, C<rmdir>
  939. these EMX functions do not work if the path contains a trailing C</>.
  940. Perl contains a workaround for this.
  941. =item C<flock>
  942. Since L<flock(3)> is present in EMX, but is not functional, it is
  943. emulated by perl. To disable the emulations, set environment variable
  944. C<USE_PERL_FLOCK=0>.
  945. =back
  946. =head2 Identifying DLLs
  947. All the DLLs built with the current versions of Perl have ID strings
  948. identifying the name of the extension, its version, and the version
  949. of Perl required for this DLL. Run C<bldlevel DLL-name> to find this
  950. info.
  951. =head2 Centralized management of resources
  952. Since to call certain OS/2 API one needs to have a correctly initialized
  953. C<Win> subsystem, OS/2-specific extensions may require getting C<HAB>s and
  954. C<HMQ>s. If an extension would do it on its own, another extension could
  955. fail to initialize.
  956. Perl provides a centralized management of these resources:
  957. =over
  958. =item C<HAB>
  959. To get the HAB, the extension should call C<hab = perl_hab_GET()> in C. After
  960. this call is performed, C<hab> may be accessed as C<Perl_hab>. There is
  961. no need to release the HAB after it is used.
  962. If by some reasons F<perl.h> cannot be included, use
  963. extern int Perl_hab_GET(void);
  964. instead.
  965. =item C<HMQ>
  966. There are two cases:
  967. =over
  968. =item *
  969. the extension needs an C<HMQ> only because some API will not work otherwise.
  970. Use C<serve = 0> below.
  971. =item *
  972. the extension needs an C<HMQ> since it wants to engage in a PM event loop.
  973. Use C<serve = 1> below.
  974. =back
  975. To get an C<HMQ>, the extension should call C<hmq = perl_hmq_GET(serve)> in C.
  976. After this call is performed, C<hmq> may be accessed as C<Perl_hmq>.
  977. To signal to Perl that HMQ is not needed any more, call
  978. C<perl_hmq_UNSET(serve)>. Perl process will automatically morph/unmorph itself
  979. into/from a PM process if HMQ is needed/not-needed. Perl will automatically
  980. enable/disable C<WM_QUIT> message during shutdown if the message queue is
  981. served/not-served.
  982. B<NOTE>. If during a shutdown there is a message queue which did not disable
  983. WM_QUIT, and which did not process the received WM_QUIT message, the
  984. shutdown will be automatically cancelled. Do not call C<perl_hmq_GET(1)>
  985. unless you are going to process messages on an orderly basis.
  986. =back
  987. =head1 Perl flavors
  988. Because of idiosyncrasies of OS/2 one cannot have all the eggs in the
  989. same basket (though EMX environment tries hard to overcome this
  990. limitations, so the situation may somehow improve). There are 4
  991. executables for Perl provided by the distribution:
  992. =head2 F<perl.exe>
  993. The main workhorse. This is a chimera executable: it is compiled as an
  994. C<a.out>-style executable, but is linked with C<omf>-style dynamic
  995. library F<perl.dll>, and with dynamic CRT DLL. This executable is a
  996. VIO application.
  997. It can load perl dynamic extensions, and it can fork().
  998. B<Note.> Keep in mind that fork() is needed to open a pipe to yourself.
  999. =head2 F<perl_.exe>
  1000. This is a statically linked C<a.out>-style executable. It cannot
  1001. load dynamic Perl extensions. The executable supplied in binary
  1002. distributions has a lot of extensions prebuilt, thus the above restriction is
  1003. important only if you use custom-built extensions. This executable is a VIO
  1004. application.
  1005. I<This is the only executable with does not require OS/2.> The
  1006. friends locked into C<M$> world would appreciate the fact that this
  1007. executable runs under DOS, Win0.3*, Win0.95 and WinNT with an
  1008. appropriate extender. See L<"Other OSes">.
  1009. =head2 F<perl__.exe>
  1010. This is the same executable as F<perl___.exe>, but it is a PM
  1011. application.
  1012. B<Note.> Usually (unless explicitly redirected during the startup)
  1013. STDIN, STDERR, and STDOUT of a PM
  1014. application are redirected to F<nul>. However, it is possible to I<see>
  1015. them if you start C<perl__.exe> from a PM program which emulates a
  1016. console window, like I<Shell mode> of Emacs or EPM. Thus it I<is
  1017. possible> to use Perl debugger (see L<perldebug>) to debug your PM
  1018. application (but beware of the message loop lockups - this will not
  1019. work if you have a message queue to serve, unless you hook the serving
  1020. into the getc() function of the debugger).
  1021. Another way to see the output of a PM program is to run it as
  1022. pm_prog args 2>&1 | cat -
  1023. with a shell I<different> from F<cmd.exe>, so that it does not create
  1024. a link between a VIO session and the session of C<pm_porg>. (Such a link
  1025. closes the VIO window.) E.g., this works with F<sh.exe> - or with Perl!
  1026. open P, 'pm_prog args 2>&1 |' or die;
  1027. print while <P>;
  1028. The flavor F<perl__.exe> is required if you want to start your program without
  1029. a VIO window present, but not C<detach>ed (run C<help detach> for more info).
  1030. Very useful for extensions which use PM, like C<Perl/Tk> or C<OpenGL>.
  1031. =head2 F<perl___.exe>
  1032. This is an C<omf>-style executable which is dynamically linked to
  1033. F<perl.dll> and CRT DLL. I know no advantages of this executable
  1034. over C<perl.exe>, but it cannot fork() at all. Well, one advantage is
  1035. that the build process is not so convoluted as with C<perl.exe>.
  1036. It is a VIO application.
  1037. =head2 Why strange names?
  1038. Since Perl processes the C<#!>-line (cf.
  1039. L<perlrun/DESCRIPTION>, L<perlrun/Switches>,
  1040. L<perldiag/"Not a perl script">,
  1041. L<perldiag/"No Perl script found in input">), it should know when a
  1042. program I<is a Perl>. There is some naming convention which allows
  1043. Perl to distinguish correct lines from wrong ones. The above names are
  1044. almost the only names allowed by this convention which do not contain
  1045. digits (which have absolutely different semantics).
  1046. =head2 Why dynamic linking?
  1047. Well, having several executables dynamically linked to the same huge
  1048. library has its advantages, but this would not substantiate the
  1049. additional work to make it compile. The reason is the complicated-to-developers
  1050. but very quick and convenient-to-users "hard" dynamic linking used by OS/2.
  1051. There are two distinctive features of the dyna-linking model of OS/2:
  1052. all the references to external functions are resolved at the compile time;
  1053. there is no runtime fixup of the DLLs after they are loaded into memory.
  1054. The first feature is an enormous advantage over other models: it avoids
  1055. conflicts when several DLLs used by an application export entries with
  1056. the same name. In such cases "other" models of dyna-linking just choose
  1057. between these two entry points using some random criterion - with predictable
  1058. disasters as results. But it is the second feature which requires the build
  1059. of F<perl.dll>.
  1060. The address tables of DLLs are patched only once, when they are
  1061. loaded. The addresses of the entry points into DLLs are guaranteed to be
  1062. the same for all the programs which use the same DLL. This removes the
  1063. runtime fixup - once DLL is loaded, its code is read-only.
  1064. While this allows some (significant?) performance advantages, this makes life
  1065. much harder for developers, since the above scheme makes it impossible
  1066. for a DLL to be "linked" to a symbol in the F<.EXE> file. Indeed, this
  1067. would need a DLL to have different relocations tables for the
  1068. (different) executables which use this DLL.
  1069. However, a dynamically loaded Perl extension is forced to use some symbols
  1070. from the perl
  1071. executable, e.g., to know how to find the arguments to the functions:
  1072. the arguments live on the perl
  1073. internal evaluation stack. The solution is to put the main code of
  1074. the interpreter into a DLL, and make the F<.EXE> file which just loads
  1075. this DLL into memory and supplies command-arguments. The extension DLL
  1076. cannot link to symbols in F<.EXE>, but it has no problem linking
  1077. to symbols in the F<.DLL>.
  1078. This I<greatly> increases the load time for the application (as well as
  1079. complexity of the compilation). Since interpreter is in a DLL,
  1080. the C RTL is basically forced to reside in a DLL as well (otherwise
  1081. extensions would not be able to use CRT). There are some advantages if
  1082. you use different flavors of perl, such as running F<perl.exe> and
  1083. F<perl__.exe> simultaneously: they share the memory of F<perl.dll>.
  1084. B<NOTE>. There is one additional effect which makes DLLs more wasteful:
  1085. DLLs are loaded in the shared memory region, which is a scarse resource
  1086. given the 512M barrier of the "standard" OS/2 virtual memory. The code of
  1087. F<.EXE> files is also shared by all the processes which use the particular
  1088. F<.EXE>, but they are "shared in the private address space of the process";
  1089. this is possible because the address at which different sections
  1090. of the F<.EXE> file are loaded is decided at compile-time, thus all the
  1091. processes have these sections loaded at same addresses, and no fixup
  1092. of internal links inside the F<.EXE> is needed.
  1093. Since DLLs may be loaded at run time, to have the same mechanism for for DLLs
  1094. one needs to have the address range of I<any of the loaded> DLLs in the
  1095. system to be available I<in all the processes> which did not load a particular
  1096. DLL yet. This is why the DLLs are mapped to the shared memory region.
  1097. =head2 Why chimera build?
  1098. Current EMX environment does not allow DLLs compiled using Unixish
  1099. C<a.out> format to export symbols for data (or at least some types of
  1100. data). This forces C<omf>-style compile of F<perl.dll>.
  1101. Current EMX environment does not allow F<.EXE> files compiled in
  1102. C<omf> format to fork(). fork() is needed for exactly three Perl
  1103. operations:
  1104. =over 4
  1105. =item *
  1106. explicit fork() in the script,
  1107. =item *
  1108. C<open FH, "|-">
  1109. =item *
  1110. C<open FH, "-|">, in other words, opening pipes to itself.
  1111. =back
  1112. While these operations are not questions of life and death, they are
  1113. needed for a lot of
  1114. useful scripts. This forces C<a.out>-style compile of
  1115. F<perl.exe>.
  1116. =head1 ENVIRONMENT
  1117. Here we list environment variables with are either OS/2- and DOS- and
  1118. Win*-specific, or are more important under OS/2 than under other OSes.
  1119. =head2 C<PERLLIB_PREFIX>
  1120. Specific for EMX port. Should have the form
  1121. path1;path2
  1122. or
  1123. path1 path2
  1124. If the beginning of some prebuilt path matches F<path1>, it is
  1125. substituted with F<path2>.
  1126. Should be used if the perl library is moved from the default
  1127. location in preference to C<PERL(5)LIB>, since this would not leave wrong
  1128. entries in @INC. For example, if the compiled version of perl looks for @INC
  1129. in F<f:/perllib/lib>, and you want to install the library in
  1130. F<h:/opt/gnu>, do
  1131. set PERLLIB_PREFIX=f:/perllib/lib;h:/opt/gnu
  1132. This will cause Perl with the prebuilt @INC of
  1133. f:/perllib/lib/5.00553/os2
  1134. f:/perllib/lib/5.00553
  1135. f:/perllib/lib/site_perl/5.00553/os2
  1136. f:/perllib/lib/site_perl/5.00553
  1137. .
  1138. to use the following @INC:
  1139. h:/opt/gnu/5.00553/os2
  1140. h:/opt/gnu/5.00553
  1141. h:/opt/gnu/site_perl/5.00553/os2
  1142. h:/opt/gnu/site_perl/5.00553
  1143. .
  1144. =head2 C<PERL_BADLANG>
  1145. If 0, perl ignores setlocale() failing. May be useful with some
  1146. strange I<locale>s.
  1147. =head2 C<PERL_BADFREE>
  1148. If 0, perl would not warn of in case of unwarranted free(). With older
  1149. perls this might be
  1150. useful in conjunction with the module DB_File, which was buggy when
  1151. dynamically linked and OMF-built.
  1152. Should not be set with newer Perls, since this may hide some I<real> problems.
  1153. =head2 C<PERL_SH_DIR>
  1154. Specific for EMX port. Gives the directory part of the location for
  1155. F<sh.exe>.
  1156. =head2 C<USE_PERL_FLOCK>
  1157. Specific for EMX port. Since L<flock(3)> is present in EMX, but is not
  1158. functional, it is emulated by perl. To disable the emulations, set
  1159. environment variable C<USE_PERL_FLOCK=0>.
  1160. =head2 C<TMP> or C<TEMP>
  1161. Specific for EMX port. Used as storage place for temporary files.
  1162. =head1 Evolution
  1163. Here we list major changes which could make you by surprise.
  1164. =head2 Priorities
  1165. C<setpriority> and C<getpriority> are not compatible with earlier
  1166. ports by Andreas Kaiser. See C<"setpriority, getpriority">.
  1167. =head2 DLL name mangling
  1168. With the release 5.003_01 the dynamically loadable libraries
  1169. should be rebuilt when a different version of Perl is compiled. In particular,
  1170. DLLs (including F<perl.dll>) are now created with the names
  1171. which contain a checksum, thus allowing workaround for OS/2 scheme of
  1172. caching DLLs.
  1173. It may be possible to code a simple workaround which would
  1174. =over
  1175. =item *
  1176. find the old DLLs looking through the old @INC;
  1177. =item *
  1178. mangle the names according to the scheme of new perl and copy the DLLs to
  1179. these names;
  1180. =item *
  1181. edit the internal C<LX> tables of DLL to reflect the change of the name
  1182. (probably not needed for Perl extension DLLs, since the internally coded names
  1183. are not used for "specific" DLLs, they used only for "global" DLLs).
  1184. =item *
  1185. edit the internal C<IMPORT> tables and change the name of the "old"
  1186. F<perl????.dll> to the "new" F<perl????.dll>.
  1187. =back
  1188. =head2 Threading
  1189. As of release 5.003_01 perl is linked to multithreaded C RTL
  1190. DLL. If perl itself is not compiled multithread-enabled, so will not be perl's
  1191. malloc(). However, extensions may use multiple thread on their own
  1192. risk.
  1193. This was needed to compile C<Perl/Tk> for XFree86-OS/2 out-of-the-box, and
  1194. link with DLLs for other useful libraries, which typically are compiled
  1195. with C<-Zmt -Zcrtdll>.
  1196. =head2 Calls to external programs
  1197. Due to a popular demand the perl external program calling has been
  1198. changed wrt Andreas Kaiser's port. I<If> perl needs to call an
  1199. external program I<via shell>, the F<f:/bin/sh.exe> will be called, or
  1200. whatever is the override, see L<"PERL_SH_DIR">.
  1201. Thus means that you need to get some copy of a F<sh.exe> as well (I
  1202. use one from pdksh). The path F<F:/bin> above is set up automatically during
  1203. the build to a correct value on the builder machine, but is
  1204. overridable at runtime,
  1205. B<Reasons:> a consensus on C<perl5-porters> was that perl should use
  1206. one non-overridable shell per platform. The obvious choices for OS/2
  1207. are F<cmd.exe> and F<sh.exe>. Having perl build itself would be impossible
  1208. with F<cmd.exe> as a shell, thus I picked up C<sh.exe>. This assures almost
  1209. 100% compatibility with the scripts coming from *nix. As an added benefit
  1210. this works as well under DOS if you use DOS-enabled port of pdksh
  1211. (see L<"Prerequisites">).
  1212. B<Disadvantages:> currently F<sh.exe> of pdksh calls external programs
  1213. via fork()/exec(), and there is I<no> functioning exec() on
  1214. OS/2. exec() is emulated by EMX by an asynchronous call while the caller
  1215. waits for child completion (to pretend that the C<pid> did not change). This
  1216. means that 1 I<extra> copy of F<sh.exe> is made active via fork()/exec(),
  1217. which may lead to some resources taken from the system (even if we do
  1218. not count extra work needed for fork()ing).
  1219. Note that this a lesser issue now when we do not spawn F<sh.exe>
  1220. unless needed (metachars found).
  1221. One can always start F<cmd.exe> explicitly via
  1222. system 'cmd', '/c', 'mycmd', 'arg1', 'arg2', ...
  1223. If you need to use F<cmd.exe>, and do not want to hand-edit thousands of your
  1224. scripts, the long-term solution proposed on p5-p is to have a directive
  1225. use OS2::Cmd;
  1226. which will override system(), exec(), C<``>, and
  1227. C<open(,'...|')>. With current perl you may override only system(),
  1228. readpipe() - the explicit version of C<``>, and maybe exec(). The code
  1229. will substitute the one-argument call to system() by
  1230. C<CORE::system('cmd.exe', '/c', shift)>.
  1231. If you have some working code for C<OS2::Cmd>, please send it to me,
  1232. I will include it into distribution. I have no need for such a module, so
  1233. cannot test it.
  1234. For the details of the current situation with calling external programs,
  1235. see L<Starting OS/2 (and DOS) programs under Perl>. Set us mention a couple
  1236. of features:
  1237. =over 4
  1238. =item *
  1239. External scripts may be called by their basename. Perl will try the same
  1240. extensions as when processing B<-S> command-line switch.
  1241. =item *
  1242. External scripts starting with C<#!> or C<extproc > will be executed directly,
  1243. without calling the shell, by calling the program specified on the rest of
  1244. the first line.
  1245. =back
  1246. =head2 Memory allocation
  1247. Perl uses its own malloc() under OS/2 - interpreters are usually malloc-bound
  1248. for speed, but perl is not, since its malloc is lightning-fast.
  1249. Perl-memory-usage-tuned benchmarks show that Perl's malloc is 5 times quicker
  1250. than EMX one. I do not have convincing data about memory footprint, but
  1251. a (pretty random) benchmark showed that Perl's one is 5% better.
  1252. Combination of perl's malloc() and rigid DLL name resolution creates
  1253. a special problem with library functions which expect their return value to
  1254. be free()d by system's free(). To facilitate extensions which need to call
  1255. such functions, system memory-allocation functions are still available with
  1256. the prefix C<emx_> added. (Currently only DLL perl has this, it should
  1257. propagate to F<perl_.exe> shortly.)
  1258. =head2 Threads
  1259. One can build perl with thread support enabled by providing C<-D usethreads>
  1260. option to F<Configure>. Currently OS/2 support of threads is very
  1261. preliminary.
  1262. Most notable problems:
  1263. =over 4
  1264. =item C<COND_WAIT>
  1265. may have a race condition. Needs a reimplementation (in terms of chaining
  1266. waiting threads, with the linked list stored in per-thread structure?).
  1267. =item F<os2.c>
  1268. has a couple of static variables used in OS/2-specific functions. (Need to be
  1269. moved to per-thread structure, or serialized?)
  1270. =back
  1271. Note that these problems should not discourage experimenting, since they
  1272. have a low probability of affecting small programs.
  1273. =cut
  1274. OS/2 extensions
  1275. ~~~~~~~~~~~~~~~
  1276. I include 3 extensions by Andreas Kaiser, OS2::REXX, OS2::UPM, and OS2::FTP,
  1277. into my ftp directory, mirrored on CPAN. I made
  1278. some minor changes needed to compile them by standard tools. I cannot
  1279. test UPM and FTP, so I will appreciate your feedback. Other extensions
  1280. there are OS2::ExtAttr, OS2::PrfDB for tied access to EAs and .INI
  1281. files - and maybe some other extensions at the time you read it.
  1282. Note that OS2 perl defines 2 pseudo-extension functions
  1283. OS2::Copy::copy and DynaLoader::mod2fname (many more now, see
  1284. L<Prebuilt methods>).
  1285. The -R switch of older perl is deprecated. If you need to call a REXX code
  1286. which needs access to variables, include the call into a REXX compartment
  1287. created by
  1288. REXX_call {...block...};
  1289. Two new functions are supported by REXX code,
  1290. REXX_eval 'string';
  1291. REXX_eval_with 'string', REXX_function_name => \&perl_sub_reference;
  1292. If you have some other extensions you want to share, send the code to
  1293. me. At least two are available: tied access to EA's, and tied access
  1294. to system databases.
  1295. =head1 AUTHOR
  1296. Ilya Zakharevich, [email protected]
  1297. =head1 SEE ALSO
  1298. perl(1).
  1299. =cut