Install Perl 5.8.8
[msysgit.git] / mingw / html / pod / perlos2.html
blob09547ae3529b92bcc105b7983ad5702b3decb692
1 <?xml version="1.0" ?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
4 <head>
5 <title>perlos2 - Perl under OS/2, DOS, Win0.3*, Win0.95 and WinNT.</title>
6 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
7 <link rev="made" href="mailto:" />
8 </head>
10 <body style="background-color: white">
11 <table border="0" width="100%" cellspacing="0" cellpadding="3">
12 <tr><td class="block" style="background-color: #cccccc" valign="middle">
13 <big><strong><span class="block">&nbsp;perlos2 - Perl under OS/2, DOS, Win0.3*, Win0.95 and WinNT.</span></strong></big>
14 </td></tr>
15 </table>
17 <p><a name="__index__"></a></p>
18 <!-- INDEX BEGIN -->
20 <ul>
22 <li><a href="#name">NAME</a></li>
23 <li><a href="#synopsis">SYNOPSIS</a></li>
24 <li><a href="#description">DESCRIPTION</a></li>
25 <ul>
27 <li><a href="#target">Target</a></li>
28 <li><a href="#other_oses">Other OSes</a></li>
29 <li><a href="#prerequisites">Prerequisites</a></li>
30 <li><a href="#starting_perl_programs_under_os_2__and_dos_and____">Starting Perl programs under OS/2 (and DOS and...)</a></li>
31 <li><a href="#starting_os_2__and_dos__programs_under_perl">Starting OS/2 (and DOS) programs under Perl</a></li>
32 </ul>
34 <li><a href="#frequently_asked_questions">Frequently asked questions</a></li>
35 <ul>
37 <li><a href="#it_does_not_work">``It does not work''</a></li>
38 <li><a href="#i_cannot_run_external_programs">I cannot run external programs</a></li>
39 <li><a href="#i_cannot_embed_perl_into_my_program__or_use_perl_dll_from_my">I cannot embed perl into my program, or use <em>perl.dll</em> from my</a></li>
40 <li><a href="#___and_pipeopen_do_not_work_under_dos_"><code>``</code> and pipe-<a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_open"><code>open</code></a> do not work under DOS.</a></li>
41 <li><a href="#cannot_start_find_exe_pattern_file">Cannot start <code>find.exe &quot;pattern&quot; file</code></a></li>
42 </ul>
44 <li><a href="#installation">INSTALLATION</a></li>
45 <ul>
47 <li><a href="#automatic_binary_installation">Automatic binary installation</a></li>
48 <li><a href="#manual_binary_installation">Manual binary installation</a></li>
49 <li><a href="#warning"><strong>Warning</strong></a></li>
50 </ul>
52 <li><a href="#accessing_documentation">Accessing documentation</a></li>
53 <ul>
55 <li><a href="#os_2__inf_file">OS/2 <em>.INF</em> file</a></li>
56 <li><a href="#plain_text">Plain text</a></li>
57 <li><a href="#manpages">Manpages</a></li>
58 <li><a href="#html">HTML</a></li>
59 <li><a href="#gnu_info_files">GNU <code>info</code> files</a></li>
60 <li><a href="#pdf_files"><em>PDF</em> files</a></li>
61 <li><a href="#latex_docs"><code>LaTeX</code> docs</a></li>
62 </ul>
64 <li><a href="#build">BUILD</a></li>
65 <ul>
67 <li><a href="#the_short_story">The short story</a></li>
68 <li><a href="#prerequisites">Prerequisites</a></li>
69 <li><a href="#getting_perl_source">Getting perl source</a></li>
70 <li><a href="#application_of_the_patches">Application of the patches</a></li>
71 <li><a href="#handediting">Hand-editing</a></li>
72 <li><a href="#making">Making</a></li>
73 <li><a href="#testing">Testing</a></li>
74 <li><a href="#installing_the_built_perl">Installing the built perl</a></li>
75 <li><a href="#a_outstyle_build"><code>a.out</code>-style build</a></li>
76 </ul>
78 <li><a href="#building_a_binary_distribution">Building a binary distribution</a></li>
79 <li><a href="#building_custom__exe_files">Building custom <em>.EXE</em> files</a></li>
80 <ul>
82 <li><a href="#making_executables_with_a_custom_collection_of_statically_loaded_extensions">Making executables with a custom collection of statically loaded extensions</a></li>
83 <li><a href="#making_executables_with_a_custom_searchpaths">Making executables with a custom search-paths</a></li>
84 </ul>
86 <li><a href="#build_faq">Build FAQ</a></li>
87 <ul>
89 <li><a href="#some___became___in_pdksh_">Some <code>/</code> became <code>\</code> in pdksh.</a></li>
90 <li><a href="#_errno___unresolved_external"><code>'errno'</code> - unresolved external</a></li>
91 <li><a href="#problems_with_tr_or_sed">Problems with tr or sed</a></li>
92 <li><a href="#some_problem__forget_which___">Some problem (forget which ;-)</a></li>
93 <li><a href="#library_____not_found">Library ... not found</a></li>
94 <li><a href="#segfault_in_make">Segfault in make</a></li>
95 <li><a href="#op_sprintf_test_failure">op/sprintf test failure</a></li>
96 </ul>
98 <li><a href="#specific__mis_features_of_os_2_port">Specific (mis)features of OS/2 port</a></li>
99 <ul>
101 <li><a href="#setpriority__getpriority"><code>setpriority</code>, <code>getpriority</code></a></li>
102 <li><a href="#system__"><a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_system"><code>system()</code></a></a></li>
103 <li><a href="#extproc_on_the_first_line"><code>extproc</code> on the first line</a></li>
104 <li><a href="#additional_modules_">Additional modules:</a></li>
105 <li><a href="#prebuilt_methods_">Prebuilt methods:</a></li>
106 <li><a href="#prebuilt_variables_">Prebuilt variables:</a></li>
107 <li><a href="#misfeatures">Misfeatures</a></li>
108 <li><a href="#modifications">Modifications</a></li>
109 <li><a href="#identifying_dlls">Identifying DLLs</a></li>
110 <li><a href="#centralized_management_of_resources">Centralized management of resources</a></li>
111 </ul>
113 <li><a href="#perl_flavors">Perl flavors</a></li>
114 <ul>
116 <li><a href="#perl_exe"><em>perl.exe</em></a></li>
117 <li><a href="#perl__exe"><em>perl_.exe</em></a></li>
118 <li><a href="#perl___exe"><em>perl__.exe</em></a></li>
119 <li><a href="#perl____exe"><em>perl___.exe</em></a></li>
120 <li><a href="#why_strange_names">Why strange names?</a></li>
121 <li><a href="#why_dynamic_linking">Why dynamic linking?</a></li>
122 <li><a href="#why_chimera_build">Why chimera build?</a></li>
123 </ul>
125 <li><a href="#environment">ENVIRONMENT</a></li>
126 <ul>
128 <li><a href="#perllib_prefix"><code>PERLLIB_PREFIX</code></a></li>
129 <li><a href="#perl_badlang"><code>PERL_BADLANG</code></a></li>
130 <li><a href="#perl_badfree"><code>PERL_BADFREE</code></a></li>
131 <li><a href="#perl_sh_dir"><code>PERL_SH_DIR</code></a></li>
132 <li><a href="#use_perl_flock"><code>USE_PERL_FLOCK</code></a></li>
133 <li><a href="#tmp_or_temp"><code>TMP</code> or <code>TEMP</code></a></li>
134 </ul>
136 <li><a href="#evolution">Evolution</a></li>
137 <ul>
139 <li><a href="#textmode_filehandles">Text-mode filehandles</a></li>
140 <li><a href="#priorities">Priorities</a></li>
141 <li><a href="#dll_name_mangling__pre_5_6_2">DLL name mangling: pre 5.6.2</a></li>
142 <li><a href="#dll_name_mangling__5_6_2_and_beyond">DLL name mangling: 5.6.2 and beyond</a></li>
143 <li><a href="#dll_forwarder_generation">DLL forwarder generation</a></li>
144 <li><a href="#threading">Threading</a></li>
145 <li><a href="#calls_to_external_programs">Calls to external programs</a></li>
146 <li><a href="#memory_allocation">Memory allocation</a></li>
147 <li><a href="#threads">Threads</a></li>
148 </ul>
150 <li><a href="#bugs">BUGS</a></li>
151 <li><a href="#author">AUTHOR</a></li>
152 <li><a href="#see_also">SEE ALSO</a></li>
153 </ul>
154 <!-- INDEX END -->
156 <hr />
158 </p>
159 <h1><a name="name">NAME</a></h1>
160 <p>perlos2 - Perl under OS/2, DOS, Win0.3*, Win0.95 and WinNT.</p>
162 </p>
163 <hr />
164 <h1><a name="synopsis">SYNOPSIS</a></h1>
165 <p>One can read this document in the following formats:</p>
166 <pre>
167 man <a href="//C|\msysgit\mingw\html/pod/perlos2.html">perlos2</a>
168 view perl <a href="//C|\msysgit\mingw\html/pod/perlos2.html">perlos2</a>
169 explorer <a href="//C|\msysgit\mingw\html/pod/perlos2.html">perlos2</a>.html
170 info <a href="//C|\msysgit\mingw\html/pod/perlos2.html">perlos2</a></pre>
171 <p>to list some (not all may be available simultaneously), or it may
172 be read <em>as is</em>: either as <em>README.os2</em>, or <em>pod/perlos2.pod</em>.</p>
173 <p>To read the <em>.INF</em> version of documentation (<strong>very</strong> recommended)
174 outside of OS/2, one needs an IBM's reader (may be available on IBM
175 ftp sites (?) (URL anyone?)) or shipped with PC DOS 7.0 and IBM's
176 Visual Age C++ 3.5.</p>
177 <p>A copy of a Win* viewer is contained in the ``Just add OS/2 Warp'' package</p>
178 <pre>
179 <a href="ftp://ftp.software.ibm.com/ps/products/os2/tools/jaow/jaow.zip">ftp://ftp.software.ibm.com/ps/products/os2/tools/jaow/jaow.zip</a></pre>
180 <p>in <em>?:\JUST_ADD\view.exe</em>. This gives one an access to EMX's
181 <em>.INF</em> docs as well (text form is available in <em>/emx/doc</em> in
182 EMX's distribution). There is also a different viewer named xview.</p>
183 <p>Note that if you have <em>lynx.exe</em> or <em>netscape.exe</em> installed, you can follow WWW links
184 from this document in <em>.INF</em> format. If you have EMX docs installed
185 correctly, you can follow library links (you need to have <code>view emxbook</code>
186 working by setting <code>EMXBOOK</code> environment variable as it is described
187 in EMX docs).</p>
189 </p>
190 <hr />
191 <h1><a name="description">DESCRIPTION</a></h1>
193 </p>
194 <h2><a name="target">Target</a></h2>
195 <p>The target is to make OS/2 one of the best supported platform for
196 using/building/developing Perl and <em>Perl applications</em>, as well as
197 make Perl the best language to use under OS/2. The secondary target is
198 to try to make this work under DOS and Win* as well (but not <strong>too</strong> hard).</p>
199 <p>The current state is quite close to this target. Known limitations:</p>
200 <ul>
201 <li>
202 <p>Some *nix programs use <code>fork()</code> a lot; with the mostly useful flavors of
203 perl for OS/2 (there are several built simultaneously) this is
204 supported; but some flavors do not support this (e.g., when Perl is
205 called from inside REXX). Using <code>fork()</code> after
206 <em>use</em>ing dynamically loading extensions would not work with <em>very</em> old
207 versions of EMX.</p>
208 </li>
209 <li>
210 <p>You need a separate perl executable <em>perl__.exe</em> (see <em>perl__.exe</em>)
211 if you want to use PM code in your application (as Perl/Tk or OpenGL
212 Perl modules do) without having a text-mode window present.</p>
213 <p>While using the standard <em>perl.exe</em> from a text-mode window is possible
214 too, I have seen cases when this causes degradation of the system stability.
215 Using <em>perl__.exe</em> avoids such a degradation.</p>
216 </li>
217 <li>
218 <p>There is no simple way to access WPS objects. The only way I know
219 is via <code>OS2::REXX</code> and <code>SOM</code> extensions (see <a href="file://C|\msysgit\mingw\html/OS2/REXX.html">the OS2::REXX manpage</a>, <em>Som</em>).
220 However, we do not have access to
221 convenience methods of Object-REXX. (Is it possible at all? I know
222 of no Object-REXX API.) The <code>SOM</code> extension (currently in alpha-text)
223 may eventually remove this shortcoming; however, due to the fact that
224 DII is not supported by the <code>SOM</code> module, using <code>SOM</code> is not as
225 convenient as one would like it.</p>
226 </li>
227 </ul>
228 <p>Please keep this list up-to-date by informing me about other items.</p>
230 </p>
231 <h2><a name="other_oses">Other OSes</a></h2>
232 <p>Since OS/2 port of perl uses a remarkable EMX environment, it can
233 run (and build extensions, and - possibly - be built itself) under any
234 environment which can run EMX. The current list is DOS,
235 DOS-inside-OS/2, Win0.3*, Win0.95 and WinNT. Out of many perl flavors,
236 only one works, see <a href="#perl__exe">perl_.exe</a>.</p>
237 <p>Note that not all features of Perl are available under these
238 environments. This depends on the features the <em>extender</em> - most
239 probably RSX - decided to implement.</p>
240 <p>Cf. <em>Prerequisites</em>.</p>
242 </p>
243 <h2><a name="prerequisites">Prerequisites</a></h2>
244 <dl>
245 <dt><strong><a name="item_emx">EMX</a></strong>
247 <dd>
248 <p>EMX runtime is required (may be substituted by RSX). Note that
249 it is possible to make <em>perl_.exe</em> to run under DOS without any
250 external support by binding <em>emx.exe</em>/<em>rsx.exe</em> to it, see <em>emxbind</em>. Note
251 that under DOS for best results one should use RSX runtime, which
252 has much more functions working (like <code>fork</code>, <a href="#item_popen"><code>popen</code></a> and so on). In
253 fact RSX is required if there is no VCPI present. Note the
254 RSX requires DPMI. Many implementations of DPMI are known to be very
255 buggy, beware!</p>
256 </dd>
257 <dd>
258 <p>Only the latest runtime is supported, currently <code>0.9d fix 03</code>. Perl may run
259 under earlier versions of EMX, but this is not tested.</p>
260 </dd>
261 <dd>
262 <p>One can get different parts of EMX from, say</p>
263 </dd>
264 <dd>
265 <pre>
266 <a href="http://www.leo.org/pub/comp/os/os2/leo/gnu/emx+gcc/">http://www.leo.org/pub/comp/os/os2/leo/gnu/emx+gcc/</a>
267 <a href="http://powerusersbbs.com/pub/os2/dev/">http://powerusersbbs.com/pub/os2/dev/</a> [EMX+GCC Development]
268 <a href="http://hobbes.nmsu.edu/pub/os2/dev/emx/v0.9d/">http://hobbes.nmsu.edu/pub/os2/dev/emx/v0.9d/</a></pre>
269 </dd>
270 <dd>
271 <p>The runtime component should have the name <em>emxrt.zip</em>.</p>
272 </dd>
273 <dd>
274 <p><strong>NOTE</strong>. When using <em>emx.exe</em>/<em>rsx.exe</em>, it is enough to have them on your path. One
275 does not need to specify them explicitly (though this</p>
276 </dd>
277 <dd>
278 <pre>
279 emx perl_.exe -de 0</pre>
280 </dd>
281 <dd>
282 <p>will work as well.)</p>
283 </dd>
284 </li>
285 <dt><strong><a name="item_rsx">RSX</a></strong>
287 <dd>
288 <p>To run Perl on DPMI platforms one needs RSX runtime. This is
289 needed under DOS-inside-OS/2, Win0.3*, Win0.95 and WinNT (see
290 <a href="#other_oses">Other OSes</a>). RSX would not work with VCPI
291 only, as EMX would, it requires DMPI.</p>
292 </dd>
293 <dd>
294 <p>Having RSX and the latest <em>sh.exe</em> one gets a fully functional
295 <strong>*nix</strong>-ish environment under DOS, say, <code>fork</code>, <code>``</code> and
296 pipe-<a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_open"><code>open</code></a> work. In fact, MakeMaker works (for static build), so one
297 can have Perl development environment under DOS.</p>
298 </dd>
299 <dd>
300 <p>One can get RSX from, say</p>
301 </dd>
302 <dd>
303 <pre>
304 <a href="ftp://ftp.cdrom.com/pub/os2/emx09c/contrib">ftp://ftp.cdrom.com/pub/os2/emx09c/contrib</a>
305 <a href="ftp://ftp.uni-bielefeld.de/pub/systems/msdos/misc">ftp://ftp.uni-bielefeld.de/pub/systems/msdos/misc</a>
306 <a href="ftp://ftp.leo.org/pub/comp/os/os2/leo/devtools/emx+gcc/contrib">ftp://ftp.leo.org/pub/comp/os/os2/leo/devtools/emx+gcc/contrib</a></pre>
307 </dd>
308 <dd>
309 <p>Contact the author on <code>rainer@mathematik.uni-bielefeld.de</code>.</p>
310 </dd>
311 <dd>
312 <p>The latest <em>sh.exe</em> with DOS hooks is available in</p>
313 </dd>
314 <dd>
315 <pre>
316 <a href="http://www.ilyaz.org/software/os2/">http://www.ilyaz.org/software/os2/</a></pre>
317 </dd>
318 <dd>
319 <p>as <em>sh_dos.zip</em> or under similar names starting with <code>sh</code>, <a href="#item_pdksh"><code>pdksh</code></a> etc.</p>
320 </dd>
321 </li>
322 <dt><strong><a name="item_hpfs">HPFS</a></strong>
324 <dd>
325 <p>Perl does not care about file systems, but the perl library contains
326 many files with long names, so to install it intact one needs a file
327 system which supports long file names.</p>
328 </dd>
329 <dd>
330 <p>Note that if you do not plan to build the perl itself, it may be
331 possible to fool EMX to truncate file names. This is not supported,
332 read EMX docs to see how to do it.</p>
333 </dd>
334 </li>
335 <dt><strong><a name="item_pdksh">pdksh</a></strong>
337 <dd>
338 <p>To start external programs with complicated command lines (like with
339 pipes in between, and/or quoting of arguments), Perl uses an external
340 shell. With EMX port such shell should be named <em>sh.exe</em>, and located
341 either in the wired-in-during-compile locations (usually <em>F:/bin</em>),
342 or in configurable location (see <a href="#perl_sh_dir">PERL_SH_DIR</a>).</p>
343 </dd>
344 <dd>
345 <p>For best results use EMX pdksh. The standard binary (5.2.14 or later) runs
346 under DOS (with <a href="#item_rsx">RSX</a>) as well, see</p>
347 </dd>
348 <dd>
349 <pre>
350 <a href="http://www.ilyaz.org/software/os2/">http://www.ilyaz.org/software/os2/</a></pre>
351 </dd>
352 </li>
353 </dl>
355 </p>
356 <h2><a name="starting_perl_programs_under_os_2__and_dos_and____">Starting Perl programs under OS/2 (and DOS and...)</a></h2>
357 <p>Start your Perl program <em>foo.pl</em> with arguments <code>arg1 arg2 arg3</code> the
358 same way as on any other platform, by</p>
359 <pre>
360 perl foo.pl arg1 arg2 arg3</pre>
361 <p>If you want to specify perl options <code>-my_opts</code> to the perl itself (as
362 opposed to your program), use</p>
363 <pre>
364 perl -my_opts foo.pl arg1 arg2 arg3</pre>
365 <p>Alternately, if you use OS/2-ish shell, like CMD or 4os2, put
366 the following at the start of your perl script:</p>
367 <pre>
368 extproc perl -S -my_opts</pre>
369 <p>rename your program to <em>foo.cmd</em>, and start it by typing</p>
370 <pre>
371 foo arg1 arg2 arg3</pre>
372 <p>Note that because of stupid OS/2 limitations the full path of the perl
373 script is not available when you use <code>extproc</code>, thus you are forced to
374 use <code>-S</code> perl switch, and your script should be on the <code>PATH</code>. As a plus
375 side, if you know a full path to your script, you may still start it
376 with</p>
377 <pre>
378 perl ../../blah/foo.cmd arg1 arg2 arg3</pre>
379 <p>(note that the argument <code>-my_opts</code> is taken care of by the <code>extproc</code> line
380 in your script, see <a href="#c_extproc__on_the_first_line"><code>extproc</code> on the first line</a>).</p>
381 <p>To understand what the above <em>magic</em> does, read perl docs about <code>-S</code>
382 switch - see <a href="file://C|\msysgit\mingw\html/pod/perlrun.html">the perlrun manpage</a>, and cmdref about <code>extproc</code>:</p>
383 <pre>
384 view perl <a href="//C|\msysgit\mingw\html/pod/perlrun.html">perlrun</a>
385 man <a href="//C|\msysgit\mingw\html/pod/perlrun.html">perlrun</a>
386 view cmdref extproc
387 help extproc</pre>
388 <p>or whatever method you prefer.</p>
389 <p>There are also endless possibilities to use <em>executable extensions</em> of
390 4os2, <em>associations</em> of WPS and so on... However, if you use
391 *nixish shell (like <em>sh.exe</em> supplied in the binary distribution),
392 you need to follow the syntax specified in <a href="file://C|\msysgit\mingw\html/pod/perlrun.html#switches">Switches in the perlrun manpage</a>.</p>
393 <p>Note that <strong>-S</strong> switch supports scripts with additional extensions
394 <em>.cmd</em>, <em>.btm</em>, <em>.bat</em>, <em>.pl</em> as well.</p>
396 </p>
397 <h2><a name="starting_os_2__and_dos__programs_under_perl">Starting OS/2 (and DOS) programs under Perl</a></h2>
398 <p>This is what <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_system"><code>system()</code></a> (see <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_system">system in the perlfunc manpage</a>), <code>``</code> (see
399 <a href="file://C|\msysgit\mingw\html/pod/perlop.html#i_o_operators">I/O Operators in the perlop manpage</a>), and <em>open pipe</em> (see <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_open">open in the perlfunc manpage</a>)
400 are for. (Avoid <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_exec"><code>exec()</code></a> (see <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_exec">exec in the perlfunc manpage</a>) unless you know what you
401 do).</p>
402 <p>Note however that to use some of these operators you need to have a
403 sh-syntax shell installed (see <a href="#item_pdksh">Pdksh</a>,
404 <a href="#frequently_asked_questions">Frequently asked questions</a>), and perl should be able to find it
405 (see <a href="#perl_sh_dir">PERL_SH_DIR</a>).</p>
406 <p>The cases when the shell is used are:</p>
407 <ol>
408 <li>
409 <p>One-argument <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_system"><code>system()</code></a> (see <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_system">system in the perlfunc manpage</a>), <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_exec"><code>exec()</code></a> (see <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_exec">exec in the perlfunc manpage</a>)
410 with redirection or shell meta-characters;</p>
411 </li>
412 <li>
413 <p>Pipe-open (see <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_open">open in the perlfunc manpage</a>) with the command which contains redirection
414 or shell meta-characters;</p>
415 </li>
416 <li>
417 <p>Backticks <code>``</code> (see <a href="file://C|\msysgit\mingw\html/pod/perlop.html#i_o_operators">I/O Operators in the perlop manpage</a>) with the command which contains
418 redirection or shell meta-characters;</p>
419 </li>
420 <li>
421 <p>If the executable called by system()/exec()/pipe-open()/<code>``</code> is a script
422 with the ``magic'' <code>#!</code> line or <code>extproc</code> line which specifies shell;</p>
423 </li>
424 <li>
425 <p>If the executable called by system()/exec()/pipe-open()/<code>``</code> is a script
426 without ``magic'' line, and <code>$ENV{EXECSHELL}</code> is set to shell;</p>
427 </li>
428 <li>
429 <p>If the executable called by system()/exec()/pipe-open()/<code>``</code> is not
430 found (is not this remark obsolete?);</p>
431 </li>
432 <li>
433 <p>For globbing (see <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_glob">glob in the perlfunc manpage</a>, <a href="file://C|\msysgit\mingw\html/pod/perlop.html#i_o_operators">I/O Operators in the perlop manpage</a>)
434 (obsolete? Perl uses builtin globbing nowadays...).</p>
435 </li>
436 </ol>
437 <p>For the sake of speed for a common case, in the above algorithms
438 backslashes in the command name are not considered as shell metacharacters.</p>
439 <p>Perl starts scripts which begin with cookies
440 <code>extproc</code> or <code>#!</code> directly, without an intervention of shell. Perl uses the
441 same algorithm to find the executable as <em>pdksh</em>: if the path
442 on <code>#!</code> line does not work, and contains <code>/</code>, then the directory
443 part of the executable is ignored, and the executable
444 is searched in <em>.</em> and on <code>PATH</code>. To find arguments for these scripts
445 Perl uses a different algorithm than <em>pdksh</em>: up to 3 arguments are
446 recognized, and trailing whitespace is stripped.</p>
447 <p>If a script
448 does not contain such a cooky, then to avoid calling <em>sh.exe</em>, Perl uses
449 the same algorithm as <em>pdksh</em>: if <code>$ENV{EXECSHELL}</code> is set, the
450 script is given as the first argument to this command, if not set, then
451 <code>$ENV{COMSPEC} /c</code> is used (or a hardwired guess if <code>$ENV{COMSPEC}</code> is
452 not set).</p>
453 <p>When starting scripts directly, Perl uses exactly the same algorithm as for
454 the search of script given by <strong>-S</strong> command-line option: it will look in
455 the current directory, then on components of <code>$ENV{PATH}</code> using the
456 following order of appended extensions: no extension, <em>.cmd</em>, <em>.btm</em>,
457 <em>.bat</em>, <em>.pl</em>.</p>
458 <p>Note that Perl will start to look for scripts only if OS/2 cannot start the
459 specified application, thus <code>system 'blah'</code> will not look for a script if
460 there is an executable file <em>blah.exe</em> <em>anywhere</em> on <code>PATH</code>. In
461 other words, <code>PATH</code> is essentially searched twice: once by the OS for
462 an executable, then by Perl for scripts.</p>
463 <p>Note also that executable files on OS/2 can have an arbitrary extension,
464 but <em>.exe</em> will be automatically appended if no dot is present in the name.
465 The workaround is as simple as that: since <em>blah.</em> and <em>blah</em> denote the
466 same file (at list on FAT and HPFS file systems), to start an executable residing in file <em>n:/bin/blah</em> (no
467 extension) give an argument <code>n:/bin/blah.</code> (dot appended) to system().</p>
468 <p>Perl will start PM programs from VIO (=text-mode) Perl process in a
469 separate PM session;
470 the opposite is not true: when you start a non-PM program from a PM
471 Perl process, Perl would not run it in a separate session. If a separate
472 session is desired, either ensure
473 that shell will be used, as in <code>system 'cmd /c myprog'</code>, or start it using
474 optional arguments to <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_system"><code>system()</code></a> documented in <code>OS2::Process</code> module. This
475 is considered to be a feature.</p>
477 </p>
478 <hr />
479 <h1><a name="frequently_asked_questions">Frequently asked questions</a></h1>
481 </p>
482 <h2><a name="it_does_not_work">``It does not work''</a></h2>
483 <p>Perl binary distributions come with a <em>testperl.cmd</em> script which tries
484 to detect common problems with misconfigured installations. There is a
485 pretty large chance it will discover which step of the installation you
486 managed to goof. <code>;-)</code></p>
488 </p>
489 <h2><a name="i_cannot_run_external_programs">I cannot run external programs</a></h2>
490 <ul>
491 <li>
492 <p>Did you run your programs with <code>-w</code> switch? See
493 <em>Starting OS/2 (and DOS) programs under Perl</em>.</p>
494 </li>
495 <li>
496 <p>Do you try to run <em>internal</em> shell commands, like <code>`copy a b`</code>
497 (internal for <em>cmd.exe</em>), or <code>`glob a*b`</code> (internal for ksh)? You
498 need to specify your shell explicitly, like <code>`cmd /c copy a b`</code>,
499 since Perl cannot deduce which commands are internal to your shell.</p>
500 </li>
501 </ul>
503 </p>
504 <h2><a name="i_cannot_embed_perl_into_my_program__or_use_perl_dll_from_my_program_">I cannot embed perl into my program, or use <em>perl.dll</em> from my
505 program.</a></h2>
506 <dl>
507 <dt><strong><a name="item_is_your_program_emx_2dcompiled_with__2dzmt__2dzcrt">Is your program EMX-compiled with <code>-Zmt -Zcrtdll</code>?</a></strong>
509 <dd>
510 <p>Well, nowadays Perl DLL should be usable from a differently compiled
511 program too... If you can run Perl code from REXX scripts (see
512 <a href="file://C|\msysgit\mingw\html/OS2/REXX.html">the OS2::REXX manpage</a>), then there are some other aspect of interaction which
513 are overlooked by the current hackish code to support
514 differently-compiled principal programs.</p>
515 </dd>
516 <dd>
517 <p>If everything else fails, you need to build a stand-alone DLL for
518 perl. Contact me, I did it once. Sockets would not work, as a lot of
519 other stuff.</p>
520 </dd>
521 </li>
522 <dt><strong><a name="item_did_you_use_extutils_3a_3aembed_3f">Did you use <a href="file://C|\msysgit\mingw\html/lib/ExtUtils/Embed.html">the ExtUtils::Embed manpage</a>?</a></strong>
524 <dd>
525 <p>Some time ago I had reports it does not work. Nowadays it is checked
526 in the Perl test suite, so grep <em>./t</em> subdirectory of the build tree
527 (as well as <em>*.t</em> files in the <em>./lib</em> subdirectory) to find how it
528 should be done ``correctly''.</p>
529 </dd>
530 </li>
531 </dl>
533 </p>
534 <h2><a name="___and_pipeopen_do_not_work_under_dos_"><code>``</code> and pipe-<a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_open"><code>open</code></a> do not work under DOS.</a></h2>
535 <p>This may a variant of just <a href="#i_cannot_run_external_programs">I cannot run external programs</a>, or a
536 deeper problem. Basically: you <em>need</em> RSX (see <a href="#prerequisites">Prerequisites</a>)
537 for these commands to work, and you may need a port of <em>sh.exe</em> which
538 understands command arguments. One of such ports is listed in
539 <a href="#prerequisites">Prerequisites</a> under RSX. Do not forget to set variable
540 <code>&quot;PERL_SH_DIR&quot;</code> as well.</p>
541 <p>DPMI is required for RSX.</p>
543 </p>
544 <h2><a name="cannot_start_find_exe_pattern_file">Cannot start <code>find.exe &quot;pattern&quot; file</code></a></h2>
545 <p>The whole idea of the ``standard C API to start applications'' is that
546 the forms <code>foo</code> and <code>&quot;foo&quot;</code> of program arguments are completely
547 interchangable. <em>find</em> breaks this paradigm;</p>
548 <pre>
549 find &quot;pattern&quot; file
550 find pattern file</pre>
551 <p>are not equivalent; <em>find</em> cannot be started directly using the above
552 API. One needs a way to surround the doublequotes in some other
553 quoting construction, necessarily having an extra non-Unixish shell in
554 between.</p>
555 <p>Use one of</p>
556 <pre>
557 system 'cmd', '/c', 'find &quot;pattern&quot; file';
558 `cmd /c 'find &quot;pattern&quot; file'`</pre>
559 <p>This would start <em>find.exe</em> via <em>cmd.exe</em> via <code>sh.exe</code> via
560 <code>perl.exe</code>, but this is a price to pay if you want to use
561 non-conforming program.</p>
563 </p>
564 <hr />
565 <h1><a name="installation">INSTALLATION</a></h1>
567 </p>
568 <h2><a name="automatic_binary_installation">Automatic binary installation</a></h2>
569 <p>The most convenient way of installing a binary distribution of perl is via perl installer
570 <em>install.exe</em>. Just follow the instructions, and 99% of the
571 installation blues would go away.</p>
572 <p>Note however, that you need to have <em>unzip.exe</em> on your path, and
573 EMX environment <em>running</em>. The latter means that if you just
574 installed EMX, and made all the needed changes to <em>Config.sys</em>,
575 you may need to reboot in between. Check EMX runtime by running</p>
576 <pre>
577 emxrev</pre>
578 <p>Binary installer also creates a folder on your desktop with some useful
579 objects. If you need to change some aspects of the work of the binary
580 installer, feel free to edit the file <em>Perl.pkg</em>. This may be useful
581 e.g., if you need to run the installer many times and do not want to
582 make many interactive changes in the GUI.</p>
583 <p><strong>Things not taken care of by automatic binary installation:</strong></p>
584 <dl>
585 <dt><strong><a name="item_perl_badlang"><code>PERL_BADLANG</code></a></strong>
587 <dd>
588 <p>may be needed if you change your codepage <em>after</em> perl installation,
589 and the new value is not supported by EMX. See <a href="#item_perl_badlang">PERL_BADLANG</a>.</p>
590 </dd>
591 </li>
592 <dt><strong><a name="item_perl_badfree"><code>PERL_BADFREE</code></a></strong>
594 <dd>
595 <p>see <a href="#item_perl_badfree">PERL_BADFREE</a>.</p>
596 </dd>
597 </li>
598 <dt><strong><a name="item_config_2epm"><em>Config.pm</em></a></strong>
600 <dd>
601 <p>This file resides somewhere deep in the location you installed your
602 perl library, find it out by</p>
603 </dd>
604 <dd>
605 <pre>
606 perl -MConfig -le &quot;print $INC{'Config.pm'}&quot;</pre>
607 </dd>
608 <dd>
609 <p>While most important values in this file <em>are</em> updated by the binary
610 installer, some of them may need to be hand-edited. I know no such
611 data, please keep me informed if you find one. Moreover, manual
612 changes to the installed version may need to be accompanied by an edit
613 of this file.</p>
614 </dd>
615 </li>
616 </dl>
617 <p><strong>NOTE</strong>. Because of a typo the binary installer of 5.00305
618 would install a variable <code>PERL_SHPATH</code> into <em>Config.sys</em>. Please
619 remove this variable and put <code>PERL_SH_DIR</code> instead.</p>
621 </p>
622 <h2><a name="manual_binary_installation">Manual binary installation</a></h2>
623 <p>As of version 5.00305, OS/2 perl binary distribution comes split
624 into 11 components. Unfortunately, to enable configurable binary
625 installation, the file paths in the zip files are not absolute, but
626 relative to some directory.</p>
627 <p>Note that the extraction with the stored paths is still necessary
628 (default with unzip, specify <code>-d</code> to pkunzip). However, you
629 need to know where to extract the files. You need also to manually
630 change entries in <em>Config.sys</em> to reflect where did you put the
631 files. Note that if you have some primitive unzipper (like
632 <code>pkunzip</code>), you may get a lot of warnings/errors during
633 unzipping. Upgrade to <code>(w)unzip</code>.</p>
634 <p>Below is the sample of what to do to reproduce the configuration on my
635 machine. In <em>VIEW.EXE</em> you can press <code>Ctrl-Insert</code> now, and
636 cut-and-paste from the resulting file - created in the directory you
637 started <em>VIEW.EXE</em> from.</p>
638 <p>For each component, we mention environment variables related to each
639 installation directory. Either choose directories to match your
640 values of the variables, or create/append-to variables to take into
641 account the directories.</p>
642 <dl>
643 <dt><strong><a name="item_executables">Perl VIO and PM executables (dynamically linked)</a></strong>
645 <dd>
646 <pre>
647 unzip perl_exc.zip *.exe *.ico -d f:/emx.add/bin
648 unzip perl_exc.zip *.dll -d f:/emx.add/dll</pre>
649 </dd>
650 <dd>
651 <p>(have the directories with <code>*.exe</code> on PATH, and <code>*.dll</code> on
652 LIBPATH);</p>
653 </dd>
654 <dt><strong><a name="item_executable">Perl_ VIO executable (statically linked)</a></strong>
656 <dd>
657 <pre>
658 unzip perl_aou.zip -d f:/emx.add/bin</pre>
659 </dd>
660 <dd>
661 <p>(have the directory on PATH);</p>
662 </dd>
663 <dt><strong><a name="item_executables_for_perl_utilities">Executables for Perl utilities</a></strong>
665 <dd>
666 <pre>
667 unzip perl_utl.zip -d f:/emx.add/bin</pre>
668 </dd>
669 <dd>
670 <p>(have the directory on PATH);</p>
671 </dd>
672 <dt><strong><a name="item_main_perl_library">Main Perl library</a></strong>
674 <dd>
675 <pre>
676 unzip perl_mlb.zip -d f:/perllib/lib</pre>
677 </dd>
678 <dd>
679 <p>If this directory is exactly the same as the prefix which was compiled
680 into <em>perl.exe</em>, you do not need to change
681 anything. However, for perl to find the library if you use a different
682 path, you need to
683 <code>set PERLLIB_PREFIX</code> in <em>Config.sys</em>, see <a href="#perllib_prefix">PERLLIB_PREFIX</a>.</p>
684 </dd>
685 <dt><strong><a name="item_additional_perl_modules">Additional Perl modules</a></strong>
687 <dd>
688 <pre>
689 unzip perl_ste.zip -d f:/perllib/lib/site_perl/5.8.8/</pre>
690 </dd>
691 <dd>
692 <p>Same remark as above applies. Additionally, if this directory is not
693 one of directories on @INC (and @INC is influenced by <code>PERLLIB_PREFIX</code>), you
694 need to put this
695 directory and subdirectory <em>./os2</em> in <code>PERLLIB</code> or <code>PERL5LIB</code>
696 variable. Do not use <code>PERL5LIB</code> unless you have it set already. See
697 <a href="file://C|\msysgit\mingw\html/pod/perl.html#environment">ENVIRONMENT in the perl manpage</a>.</p>
698 </dd>
699 <dd>
700 <p><strong>[Check whether this extraction directory is still applicable with
701 the new directory structure layout!]</strong></p>
702 </dd>
703 <dt><strong><a name="item_tools_to_compile_perl_modules">Tools to compile Perl modules</a></strong>
705 <dd>
706 <pre>
707 unzip perl_blb.zip -d f:/perllib/lib</pre>
708 </dd>
709 <dd>
710 <p>Same remark as for <em>perl_ste.zip</em>.</p>
711 </dd>
712 <dt><strong><a name="item_manpages_for_perl_and_utilities">Manpages for Perl and utilities</a></strong>
714 <dd>
715 <pre>
716 unzip perl_man.zip -d f:/perllib/man</pre>
717 </dd>
718 <dd>
719 <p>This directory should better be on <code>MANPATH</code>. You need to have a
720 working <em>man</em> to access these files.</p>
721 </dd>
722 <dt><strong><a name="item_manpages_for_perl_modules">Manpages for Perl modules</a></strong>
724 <dd>
725 <pre>
726 unzip perl_mam.zip -d f:/perllib/man</pre>
727 </dd>
728 <dd>
729 <p>This directory should better be on <code>MANPATH</code>. You need to have a
730 working man to access these files.</p>
731 </dd>
732 <dt><strong><a name="item_source_for_perl_documentation">Source for Perl documentation</a></strong>
734 <dd>
735 <pre>
736 unzip perl_pod.zip -d f:/perllib/lib</pre>
737 </dd>
738 <dd>
739 <p>This is used by the <code>perldoc</code> program (see <a href="file://C|\msysgit\mingw\html/pod/perldoc.html">the perldoc manpage</a>), and may be used to
740 generate HTML documentation usable by WWW browsers, and
741 documentation in zillions of other formats: <code>info</code>, <code>LaTeX</code>,
742 <code>Acrobat</code>, <code>FrameMaker</code> and so on. [Use programs such as
743 <em>pod2latex</em> etc.]</p>
744 </dd>
745 <dt><strong><a name="item_perl_manual_in__2einf_format">Perl manual in <em>.INF</em> format</a></strong>
747 <dd>
748 <pre>
749 unzip perl_inf.zip -d d:/os2/book</pre>
750 </dd>
751 <dd>
752 <p>This directory should better be on <code>BOOKSHELF</code>.</p>
753 </dd>
754 <dt><strong><a name="item_pdksh">Pdksh</a></strong>
756 <dd>
757 <pre>
758 unzip perl_sh.zip -d f:/bin</pre>
759 </dd>
760 <dd>
761 <p>This is used by perl to run external commands which explicitly
762 require shell, like the commands using <em>redirection</em> and <em>shell
763 metacharacters</em>. It is also used instead of explicit <em>/bin/sh</em>.</p>
764 </dd>
765 <dd>
766 <p>Set <code>PERL_SH_DIR</code> (see <a href="#perl_sh_dir">PERL_SH_DIR</a>) if you move <em>sh.exe</em> from
767 the above location.</p>
768 </dd>
769 <dd>
770 <p><strong>Note.</strong> It may be possible to use some other sh-compatible shell (untested).</p>
771 </dd>
772 </dl>
773 <p>After you installed the components you needed and updated the
774 <em>Config.sys</em> correspondingly, you need to hand-edit
775 <em>Config.pm</em>. This file resides somewhere deep in the location you
776 installed your perl library, find it out by</p>
777 <pre>
778 perl -MConfig -le &quot;print $INC{'Config.pm'}&quot;</pre>
779 <p>You need to correct all the entries which look like file paths (they
780 currently start with <code>f:/</code>).</p>
782 </p>
783 <h2><a name="warning"><strong>Warning</strong></a></h2>
784 <p>The automatic and manual perl installation leave precompiled paths
785 inside perl executables. While these paths are overwriteable (see
786 <a href="#perllib_prefix">PERLLIB_PREFIX</a>, <a href="#perl_sh_dir">PERL_SH_DIR</a>), some people may prefer
787 binary editing of paths inside the executables/DLLs.</p>
789 </p>
790 <hr />
791 <h1><a name="accessing_documentation">Accessing documentation</a></h1>
792 <p>Depending on how you built/installed perl you may have (otherwise
793 identical) Perl documentation in the following formats:</p>
795 </p>
796 <h2><a name="os_2__inf_file">OS/2 <em>.INF</em> file</a></h2>
797 <p>Most probably the most convenient form. Under OS/2 view it as</p>
798 <pre>
799 view perl
800 view perl <a href="//C|\msysgit\mingw\html/pod/perlfunc.html">perlfunc</a>
801 view perl less
802 view perl ExtUtils::MakeMaker</pre>
803 <p>(currently the last two may hit a wrong location, but this may improve
804 soon). Under Win* see <a href="#synopsis">SYNOPSIS</a>.</p>
805 <p>If you want to build the docs yourself, and have <em>OS/2 toolkit</em>, run</p>
806 <pre>
807 pod2ipf &gt; perl.ipf</pre>
808 <p>in <em>/perllib/lib/pod</em> directory, then</p>
809 <pre>
810 ipfc /inf perl.ipf</pre>
811 <p>(Expect a lot of errors during the both steps.) Now move it on your
812 BOOKSHELF path.</p>
814 </p>
815 <h2><a name="plain_text">Plain text</a></h2>
816 <p>If you have perl documentation in the source form, perl utilities
817 installed, and GNU groff installed, you may use</p>
818 <pre>
819 <a href="//C|\msysgit\mingw\html/pod/perldoc.html">perldoc</a> <a href="//C|\msysgit\mingw\html/pod/perlfunc.html">perlfunc</a>
820 <a href="//C|\msysgit\mingw\html/pod/perldoc.html">perldoc</a> less
821 <a href="//C|\msysgit\mingw\html/pod/perldoc.html">perldoc</a> ExtUtils::MakeMaker</pre>
822 <p>to access the perl documentation in the text form (note that you may get
823 better results using perl manpages).</p>
824 <p>Alternately, try running pod2text on <em>.pod</em> files.</p>
826 </p>
827 <h2><a name="manpages">Manpages</a></h2>
828 <p>If you have <em>man</em> installed on your system, and you installed perl
829 manpages, use something like this:</p>
830 <pre>
831 man <a href="//C|\msysgit\mingw\html/pod/perlfunc.html">perlfunc</a>
832 man 3 less
833 man ExtUtils.MakeMaker</pre>
834 <p>to access documentation for different components of Perl. Start with</p>
835 <pre>
836 man perl</pre>
837 <p>Note that dot (<em>.</em>) is used as a package separator for documentation
838 for packages, and as usual, sometimes you need to give the section - <code>3</code>
839 above - to avoid shadowing by the <em>less(1) manpage</em>.</p>
840 <p>Make sure that the directory <strong>above</strong> the directory with manpages is
841 on our <code>MANPATH</code>, like this</p>
842 <pre>
843 set MANPATH=c:/man;f:/perllib/man</pre>
844 <p>for Perl manpages in <code>f:/perllib/man/man1/</code> etc.</p>
846 </p>
847 <h2><a name="html">HTML</a></h2>
848 <p>If you have some WWW browser available, installed the Perl
849 documentation in the source form, and Perl utilities, you can build
850 HTML docs. Cd to directory with <em>.pod</em> files, and do like this</p>
851 <pre>
852 cd f:/perllib/lib/pod
853 pod2html</pre>
854 <p>After this you can direct your browser the file <em>perl.html</em> in this
855 directory, and go ahead with reading docs, like this:</p>
856 <pre>
857 explore <a href="file:///f:/perllib/lib/pod/perl.html">file:///f:/perllib/lib/pod/perl.html</a></pre>
858 <p>Alternatively you may be able to get these docs prebuilt from CPAN.</p>
860 </p>
861 <h2><a name="gnu_info_files">GNU <code>info</code> files</a></h2>
862 <p>Users of Emacs would appreciate it very much, especially with
863 <code>CPerl</code> mode loaded. You need to get latest <code>pod2texi</code> from <code>CPAN</code>,
864 or, alternately, the prebuilt info pages.</p>
866 </p>
867 <h2><a name="pdf_files"><em>PDF</em> files</a></h2>
868 <p>for <code>Acrobat</code> are available on CPAN (may be for slightly older version of
869 perl).</p>
871 </p>
872 <h2><a name="latex_docs"><code>LaTeX</code> docs</a></h2>
873 <p>can be constructed using <code>pod2latex</code>.</p>
875 </p>
876 <hr />
877 <h1><a name="build">BUILD</a></h1>
878 <p>Here we discuss how to build Perl under OS/2. There is an alternative
879 (but maybe older) view on <a href="http://www.shadow.net/~troc/os2perl.html">http://www.shadow.net/~troc/os2perl.html</a>.</p>
881 </p>
882 <h2><a name="the_short_story">The short story</a></h2>
883 <p>Assume that you are a seasoned porter, so are sure that all the necessary
884 tools are already present on your system, and you know how to get the Perl
885 source distribution. Untar it, change to the extract directory, and</p>
886 <pre>
887 gnupatch -p0 &lt; os2\diff.configure
888 sh Configure -des -D prefix=f:/perllib
889 make
890 make test
891 make install
892 make aout_test
893 make aout_install</pre>
894 <p>This puts the executables in f:/perllib/bin. Manually move them to the
895 <code>PATH</code>, manually move the built <em>perl*.dll</em> to <code>LIBPATH</code> (here for
896 Perl DLL <em>*</em> is a not-very-meaningful hex checksum), and run</p>
897 <pre>
898 make installcmd INSTALLCMDDIR=d:/ir/on/path</pre>
899 <p>Assuming that the <code>man</code>-files were put on an appropriate location,
900 this completes the installation of minimal Perl system. (The binary
901 distribution contains also a lot of additional modules, and the
902 documentation in INF format.)</p>
903 <p>What follows is a detailed guide through these steps.</p>
905 </p>
906 <h2><a name="prerequisites">Prerequisites</a></h2>
907 <p>You need to have the latest EMX development environment, the full
908 GNU tool suite (gawk renamed to awk, and GNU <em>find.exe</em>
909 earlier on path than the OS/2 <em>find.exe</em>, same with <em>sort.exe</em>, to
910 check use</p>
911 <pre>
912 find --version
913 sort --version</pre>
914 <p>). You need the latest version of <em>pdksh</em> installed as <em>sh.exe</em>.</p>
915 <p>Check that you have <strong>BSD</strong> libraries and headers installed, and -
916 optionally - Berkeley DB headers and libraries, and crypt.</p>
917 <p>Possible locations to get the files:</p>
918 <pre>
919 <a href="ftp://hobbes.nmsu.edu/os2/unix/">ftp://hobbes.nmsu.edu/os2/unix/</a>
920 <a href="ftp://ftp.cdrom.com/pub/os2/unix/">ftp://ftp.cdrom.com/pub/os2/unix/</a>
921 <a href="ftp://ftp.cdrom.com/pub/os2/dev32/">ftp://ftp.cdrom.com/pub/os2/dev32/</a>
922 <a href="ftp://ftp.cdrom.com/pub/os2/emx09c/">ftp://ftp.cdrom.com/pub/os2/emx09c/</a></pre>
923 <p>It is reported that the following archives contain enough utils to
924 build perl: <em>gnufutil.zip</em>, <em>gnusutil.zip</em>, <em>gnututil.zip</em>, <em>gnused.zip</em>,
925 <em>gnupatch.zip</em>, <em>gnuawk.zip</em>, <em>gnumake.zip</em>, <em>gnugrep.zip</em>, <em>bsddev.zip</em> and
926 <em>ksh527rt.zip</em> (or a later version). Note that all these utilities are
927 known to be available from LEO:</p>
928 <pre>
929 <a href="ftp://ftp.leo.org/pub/comp/os/os2/leo/gnu">ftp://ftp.leo.org/pub/comp/os/os2/leo/gnu</a></pre>
930 <p>Note also that the <em>db.lib</em> and <em>db.a</em> from the EMX distribution
931 are not suitable for multi-threaded compile (even single-threaded
932 flavor of Perl uses multi-threaded C RTL, for
933 compatibility with XFree86-OS/2). Get a corrected one from</p>
934 <pre>
935 <a href="http://www.ilyaz.org/software/os2/db_mt.zip">http://www.ilyaz.org/software/os2/db_mt.zip</a></pre>
936 <p>If you have <em>exactly the same version of Perl</em> installed already,
937 make sure that no copies or perl are currently running. Later steps
938 of the build may fail since an older version of <em>perl.dll</em> loaded into
939 memory may be found. Running <code>make test</code> becomes meaningless, since
940 the test are checking a previous build of perl (this situation is detected
941 and reported by <em>lib/os2_base.t</em> test). Do not forget to unset
942 <code>PERL_EMXLOAD_SEC</code> in environment.</p>
943 <p>Also make sure that you have <em>/tmp</em> directory on the current drive,
944 and <em>.</em> directory in your <code>LIBPATH</code>. One may try to correct the
945 latter condition by</p>
946 <pre>
947 set BEGINLIBPATH .\.</pre>
948 <p>if you use something like <em>CMD.EXE</em> or latest versions of
949 <em>4os2.exe</em>. (Setting BEGINLIBPATH to just <code>.</code> is ignored by the
950 OS/2 kernel.)</p>
951 <p>Make sure your gcc is good for <code>-Zomf</code> linking: run <code>omflibs</code>
952 script in <em>/emx/lib</em> directory.</p>
953 <p>Check that you have link386 installed. It comes standard with OS/2,
954 but may be not installed due to customization. If typing</p>
955 <pre>
956 link386</pre>
957 <p>shows you do not have it, do <em>Selective install</em>, and choose <code>Link
958 object modules</code> in <em>Optional system utilities/More</em>. If you get into
959 link386 prompts, press <code>Ctrl-C</code> to exit.</p>
961 </p>
962 <h2><a name="getting_perl_source">Getting perl source</a></h2>
963 <p>You need to fetch the latest perl source (including developers
964 releases). With some probability it is located in</p>
965 <pre>
966 <a href="http://www.cpan.org/src/5.0">http://www.cpan.org/src/5.0</a>
967 <a href="http://www.cpan.org/src/5.0/unsupported">http://www.cpan.org/src/5.0/unsupported</a></pre>
968 <p>If not, you may need to dig in the indices to find it in the directory
969 of the current maintainer.</p>
970 <p>Quick cycle of developers release may break the OS/2 build time to
971 time, looking into</p>
972 <pre>
973 <a href="http://www.cpan.org/ports/os2/">http://www.cpan.org/ports/os2/</a></pre>
974 <p>may indicate the latest release which was publicly released by the
975 maintainer. Note that the release may include some additional patches
976 to apply to the current source of perl.</p>
977 <p>Extract it like this</p>
978 <pre>
979 tar vzxf perl5.00409.tar.gz</pre>
980 <p>You may see a message about errors while extracting <em>Configure</em>. This is
981 because there is a conflict with a similarly-named file <em>configure</em>.</p>
982 <p>Change to the directory of extraction.</p>
984 </p>
985 <h2><a name="application_of_the_patches">Application of the patches</a></h2>
986 <p>You need to apply the patches in <em>./os2/diff.*</em> like this:</p>
987 <pre>
988 gnupatch -p0 &lt; os2\diff.configure</pre>
989 <p>You may also need to apply the patches supplied with the binary
990 distribution of perl. It also makes sense to look on the
991 perl5-porters mailing list for the latest OS/2-related patches (see
992 <a href="http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/">http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/</a>). Such
993 patches usually contain strings <code>/os2/</code> and <code>patch</code>, so it makes
994 sense looking for these strings.</p>
996 </p>
997 <h2><a name="handediting">Hand-editing</a></h2>
998 <p>You may look into the file <em>./hints/os2.sh</em> and correct anything
999 wrong you find there. I do not expect it is needed anywhere.</p>
1001 </p>
1002 <h2><a name="making">Making</a></h2>
1003 <pre>
1004 sh Configure -des -D prefix=f:/perllib</pre>
1005 <p><code>prefix</code> means: where to install the resulting perl library. Giving
1006 correct prefix you may avoid the need to specify <code>PERLLIB_PREFIX</code>,
1007 see <a href="#perllib_prefix">PERLLIB_PREFIX</a>.</p>
1008 <p><em>Ignore the message about missing <code>ln</code>, and about <code>-c</code> option to
1009 tr</em>. The latter is most probably already fixed, if you see it and can trace
1010 where the latter spurious warning comes from, please inform me.</p>
1011 <p>Now</p>
1012 <pre>
1013 make</pre>
1014 <p>At some moment the built may die, reporting a <em>version mismatch</em> or
1015 <em>unable to run <em>perl</em></em>. This means that you do not have <em>.</em> in
1016 your LIBPATH, so <em>perl.exe</em> cannot find the needed <em>perl67B2.dll</em> (treat
1017 these hex digits as line noise). After this is fixed the build
1018 should finish without a lot of fuss.</p>
1020 </p>
1021 <h2><a name="testing">Testing</a></h2>
1022 <p>Now run</p>
1023 <pre>
1024 make test</pre>
1025 <p>All tests should succeed (with some of them skipped). If you have the
1026 same version of Perl installed, it is crucial that you have <code>.</code> early
1027 in your LIBPATH (or in BEGINLIBPATH), otherwise your tests will most
1028 probably test the wrong version of Perl.</p>
1029 <p>Some tests may generate extra messages similar to</p>
1030 <dl>
1031 <dt><strong><a name="item_a_lot_of_bad_free">A lot of <code>bad free</code></a></strong>
1033 <dd>
1034 <p>in database tests related to Berkeley DB. <em>This should be fixed already.</em>
1035 If it persists, you may disable this warnings, see <a href="#item_perl_badfree">PERL_BADFREE</a>.</p>
1036 </dd>
1037 </li>
1038 <dt><strong><a name="item_process_terminated_by_sigterm_2fsigint">Process terminated by SIGTERM/SIGINT</a></strong>
1040 <dd>
1041 <p>This is a standard message issued by OS/2 applications. *nix
1042 applications die in silence. It is considered to be a feature. One can
1043 easily disable this by appropriate sighandlers.</p>
1044 </dd>
1045 <dd>
1046 <p>However the test engine bleeds these message to screen in unexpected
1047 moments. Two messages of this kind <em>should</em> be present during
1048 testing.</p>
1049 </dd>
1050 </li>
1051 </dl>
1052 <p>To get finer test reports, call</p>
1053 <pre>
1054 perl t/harness</pre>
1055 <p>The report with <em>io/pipe.t</em> failing may look like this:</p>
1056 <pre>
1057 Failed Test Status Wstat Total Fail Failed List of failed
1058 ------------------------------------------------------------
1059 io/pipe.t 12 1 8.33% 9
1060 7 tests skipped, plus 56 subtests skipped.
1061 Failed 1/195 test scripts, 99.49% okay. 1/6542 subtests failed, 99.98% okay.</pre>
1062 <p>The reasons for most important skipped tests are:</p>
1063 <dl>
1064 <dt><strong><a name="item_op_2ffs_2et"><em>op/fs.t</em></a></strong>
1066 <ol>
1067 <li>
1068 <p>Checks <code>atime</code> and <code>mtime</code> of <a href="#item_stat"><code>stat()</code></a> - unfortunately, HPFS
1069 provides only 2sec time granularity (for compatibility with FAT?).</p>
1070 </li>
1071 <li>
1072 <p>Checks <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_truncate"><code>truncate()</code></a> on a filehandle just opened for write - I do not
1073 know why this should or should not work.</p>
1074 </li>
1075 </ol>
1076 <dt><strong><a name="item_op_2fstat_2et"><em>op/stat.t</em></a></strong>
1078 <dd>
1079 <p>Checks <a href="#item_stat"><code>stat()</code></a>. Tests:</p>
1080 </dd>
1081 <ol>
1082 <li>
1083 <p>Checks <code>atime</code> and <code>mtime</code> of <a href="#item_stat"><code>stat()</code></a> - unfortunately, HPFS
1084 provides only 2sec time granularity (for compatibility with FAT?).</p>
1085 </li>
1086 </ol>
1087 </dl>
1089 </p>
1090 <h2><a name="installing_the_built_perl">Installing the built perl</a></h2>
1091 <p>If you haven't yet moved <code>perl*.dll</code> onto LIBPATH, do it now.</p>
1092 <p>Run</p>
1093 <pre>
1094 make install</pre>
1095 <p>It would put the generated files into needed locations. Manually put
1096 <em>perl.exe</em>, <em>perl__.exe</em> and <em>perl___.exe</em> to a location on your
1097 PATH, <em>perl.dll</em> to a location on your LIBPATH.</p>
1098 <p>Run</p>
1099 <pre>
1100 make installcmd INSTALLCMDDIR=d:/ir/on/path</pre>
1101 <p>to convert perl utilities to <em>.cmd</em> files and put them on
1102 PATH. You need to put <em>.EXE</em>-utilities on path manually. They are
1103 installed in <code>$prefix/bin</code>, here <code>$prefix</code> is what you gave to
1104 <em>Configure</em>, see <em>Making</em>.</p>
1105 <p>If you use <code>man</code>, either move the installed <em>*/man/</em> directories to
1106 your <code>MANPATH</code>, or modify <code>MANPATH</code> to match the location. (One
1107 could have avoided this by providing a correct <code>manpath</code> option to
1108 <em>./Configure</em>, or editing <em>./config.sh</em> between configuring and
1109 making steps.)</p>
1111 </p>
1112 <h2><a name="a_outstyle_build"><code>a.out</code>-style build</a></h2>
1113 <p>Proceed as above, but make <em>perl_.exe</em> (see <a href="#perl__exe">perl_.exe</a>) by</p>
1114 <pre>
1115 make perl_</pre>
1116 <p>test and install by</p>
1117 <pre>
1118 make aout_test
1119 make aout_install</pre>
1120 <p>Manually put <em>perl_.exe</em> to a location on your PATH.</p>
1121 <p><strong>Note.</strong> The build process for <code>perl_</code> <em>does not know</em> about all the
1122 dependencies, so you should make sure that anything is up-to-date,
1123 say, by doing</p>
1124 <pre>
1125 make perl_dll</pre>
1126 <p>first.</p>
1128 </p>
1129 <hr />
1130 <h1><a name="building_a_binary_distribution">Building a binary distribution</a></h1>
1131 <p>[This section provides a short overview only...]</p>
1132 <p>Building should proceed differently depending on whether the version of perl
1133 you install is already present and used on your system, or is a new version
1134 not yet used. The description below assumes that the version is new, so
1135 installing its DLLs and <em>.pm</em> files will not disrupt the operation of your
1136 system even if some intermediate steps are not yet fully working.</p>
1137 <p>The other cases require a little bit more convoluted procedures. Below I
1138 suppose that the current version of Perl is <code>5.8.2</code>, so the executables are
1139 named accordingly.</p>
1140 <ol>
1141 <li>
1142 <p>Fully build and test the Perl distribution. Make sure that no tests are
1143 failing with <code>test</code> and <code>aout_test</code> targets; fix the bugs in Perl and
1144 the Perl test suite detected by these tests. Make sure that <code>all_test</code>
1145 make target runs as clean as possible. Check that <code>os2/perlrexx.cmd</code>
1146 runs fine.</p>
1147 </li>
1148 <li>
1149 <p>Fully install Perl, including <code>installcmd</code> target. Copy the generated DLLs
1150 to <code>LIBPATH</code>; copy the numbered Perl executables (as in <em>perl5.8.2.exe</em>)
1151 to <code>PATH</code>; copy <code>perl_.exe</code> to <code>PATH</code> as <code>perl_5.8.2.exe</code>. Think whether
1152 you need backward-compatibility DLLs. In most cases you do not need to install
1153 them yet; but sometime this may simplify the following steps.</p>
1154 </li>
1155 <li>
1156 <p>Make sure that <code>CPAN.pm</code> can download files from CPAN. If not, you may need
1157 to manually install <code>Net::FTP</code>.</p>
1158 </li>
1159 <li>
1160 <p>Install the bundle <code>Bundle::OS2_default</code></p>
1161 <pre>
1162 perl5.8.2 -MCPAN -e &quot;install Bundle::OS2_default&quot; &lt; nul |&amp; tee 00cpan_i_1</pre>
1163 <p>This may take a couple of hours on 1GHz processor (when run the first time).
1164 And this should not be necessarily a smooth procedure. Some modules may not
1165 specify required dependencies, so one may need to repeat this procedure several
1166 times until the results stabilize.</p>
1167 <pre>
1168 perl5.8.2 -MCPAN -e &quot;install Bundle::OS2_default&quot; &lt; nul |&amp; tee 00cpan_i_2
1169 perl5.8.2 -MCPAN -e &quot;install Bundle::OS2_default&quot; &lt; nul |&amp; tee 00cpan_i_3</pre>
1170 <p>Even after they stabilize, some tests may fail.</p>
1171 <p>Fix as many discovered bugs as possible. Document all the bugs which are not
1172 fixed, and all the failures with unknown reasons. Inspect the produced logs
1173 <em>00cpan_i_1</em> to find suspiciously skipped tests, and other fishy events.</p>
1174 <p>Keep in mind that <em>installation</em> of some modules may fail too: for example,
1175 the DLLs to update may be already loaded by <em>CPAN.pm</em>. Inspect the <code>install</code>
1176 logs (in the example above <em>00cpan_i_1</em> etc) for errors, and install things
1177 manually, as in</p>
1178 <pre>
1179 cd $CPANHOME/.cpan/build/Digest-MD5-2.31
1180 make install</pre>
1181 <p>Some distributions may fail some tests, but you may want to install them
1182 anyway (as above, or via <code>force install</code> command of <code>CPAN.pm</code> shell-mode).</p>
1183 <p>Since this procedure may take quite a long time to complete, it makes sense
1184 to ``freeze'' your CPAN configuration by disabling periodic updates of the
1185 local copy of CPAN index: set <code>index_expire</code> to some big value (I use 365),
1186 then save the settings</p>
1187 <pre>
1188 CPAN&gt; o conf index_expire 365
1189 CPAN&gt; o conf commit</pre>
1190 <p>Reset back to the default value <code>1</code> when you are finished.</p>
1191 </li>
1192 <li>
1193 <p>When satisfied with the results, rerun the <code>installcmd</code> target. Now you
1194 can copy <code>perl5.8.2.exe</code> to <code>perl.exe</code>, and install the other OMF-build
1195 executables: <code>perl__.exe</code> etc. They are ready to be used.</p>
1196 </li>
1197 <li>
1198 <p>Change to the <code>./pod</code> directory of the build tree, download the Perl logo
1199 <em>CamelGrayBig.BMP</em>, and run</p>
1200 <pre>
1201 ( perl2ipf &gt; perl.ipf ) |&amp; tee 00ipf
1202 ipfc /INF perl.ipf |&amp; tee 00inf</pre>
1203 <p>This produces the Perl docs online book <code>perl.INF</code>. Install in on
1204 <code>BOOKSHELF</code> path.</p>
1205 </li>
1206 <li>
1207 <p>Now is the time to build statically linked executable <em>perl_.exe</em> which
1208 includes newly-installed via <code>Bundle::OS2_default</code> modules. Doing testing
1209 via <code>CPAN.pm</code> is going to be painfully slow, since it statically links
1210 a new executable per XS extension.</p>
1211 <p>Here is a possible workaround: create a toplevel <em>Makefile.PL</em> in
1212 <em>$CPANHOME/.cpan/build/</em> with contents being (compare with <a href="#making_executables_with_a_custom_collection_of_statically_loaded_extensions">Making executables with a custom collection of statically loaded extensions</a>)</p>
1213 <pre>
1214 use ExtUtils::MakeMaker;
1215 WriteMakefile NAME =&gt; 'dummy';</pre>
1216 <p>execute this as</p>
1217 <pre>
1218 perl_5.8.2.exe Makefile.PL &lt;nul |&amp; tee 00aout_c1
1219 make -k all test &lt;nul |&amp; 00aout_t1</pre>
1220 <p>Again, this procedure should not be absolutely smooth. Some <code>Makefile.PL</code>'s
1221 in subdirectories may be buggy, and would not run as ``child'' scripts. The
1222 interdependency of modules can strike you; however, since non-XS modules
1223 are already installed, the prerequisites of most modules have a very good
1224 chance to be present.</p>
1225 <p>If you discover some glitches, move directories of problematic modules to a
1226 different location; if these modules are non-XS modules, you may just ignore
1227 them - they are already installed; the remaining, XS, modules you need to
1228 install manually one by one.</p>
1229 <p>After each such removal you need to rerun the <code>Makefile.PL</code>/<code>make</code> process;
1230 usually this procedure converges soon. (But be sure to convert all the
1231 necessary external C libraries from <em>.lib</em> format to <em>.a</em> format: run one of</p>
1232 <pre>
1233 emxaout foo.lib
1234 emximp -o foo.a foo.lib</pre>
1235 <p>whichever is appropriate.) Also, make sure that the DLLs for external
1236 libraries are usable with with executables compiled without <code>-Zmtd</code> options.</p>
1237 <p>When you are sure that only a few subdirectories
1238 lead to failures, you may want to add <code>-j4</code> option to <code>make</code> to speed up
1239 skipping subdirectories with already finished build.</p>
1240 <p>When you are satisfied with the results of tests, install the build C libraries
1241 for extensions:</p>
1242 <pre>
1243 make install |&amp; tee 00aout_i</pre>
1244 <p>Now you can rename the file <em>./perl.exe</em> generated during the last phase
1245 to <em>perl_5.8.2.exe</em>; place it on <code>PATH</code>; if there is an inter-dependency
1246 between some XS modules, you may need to repeat the <code>test</code>/<code>install</code> loop
1247 with this new executable and some excluded modules - until the procedure
1248 converges.</p>
1249 <p>Now you have all the necessary <em>.a</em> libraries for these Perl modules in the
1250 places where Perl builder can find it. Use the perl builder: change to an
1251 empty directory, create a ``dummy'' <em>Makefile.PL</em> again, and run</p>
1252 <pre>
1253 perl_5.8.2.exe Makefile.PL |&amp; tee 00c
1254 make perl |&amp; tee 00p</pre>
1255 <p>This should create an executable <em>./perl.exe</em> with all the statically loaded
1256 extensions built in. Compare the generated <em>perlmain.c</em> files to make sure
1257 that during the iterations the number of loaded extensions only increases.
1258 Rename <em>./perl.exe</em> to <em>perl_5.8.2.exe</em> on <code>PATH</code>.</p>
1259 <p>When it converges, you got a functional variant of <em>perl_5.8.2.exe</em>; copy it
1260 to <code>perl_.exe</code>. You are done with generation of the local Perl installation.</p>
1261 </li>
1262 <li>
1263 <p>Make sure that the installed modules are actually installed in the location
1264 of the new Perl, and are not inherited from entries of @INC given for
1265 inheritance from the older versions of Perl: set <code>PERLLIB_582_PREFIX</code> to
1266 redirect the new version of Perl to a new location, and copy the installed
1267 files to this new location. Redo the tests to make sure that the versions of
1268 modules inherited from older versions of Perl are not needed.</p>
1269 <p>Actually, the log output of <em>pod2ipf</em> during the step 6 gives a very detailed
1270 info about which modules are loaded from which place; so you may use it as
1271 an additional verification tool.</p>
1272 <p>Check that some temporary files did not make into the perl install tree.
1273 Run something like this</p>
1274 <pre>
1275 pfind . -f &quot;!(/\.(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+$/&quot;) | less</pre>
1276 <p>in the install tree (both top one and <em>sitelib</em> one).</p>
1277 <p>Compress all the DLLs with <em>lxlite</em>. The tiny <em>.exe</em> can be compressed with
1278 <code>/c:max</code> (the bug only appears when there is a fixup in the last 6 bytes of a
1279 page (?); since the tiny executables are much smaller than a page, the bug
1280 will not hit). Do not compress <code>perl_.exe</code> - it would not work under DOS.</p>
1281 </li>
1282 <li>
1283 <p>Now you can generate the binary distribution. This is done by running the
1284 test of the CPAN distribution <code>OS2::SoftInstaller</code>. Tune up the file
1285 <em>test.pl</em> to suit the layout of current version of Perl first. Do not
1286 forget to pack the necessary external DLLs accordingly. Include the
1287 description of the bugs and test suite failures you could not fix. Include
1288 the small-stack versions of Perl executables from Perl build directory.</p>
1289 <p>Include <em>perl5.def</em> so that people can relink the perl DLL preserving
1290 the binary compatibility, or can create compatibility DLLs. Include the diff
1291 files (<code>diff -pu old new</code>) of fixes you did so that people can rebuild your
1292 version. Include <em>perl5.map</em> so that one can use remote debugging.</p>
1293 </li>
1294 <li>
1295 <p>Share what you did with the other people. Relax. Enjoy fruits of your work.</p>
1296 </li>
1297 <li>
1298 <p>Brace yourself for thanks, bug reports, hate mail and spam coming as result
1299 of the previous step. No good deed should remain unpunished!</p>
1300 </li>
1301 </ol>
1303 </p>
1304 <hr />
1305 <h1><a name="building_custom__exe_files">Building custom <em>.EXE</em> files</a></h1>
1306 <p>The Perl executables can be easily rebuilt at any moment. Moreover, one can
1307 use the <em>embedding</em> interface (see <a href="file://C|\msysgit\mingw\html/pod/perlembed.html">the perlembed manpage</a>) to make very customized
1308 executables.</p>
1310 </p>
1311 <h2><a name="making_executables_with_a_custom_collection_of_statically_loaded_extensions">Making executables with a custom collection of statically loaded extensions</a></h2>
1312 <p>It is a little bit easier to do so while <em>decreasing</em> the list of statically
1313 loaded extensions. We discuss this case only here.</p>
1314 <ol>
1315 <li>
1316 <p>Change to an empty directory, and create a placeholder &lt;Makefile.PL&gt;:</p>
1317 <pre>
1318 use ExtUtils::MakeMaker;
1319 WriteMakefile NAME =&gt; 'dummy';</pre>
1320 </li>
1321 <li>
1322 <p>Run it with the flavor of Perl (<em>perl.exe</em> or <em>perl_.exe</em>) you want to
1323 rebuild.</p>
1324 <pre>
1325 perl_ Makefile.PL</pre>
1326 </li>
1327 <li>
1328 <p>Ask it to create new Perl executable:</p>
1329 <pre>
1330 make perl</pre>
1331 <p>(you may need to manually add <code>PERLTYPE=-DPERL_CORE</code> to this commandline on
1332 some versions of Perl; the symptom is that the command-line globbing does not
1333 work from OS/2 shells with the newly-compiled executable; check with</p>
1334 <pre>
1335 .\perl.exe -wle &quot;print for @ARGV&quot; *</pre>
1336 <p>).</p>
1337 </li>
1338 <li>
1339 <p>The previous step created <em>perlmain.c</em> which contains a list of <code>newXS()</code> calls
1340 near the end. Removing unnecessary calls, and rerunning</p>
1341 <pre>
1342 make perl</pre>
1343 <p>will produce a customized executable.</p>
1344 </li>
1345 </ol>
1347 </p>
1348 <h2><a name="making_executables_with_a_custom_searchpaths">Making executables with a custom search-paths</a></h2>
1349 <p>The default perl executable is flexible enough to support most usages.
1350 However, one may want something yet more flexible; for example, one may want
1351 to find Perl DLL relatively to the location of the EXE file; or one may want
1352 to ignore the environment when setting the Perl-library search patch, etc.</p>
1353 <p>If you fill comfortable with <em>embedding</em> interface (see <a href="file://C|\msysgit\mingw\html/pod/perlembed.html">the perlembed manpage</a>), such
1354 things are easy to do repeating the steps outlined in <a href="#making_executables_with_a_custom_collection_of_statically_loaded_extensions">Making executables with a custom collection of statically loaded extensions</a>, and
1355 doing more comprehensive edits to <code>main()</code> of <em>perlmain.c</em>. The people with
1356 little desire to understand Perl can just rename main(), and do necessary
1357 modification in a custom <code>main()</code> which calls the renamed function in appropriate
1358 time.</p>
1359 <p>However, there is a third way: perl DLL exports the <code>main()</code> function and several
1360 callbacks to customize the search path. Below is a complete example of a
1361 ``Perl loader'' which</p>
1362 <ol>
1363 <li>
1364 <p>Looks for Perl DLL in the directory <code>$exedir/../dll</code>;</p>
1365 </li>
1366 <li>
1367 <p>Prepends the above directory to <code>BEGINLIBPATH</code>;</p>
1368 </li>
1369 <li>
1370 <p>Fails if the Perl DLL found via <code>BEGINLIBPATH</code> is different from what was
1371 loaded on step 1; e.g., another process could have loaded it from <code>LIBPATH</code>
1372 or from a different value of <code>BEGINLIBPATH</code>. In these cases one needs to
1373 modify the setting of the system so that this other process either does not
1374 run, or loads the DLL from <code>BEGINLIBPATH</code> with <code>LIBPATHSTRICT=T</code> (available
1375 with kernels after September 2000).</p>
1376 </li>
1377 <li>
1378 <p>Loads Perl library from <code>$exedir/../dll/lib/</code>.</p>
1379 </li>
1380 <li>
1381 <p>Uses Bourne shell from <code>$exedir/../dll/sh/ksh.exe</code>.</p>
1382 </li>
1383 </ol>
1384 <p>For best results compile the C file below with the same options as the Perl
1385 DLL. However, a lot of functionality will work even if the executable is not
1386 an EMX applications, e.g., if compiled with</p>
1387 <pre>
1388 gcc -Wall -DDOSISH -DOS2=1 -O2 -s -Zomf -Zsys perl-starter.c -DPERL_DLL_BASENAME=\&quot;perl312F\&quot; -Zstack 8192 -Zlinker /PM:VIO</pre>
1389 <p>Here is the sample C file:</p>
1390 <pre>
1391 #define INCL_DOS
1392 #define INCL_NOPM
1393 /* These are needed for compile if os2.h includes os2tk.h, not os2emx.h */
1394 #define INCL_DOSPROCESS
1395 #include &lt;os2.h&gt;</pre>
1396 <pre>
1397 #include &quot;EXTERN.h&quot;
1398 #define PERL_IN_MINIPERLMAIN_C
1399 #include &quot;perl.h&quot;</pre>
1400 <pre>
1401 static char *me;
1402 HMODULE handle;</pre>
1403 <pre>
1404 static void
1405 die_with(char *msg1, char *msg2, char *msg3, char *msg4)
1407 ULONG c;
1408 char *s = &quot; error: &quot;;</pre>
1409 <pre>
1410 DosWrite(2, me, strlen(me), &amp;c);
1411 DosWrite(2, s, strlen(s), &amp;c);
1412 DosWrite(2, msg1, strlen(msg1), &amp;c);
1413 DosWrite(2, msg2, strlen(msg2), &amp;c);
1414 DosWrite(2, msg3, strlen(msg3), &amp;c);
1415 DosWrite(2, msg4, strlen(msg4), &amp;c);
1416 DosWrite(2, &quot;\r\n&quot;, 2, &amp;c);
1417 exit(255);
1418 }</pre>
1419 <pre>
1420 typedef ULONG (*fill_extLibpath_t)(int type, char *pre, char *post, int replace, char *msg);
1421 typedef int (*main_t)(int type, char *argv[], char *env[]);
1422 typedef int (*handler_t)(void* data, int which);</pre>
1423 <pre>
1424 #ifndef PERL_DLL_BASENAME
1425 # define PERL_DLL_BASENAME &quot;perl&quot;
1426 #endif</pre>
1427 <pre>
1428 static HMODULE
1429 load_perl_dll(char *basename)
1431 char buf[300], fail[260];
1432 STRLEN l, dirl;
1433 fill_extLibpath_t f;
1434 ULONG rc_fullname;
1435 HMODULE handle, handle1;</pre>
1436 <pre>
1437 if (_execname(buf, sizeof(buf) - 13) != 0)
1438 die_with(&quot;Can't find full path: &quot;, strerror(errno), &quot;&quot;, &quot;&quot;);
1439 /* XXXX Fill `me' with new value */
1440 l = strlen(buf);
1441 while (l &amp;&amp; buf[l-1] != '/' &amp;&amp; buf[l-1] != '\\')
1442 l--;
1443 dirl = l - 1;
1444 strcpy(buf + l, basename);
1445 l += strlen(basename);
1446 strcpy(buf + l, &quot;.dll&quot;);
1447 if ( (rc_fullname = DosLoadModule(fail, sizeof fail, buf, &amp;handle)) != 0
1448 &amp;&amp; DosLoadModule(fail, sizeof fail, basename, &amp;handle) != 0 )
1449 die_with(&quot;Can't load DLL &quot;, buf, &quot;&quot;, &quot;&quot;);
1450 if (rc_fullname)
1451 return handle; /* was loaded with short name; all is fine */
1452 if (DosQueryProcAddr(handle, 0, &quot;fill_extLibpath&quot;, (PFN*)&amp;f))
1453 die_with(buf, &quot;: DLL exports no symbol &quot;, &quot;fill_extLibpath&quot;, &quot;&quot;);
1454 buf[dirl] = 0;
1455 if (f(0 /*BEGINLIBPATH*/, buf /* prepend */, NULL /* append */,
1456 0 /* keep old value */, me))
1457 die_with(me, &quot;: prepending BEGINLIBPATH&quot;, &quot;&quot;, &quot;&quot;);
1458 if (DosLoadModule(fail, sizeof fail, basename, &amp;handle1) != 0)
1459 die_with(me, &quot;: finding perl DLL again via BEGINLIBPATH&quot;, &quot;&quot;, &quot;&quot;);
1460 buf[dirl] = '\\';
1461 if (handle1 != handle) {
1462 if (DosQueryModuleName(handle1, sizeof(fail), fail))
1463 strcpy(fail, &quot;???&quot;);
1464 die_with(buf, &quot;:\n\tperl DLL via BEGINLIBPATH is different: \n\t&quot;,
1465 fail,
1466 &quot;\n\tYou may need to manipulate global BEGINLIBPATH and LIBPATHSTRICT&quot;
1467 &quot;\n\tso that the other copy is loaded via BEGINLIBPATH.&quot;);
1469 return handle;
1470 }</pre>
1471 <pre>
1473 main(int argc, char **argv, char **env)
1475 main_t f;
1476 handler_t h;
1478 me = argv[0];
1479 /**/
1480 handle = load_perl_dll(PERL_DLL_BASENAME);</pre>
1481 <pre>
1482 if (DosQueryProcAddr(handle, 0, &quot;Perl_OS2_handler_install&quot;, (PFN*)&amp;h))
1483 die_with(PERL_DLL_BASENAME, &quot;: DLL exports no symbol &quot;, &quot;Perl_OS2_handler_install&quot;, &quot;&quot;);
1484 if ( !h((void *)&quot;~installprefix&quot;, Perlos2_handler_perllib_from)
1485 || !h((void *)&quot;~dll&quot;, Perlos2_handler_perllib_to)
1486 || !h((void *)&quot;~dll/sh/ksh.exe&quot;, Perlos2_handler_perl_sh) )
1487 die_with(PERL_DLL_BASENAME, &quot;: Can't install @INC manglers&quot;, &quot;&quot;, &quot;&quot;);</pre>
1488 <pre>
1489 if (DosQueryProcAddr(handle, 0, &quot;dll_perlmain&quot;, (PFN*)&amp;f))
1490 die_with(PERL_DLL_BASENAME, &quot;: DLL exports no symbol &quot;, &quot;dll_perlmain&quot;, &quot;&quot;);
1491 return f(argc, argv, env);
1492 }</pre>
1494 </p>
1495 <hr />
1496 <h1><a name="build_faq">Build FAQ</a></h1>
1498 </p>
1499 <h2><a name="some___became___in_pdksh_">Some <code>/</code> became <code>\</code> in pdksh.</a></h2>
1500 <p>You have a very old pdksh. See <em>Prerequisites</em>.</p>
1502 </p>
1503 <h2><a name="_errno___unresolved_external"><code>'errno'</code> - unresolved external</a></h2>
1504 <p>You do not have MT-safe <em>db.lib</em>. See <em>Prerequisites</em>.</p>
1506 </p>
1507 <h2><a name="problems_with_tr_or_sed">Problems with tr or sed</a></h2>
1508 <p>reported with very old version of tr and sed.</p>
1510 </p>
1511 <h2><a name="some_problem__forget_which___">Some problem (forget which ;-)</a></h2>
1512 <p>You have an older version of <em>perl.dll</em> on your LIBPATH, which
1513 broke the build of extensions.</p>
1515 </p>
1516 <h2><a name="library_____not_found">Library ... not found</a></h2>
1517 <p>You did not run <code>omflibs</code>. See <em>Prerequisites</em>.</p>
1519 </p>
1520 <h2><a name="segfault_in_make">Segfault in make</a></h2>
1521 <p>You use an old version of GNU make. See <em>Prerequisites</em>.</p>
1523 </p>
1524 <h2><a name="op_sprintf_test_failure">op/sprintf test failure</a></h2>
1525 <p>This can result from a bug in emx sprintf which was fixed in 0.9d fix 03.</p>
1527 </p>
1528 <hr />
1529 <h1><a name="specific__mis_features_of_os_2_port">Specific (mis)features of OS/2 port</a></h1>
1531 </p>
1532 <h2><a name="setpriority__getpriority"><code>setpriority</code>, <code>getpriority</code></a></h2>
1533 <p>Note that these functions are compatible with *nix, not with the older
1534 ports of '94 - 95. The priorities are absolute, go from 32 to -95,
1535 lower is quicker. 0 is the default priority.</p>
1536 <p><strong>WARNING</strong>. Calling <code>getpriority</code> on a non-existing process could lock
1537 the system before Warp3 fixpak22. Starting with Warp3, Perl will use
1538 a workaround: it aborts <code>getpriority()</code> if the process is not present.
1539 This is not possible on older versions <code>2.*</code>, and has a race
1540 condition anyway.</p>
1542 </p>
1543 <h2><a name="system__"><a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_system"><code>system()</code></a></a></h2>
1544 <p>Multi-argument form of <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_system"><code>system()</code></a> allows an additional numeric
1545 argument. The meaning of this argument is described in
1546 <a href="file://C|\msysgit\mingw\html/OS2/Process.html">the OS2::Process manpage</a>.</p>
1547 <p>When finding a program to run, Perl first asks the OS to look for executables
1548 on <code>PATH</code> (OS/2 adds extension <em>.exe</em> if no extension is present).
1549 If not found, it looks for a script with possible extensions
1550 added in this order: no extension, <em>.cmd</em>, <em>.btm</em>,
1551 <em>.bat</em>, <em>.pl</em>. If found, Perl checks the start of the file for magic
1552 strings <code>&quot;#!&quot;</code> and <code>&quot;extproc &quot;</code>. If found, Perl uses the rest of the
1553 first line as the beginning of the command line to run this script. The
1554 only mangling done to the first line is extraction of arguments (currently
1555 up to 3), and ignoring of the path-part of the ``interpreter'' name if it can't
1556 be found using the full path.</p>
1557 <p>E.g., <code>system 'foo', 'bar', 'baz'</code> may lead Perl to finding
1558 <em>C:/emx/bin/foo.cmd</em> with the first line being</p>
1559 <pre>
1560 extproc /bin/bash -x -c</pre>
1561 <p>If <em>/bin/bash.exe</em> is not found, then Perl looks for an executable <em>bash.exe</em> on
1562 <code>PATH</code>. If found in <em>C:/emx.add/bin/bash.exe</em>, then the above <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_system"><code>system()</code></a> is
1563 translated to</p>
1564 <pre>
1565 system qw(C:/emx.add/bin/bash.exe -x -c C:/emx/bin/foo.cmd bar baz)</pre>
1566 <p>One additional translation is performed: instead of <em>/bin/sh</em> Perl uses
1567 the hardwired-or-customized shell (see <code>&quot;PERL_SH_DIR&quot;</code>).</p>
1568 <p>The above search for ``interpreter'' is recursive: if <em>bash</em> executable is not
1569 found, but <em>bash.btm</em> is found, Perl will investigate its first line etc.
1570 The only hardwired limit on the recursion depth is implicit: there is a limit
1571 4 on the number of additional arguments inserted before the actual arguments
1572 given to system(). In particular, if no additional arguments are specified
1573 on the ``magic'' first lines, then the limit on the depth is 4.</p>
1574 <p>If Perl finds that the found executable is of PM type when the
1575 current session is not, it will start the new process in a separate session of
1576 necessary type. Call via <code>OS2::Process</code> to disable this magic.</p>
1577 <p><strong>WARNING</strong>. Due to the described logic, you need to explicitly
1578 specify <em>.com</em> extension if needed. Moreover, if the executable
1579 <em>perl5.6.1</em> is requested, Perl will not look for <em>perl5.6.1.exe</em>.
1580 [This may change in the future.]</p>
1582 </p>
1583 <h2><a name="extproc_on_the_first_line"><code>extproc</code> on the first line</a></h2>
1584 <p>If the first chars of a Perl script are <code>&quot;extproc &quot;</code>, this line is treated
1585 as <code>#!</code>-line, thus all the switches on this line are processed (twice
1586 if script was started via cmd.exe). See <a href="file://C|\msysgit\mingw\html/pod/perlrun.html#description">DESCRIPTION in the perlrun manpage</a>.</p>
1588 </p>
1589 <h2><a name="additional_modules_">Additional modules:</a></h2>
1590 <p><a href="file://C|\msysgit\mingw\html/OS2/Process.html">the OS2::Process manpage</a>, <a href="file://C|\msysgit\mingw\html/OS2/DLL.html">the OS2::DLL manpage</a>, <a href="file://C|\msysgit\mingw\html/OS2/REXX.html">the OS2::REXX manpage</a>, <a href="file://C|\msysgit\mingw\html/OS2/PrfDB.html">the OS2::PrfDB manpage</a>, <a href="file://C|\msysgit\mingw\html/OS2/ExtAttr.html">the OS2::ExtAttr manpage</a>. These
1591 modules provide access to additional numeric argument for <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_system"><code>system</code></a>
1592 and to the information about the running process,
1593 to DLLs having functions with REXX signature and to the REXX runtime, to
1594 OS/2 databases in the <em>.INI</em> format, and to Extended Attributes.</p>
1595 <p>Two additional extensions by Andreas Kaiser, <code>OS2::UPM</code>, and
1596 <code>OS2::FTP</code>, are included into <code>ILYAZ</code> directory, mirrored on CPAN.
1597 Other OS/2-related extensions are available too.</p>
1599 </p>
1600 <h2><a name="prebuilt_methods_">Prebuilt methods:</a></h2>
1601 <dl>
1602 <dt><strong><a name="item_file_3a_3acopy_3a_3asyscopy"><code>File::Copy::syscopy</code></a></strong>
1604 <dd>
1605 <p>used by <code>File::Copy::copy</code>, see <a href="file://C|\msysgit\mingw\html/lib/File/Copy.html">the File::Copy manpage</a>.</p>
1606 </dd>
1607 </li>
1608 <dt><strong><a name="item_dynaloader_3a_3amod2fname"><code>DynaLoader::mod2fname</code></a></strong>
1610 <dd>
1611 <p>used by <code>DynaLoader</code> for DLL name mangling.</p>
1612 </dd>
1613 </li>
1614 <dt><strong><a name="item_current_drive"><code>Cwd::current_drive()</code></a></strong>
1616 <dd>
1617 <p>Self explanatory.</p>
1618 </dd>
1619 </li>
1620 <dt><strong><a name="item_sys_chdir"><code>Cwd::sys_chdir(name)</code></a></strong>
1622 <dd>
1623 <p>leaves drive as it is.</p>
1624 </dd>
1625 </li>
1626 <dt><strong><a name="item_change_drive"><code>Cwd::change_drive(name)</code></a></strong>
1628 <dd>
1629 <p>chanes the ``current'' drive.</p>
1630 </dd>
1631 </li>
1632 <dt><strong><a name="item_sys_is_absolute"><code>Cwd::sys_is_absolute(name)</code></a></strong>
1634 <dd>
1635 <p>means has drive letter and is_rooted.</p>
1636 </dd>
1637 </li>
1638 <dt><strong><a name="item_sys_is_rooted"><code>Cwd::sys_is_rooted(name)</code></a></strong>
1640 <dd>
1641 <p>means has leading <code>[/\\]</code> (maybe after a drive-letter:).</p>
1642 </dd>
1643 </li>
1644 <dt><strong><a name="item_sys_is_relative"><code>Cwd::sys_is_relative(name)</code></a></strong>
1646 <dd>
1647 <p>means changes with current dir.</p>
1648 </dd>
1649 </li>
1650 <dt><strong><a name="item_sys_cwd"><code>Cwd::sys_cwd(name)</code></a></strong>
1652 <dd>
1653 <p>Interface to cwd from EMX. Used by <code>Cwd::cwd</code>.</p>
1654 </dd>
1655 </li>
1656 <dt><strong><a name="item_sys_abspath"><code>Cwd::sys_abspath(name, dir)</code></a></strong>
1658 <dd>
1659 <p>Really really odious function to implement. Returns absolute name of
1660 file which would have <code>name</code> if CWD were <code>dir</code>. <code>Dir</code> defaults to the
1661 current dir.</p>
1662 </dd>
1663 </li>
1664 <dt><strong><a name="item_extlibpath"><code>Cwd::extLibpath([type])</code></a></strong>
1666 <dd>
1667 <p>Get current value of extended library search path. If <code>type</code> is
1668 present and positive, works with <code>END_LIBPATH</code>, if negative, works
1669 with <code>LIBPATHSTRICT</code>, otherwise with <code>BEGIN_LIBPATH</code>.</p>
1670 </dd>
1671 </li>
1672 <dt><strong><a name="item_extlibpath_set"><code>Cwd::extLibpath_set( path [, type ] )</code></a></strong>
1674 <dd>
1675 <p>Set current value of extended library search path. If <code>type</code> is
1676 present and positive, works with &lt;END_LIBPATH&gt;, if negative, works
1677 with <code>LIBPATHSTRICT</code>, otherwise with <code>BEGIN_LIBPATH</code>.</p>
1678 </dd>
1679 </li>
1680 <dt><strong><a name="item_error"><code>OS2::Error(do_harderror,do_exception)</code></a></strong>
1682 <dd>
1683 <p>Returns <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_undef"><code>undef</code></a> if it was not called yet, otherwise bit 1 is
1684 set if on the previous call do_harderror was enabled, bit
1685 2 is set if on previous call do_exception was enabled.</p>
1686 </dd>
1687 <dd>
1688 <p>This function enables/disables error popups associated with
1689 hardware errors (Disk not ready etc.) and software exceptions.</p>
1690 </dd>
1691 <dd>
1692 <p>I know of no way to find out the state of popups <em>before</em> the first call
1693 to this function.</p>
1694 </dd>
1695 </li>
1696 <dt><strong><a name="item_errors2drive"><code>OS2::Errors2Drive(drive)</code></a></strong>
1698 <dd>
1699 <p>Returns <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_undef"><code>undef</code></a> if it was not called yet, otherwise return false if errors
1700 were not requested to be written to a hard drive, or the drive letter if
1701 this was requested.</p>
1702 </dd>
1703 <dd>
1704 <p>This function may redirect error popups associated with hardware errors
1705 (Disk not ready etc.) and software exceptions to the file POPUPLOG.OS2 at
1706 the root directory of the specified drive. Overrides OS2::Error() specified
1707 by individual programs. Given argument undef will disable redirection.</p>
1708 </dd>
1709 <dd>
1710 <p>Has global effect, persists after the application exits.</p>
1711 </dd>
1712 <dd>
1713 <p>I know of no way to find out the state of redirection of popups to the disk
1714 <em>before</em> the first call to this function.</p>
1715 </dd>
1716 </li>
1717 <dt><strong><a name="item_sysinfo">OS2::SysInfo()</a></strong>
1719 <dd>
1720 <p>Returns a hash with system information. The keys of the hash are</p>
1721 </dd>
1722 <dd>
1723 <pre>
1724 MAX_PATH_LENGTH, MAX_TEXT_SESSIONS, MAX_PM_SESSIONS,
1725 MAX_VDM_SESSIONS, BOOT_DRIVE, DYN_PRI_VARIATION,
1726 MAX_WAIT, MIN_SLICE, MAX_SLICE, PAGE_SIZE,
1727 VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION,
1728 MS_COUNT, TIME_LOW, TIME_HIGH, TOTPHYSMEM, TOTRESMEM,
1729 TOTAVAILMEM, MAXPRMEM, MAXSHMEM, TIMER_INTERVAL,
1730 MAX_COMP_LENGTH, FOREGROUND_FS_SESSION,
1731 FOREGROUND_PROCESS</pre>
1732 </dd>
1733 </li>
1734 <dt><strong><a name="item_bootdrive">OS2::BootDrive()</a></strong>
1736 <dd>
1737 <p>Returns a letter without colon.</p>
1738 </dd>
1739 </li>
1740 <dt><strong><a name="item_morphpm"><code>OS2::MorphPM(serve)</code>, <code>OS2::UnMorphPM(serve)</code></a></strong>
1742 <dd>
1743 <p>Transforms the current application into a PM application and back.
1744 The argument true means that a real message loop is going to be served.
1745 OS2::MorphPM() returns the PM message queue handle as an integer.</p>
1746 </dd>
1747 <dd>
1748 <p>See <a href="#centralized_management_of_resources">Centralized management of resources</a> for additional details.</p>
1749 </dd>
1750 </li>
1751 <dt><strong><a name="item_serve_messages"><code>OS2::Serve_Messages(force)</code></a></strong>
1753 <dd>
1754 <p>Fake on-demand retrieval of outstanding PM messages. If <code>force</code> is false,
1755 will not dispatch messages if a real message loop is known to
1756 be present. Returns number of messages retrieved.</p>
1757 </dd>
1758 <dd>
1759 <p>Dies with ``QUITing...'' if WM_QUIT message is obtained.</p>
1760 </dd>
1761 </li>
1762 <dt><strong><a name="item_process_messages"><code>OS2::Process_Messages(force [, cnt])</code></a></strong>
1764 <dd>
1765 <p>Retrieval of PM messages until window creation/destruction.
1766 If <code>force</code> is false, will not dispatch messages if a real message loop
1767 is known to be present.</p>
1768 </dd>
1769 <dd>
1770 <p>Returns change in number of windows. If <code>cnt</code> is given,
1771 it is incremented by the number of messages retrieved.</p>
1772 </dd>
1773 <dd>
1774 <p>Dies with ``QUITing...'' if WM_QUIT message is obtained.</p>
1775 </dd>
1776 </li>
1777 <dt><strong><a name="item__control87"><code>OS2::_control87(new,mask)</code></a></strong>
1779 <dd>
1780 <p>the same as <a href="#item__control87">_control87(3)</a> of EMX. Takes integers as arguments, returns
1781 the previous coprocessor control word as an integer. Only bits in <code>new</code> which
1782 are present in <code>mask</code> are changed in the control word.</p>
1783 </dd>
1784 </li>
1785 <dt><strong><a name="item_get_control87">OS2::get_control87()</a></strong>
1787 <dd>
1788 <p>gets the coprocessor control word as an integer.</p>
1789 </dd>
1790 </li>
1791 <dt><strong><a name="item_set_control87_em"><code>OS2::set_control87_em(new=MCW_EM,mask=MCW_EM)</code></a></strong>
1793 <dd>
1794 <p>The variant of OS2::_control87() with default values good for
1795 handling exception mask: if no <code>mask</code>, uses exception mask part of <code>new</code>
1796 only. If no <code>new</code>, disables all the floating point exceptions.</p>
1797 </dd>
1798 <dd>
1799 <p>See <a href="#misfeatures">Misfeatures</a> for details.</p>
1800 </dd>
1801 </li>
1802 <dt><strong><a name="item_dllname"><code>OS2::DLLname([how [, \&amp;xsub]])</code></a></strong>
1804 <dd>
1805 <p>Gives the information about the Perl DLL or the DLL containing the C
1806 function bound to by <code>&amp;xsub</code>. The meaning of <code>how</code> is: default (2):
1807 full name; 0: handle; 1: module name.</p>
1808 </dd>
1809 </li>
1810 </dl>
1811 <p>(Note that some of these may be moved to different libraries -
1812 eventually).</p>
1814 </p>
1815 <h2><a name="prebuilt_variables_">Prebuilt variables:</a></h2>
1816 <dl>
1817 <dt><strong><a name="item__os2__emx_rev">$OS2::emx_rev</a></strong>
1819 <dd>
1820 <p>numeric value is the same as _emx_rev of EMX, a string value the same
1821 as _emx_vprt (similar to <code>0.9c</code>).</p>
1822 </dd>
1823 </li>
1824 <dt><strong><a name="item__os2__emx_env">$OS2::emx_env</a></strong>
1826 <dd>
1827 <p>same as _emx_env of EMX, a number similar to 0x8001.</p>
1828 </dd>
1829 </li>
1830 <dt><strong><a name="item__os2__os_ver">$OS2::os_ver</a></strong>
1832 <dd>
1833 <p>a number <code>OS_MAJOR + 0.001 * OS_MINOR</code>.</p>
1834 </dd>
1835 </li>
1836 <dt><strong><a name="item__os2__is_aout">$OS2::is_aout</a></strong>
1838 <dd>
1839 <p>true if the Perl library was compiled in AOUT format.</p>
1840 </dd>
1841 </li>
1842 <dt><strong><a name="item__os2__can_fork">$OS2::can_fork</a></strong>
1844 <dd>
1845 <p>true if the current executable is an AOUT EMX executable, so Perl can
1846 fork. Do not use this, use the portable check for
1847 $Config::Config{dfork}.</p>
1848 </dd>
1849 </li>
1850 <dt><strong><a name="item__os2__nsyserror">$OS2::nsyserror</a></strong>
1852 <dd>
1853 <p>This variable (default is 1) controls whether to enforce the contents
1854 of $^E to start with <code>SYS0003</code>-like id. If set to 0, then the string
1855 value of $^E is what is available from the OS/2 message file. (Some
1856 messages in this file have an <code>SYS0003</code>-like id prepended, some not.)</p>
1857 </dd>
1858 </li>
1859 </dl>
1861 </p>
1862 <h2><a name="misfeatures">Misfeatures</a></h2>
1863 <ul>
1864 <li>
1865 <p>Since <a href="#item_flock">flock(3)</a> is present in EMX, but is not functional, it is
1866 emulated by perl. To disable the emulations, set environment variable
1867 <code>USE_PERL_FLOCK=0</code>.</p>
1868 </li>
1869 <li>
1870 <p>Here is the list of things which may be ``broken'' on
1871 EMX (from EMX docs):</p>
1872 <ul>
1873 <li>
1874 <p>The functions <em>recvmsg(3)</em>, <em>sendmsg(3)</em>, and <em>socketpair(3)</em> are not
1875 implemented.</p>
1876 </li>
1877 <li>
1878 <p><em>sock_init(3)</em> is not required and not implemented.</p>
1879 </li>
1880 <li>
1881 <p><a href="#item_flock">flock(3)</a> is not yet implemented (dummy function). (Perl has a workaround.)</p>
1882 </li>
1883 <li>
1884 <p><em>kill(3)</em>: Special treatment of PID=0, PID=1 and PID=-1 is not implemented.</p>
1885 </li>
1886 <li>
1887 <p><em>waitpid(3)</em>:</p>
1888 <pre>
1889 WUNTRACED
1890 Not implemented.
1891 waitpid() is not implemented for negative values of PID.</pre>
1892 </li>
1893 </ul>
1894 <p>Note that <code>kill -9</code> does not work with the current version of EMX.</p>
1895 <li>
1896 <p>See <a href="#textmode_filehandles">Text-mode filehandles</a>.</p>
1897 </li>
1898 <li>
1899 <p>Unix-domain sockets on OS/2 live in a pseudo-file-system <code>/sockets/...</code>.
1900 To avoid a failure to create a socket with a name of a different form,
1901 <code>&quot;/socket/&quot;</code> is prepended to the socket name (unless it starts with this
1902 already).</p>
1903 <p>This may lead to problems later in case the socket is accessed via the
1904 ``usual'' file-system calls using the ``initial'' name.</p>
1905 </li>
1906 <li>
1907 <p>Apparently, IBM used a compiler (for some period of time around '95?) which
1908 changes FP mask right and left. This is not <em>that</em> bad for IBM's
1909 programs, but the same compiler was used for DLLs which are used with
1910 general-purpose applications. When these DLLs are used, the state of
1911 floating-point flags in the application is not predictable.</p>
1912 <p>What is much worse, some DLLs change the floating point flags when in
1913 <code>_DLLInitTerm()</code> (e.g., <em>TCP32IP</em>). This means that even if you do not <em>call</em>
1914 any function in the DLL, just the act of loading this DLL will reset your
1915 flags. What is worse, the same compiler was used to compile some HOOK DLLs.
1916 Given that HOOK dlls are executed in the context of <em>all</em> the applications
1917 in the system, this means a complete unpredictablity of floating point
1918 flags on systems using such HOOK DLLs. E.g., <em>GAMESRVR.DLL</em> of <strong>DIVE</strong>
1919 origin changes the floating point flags on each write to the TTY of a VIO
1920 (windowed text-mode) applications.</p>
1921 <p>Some other (not completely debugged) situations when FP flags change include
1922 some video drivers (?), and some operations related to creation of the windows.
1923 People who code <strong>OpenGL</strong> may have more experience on this.</p>
1924 <p>Perl is generally used in the situation when all the floating-point
1925 exceptions are ignored, as is the default under EMX. If they are not ignored,
1926 some benign Perl programs would get a <code>SIGFPE</code> and would die a horrible death.</p>
1927 <p>To circumvent this, Perl uses two hacks. They help against <em>one</em> type of
1928 damage only: FP flags changed when loading a DLL.</p>
1929 <p>One of the hacks is to disable floating point exceptions on Perl startup (as
1930 is the default with EMX). This helps only with compile-time-linked DLLs
1931 changing the flags before <code>main()</code> had a chance to be called.</p>
1932 <p>The other hack is to restore FP flags after a call to dlopen(). This helps
1933 against similar damage done by DLLs <code>_DLLInitTerm()</code> at runtime. Currently
1934 no way to switch these hacks off is provided.</p>
1935 </li>
1936 </ul>
1938 </p>
1939 <h2><a name="modifications">Modifications</a></h2>
1940 <p>Perl modifies some standard C library calls in the following ways:</p>
1941 <dl>
1942 <dt><strong><a name="item_popen"><code>popen</code></a></strong>
1944 <dd>
1945 <p><code>my_popen</code> uses <em>sh.exe</em> if shell is required, cf. <a href="#perl_sh_dir">PERL_SH_DIR</a>.</p>
1946 </dd>
1947 </li>
1948 <dt><strong><a name="item_tmpnam"><code>tmpnam</code></a></strong>
1950 <dd>
1951 <p>is created using <code>TMP</code> or <code>TEMP</code> environment variable, via
1952 <code>tempnam</code>.</p>
1953 </dd>
1954 </li>
1955 <dt><strong><a name="item_tmpfile"><code>tmpfile</code></a></strong>
1957 <dd>
1958 <p>If the current directory is not writable, file is created using modified
1959 <a href="#item_tmpnam"><code>tmpnam</code></a>, so there may be a race condition.</p>
1960 </dd>
1961 </li>
1962 <dt><strong><a name="item_ctermid"><code>ctermid</code></a></strong>
1964 <dd>
1965 <p>a dummy implementation.</p>
1966 </dd>
1967 </li>
1968 <dt><strong><a name="item_stat"><code>stat</code></a></strong>
1970 <dd>
1971 <p><code>os2_stat</code> special-cases <em>/dev/tty</em> and <em>/dev/con</em>.</p>
1972 </dd>
1973 </li>
1974 <dt><strong><a name="item_mkdir_2c_rmdir"><a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_mkdir"><code>mkdir</code></a>, <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_rmdir"><code>rmdir</code></a></a></strong>
1976 <dd>
1977 <p>these EMX functions do not work if the path contains a trailing <code>/</code>.
1978 Perl contains a workaround for this.</p>
1979 </dd>
1980 </li>
1981 <dt><strong><a name="item_flock"><code>flock</code></a></strong>
1983 <dd>
1984 <p>Since <a href="#item_flock">flock(3)</a> is present in EMX, but is not functional, it is
1985 emulated by perl. To disable the emulations, set environment variable
1986 <code>USE_PERL_FLOCK=0</code>.</p>
1987 </dd>
1988 </li>
1989 </dl>
1991 </p>
1992 <h2><a name="identifying_dlls">Identifying DLLs</a></h2>
1993 <p>All the DLLs built with the current versions of Perl have ID strings
1994 identifying the name of the extension, its version, and the version
1995 of Perl required for this DLL. Run <code>bldlevel DLL-name</code> to find this
1996 info.</p>
1998 </p>
1999 <h2><a name="centralized_management_of_resources">Centralized management of resources</a></h2>
2000 <p>Since to call certain OS/2 API one needs to have a correctly initialized
2001 <code>Win</code> subsystem, OS/2-specific extensions may require getting <a href="#item_hab"><code>HAB</code></a>s and
2002 <a href="#item_hmq"><code>HMQ</code></a>s. If an extension would do it on its own, another extension could
2003 fail to initialize.</p>
2004 <p>Perl provides a centralized management of these resources:</p>
2005 <dl>
2006 <dt><strong><a name="item_hab"><code>HAB</code></a></strong>
2008 <dd>
2009 <p>To get the HAB, the extension should call <code>hab = perl_hab_GET()</code> in C. After
2010 this call is performed, <code>hab</code> may be accessed as <code>Perl_hab</code>. There is
2011 no need to release the HAB after it is used.</p>
2012 </dd>
2013 <dd>
2014 <p>If by some reasons <em>perl.h</em> cannot be included, use</p>
2015 </dd>
2016 <dd>
2017 <pre>
2018 extern int Perl_hab_GET(void);</pre>
2019 </dd>
2020 <dd>
2021 <p>instead.</p>
2022 </dd>
2023 </li>
2024 <dt><strong><a name="item_hmq"><code>HMQ</code></a></strong>
2026 <dd>
2027 <p>There are two cases:</p>
2028 </dd>
2029 <ul>
2030 <li>
2031 <p>the extension needs an <a href="#item_hmq"><code>HMQ</code></a> only because some API will not work otherwise.
2032 Use <code>serve = 0</code> below.</p>
2033 </li>
2034 <li>
2035 <p>the extension needs an <a href="#item_hmq"><code>HMQ</code></a> since it wants to engage in a PM event loop.
2036 Use <code>serve = 1</code> below.</p>
2037 </li>
2038 </ul>
2039 <p>To get an <a href="#item_hmq"><code>HMQ</code></a>, the extension should call <code>hmq = perl_hmq_GET(serve)</code> in C.
2040 After this call is performed, <code>hmq</code> may be accessed as <code>Perl_hmq</code>.</p>
2041 <p>To signal to Perl that HMQ is not needed any more, call
2042 <code>perl_hmq_UNSET(serve)</code>. Perl process will automatically morph/unmorph itself
2043 into/from a PM process if HMQ is needed/not-needed. Perl will automatically
2044 enable/disable <code>WM_QUIT</code> message during shutdown if the message queue is
2045 served/not-served.</p>
2046 <p><strong>NOTE</strong>. If during a shutdown there is a message queue which did not disable
2047 WM_QUIT, and which did not process the received WM_QUIT message, the
2048 shutdown will be automatically cancelled. Do not call <code>perl_hmq_GET(1)</code>
2049 unless you are going to process messages on an orderly basis.</p>
2050 <li><strong><a name="item_treating_errors_reported_by_os_2f2_api">Treating errors reported by OS/2 API</a></strong>
2052 <p>There are two principal conventions (it is useful to call them <code>Dos*</code>
2053 and <code>Win*</code> - though this part of the function signature is not always
2054 determined by the name of the API) of reporting the error conditions
2055 of OS/2 API. Most of <code>Dos*</code> APIs report the error code as the result
2056 of the call (so 0 means success, and there are many types of errors).
2057 Most of <code>Win*</code> API report success/fail via the result being
2058 <code>TRUE</code>/<code>FALSE</code>; to find the reason for the failure one should call
2059 <code>WinGetLastError()</code> API.</p>
2060 <p>Some <code>Win*</code> entry points also overload a ``meaningful'' return value
2061 with the error indicator; having a 0 return value indicates an error.
2062 Yet some other <code>Win*</code> entry points overload things even more, and 0
2063 return value may mean a successful call returning a valid value 0, as
2064 well as an error condition; in the case of a 0 return value one should
2065 call <code>WinGetLastError()</code> API to distinguish a successful call from a
2066 failing one.</p>
2067 <p>By convention, all the calls to OS/2 API should indicate their
2068 failures by resetting $^E. All the Perl-accessible functions which
2069 call OS/2 API may be broken into two classes: some die()s when an API
2070 error is encountered, the other report the error via a false return
2071 value (of course, this does not concern Perl-accessible functions
2072 which <em>expect</em> a failure of the OS/2 API call, having some workarounds
2073 coded).</p>
2074 <p>Obviously, in the situation of the last type of the signature of an OS/2
2075 API, it is must more convenient for the users if the failure is
2076 indicated by die()ing: one does not need to check $^E to know that
2077 something went wrong. If, however, this solution is not desirable by
2078 some reason, the code in question should reset $^E to 0 before making
2079 this OS/2 API call, so that the caller of this Perl-accessible
2080 function has a chance to distinguish a success-but-0-return value from
2081 a failure. (One may return undef as an alternative way of reporting
2082 an error.)</p>
2083 <p>The macros to simplify this type of error propagation are</p>
2084 <dl>
2085 <dt><strong><a name="item_checkoserror"><code>CheckOSError(expr)</code></a></strong>
2087 <dd>
2088 <p>Returns true on error, sets $^E. Expects <code>expr()</code> be a call of
2089 <code>Dos*</code>-style API.</p>
2090 </dd>
2091 </li>
2092 <dt><strong><a name="item_checkwinerror"><code>CheckWinError(expr)</code></a></strong>
2094 <dd>
2095 <p>Returns true on error, sets $^E. Expects <code>expr()</code> be a call of
2096 <code>Win*</code>-style API.</p>
2097 </dd>
2098 </li>
2099 <dt><strong><a name="item_savewinerror"><code>SaveWinError(expr)</code></a></strong>
2101 <dd>
2102 <p>Returns <code>expr</code>, sets $^E from <code>WinGetLastError()</code> if <code>expr</code> is false.</p>
2103 </dd>
2104 </li>
2105 <dt><strong><a name="item_savecroakwinerror"><code>SaveCroakWinError(expr,die,name1,name2)</code></a></strong>
2107 <dd>
2108 <p>Returns <code>expr</code>, sets $^E from <code>WinGetLastError()</code> if <code>expr</code> is false,
2109 and die()s if <code>die</code> and $^E are true. The message to die is the
2110 concatenated strings <code>name1</code> and <code>name2</code>, separated by <code>&quot;: &quot;</code> from
2111 the contents of $^E.</p>
2112 </dd>
2113 </li>
2114 <dt><strong><a name="item_winerror_2_perl_rc"><code>WinError_2_Perl_rc</code></a></strong>
2116 <dd>
2117 <p>Sets <code>Perl_rc</code> to the return value of WinGetLastError().</p>
2118 </dd>
2119 </li>
2120 <dt><strong><a name="item_fillwinerror"><code>FillWinError</code></a></strong>
2122 <dd>
2123 <p>Sets <code>Perl_rc</code> to the return value of WinGetLastError(), and sets $^E
2124 to the corresponding value.</p>
2125 </dd>
2126 </li>
2127 <dt><strong><a name="item_filloserror"><code>FillOSError(rc)</code></a></strong>
2129 <dd>
2130 <p>Sets <code>Perl_rc</code> to <code>rc</code>, and sets $^E to the corresponding value.</p>
2131 </dd>
2132 </li>
2133 </dl>
2134 <li><strong><a name="item_loading_dlls_and_ordinals_in_dlls">Loading DLLs and ordinals in DLLs</a></strong>
2136 <p>Some DLLs are only present in some versions of OS/2, or in some
2137 configurations of OS/2. Some exported entry points are present only
2138 in DLLs shipped with some versions of OS/2. If these DLLs and entry
2139 points were linked directly for a Perl executable/DLL or from a Perl
2140 extensions, this binary would work only with the specified
2141 versions/setups. Even if these entry points were not needed, the
2142 <em>load</em> of the executable (or DLL) would fail.</p>
2143 <p>For example, many newer useful APIs are not present in OS/2 v2; many
2144 PM-related APIs require DLLs not available on floppy-boot setup.</p>
2145 <p>To make these calls fail <em>only when the calls are executed</em>, one
2146 should call these API via a dynamic linking API. There is a subsystem
2147 in Perl to simplify such type of calls. A large number of entry
2148 points available for such linking is provided (see <code>entries_ordinals</code>
2149 - and also <code>PMWIN_entries</code> - in <em>os2ish.h</em>). These ordinals can be
2150 accessed via the APIs:</p>
2151 <pre>
2152 CallORD(), DeclFuncByORD(), DeclVoidFuncByORD(),
2153 DeclOSFuncByORD(), DeclWinFuncByORD(), AssignFuncPByORD(),
2154 DeclWinFuncByORD_CACHE(), DeclWinFuncByORD_CACHE_survive(),
2155 DeclWinFuncByORD_CACHE_resetError_survive(),
2156 DeclWinFunc_CACHE(), DeclWinFunc_CACHE_resetError(),
2157 DeclWinFunc_CACHE_survive(), DeclWinFunc_CACHE_resetError_survive()</pre>
2158 <p>See the header files and the C code in the supplied OS/2-related
2159 modules for the details on usage of these functions.</p>
2160 <p>Some of these functions also combine dynaloading semantic with the
2161 error-propagation semantic discussed above.</p>
2162 </li>
2163 </dl>
2165 </p>
2166 <hr />
2167 <h1><a name="perl_flavors">Perl flavors</a></h1>
2168 <p>Because of idiosyncrasies of OS/2 one cannot have all the eggs in the
2169 same basket (though EMX environment tries hard to overcome this
2170 limitations, so the situation may somehow improve). There are 4
2171 executables for Perl provided by the distribution:</p>
2173 </p>
2174 <h2><a name="perl_exe"><em>perl.exe</em></a></h2>
2175 <p>The main workhorse. This is a chimera executable: it is compiled as an
2176 <code>a.out</code>-style executable, but is linked with <code>omf</code>-style dynamic
2177 library <em>perl.dll</em>, and with dynamic CRT DLL. This executable is a
2178 VIO application.</p>
2179 <p>It can load perl dynamic extensions, and it can fork().</p>
2180 <p><strong>Note.</strong> Keep in mind that <code>fork()</code> is needed to open a pipe to yourself.</p>
2182 </p>
2183 <h2><a name="perl__exe"><em>perl_.exe</em></a></h2>
2184 <p>This is a statically linked <code>a.out</code>-style executable. It cannot
2185 load dynamic Perl extensions. The executable supplied in binary
2186 distributions has a lot of extensions prebuilt, thus the above restriction is
2187 important only if you use custom-built extensions. This executable is a VIO
2188 application.</p>
2189 <p><em>This is the only executable with does not require OS/2.</em> The
2190 friends locked into <code>M$</code> world would appreciate the fact that this
2191 executable runs under DOS, Win0.3*, Win0.95 and WinNT with an
2192 appropriate extender. See <a href="#other_oses">Other OSes</a>.</p>
2194 </p>
2195 <h2><a name="perl___exe"><em>perl__.exe</em></a></h2>
2196 <p>This is the same executable as <em>perl___.exe</em>, but it is a PM
2197 application.</p>
2198 <p><strong>Note.</strong> Usually (unless explicitly redirected during the startup)
2199 STDIN, STDERR, and STDOUT of a PM
2200 application are redirected to <em>nul</em>. However, it is possible to <em>see</em>
2201 them if you start <code>perl__.exe</code> from a PM program which emulates a
2202 console window, like <em>Shell mode</em> of Emacs or EPM. Thus it <em>is
2203 possible</em> to use Perl debugger (see <a href="file://C|\msysgit\mingw\html/pod/perldebug.html">the perldebug manpage</a>) to debug your PM
2204 application (but beware of the message loop lockups - this will not
2205 work if you have a message queue to serve, unless you hook the serving
2206 into the <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_getc"><code>getc()</code></a> function of the debugger).</p>
2207 <p>Another way to see the output of a PM program is to run it as</p>
2208 <pre>
2209 pm_prog args 2&gt;&amp;1 | cat -</pre>
2210 <p>with a shell <em>different</em> from <em>cmd.exe</em>, so that it does not create
2211 a link between a VIO session and the session of <code>pm_porg</code>. (Such a link
2212 closes the VIO window.) E.g., this works with <em>sh.exe</em> - or with Perl!</p>
2213 <pre>
2214 open P, 'pm_prog args 2&gt;&amp;1 |' or die;
2215 print while &lt;P&gt;;</pre>
2216 <p>The flavor <em>perl__.exe</em> is required if you want to start your program without
2217 a VIO window present, but not <code>detach</code>ed (run <code>help detach</code> for more info).
2218 Very useful for extensions which use PM, like <code>Perl/Tk</code> or <code>OpenGL</code>.</p>
2219 <p>Note also that the differences between PM and VIO executables are only
2220 in the <em>default</em> behaviour. One can start <em>any</em> executable in
2221 <em>any</em> kind of session by using the arguments <code>/fs</code>, <code>/pm</code> or
2222 <code>/win</code> switches of the command <code>start</code> (of <em>CMD.EXE</em> or a similar
2223 shell). Alternatively, one can use the numeric first argument of the
2224 <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_system"><code>system</code></a> Perl function (see <a href="file://C|\msysgit\mingw\html/OS2/Process.html">the OS2::Process manpage</a>).</p>
2226 </p>
2227 <h2><a name="perl____exe"><em>perl___.exe</em></a></h2>
2228 <p>This is an <code>omf</code>-style executable which is dynamically linked to
2229 <em>perl.dll</em> and CRT DLL. I know no advantages of this executable
2230 over <code>perl.exe</code>, but it cannot <code>fork()</code> at all. Well, one advantage is
2231 that the build process is not so convoluted as with <code>perl.exe</code>.</p>
2232 <p>It is a VIO application.</p>
2234 </p>
2235 <h2><a name="why_strange_names">Why strange names?</a></h2>
2236 <p>Since Perl processes the <code>#!</code>-line (cf.
2237 <a href="file://C|\msysgit\mingw\html/pod/perlrun.html#description">DESCRIPTION in the perlrun manpage</a>, <a href="file://C|\msysgit\mingw\html/pod/perlrun.html#switches">Switches in the perlrun manpage</a>,
2238 <a href="file://C|\msysgit\mingw\html/pod/perldiag.html#not_a_perl_script">Not a perl script in the perldiag manpage</a>,
2239 <a href="file://C|\msysgit\mingw\html/pod/perldiag.html#no_perl_script_found_in_input">No Perl script found in input in the perldiag manpage</a>), it should know when a
2240 program <em>is a Perl</em>. There is some naming convention which allows
2241 Perl to distinguish correct lines from wrong ones. The above names are
2242 almost the only names allowed by this convention which do not contain
2243 digits (which have absolutely different semantics).</p>
2245 </p>
2246 <h2><a name="why_dynamic_linking">Why dynamic linking?</a></h2>
2247 <p>Well, having several executables dynamically linked to the same huge
2248 library has its advantages, but this would not substantiate the
2249 additional work to make it compile. The reason is the complicated-to-developers
2250 but very quick and convenient-to-users ``hard'' dynamic linking used by OS/2.</p>
2251 <p>There are two distinctive features of the dyna-linking model of OS/2:
2252 first, all the references to external functions are resolved at the compile time;
2253 second, there is no runtime fixup of the DLLs after they are loaded into memory.
2254 The first feature is an enormous advantage over other models: it avoids
2255 conflicts when several DLLs used by an application export entries with
2256 the same name. In such cases ``other'' models of dyna-linking just choose
2257 between these two entry points using some random criterion - with predictable
2258 disasters as results. But it is the second feature which requires the build
2259 of <em>perl.dll</em>.</p>
2260 <p>The address tables of DLLs are patched only once, when they are
2261 loaded. The addresses of the entry points into DLLs are guaranteed to be
2262 the same for all the programs which use the same DLL. This removes the
2263 runtime fixup - once DLL is loaded, its code is read-only.</p>
2264 <p>While this allows some (significant?) performance advantages, this makes life
2265 much harder for developers, since the above scheme makes it impossible
2266 for a DLL to be ``linked'' to a symbol in the <em>.EXE</em> file. Indeed, this
2267 would need a DLL to have different relocations tables for the
2268 (different) executables which use this DLL.</p>
2269 <p>However, a dynamically loaded Perl extension is forced to use some symbols
2270 from the perl
2271 executable, e.g., to know how to find the arguments to the functions:
2272 the arguments live on the perl
2273 internal evaluation stack. The solution is to put the main code of
2274 the interpreter into a DLL, and make the <em>.EXE</em> file which just loads
2275 this DLL into memory and supplies command-arguments. The extension DLL
2276 cannot link to symbols in <em>.EXE</em>, but it has no problem linking
2277 to symbols in the <em>.DLL</em>.</p>
2278 <p>This <em>greatly</em> increases the load time for the application (as well as
2279 complexity of the compilation). Since interpreter is in a DLL,
2280 the C RTL is basically forced to reside in a DLL as well (otherwise
2281 extensions would not be able to use CRT). There are some advantages if
2282 you use different flavors of perl, such as running <em>perl.exe</em> and
2283 <em>perl__.exe</em> simultaneously: they share the memory of <em>perl.dll</em>.</p>
2284 <p><strong>NOTE</strong>. There is one additional effect which makes DLLs more wasteful:
2285 DLLs are loaded in the shared memory region, which is a scarse resource
2286 given the 512M barrier of the ``standard'' OS/2 virtual memory. The code of
2287 <em>.EXE</em> files is also shared by all the processes which use the particular
2288 <em>.EXE</em>, but they are ``shared in the private address space of the process'';
2289 this is possible because the address at which different sections
2290 of the <em>.EXE</em> file are loaded is decided at compile-time, thus all the
2291 processes have these sections loaded at same addresses, and no fixup
2292 of internal links inside the <em>.EXE</em> is needed.</p>
2293 <p>Since DLLs may be loaded at run time, to have the same mechanism for DLLs
2294 one needs to have the address range of <em>any of the loaded</em> DLLs in the
2295 system to be available <em>in all the processes</em> which did not load a particular
2296 DLL yet. This is why the DLLs are mapped to the shared memory region.</p>
2298 </p>
2299 <h2><a name="why_chimera_build">Why chimera build?</a></h2>
2300 <p>Current EMX environment does not allow DLLs compiled using Unixish
2301 <code>a.out</code> format to export symbols for data (or at least some types of
2302 data). This forces <code>omf</code>-style compile of <em>perl.dll</em>.</p>
2303 <p>Current EMX environment does not allow <em>.EXE</em> files compiled in
2304 <code>omf</code> format to fork(). <code>fork()</code> is needed for exactly three Perl
2305 operations:</p>
2306 <ul>
2307 <li>
2308 <p>explicit <code>fork()</code> in the script,</p>
2309 </li>
2310 <li>
2311 <p><code>open FH, &quot;|-&quot;</code></p>
2312 </li>
2313 <li>
2314 <p><code>open FH, &quot;-|&quot;</code>, in other words, opening pipes to itself.</p>
2315 </li>
2316 </ul>
2317 <p>While these operations are not questions of life and death, they are
2318 needed for a lot of
2319 useful scripts. This forces <code>a.out</code>-style compile of
2320 <em>perl.exe</em>.</p>
2322 </p>
2323 <hr />
2324 <h1><a name="environment">ENVIRONMENT</a></h1>
2325 <p>Here we list environment variables with are either OS/2- and DOS- and
2326 Win*-specific, or are more important under OS/2 than under other OSes.</p>
2328 </p>
2329 <h2><a name="perllib_prefix"><code>PERLLIB_PREFIX</code></a></h2>
2330 <p>Specific for EMX port. Should have the form</p>
2331 <pre>
2332 path1;path2</pre>
2333 <p>or</p>
2334 <pre>
2335 path1 path2</pre>
2336 <p>If the beginning of some prebuilt path matches <em>path1</em>, it is
2337 substituted with <em>path2</em>.</p>
2338 <p>Should be used if the perl library is moved from the default
2339 location in preference to <code>PERL(5)LIB</code>, since this would not leave wrong
2340 entries in @INC. For example, if the compiled version of perl looks for @INC
2341 in <em>f:/perllib/lib</em>, and you want to install the library in
2342 <em>h:/opt/gnu</em>, do</p>
2343 <pre>
2344 set PERLLIB_PREFIX=f:/perllib/lib;h:/opt/gnu</pre>
2345 <p>This will cause Perl with the prebuilt @INC of</p>
2346 <pre>
2347 f:/perllib/lib/5.00553/os2
2348 f:/perllib/lib/5.00553
2349 f:/perllib/lib/site_perl/5.00553/os2
2350 f:/perllib/lib/site_perl/5.00553
2351 .</pre>
2352 <p>to use the following @INC:</p>
2353 <pre>
2354 h:/opt/gnu/5.00553/os2
2355 h:/opt/gnu/5.00553
2356 h:/opt/gnu/site_perl/5.00553/os2
2357 h:/opt/gnu/site_perl/5.00553
2358 .</pre>
2360 </p>
2361 <h2><a name="perl_badlang"><a href="#item_perl_badlang"><code>PERL_BADLANG</code></a></a></h2>
2362 <p>If 0, perl ignores <code>setlocale()</code> failing. May be useful with some
2363 strange <em>locale</em>s.</p>
2365 </p>
2366 <h2><a name="perl_badfree"><a href="#item_perl_badfree"><code>PERL_BADFREE</code></a></a></h2>
2367 <p>If 0, perl would not warn of in case of unwarranted free(). With older
2368 perls this might be
2369 useful in conjunction with the module DB_File, which was buggy when
2370 dynamically linked and OMF-built.</p>
2371 <p>Should not be set with newer Perls, since this may hide some <em>real</em> problems.</p>
2373 </p>
2374 <h2><a name="perl_sh_dir"><code>PERL_SH_DIR</code></a></h2>
2375 <p>Specific for EMX port. Gives the directory part of the location for
2376 <em>sh.exe</em>.</p>
2378 </p>
2379 <h2><a name="use_perl_flock"><code>USE_PERL_FLOCK</code></a></h2>
2380 <p>Specific for EMX port. Since <a href="#item_flock">flock(3)</a> is present in EMX, but is not
2381 functional, it is emulated by perl. To disable the emulations, set
2382 environment variable <code>USE_PERL_FLOCK=0</code>.</p>
2384 </p>
2385 <h2><a name="tmp_or_temp"><code>TMP</code> or <code>TEMP</code></a></h2>
2386 <p>Specific for EMX port. Used as storage place for temporary files.</p>
2388 </p>
2389 <hr />
2390 <h1><a name="evolution">Evolution</a></h1>
2391 <p>Here we list major changes which could make you by surprise.</p>
2393 </p>
2394 <h2><a name="textmode_filehandles">Text-mode filehandles</a></h2>
2395 <p>Starting from version 5.8, Perl uses a builtin translation layer for
2396 text-mode files. This replaces the efficient well-tested EMX layer by
2397 some code which should be best characterized as a ``quick hack''.</p>
2398 <p>In addition to possible bugs and an inability to follow changes to the
2399 translation policy with off/on switches of TERMIO translation, this
2400 introduces a serious incompatible change: before <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_sysread"><code>sysread()</code></a> on
2401 text-mode filehandles would go through the translation layer, now it
2402 would not.</p>
2404 </p>
2405 <h2><a name="priorities">Priorities</a></h2>
2406 <p><code>setpriority</code> and <code>getpriority</code> are not compatible with earlier
2407 ports by Andreas Kaiser. See <code>&quot;setpriority, getpriority&quot;</code>.</p>
2409 </p>
2410 <h2><a name="dll_name_mangling__pre_5_6_2">DLL name mangling: pre 5.6.2</a></h2>
2411 <p>With the release 5.003_01 the dynamically loadable libraries
2412 should be rebuilt when a different version of Perl is compiled. In particular,
2413 DLLs (including <em>perl.dll</em>) are now created with the names
2414 which contain a checksum, thus allowing workaround for OS/2 scheme of
2415 caching DLLs.</p>
2416 <p>It may be possible to code a simple workaround which would</p>
2417 <ul>
2418 <li>
2419 <p>find the old DLLs looking through the old @INC;</p>
2420 </li>
2421 <li>
2422 <p>mangle the names according to the scheme of new perl and copy the DLLs to
2423 these names;</p>
2424 </li>
2425 <li>
2426 <p>edit the internal <code>LX</code> tables of DLL to reflect the change of the name
2427 (probably not needed for Perl extension DLLs, since the internally coded names
2428 are not used for ``specific'' DLLs, they used only for ``global'' DLLs).</p>
2429 </li>
2430 <li>
2431 <p>edit the internal <code>IMPORT</code> tables and change the name of the ``old''
2432 <em>perl????.dll</em> to the ``new'' <em>perl????.dll</em>.</p>
2433 </li>
2434 </ul>
2436 </p>
2437 <h2><a name="dll_name_mangling__5_6_2_and_beyond">DLL name mangling: 5.6.2 and beyond</a></h2>
2438 <p>In fact mangling of <em>extension</em> DLLs was done due to misunderstanding
2439 of the OS/2 dynaloading model. OS/2 (effectively) maintains two
2440 different tables of loaded DLL:</p>
2441 <dl>
2442 <dt><strong><a name="item_global_dlls">Global DLLs</a></strong>
2444 <dd>
2445 <p>those loaded by the base name from <code>LIBPATH</code>; including those
2446 associated at link time;</p>
2447 </dd>
2448 </li>
2449 <dt><strong><a name="item_specific_dlls">specific DLLs</a></strong>
2451 <dd>
2452 <p>loaded by the full name.</p>
2453 </dd>
2454 </li>
2455 </dl>
2456 <p>When resolving a request for a global DLL, the table of already-loaded
2457 specific DLLs is (effectively) ignored; moreover, specific DLLs are
2458 <em>always</em> loaded from the prescribed path.</p>
2459 <p>There is/was a minor twist which makes this scheme fragile: what to do
2460 with DLLs loaded from</p>
2461 <dl>
2462 <dt><strong><a name="item_beginlibpath_and_endlibpath"><code>BEGINLIBPATH</code> and <code>ENDLIBPATH</code></a></strong>
2464 <dd>
2465 <p>(which depend on the process)</p>
2466 </dd>
2467 </li>
2468 <dt><strong><a name="item__2e_from_libpath"><em>.</em> from <code>LIBPATH</code></a></strong>
2470 <dd>
2471 <p>which <em>effectively</em> depends on the process (although <code>LIBPATH</code> is the
2472 same for all the processes).</p>
2473 </dd>
2474 </li>
2475 </dl>
2476 <p>Unless <code>LIBPATHSTRICT</code> is set to <code>T</code> (and the kernel is after
2477 2000/09/01), such DLLs are considered to be global. When loading a
2478 global DLL it is first looked in the table of already-loaded global
2479 DLLs. Because of this the fact that one executable loaded a DLL from
2480 <code>BEGINLIBPATH</code> and <code>ENDLIBPATH</code>, or <em>.</em> from <code>LIBPATH</code> may affect
2481 <em>which</em> DLL is loaded when <em>another</em> executable requests a DLL with
2482 the same name. <em>This</em> is the reason for version-specific mangling of
2483 the DLL name for perl DLL.</p>
2484 <p>Since the Perl extension DLLs are always loaded with the full path,
2485 there is no need to mangle their names in a version-specific ways:
2486 their directory already reflects the corresponding version of perl,
2487 and @INC takes into account binary compatibility with older version.
2488 Starting from <code>5.6.2</code> the name mangling scheme is fixed to be the
2489 same as for Perl 5.005_53 (same as in a popular binary release). Thus
2490 new Perls will be able to <em>resolve the names</em> of old extension DLLs
2491 if @INC allows finding their directories.</p>
2492 <p>However, this still does not guarantee that these DLL may be loaded.
2493 The reason is the mangling of the name of the <em>Perl DLL</em>. And since
2494 the extension DLLs link with the Perl DLL, extension DLLs for older
2495 versions would load an older Perl DLL, and would most probably
2496 segfault (since the data in this DLL is not properly initialized).</p>
2497 <p>There is a partial workaround (which can be made complete with newer
2498 OS/2 kernels): create a forwarder DLL with the same name as the DLL of
2499 the older version of Perl, which forwards the entry points to the
2500 newer Perl's DLL. Make this DLL accessible on (say) the <code>BEGINLIBPATH</code> of
2501 the new Perl executable. When the new executable accesses old Perl's
2502 extension DLLs, they would request the old Perl's DLL by name, get the
2503 forwarder instead, so effectively will link with the currently running
2504 (new) Perl DLL.</p>
2505 <p>This may break in two ways:</p>
2506 <ul>
2507 <li>
2508 <p>Old perl executable is started when a new executable is running has
2509 loaded an extension compiled for the old executable (ouph!). In this
2510 case the old executable will get a forwarder DLL instead of the old
2511 perl DLL, so would link with the new perl DLL. While not directly
2512 fatal, it will behave the same as new executable. This beats the whole
2513 purpose of explicitly starting an old executable.</p>
2514 </li>
2515 <li>
2516 <p>A new executable loads an extension compiled for the old executable
2517 when an old perl executable is running. In this case the extension
2518 will not pick up the forwarder - with fatal results.</p>
2519 </li>
2520 </ul>
2521 <p>With support for <code>LIBPATHSTRICT</code> this may be circumvented - unless
2522 one of DLLs is started from <em>.</em> from <code>LIBPATH</code> (I do not know
2523 whether <code>LIBPATHSTRICT</code> affects this case).</p>
2524 <p><strong>REMARK</strong>. Unless newer kernels allow <em>.</em> in <code>BEGINLIBPATH</code> (older
2525 do not), this mess cannot be completely cleaned. (It turns out that
2526 as of the beginning of 2002, <em>.</em> is not allowed, but <em>.\.</em> is - and
2527 it has the same effect.)</p>
2528 <p><strong>REMARK</strong>. <code>LIBPATHSTRICT</code>, <code>BEGINLIBPATH</code> and <code>ENDLIBPATH</code> are
2529 not environment variables, although <em>cmd.exe</em> emulates them on <code>SET
2530 ...</code> lines. From Perl they may be accessed by <a href="file://C|\msysgit\mingw\html/Cwd/extLibpath.html">the Cwd::extLibpath manpage</a> and
2531 <a href="file://C|\msysgit\mingw\html/Cwd/extLibpath_set.html">the Cwd::extLibpath_set manpage</a>.</p>
2533 </p>
2534 <h2><a name="dll_forwarder_generation">DLL forwarder generation</a></h2>
2535 <p>Assume that the old DLL is named <em>perlE0AC.dll</em> (as is one for
2536 5.005_53), and the new version is 5.6.1. Create a file
2537 <em>perl5shim.def-leader</em> with</p>
2538 <pre>
2539 LIBRARY 'perlE0AC' INITINSTANCE TERMINSTANCE
2540 DESCRIPTION '@#perl5-porters@perl.org:5.006001#@ Perl module for 5.00553 -&gt; Perl 5.6.1 forwarder'
2541 CODE LOADONCALL
2542 DATA LOADONCALL NONSHARED MULTIPLE
2543 EXPORTS</pre>
2544 <p>modifying the versions/names as needed. Run</p>
2545 <pre>
2546 perl -wnle &quot;next if 0../EXPORTS/; print qq( \&quot;$1\&quot;) if /\&quot;(\w+)\&quot;/&quot; perl5.def &gt;lst</pre>
2547 <p>in the Perl build directory (to make the DLL smaller replace perl5.def
2548 with the definition file for the older version of Perl if present).</p>
2549 <pre>
2550 cat perl5shim.def-leader lst &gt;perl5shim.def
2551 gcc -Zomf -Zdll -o perlE0AC.dll perl5shim.def -s -llibperl</pre>
2552 <p>(ignore multiple <code>warning L4085</code>).</p>
2554 </p>
2555 <h2><a name="threading">Threading</a></h2>
2556 <p>As of release 5.003_01 perl is linked to multithreaded C RTL
2557 DLL. If perl itself is not compiled multithread-enabled, so will not be perl's
2558 malloc(). However, extensions may use multiple thread on their own
2559 risk.</p>
2560 <p>This was needed to compile <code>Perl/Tk</code> for XFree86-OS/2 out-of-the-box, and
2561 link with DLLs for other useful libraries, which typically are compiled
2562 with <code>-Zmt -Zcrtdll</code>.</p>
2564 </p>
2565 <h2><a name="calls_to_external_programs">Calls to external programs</a></h2>
2566 <p>Due to a popular demand the perl external program calling has been
2567 changed wrt Andreas Kaiser's port. <em>If</em> perl needs to call an
2568 external program <em>via shell</em>, the <em>f:/bin/sh.exe</em> will be called, or
2569 whatever is the override, see <a href="#perl_sh_dir">PERL_SH_DIR</a>.</p>
2570 <p>Thus means that you need to get some copy of a <em>sh.exe</em> as well (I
2571 use one from pdksh). The path <em>F:/bin</em> above is set up automatically during
2572 the build to a correct value on the builder machine, but is
2573 overridable at runtime,</p>
2574 <p><strong>Reasons:</strong> a consensus on <code>perl5-porters</code> was that perl should use
2575 one non-overridable shell per platform. The obvious choices for OS/2
2576 are <em>cmd.exe</em> and <em>sh.exe</em>. Having perl build itself would be impossible
2577 with <em>cmd.exe</em> as a shell, thus I picked up <code>sh.exe</code>. This assures almost
2578 100% compatibility with the scripts coming from *nix. As an added benefit
2579 this works as well under DOS if you use DOS-enabled port of pdksh
2580 (see <a href="#prerequisites">Prerequisites</a>).</p>
2581 <p><strong>Disadvantages:</strong> currently <em>sh.exe</em> of pdksh calls external programs
2582 via fork()/exec(), and there is <em>no</em> functioning <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_exec"><code>exec()</code></a> on
2583 OS/2. <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_exec"><code>exec()</code></a> is emulated by EMX by an asynchronous call while the caller
2584 waits for child completion (to pretend that the <code>pid</code> did not change). This
2585 means that 1 <em>extra</em> copy of <em>sh.exe</em> is made active via fork()/exec(),
2586 which may lead to some resources taken from the system (even if we do
2587 not count extra work needed for fork()ing).</p>
2588 <p>Note that this a lesser issue now when we do not spawn <em>sh.exe</em>
2589 unless needed (metachars found).</p>
2590 <p>One can always start <em>cmd.exe</em> explicitly via</p>
2591 <pre>
2592 system 'cmd', '/c', 'mycmd', 'arg1', 'arg2', ...</pre>
2593 <p>If you need to use <em>cmd.exe</em>, and do not want to hand-edit thousands of your
2594 scripts, the long-term solution proposed on p5-p is to have a directive</p>
2595 <pre>
2596 use OS2::Cmd;</pre>
2597 <p>which will override system(), exec(), <code>``</code>, and
2598 <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_open"><code>open(,'...|')</code></a>. With current perl you may override only system(),
2599 <code>readpipe()</code> - the explicit version of <code>``</code>, and maybe exec(). The code
2600 will substitute the one-argument call to <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_system"><code>system()</code></a> by
2601 <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_system"><code>CORE::system('cmd.exe', '/c', shift)</code></a>.</p>
2602 <p>If you have some working code for <code>OS2::Cmd</code>, please send it to me,
2603 I will include it into distribution. I have no need for such a module, so
2604 cannot test it.</p>
2605 <p>For the details of the current situation with calling external programs,
2606 see <em>Starting OS/2 (and DOS) programs under Perl</em>. Set us mention a couple
2607 of features:</p>
2608 <ul>
2609 <li>
2610 <p>External scripts may be called by their basename. Perl will try the same
2611 extensions as when processing <strong>-S</strong> command-line switch.</p>
2612 </li>
2613 <li>
2614 <p>External scripts starting with <code>#!</code> or <code>extproc </code> will be executed directly,
2615 without calling the shell, by calling the program specified on the rest of
2616 the first line.</p>
2617 </li>
2618 </ul>
2620 </p>
2621 <h2><a name="memory_allocation">Memory allocation</a></h2>
2622 <p>Perl uses its own <code>malloc()</code> under OS/2 - interpreters are usually malloc-bound
2623 for speed, but perl is not, since its malloc is lightning-fast.
2624 Perl-memory-usage-tuned benchmarks show that Perl's malloc is 5 times quicker
2625 than EMX one. I do not have convincing data about memory footprint, but
2626 a (pretty random) benchmark showed that Perl's one is 5% better.</p>
2627 <p>Combination of perl's <code>malloc()</code> and rigid DLL name resolution creates
2628 a special problem with library functions which expect their return value to
2629 be free()d by system's free(). To facilitate extensions which need to call
2630 such functions, system memory-allocation functions are still available with
2631 the prefix <code>emx_</code> added. (Currently only DLL perl has this, it should
2632 propagate to <em>perl_.exe</em> shortly.)</p>
2634 </p>
2635 <h2><a name="threads">Threads</a></h2>
2636 <p>One can build perl with thread support enabled by providing <code>-D usethreads</code>
2637 option to <em>Configure</em>. Currently OS/2 support of threads is very
2638 preliminary.</p>
2639 <p>Most notable problems:</p>
2640 <dl>
2641 <dt><strong><a name="item_cond_wait"><code>COND_WAIT</code></a></strong>
2643 <dd>
2644 <p>may have a race condition (but probably does not due to edge-triggered
2645 nature of OS/2 Event semaphores). (Needs a reimplementation (in terms of chaining
2646 waiting threads, with the linked list stored in per-thread structure?)?)</p>
2647 </dd>
2648 </li>
2649 <dt><strong><a name="item_os2_2ec"><em>os2.c</em></a></strong>
2651 <dd>
2652 <p>has a couple of static variables used in OS/2-specific functions. (Need to be
2653 moved to per-thread structure, or serialized?)</p>
2654 </dd>
2655 </li>
2656 </dl>
2657 <p>Note that these problems should not discourage experimenting, since they
2658 have a low probability of affecting small programs.</p>
2660 </p>
2661 <hr />
2662 <h1><a name="bugs">BUGS</a></h1>
2663 <p>This description is not updated often (since 5.6.1?), see <em>./os2/Changes</em>
2664 (<em>perlos2delta</em>) for more info.</p>
2666 </p>
2667 <hr />
2668 <h1><a name="author">AUTHOR</a></h1>
2669 <p>Ilya Zakharevich, <a href="mailto:cpan@ilyaz.org">cpan@ilyaz.org</a></p>
2671 </p>
2672 <hr />
2673 <h1><a name="see_also">SEE ALSO</a></h1>
2674 <p>perl(1).</p>
2675 <table border="0" width="100%" cellspacing="0" cellpadding="3">
2676 <tr><td class="block" style="background-color: #cccccc" valign="middle">
2677 <big><strong><span class="block">&nbsp;perlos2 - Perl under OS/2, DOS, Win0.3*, Win0.95 and WinNT.</span></strong></big>
2678 </td></tr>
2679 </table>
2681 </body>
2683 </html>