Platform name is Windows, not Win32
[platform/upstream/perl.git] / README.win32
1 If you read this file _as_is_, just ignore the funny characters you
2 see. It is written in the POD format (see pod/perlpod.pod) which is
3 specially designed to be readable as is.
4
5 =head1 NAME
6
7 perlwin32 - Perl under Windows
8
9 =head1 SYNOPSIS
10
11 These are instructions for building Perl under Windows 2000 and later.
12
13 =head1 DESCRIPTION
14
15 Before you start, you should glance through the README file
16 found in the top-level directory to which the Perl distribution
17 was extracted.  Make sure you read and understand the terms under
18 which this software is being distributed.
19
20 Also make sure you read L<BUGS AND CAVEATS> below for the
21 known limitations of this port.
22
23 The INSTALL file in the perl top-level has much information that is
24 only relevant to people building Perl on Unix-like systems.  In
25 particular, you can safely ignore any information that talks about
26 "Configure".
27
28 You may also want to look at one other option for building a perl that
29 will work on Windows: the README.cygwin file, which give a different
30 set of rules to build a perl for Windows.  This method will probably
31 enable you to build a more Unix-compatible perl, but you will also
32 need to download and use various other build-time and run-time support
33 software described in that file.
34
35 This set of instructions is meant to describe a so-called "native"
36 port of Perl to the Windows platform.  This includes both 32-bit and
37 64-bit Windows operating systems.  The resulting Perl requires no
38 additional software to run (other than what came with your operating
39 system).  Currently, this port is capable of using one of the
40 following compilers on the Intel x86 architecture:
41
42       Borland C++             version 5.02 or later
43       Microsoft Visual C++    version 6.0 or later
44       Gcc by mingw.org        gcc version 2.95.2 or later
45       Gcc by mingw-w64.sf.net gcc version 4.4.3 or later
46
47 Note that the last two of these are actually competing projects both
48 delivering complete gcc toolchain for MS Windows:
49
50 - http://mingw.org - delivers gcc toolchain targeting 32-bit Windows
51   platform.  Use version 3.2.x or later for the best results with this
52   compiler.
53
54 - http://mingw-w64.sf.net - delivers gcc toolchain targeting both 64-bit
55   Windows and 32-bit Windows platforms (despite the project name "mingw-w64"
56   they are not only 64-bit oriented). They deliver the native gcc compilers
57   and cross-compilers that are also supported by perl's makefile.
58
59 The Borland C++ and Microsoft Visual C++ compilers are also now being given
60 away free.  The Borland compiler is available as "Borland C++ Compiler Free
61 Command Line Tools" and is the same compiler that ships with the full
62 "Borland C++ Builder" product.  The Microsoft compiler is available as
63 "Visual C++ Toolkit 2003" or "Visual C++ 2005/2008 Express Edition" (and also
64 as part of the ".NET Framework SDK") and is the same compiler that ships with
65 "Visual C++ .NET 2003 Professional" or "Visual C++ 2005/2008 Professional"
66 respectively.
67
68 This port can also be built on IA64/AMD64 using:
69
70       Microsoft Platform SDK    Nov 2001 (64-bit compiler and tools)
71       MinGW64 compiler (gcc version 4.4.3 or later)
72
73 The Windows SDK can be downloaded from http://www.microsoft.com/.
74 The MinGW64 compiler is available at http://sourceforge.net/projects/mingw-w64.
75 The latter is actually a cross-compiler targeting Win64. There's also a trimmed
76 down compiler (no java, or gfortran) suitable for building perl available at:
77 http://strawberryperl.com/package/kmx/64_gcctoolchain/mingw64-w64-20100123-kmx-v2.zip
78
79 NOTE: If you're using a 32-bit compiler to build perl on a 64-bit Windows
80 operating system, then you should set the WIN64 environment variable to "undef".
81 Also, the trimmed down compiler only passes tests when USE_ITHREADS *= define
82 (as opposed to undef) and when the CFG *= Debug line is commented out.
83
84 This port fully supports MakeMaker (the set of modules that
85 is used to build extensions to perl).  Therefore, you should be
86 able to build and install most extensions found in the CPAN sites.
87 See L<Usage Hints for Perl on Windows> below for general hints about this.
88
89 =head2 Setting Up Perl on Windows
90
91 =over 4
92
93 =item Make
94
95 You need a "make" program to build the sources.  If you are using
96 Visual C++ or the Windows SDK tools, nmake will work.  Builds using
97 the Borland compiler or gcc need dmake.
98
99 dmake is a freely available make that has very nice macro features
100 and parallelability.
101
102 A port of dmake for Windows is available from:
103
104     http://search.cpan.org/dist/dmake/
105
106 Fetch and install dmake somewhere on your path.
107
108 There exists a minor coexistence problem with dmake and Borland C++
109 compilers.  Namely, if a distribution has C files named with mixed
110 case letters, they will be compiled into appropriate .obj-files named
111 with all lowercase letters, and every time dmake is invoked
112 to bring files up to date, it will try to recompile such files again.
113 For example, Tk distribution has a lot of such files, resulting in
114 needless recompiles every time dmake is invoked.  To avoid this, you
115 may use the script "sync_ext.pl" after a successful build.  It is
116 available in the win32 subdirectory of the Perl source distribution.
117
118 =item Command Shell
119
120 Use the default "cmd" shell that comes with NT.  Some versions of the
121 popular 4DOS/NT shell have incompatibilities that may cause you trouble.
122 If the build fails under that shell, try building again with the cmd
123 shell.
124
125 Make sure the path to the build directory does not contain spaces.  The
126 build usually works in this circumstance, but some tests will fail.
127
128 =item Borland C++
129
130 If you are using the Borland compiler, you will need dmake.
131 (The make that Borland supplies is seriously crippled and will not
132 work for MakeMaker builds.)
133
134 See L</"Make"> above.
135
136 =item Microsoft Visual C++
137
138 The nmake that comes with Visual C++ will suffice for building.
139 You will need to run the VCVARS32.BAT file, usually found somewhere
140 like C:\Program Files\Microsoft Visual Studio\VC98\Bin.
141 This will set your build environment.
142
143 You can also use dmake to build using Visual C++; provided, however,
144 you set OSRELEASE to "microsft" (or whatever the directory name
145 under which the Visual C dmake configuration lives) in your environment
146 and edit win32/config.vc to change "make=nmake" into "make=dmake".  The
147 latter step is only essential if you want to use dmake as your default
148 make for building extensions using MakeMaker.
149
150 =item Microsoft Visual C++ 2008 Express Edition
151
152 This free version of Visual C++ 2008 Professional contains the same compiler
153 and linker that ship with the full version, and also contains everything
154 necessary to build Perl, rather than requiring a separate download of the
155 Windows SDK like previous versions did.
156
157 This package can be downloaded by searching for "Visual Studio 2008 Express
158 Edition" in the Download Center at
159 http://www.microsoft.com/downloads/search.aspx?displaylang=en.  (Providing exact
160 links to these packages has proven a pointless task because the links keep on
161 changing so often.)
162
163 Install Visual C++ 2008, then setup your environment using
164
165         C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools\vsvars32.bat
166
167 (assuming the default installation location was chosen).
168
169 Perl should now build using the win32/Makefile.  You will need to edit that
170 file to set
171
172         CCTYPE = MSVC90FREE
173
174 first.
175
176 =item Microsoft Visual C++ 2005 Express Edition
177
178 This free version of Visual C++ 2005 Professional contains the same compiler
179 and linker that ship with the full version, but doesn't contain everything
180 necessary to build Perl.
181
182 You will also need to download the "Windows SDK" (the "Core SDK" and "MDAC
183 SDK" components are required) for more header files and libraries.
184
185 These packages can both be downloaded by searching in the Download Center at
186 http://www.microsoft.com/downloads/search.aspx?displaylang=en.  (Providing exact
187 links to these packages has proven a pointless task because the links keep on
188 changing so often.)
189
190 Try to obtain the latest version of the Windows SDK.  Sometimes these packages
191 contain a particular Windows OS version in their name, but actually work on
192 other OS versions too.  For example, the "Windows Server 2003 R2 Platform SDK"
193 also runs on Windows XP SP2 and Windows 2000.
194
195 Install Visual C++ 2005 first, then the Platform SDK.  Setup your environment
196 as follows (assuming default installation locations were chosen):
197
198         SET PlatformSDKDir=C:\Program Files\Microsoft Platform SDK
199
200         SET PATH=%SystemRoot%\system32;%SystemRoot%;C:\Program Files\Microsoft Visual Studio 8\Common7\IDE;C:\Program Files\Microsoft Visual Studio 8\VC\BIN;C:\Program Files\Microsoft Visual Studio 8\Common7\Tools;C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\bin;C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;C:\Program Files\Microsoft Visual Studio 8\VC\VCPackages;%PlatformSDKDir%\Bin
201
202         SET INCLUDE=C:\Program Files\Microsoft Visual Studio 8\VC\INCLUDE;%PlatformSDKDir%\include
203
204         SET LIB=C:\Program Files\Microsoft Visual Studio 8\VC\LIB;C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\lib;%PlatformSDKDir%\lib
205
206         SET LIBPATH=C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
207
208 (The PlatformSDKDir might need to be set differently depending on which version
209 you are using. Earlier versions installed into "C:\Program Files\Microsoft SDK",
210 while the latest versions install into version-specific locations such as
211 "C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2".)
212
213 Perl should now build using the win32/Makefile.  You will need to edit that
214 file to set
215
216         CCTYPE = MSVC80FREE
217
218 and to set CCHOME, CCINCDIR and CCLIBDIR as per the environment setup above.
219
220 =item Microsoft Visual C++ Toolkit 2003
221
222 This free toolkit contains the same compiler and linker that ship with
223 Visual C++ .NET 2003 Professional, but doesn't contain everything
224 necessary to build Perl.
225
226 You will also need to download the "Platform SDK" (the "Core SDK" and "MDAC
227 SDK" components are required) for header files, libraries and rc.exe, and
228 ".NET Framework SDK" for more libraries and nmake.exe.  Note that the latter
229 (which also includes the free compiler and linker) requires the ".NET
230 Framework Redistributable" to be installed first.  This can be downloaded and
231 installed separately, but is included in the "Visual C++ Toolkit 2003" anyway.
232
233 These packages can all be downloaded by searching in the Download Center at
234 http://www.microsoft.com/downloads/search.aspx?displaylang=en.  (Providing exact
235 links to these packages has proven a pointless task because the links keep on
236 changing so often.)
237
238 Try to obtain the latest version of the Windows SDK.  Sometimes these packages
239 contain a particular Windows OS version in their name, but actually work on
240 other OS versions too.  For example, the "Windows Server 2003 R2 Platform SDK"
241 also runs on Windows XP SP2 and Windows 2000.
242
243 Install the Toolkit first, then the Platform SDK, then the .NET Framework SDK.
244 Setup your environment as follows (assuming default installation locations
245 were chosen):
246
247         SET PlatformSDKDir=C:\Program Files\Microsoft Platform SDK
248
249         SET PATH=%SystemRoot%\system32;%SystemRoot%;C:\Program Files\Microsoft Visual C++ Toolkit 2003\bin;%PlatformSDKDir%\Bin;C:\Program Files\Microsoft.NET\SDK\v1.1\Bin
250
251         SET INCLUDE=C:\Program Files\Microsoft Visual C++ Toolkit 2003\include;%PlatformSDKDir%\include;C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
252
253         SET LIB=C:\Program Files\Microsoft Visual C++ Toolkit 2003\lib;%PlatformSDKDir%\lib;C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\lib
254
255 (The PlatformSDKDir might need to be set differently depending on which version
256 you are using. Earlier versions installed into "C:\Program Files\Microsoft SDK",
257 while the latest versions install into version-specific locations such as
258 "C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2".)
259
260 Several required files will still be missing:
261
262 =over 4
263
264 =item *
265
266 cvtres.exe is required by link.exe when using a .res file.  It is actually
267 installed by the .NET Framework SDK, but into a location such as the
268 following:
269
270         C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322
271
272 Copy it from there to %PlatformSDKDir%\Bin
273
274 =item *
275
276 lib.exe is normally used to build libraries, but link.exe with the /lib
277 option also works, so change win32/config.vc to use it instead:
278
279 Change the line reading:
280
281         ar='lib'
282
283 to:
284
285         ar='link /lib'
286
287 It may also be useful to create a batch file called lib.bat in
288 C:\Program Files\Microsoft Visual C++ Toolkit 2003\bin containing:
289
290         @echo off
291         link /lib %*
292
293 for the benefit of any naughty C extension modules that you might want to build
294 later which explicitly reference "lib" rather than taking their value from
295 $Config{ar}.
296
297 =item *
298
299 setargv.obj is required to build perlglob.exe (and perl.exe if the USE_SETARGV
300 option is enabled).  The Platform SDK supplies this object file in source form
301 in %PlatformSDKDir%\src\crt.  Copy setargv.c, cruntime.h and
302 internal.h from there to some temporary location and build setargv.obj using
303
304         cl.exe /c /I. /D_CRTBLD setargv.c
305
306 Then copy setargv.obj to %PlatformSDKDir%\lib
307
308 Alternatively, if you don't need perlglob.exe and don't need to enable the
309 USE_SETARGV option then you can safely just remove all mention of $(GLOBEXE)
310 from win32/Makefile and setargv.obj won't be required anyway.
311
312 =back
313
314 Perl should now build using the win32/Makefile.  You will need to edit that
315 file to set
316
317         CCTYPE = MSVC70FREE
318
319 and to set CCHOME, CCINCDIR and CCLIBDIR as per the environment setup above.
320
321 =item Microsoft Platform SDK 64-bit Compiler
322
323 The nmake that comes with the Platform SDK will suffice for building
324 Perl.  Make sure you are building within one of the "Build Environment"
325 shells available after you install the Platform SDK from the Start Menu.
326
327 =item MinGW release 3 with gcc
328
329 The latest release of MinGW at the time of writing is 3.1.0, which contains
330 gcc-3.2.3.  It can be downloaded here:
331
332     http://www.mingw.org/
333
334 Perl also compiles with earlier releases of gcc (2.95.2 and up).  See below
335 for notes about using earlier versions of MinGW/gcc.
336
337 And perl also compiles with gcc-4.3.0 and up, and perhaps even some of the
338 earlier 4.x.x versions.
339
340 You also need dmake.  See L</"Make"> above on how to get it.
341
342 =item MinGW release 1 with gcc
343
344 The MinGW-1.1 bundle contains gcc-2.95.3.
345
346 Make sure you install the binaries that work with MSVCRT.DLL as indicated
347 in the README for the GCC bundle.  You may need to set up a few environment
348 variables (usually ran from a batch file).
349
350 There are a couple of problems with the version of gcc-2.95.2-msvcrt.exe
351 released 7 November 1999:
352
353 =over
354
355 =item *
356
357 It left out a fix for certain command line quotes.  To fix this, be sure
358 to download and install the file fixes/quote-fix-msvcrt.exe from the above
359 ftp location.
360
361 =item *
362
363 The definition of the fpos_t type in stdio.h may be wrong.  If your
364 stdio.h has this problem, you will see an exception when running the
365 test t/lib/io_xs.t.  To fix this, change the typedef for fpos_t from
366 "long" to "long long" in the file i386-mingw32msvc/include/stdio.h,
367 and rebuild.
368
369 =back
370
371 A potentially simpler to install (but probably soon-to-be-outdated) bundle
372 of the above package with the mentioned fixes already applied is available
373 here:
374
375     http://downloads.ActiveState.com/pub/staff/gsar/gcc-2.95.2-msvcrt.zip
376     ftp://ftp.ActiveState.com/pub/staff/gsar/gcc-2.95.2-msvcrt.zip
377
378 =back
379
380 =head2 Building
381
382 =over 4
383
384 =item *
385
386 Make sure you are in the "win32" subdirectory under the perl toplevel.
387 This directory contains a "Makefile" that will work with
388 versions of nmake that come with Visual C++ or the Windows SDK, and
389 a dmake "makefile.mk" that will work for all supported compilers.  The
390 defaults in the dmake makefile are setup to build using MinGW/gcc.
391
392 =item *
393
394 Edit the makefile.mk (or Makefile, if you're using nmake) and change
395 the values of INST_DRV and INST_TOP.   You can also enable various
396 build flags.  These are explained in the makefiles.
397
398 Note that it is generally not a good idea to try to build a perl with
399 INST_DRV and INST_TOP set to a path that already exists from a previous
400 build.  In particular, this may cause problems with the
401 lib/ExtUtils/t/Embed.t test, which attempts to build a test program and
402 may end up building against the installed perl's lib/CORE directory rather
403 than the one being tested.
404
405 You will have to make sure that CCTYPE is set correctly and that
406 CCHOME points to wherever you installed your compiler. If building with
407 gcc-4.x.x, you'll also need to uncomment the assignment to GCC_4XX and
408 uncomment the assignment to the appropriate GCCHELPERDLL in the makefile.mk.
409
410 If building with the cross-compiler provided by
411 mingw-w64.sourceforge.net you'll need to uncomment the line that sets
412 GCCCROSS in the makefile.mk. Do this only if it's the cross-compiler - ie
413 only if the bin folder doesn't contain a gcc.exe. (The cross-compiler
414 does not provide a gcc.exe, g++.exe, ar.exe, etc. Instead, all of these
415 executables are prefixed with 'x86_64-w64-mingw32-'.)
416
417 The default value for CCHOME in the makefiles for Visual C++
418 may not be correct for some versions.  Make sure the default exists
419 and is valid.
420
421 You may also need to comment out the C<DELAYLOAD = ...> line in the
422 Makefile if you're using VC++ 6.0 without the latest service pack and
423 the linker reports an internal error.
424
425 If you have either the source or a library that contains des_fcrypt(),
426 enable the appropriate option in the makefile.  A ready-to-use version
427 of fcrypt.c, based on the version originally written by Eric Young at
428 ftp://ftp.funet.fi/pub/crypt/mirrors/dsi/libdes/, is bundled with the
429 distribution and CRYPT_SRC is set to use it.
430 Alternatively, if you have built a library that contains des_fcrypt(),
431 you can set CRYPT_LIB to point to the library name.
432 Perl will also build without des_fcrypt(), but the crypt() builtin will
433 fail at run time.
434
435 If you want build some core extensions statically into perl's dll, specify
436 them in the STATIC_EXT macro.
437
438 Be sure to read the instructions near the top of the makefiles carefully.
439
440 =item *
441
442 Type "dmake" (or "nmake" if you are using that make).
443
444 This should build everything.  Specifically, it will create perl.exe,
445 perl513.dll at the perl toplevel, and various other extension dll's
446 under the lib\auto directory.  If the build fails for any reason, make
447 sure you have done the previous steps correctly.
448
449 =back
450
451 =head2 Testing Perl on Windows
452
453 Type "dmake test" (or "nmake test").  This will run most of the tests from
454 the testsuite (many tests will be skipped).
455
456 There should be no test failures.
457
458 Some test failures may occur if you use a command shell other than the
459 native "cmd.exe", or if you are building from a path that contains
460 spaces.  So don't do that.
461
462 If you are running the tests from a emacs shell window, you may see
463 failures in op/stat.t.  Run "dmake test-notty" in that case.
464
465 If you're using the Borland compiler, you may see a failure in op/taint.t
466 arising from the inability to find the Borland Runtime DLLs on the system
467 default path.  You will need to copy the DLLs reported by the messages
468 from where Borland chose to install it, into the Windows system directory
469 (usually somewhere like C:\WINNT\SYSTEM32) and rerun the test.
470
471 If you're using Borland compiler versions 5.2 and below, you may run into
472 problems finding the correct header files when building extensions.  For
473 example, building the "Tk" extension may fail because both perl and Tk
474 contain a header file called "patchlevel.h".  The latest Borland compiler
475 (v5.5) is free of this misbehaviour, and it even supports an
476 option -VI- for backward (bugward) compatibility for using the old Borland
477 search algorithm  to locate header files.
478
479 If you run the tests on a FAT partition, you may see some failures for
480 C<link()> related tests (I<op/write.t>, I<op/stat.t> ...). Testing on
481 NTFS avoids these errors.
482
483 Furthermore, you should make sure that during C<make test> you do not
484 have any GNU tool packages in your path: some toolkits like Unixutils
485 include some tools (C<type> for instance) which override the Windows
486 ones and makes tests fail. Remove them from your path while testing to
487 avoid these errors.
488
489 Please report any other failures as described under L<BUGS AND CAVEATS>.
490
491 =head2 Installation of Perl on Windows
492
493 Type "dmake install" (or "nmake install").  This will put the newly
494 built perl and the libraries under whatever C<INST_TOP> points to in the
495 Makefile.  It will also install the pod documentation under
496 C<$INST_TOP\$INST_VER\lib\pod> and HTML versions of the same under
497 C<$INST_TOP\$INST_VER\lib\pod\html>.
498
499 To use the Perl you just installed you will need to add a new entry to
500 your PATH environment variable: C<$INST_TOP\bin>, e.g.
501
502     set PATH=c:\perl\bin;%PATH%
503
504 If you opted to uncomment C<INST_VER> and C<INST_ARCH> in the makefile
505 then the installation structure is a little more complicated and you will
506 need to add two new PATH components instead: C<$INST_TOP\$INST_VER\bin> and
507 C<$INST_TOP\$INST_VER\bin\$ARCHNAME>, e.g.
508
509     set PATH=c:\perl\5.6.0\bin;c:\perl\5.6.0\bin\MSWin32-x86;%PATH%
510
511 =head2 Usage Hints for Perl on Windows
512
513 =over 4
514
515 =item Environment Variables
516
517 The installation paths that you set during the build get compiled
518 into perl, so you don't have to do anything additional to start
519 using that perl (except add its location to your PATH variable).
520
521 If you put extensions in unusual places, you can set PERL5LIB
522 to a list of paths separated by semicolons where you want perl
523 to look for libraries.  Look for descriptions of other environment
524 variables you can set in L<perlrun>.
525
526 You can also control the shell that perl uses to run system() and
527 backtick commands via PERL5SHELL.  See L<perlrun>.
528
529 Perl does not depend on the registry, but it can look up certain default
530 values if you choose to put them there.  Perl attempts to read entries from
531 C<HKEY_CURRENT_USER\Software\Perl> and C<HKEY_LOCAL_MACHINE\Software\Perl>.
532 Entries in the former override entries in the latter.  One or more of the
533 following entries (of type REG_SZ or REG_EXPAND_SZ) may be set:
534
535     lib-$]              version-specific standard library path to add to @INC
536     lib                 standard library path to add to @INC
537     sitelib-$]          version-specific site library path to add to @INC
538     sitelib             site library path to add to @INC
539     vendorlib-$]        version-specific vendor library path to add to @INC
540     vendorlib           vendor library path to add to @INC
541     PERL*               fallback for all %ENV lookups that begin with "PERL"
542
543 Note the C<$]> in the above is not literal.  Substitute whatever version
544 of perl you want to honor that entry, e.g. C<5.6.0>.  Paths must be
545 separated with semicolons, as usual on Windows.
546
547 =item File Globbing
548
549 By default, perl handles file globbing using the File::Glob extension,
550 which provides portable globbing.
551
552 If you want perl to use globbing that emulates the quirks of DOS
553 filename conventions, you might want to consider using File::DosGlob
554 to override the internal glob() implementation.  See L<File::DosGlob> for
555 details.
556
557 =item Using perl from the command line
558
559 If you are accustomed to using perl from various command-line
560 shells found in UNIX environments, you will be less than pleased
561 with what Windows offers by way of a command shell.
562
563 The crucial thing to understand about the Windows environment is that
564 the command line you type in is processed twice before Perl sees it.
565 First, your command shell (usually CMD.EXE on Windows NT, and
566 COMMAND.COM on Windows 9x) preprocesses the command line, to handle
567 redirection, environment variable expansion, and location of the
568 executable to run. Then, the perl executable splits the remaining
569 command line into individual arguments, using the C runtime library
570 upon which Perl was built.
571
572 It is particularly important to note that neither the shell nor the C
573 runtime do any wildcard expansions of command-line arguments (so
574 wildcards need not be quoted).  Also, the quoting behaviours of the
575 shell and the C runtime are rudimentary at best (and may, if you are
576 using a non-standard shell, be inconsistent).  The only (useful) quote
577 character is the double quote (").  It can be used to protect spaces
578 and other special characters in arguments.
579
580 The Windows NT documentation has almost no description of how the
581 quoting rules are implemented, but here are some general observations
582 based on experiments: The C runtime breaks arguments at spaces and
583 passes them to programs in argc/argv.  Double quotes can be used to
584 prevent arguments with spaces in them from being split up.  You can
585 put a double quote in an argument by escaping it with a backslash and
586 enclosing the whole argument within double quotes.  The backslash and
587 the pair of double quotes surrounding the argument will be stripped by
588 the C runtime.
589
590 The file redirection characters "E<lt>", "E<gt>", and "|" can be quoted by
591 double quotes (although there are suggestions that this may not always
592 be true).  Single quotes are not treated as quotes by the shell or
593 the C runtime, they don't get stripped by the shell (just to make
594 this type of quoting completely useless).  The caret "^" has also
595 been observed to behave as a quoting character, but this appears
596 to be a shell feature, and the caret is not stripped from the command
597 line, so Perl still sees it (and the C runtime phase does not treat
598 the caret as a quote character).
599
600 Here are some examples of usage of the "cmd" shell:
601
602 This prints two doublequotes:
603
604     perl -e "print '\"\"' "
605
606 This does the same:
607
608     perl -e "print \"\\\"\\\"\" "
609
610 This prints "bar" and writes "foo" to the file "blurch":
611
612     perl -e "print 'foo'; print STDERR 'bar'" > blurch
613
614 This prints "foo" ("bar" disappears into nowhereland):
615
616     perl -e "print 'foo'; print STDERR 'bar'" 2> nul
617
618 This prints "bar" and writes "foo" into the file "blurch":
619
620     perl -e "print 'foo'; print STDERR 'bar'" 1> blurch
621
622 This pipes "foo" to the "less" pager and prints "bar" on the console:
623
624     perl -e "print 'foo'; print STDERR 'bar'" | less
625
626 This pipes "foo\nbar\n" to the less pager:
627
628     perl -le "print 'foo'; print STDERR 'bar'" 2>&1 | less
629
630 This pipes "foo" to the pager and writes "bar" in the file "blurch":
631
632     perl -e "print 'foo'; print STDERR 'bar'" 2> blurch | less
633
634
635 Discovering the usefulness of the "command.com" shell on Windows 9x
636 is left as an exercise to the reader :)
637
638 One particularly pernicious problem with the 4NT command shell for
639 Windows NT is that it (nearly) always treats a % character as indicating
640 that environment variable expansion is needed.  Under this shell, it is
641 therefore important to always double any % characters which you want
642 Perl to see (for example, for hash variables), even when they are
643 quoted.
644
645 =item Building Extensions
646
647 The Comprehensive Perl Archive Network (CPAN) offers a wealth
648 of extensions, some of which require a C compiler to build.
649 Look in http://www.cpan.org/ for more information on CPAN.
650
651 Note that not all of the extensions available from CPAN may work
652 in the Windows environment; you should check the information at
653 http://testers.cpan.org/ before investing too much effort into
654 porting modules that don't readily build.
655
656 Most extensions (whether they require a C compiler or not) can
657 be built, tested and installed with the standard mantra:
658
659     perl Makefile.PL
660     $MAKE
661     $MAKE test
662     $MAKE install
663
664 where $MAKE is whatever 'make' program you have configured perl to
665 use.  Use "perl -V:make" to find out what this is.  Some extensions
666 may not provide a testsuite (so "$MAKE test" may not do anything or
667 fail), but most serious ones do.
668
669 It is important that you use a supported 'make' program, and
670 ensure Config.pm knows about it.  If you don't have nmake, you can
671 either get dmake from the location mentioned earlier or get an
672 old version of nmake reportedly available from:
673
674  http://download.microsoft.com/download/vc15/Patch/1.52/W95/EN-US/nmake15.exe
675
676 Another option is to use the make written in Perl, available from
677 CPAN.
678
679     http://www.cpan.org/modules/by-module/Make/
680
681 You may also use dmake.  See L</"Make"> above on how to get it.
682
683 Note that MakeMaker actually emits makefiles with different syntax
684 depending on what 'make' it thinks you are using.  Therefore, it is
685 important that one of the following values appears in Config.pm:
686
687     make='nmake'        # MakeMaker emits nmake syntax
688     make='dmake'        # MakeMaker emits dmake syntax
689     any other value     # MakeMaker emits generic make syntax
690                             (e.g GNU make, or Perl make)
691
692 If the value doesn't match the 'make' program you want to use,
693 edit Config.pm to fix it.
694
695 If a module implements XSUBs, you will need one of the supported
696 C compilers.  You must make sure you have set up the environment for
697 the compiler for command-line compilation.
698
699 If a module does not build for some reason, look carefully for
700 why it failed, and report problems to the module author.  If
701 it looks like the extension building support is at fault, report
702 that with full details of how the build failed using the perlbug
703 utility.
704
705 =item Command-line Wildcard Expansion
706
707 The default command shells on DOS descendant operating systems (such
708 as they are) usually do not expand wildcard arguments supplied to
709 programs.  They consider it the application's job to handle that.
710 This is commonly achieved by linking the application (in our case,
711 perl) with startup code that the C runtime libraries usually provide.
712 However, doing that results in incompatible perl versions (since the
713 behavior of the argv expansion code differs depending on the
714 compiler, and it is even buggy on some compilers).  Besides, it may
715 be a source of frustration if you use such a perl binary with an
716 alternate shell that *does* expand wildcards.
717
718 Instead, the following solution works rather well. The nice things
719 about it are 1) you can start using it right away; 2) it is more
720 powerful, because it will do the right thing with a pattern like
721 */*/*.c; 3) you can decide whether you do/don't want to use it; and
722 4) you can extend the method to add any customizations (or even
723 entirely different kinds of wildcard expansion).
724
725         C:\> copy con c:\perl\lib\Wild.pm
726         # Wild.pm - emulate shell @ARGV expansion on shells that don't
727         use File::DosGlob;
728         @ARGV = map {
729                       my @g = File::DosGlob::glob($_) if /[*?]/;
730                       @g ? @g : $_;
731                     } @ARGV;
732         1;
733         ^Z
734         C:\> set PERL5OPT=-MWild
735         C:\> perl -le "for (@ARGV) { print }" */*/perl*.c
736         p4view/perl/perl.c
737         p4view/perl/perlio.c
738         p4view/perl/perly.c
739         perl5.005/win32/perlglob.c
740         perl5.005/win32/perllib.c
741         perl5.005/win32/perlglob.c
742         perl5.005/win32/perllib.c
743         perl5.005/win32/perlglob.c
744         perl5.005/win32/perllib.c
745
746 Note there are two distinct steps there: 1) You'll have to create
747 Wild.pm and put it in your perl lib directory. 2) You'll need to
748 set the PERL5OPT environment variable.  If you want argv expansion
749 to be the default, just set PERL5OPT in your default startup
750 environment.
751
752 If you are using the Visual C compiler, you can get the C runtime's
753 command line wildcard expansion built into perl binary.  The resulting
754 binary will always expand unquoted command lines, which may not be
755 what you want if you use a shell that does that for you.  The expansion
756 done is also somewhat less powerful than the approach suggested above.
757
758 =item Windows Specific Extensions
759
760 A number of extensions specific to the Windows platform are available
761 from CPAN.  You may find that many of these extensions are meant to
762 be used under the Activeware port of Perl, which used to be the only
763 native port for the Windows platform.  Since the Activeware port does not
764 have adequate support for Perl's extension building tools, these
765 extensions typically do not support those tools either and, therefore,
766 cannot be built using the generic steps shown in the previous section.
767
768 To ensure smooth transitioning of existing code that uses the
769 ActiveState port, there is a bundle of Win32 extensions that contains
770 all of the ActiveState extensions and several other Win32 extensions from
771 CPAN in source form, along with many added bugfixes, and with MakeMaker
772 support.  The latest version of this bundle is available at:
773
774     http://search.cpan.org/dist/libwin32/
775
776 See the README in that distribution for building and installation
777 instructions.
778
779 =item Notes on 64-bit Windows
780
781 Windows .NET Server supports the LLP64 data model on the Intel Itanium
782 architecture.
783
784 The LLP64 data model is different from the LP64 data model that is the
785 norm on 64-bit Unix platforms.  In the former, C<int> and C<long> are
786 both 32-bit data types, while pointers are 64 bits wide.  In addition,
787 there is a separate 64-bit wide integral type, C<__int64>.  In contrast,
788 the LP64 data model that is pervasive on Unix platforms provides C<int>
789 as the 32-bit type, while both the C<long> type and pointers are of
790 64-bit precision.  Note that both models provide for 64-bits of
791 addressability.
792
793 64-bit Windows running on Itanium is capable of running 32-bit x86
794 binaries transparently.  This means that you could use a 32-bit build
795 of Perl on a 64-bit system.  Given this, why would one want to build
796 a 64-bit build of Perl?  Here are some reasons why you would bother:
797
798 =over
799
800 =item *
801
802 A 64-bit native application will run much more efficiently on
803 Itanium hardware.
804
805 =item *
806
807 There is no 2GB limit on process size.
808
809 =item *
810
811 Perl automatically provides large file support when built under
812 64-bit Windows.
813
814 =item *
815
816 Embedding Perl inside a 64-bit application.
817
818 =back
819
820 =back
821
822 =head2 Running Perl Scripts
823
824 Perl scripts on UNIX use the "#!" (a.k.a "shebang") line to
825 indicate to the OS that it should execute the file using perl.
826 Windows has no comparable means to indicate arbitrary files are
827 executables.
828
829 Instead, all available methods to execute plain text files on
830 Windows rely on the file "extension".  There are three methods
831 to use this to execute perl scripts:
832
833 =over 8
834
835 =item 1
836
837 There is a facility called "file extension associations" that will
838 work in Windows NT 4.0.  This can be manipulated via the two
839 commands "assoc" and "ftype" that come standard with Windows NT
840 4.0.  Type "ftype /?" for a complete example of how to set this
841 up for perl scripts (Say what?  You thought Windows NT wasn't
842 perl-ready? :).
843
844 =item 2
845
846 Since file associations don't work everywhere, and there are
847 reportedly bugs with file associations where it does work, the
848 old method of wrapping the perl script to make it look like a
849 regular batch file to the OS, may be used.  The install process
850 makes available the "pl2bat.bat" script which can be used to wrap
851 perl scripts into batch files.  For example:
852
853         pl2bat foo.pl
854
855 will create the file "FOO.BAT".  Note "pl2bat" strips any
856 .pl suffix and adds a .bat suffix to the generated file.
857
858 If you use the 4DOS/NT or similar command shell, note that
859 "pl2bat" uses the "%*" variable in the generated batch file to
860 refer to all the command line arguments, so you may need to make
861 sure that construct works in batch files.  As of this writing,
862 4DOS/NT users will need a "ParameterChar = *" statement in their
863 4NT.INI file or will need to execute "setdos /p*" in the 4DOS/NT
864 startup file to enable this to work.
865
866 =item 3
867
868 Using "pl2bat" has a few problems:  the file name gets changed,
869 so scripts that rely on C<$0> to find what they must do may not
870 run properly; running "pl2bat" replicates the contents of the
871 original script, and so this process can be maintenance intensive
872 if the originals get updated often.  A different approach that
873 avoids both problems is possible.
874
875 A script called "runperl.bat" is available that can be copied
876 to any filename (along with the .bat suffix).  For example,
877 if you call it "foo.bat", it will run the file "foo" when it is
878 executed.  Since you can run batch files on Windows platforms simply
879 by typing the name (without the extension), this effectively
880 runs the file "foo", when you type either "foo" or "foo.bat".
881 With this method, "foo.bat" can even be in a different location
882 than the file "foo", as long as "foo" is available somewhere on
883 the PATH.  If your scripts are on a filesystem that allows symbolic
884 links, you can even avoid copying "runperl.bat".
885
886 Here's a diversion:  copy "runperl.bat" to "runperl", and type
887 "runperl".  Explain the observed behavior, or lack thereof. :)
888 Hint: .gnidnats llits er'uoy fi ,"lrepnur" eteled :tniH
889
890 =back
891
892 =head2 Miscellaneous Things
893
894 A full set of HTML documentation is installed, so you should be
895 able to use it if you have a web browser installed on your
896 system.
897
898 C<perldoc> is also a useful tool for browsing information contained
899 in the documentation, especially in conjunction with a pager
900 like C<less> (recent versions of which have Windows support).  You may
901 have to set the PAGER environment variable to use a specific pager.
902 "perldoc -f foo" will print information about the perl operator
903 "foo".
904
905 One common mistake when using this port with a GUI library like C<Tk>
906 is assuming that Perl's normal behavior of opening a command-line
907 window will go away.  This isn't the case.  If you want to start a copy
908 of C<perl> without opening a command-line window, use the C<wperl>
909 executable built during the installation process.  Usage is exactly
910 the same as normal C<perl> on Windows, except that options like C<-h>
911 don't work (since they need a command-line window to print to).
912
913 If you find bugs in perl, you can run C<perlbug> to create a
914 bug report (you may have to send it manually if C<perlbug> cannot
915 find a mailer on your system).
916
917 =head1 BUGS AND CAVEATS
918
919 Norton AntiVirus interferes with the build process, particularly if
920 set to "AutoProtect, All Files, when Opened". Unlike large applications
921 the perl build process opens and modifies a lot of files. Having the
922 the AntiVirus scan each and every one slows build the process significantly.
923 Worse, with PERLIO=stdio the build process fails with peculiar messages
924 as the virus checker interacts badly with miniperl.exe writing configure
925 files (it seems to either catch file part written and treat it as suspicious,
926 or virus checker may have it "locked" in a way which inhibits miniperl
927 updating it). The build does complete with
928
929    set PERLIO=perlio
930
931 but that may be just luck. Other AntiVirus software may have similar issues.
932
933 Some of the built-in functions do not act exactly as documented in
934 L<perlfunc>, and a few are not implemented at all.  To avoid
935 surprises, particularly if you have had prior exposure to Perl
936 in other operating environments or if you intend to write code
937 that will be portable to other environments, see L<perlport>
938 for a reasonably definitive list of these differences.
939
940 Not all extensions available from CPAN may build or work properly
941 in the Windows environment.  See L</"Building Extensions">.
942
943 Most C<socket()> related calls are supported, but they may not
944 behave as on Unix platforms.  See L<perlport> for the full list.
945 Perl requires Winsock2 to be installed on the system. If you're
946 running Win95, you can download Winsock upgrade from here:
947
948 http://www.microsoft.com/windows95/downloads/contents/WUAdminTools/S_WUNetworkingTools/W95Sockets2/Default.asp
949
950 Later OS versions already include Winsock2 support.
951
952 Signal handling may not behave as on Unix platforms (where it
953 doesn't exactly "behave", either :).  For instance, calling C<die()>
954 or C<exit()> from signal handlers will cause an exception, since most
955 implementations of C<signal()> on Windows are severely crippled.
956 Thus, signals may work only for simple things like setting a flag
957 variable in the handler.  Using signals under this port should
958 currently be considered unsupported.
959
960 Please send detailed descriptions of any problems and solutions that
961 you may find to E<lt>F<perlbug@perl.org>E<gt>, along with the output
962 produced by C<perl -V>.
963
964 =head1 ACKNOWLEDGEMENTS
965
966 The use of a camel with the topic of Perl is a trademark
967 of O'Reilly and Associates, Inc. Used with permission.
968
969 =head1 AUTHORS
970
971 =over 4
972
973 =item Gary Ng E<lt>71564.1743@CompuServe.COME<gt>
974
975 =item Gurusamy Sarathy E<lt>gsar@activestate.comE<gt>
976
977 =item Nick Ing-Simmons E<lt>nick@ing-simmons.netE<gt>
978
979 =item Jan Dubois E<lt>jand@activestate.comE<gt>
980
981 =item Steve Hay E<lt>steve.hay@uk.radan.comE<gt>
982
983 =back
984
985 This document is maintained by Jan Dubois.
986
987 =head1 SEE ALSO
988
989 L<perl>
990
991 =head1 HISTORY
992
993 This port was originally contributed by Gary Ng around 5.003_24,
994 and borrowed from the Hip Communications port that was available
995 at the time.  Various people have made numerous and sundry hacks
996 since then.
997
998 Borland support was added in 5.004_01 (Gurusamy Sarathy).
999
1000 GCC/mingw32 support was added in 5.005 (Nick Ing-Simmons).
1001
1002 Support for PERL_OBJECT was added in 5.005 (ActiveState Tool Corp).
1003
1004 Support for fork() emulation was added in 5.6 (ActiveState Tool Corp).
1005
1006 Win9x support was added in 5.6 (Benjamin Stuhl).
1007
1008 Support for 64-bit Windows added in 5.8 (ActiveState Corp).
1009
1010 Last updated: 29 August 2007
1011
1012 =cut