This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
cflags.SH was broken: it was compiling a C file for testing available
[perl5.git] / README.cygwin
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 README.cygwin - Perl for Cygwin
8
9 =head1 SYNOPSIS
10
11 This document will help you configure, make, test and install Perl
12 on Cygwin.  This document also describes features of Cygwin that will
13 affect how Perl behaves at runtime.
14
15 B<NOTE:> There are pre-built Perl packages available for Cygwin and a
16 version of Perl is provided in the normal Cygwin install.  If you do
17 not need to customize the configuration, consider using one of those
18 packages.
19
20
21 =head1 PREREQUISITES FOR COMPILING PERL ON CYGWIN
22
23 =head2 Cygwin = GNU+Cygnus+Windows (Don't leave UNIX without it)
24
25 The Cygwin tools are ports of the popular GNU development tools for Win32
26 platforms.  They run thanks to the Cygwin library which provides the UNIX
27 system calls and environment these programs expect.  More information
28 about this project can be found at:
29
30   http://www.cygwin.com/
31
32 A recent net or commercial release of Cygwin is required.
33
34 At the time this document was last updated, Cygwin 1.5.2 was current.
35
36
37 =head2 Cygwin Configuration
38
39 While building Perl some changes may be necessary to your Cygwin setup so
40 that Perl builds cleanly.  These changes are B<not> required for normal
41 Perl usage.
42
43 B<NOTE:> The binaries that are built will run on all Win32 versions.
44 They do not depend on your host system (Win9x/WinME, WinNT/Win2K)
45 or your Cygwin configuration (I<ntea>, I<ntsec>, binary/text mounts).
46 The only dependencies come from hard-coded pathnames like C</usr/local>.
47 However, your host system and Cygwin configuration will affect Perl's
48 runtime behavior (see L</"TEST">).
49
50 =over 4
51
52 =item * C<PATH>
53
54 Set the C<PATH> environment variable so that Configure finds the Cygwin
55 versions of programs.  Any Windows directories should be removed or
56 moved to the end of your C<PATH>.
57
58 =item * I<nroff>
59
60 If you do not have I<nroff> (which is part of the I<groff> package),
61 Configure will B<not> prompt you to install I<man> pages.
62
63 =item * Permissions
64
65 On WinNT with either the I<ntea> or I<ntsec> C<CYGWIN> settings, directory
66 and file permissions may not be set correctly.  Since the build process
67 creates directories and files, to be safe you may want to run a
68 C<chmod -R +w *> on the entire Perl source tree.
69
70 Also, it is a well known WinNT "feature" that files created by a login
71 that is a member of the I<Administrators> group will be owned by the
72 I<Administrators> group.  Depending on your umask, you may find that you
73 can not write to files that you just created (because you are no longer
74 the owner).  When using the I<ntsec> C<CYGWIN> setting, this is not an
75 issue because it "corrects" the ownership to what you would expect on
76 a UNIX system.
77
78 =back
79
80 =head1 CONFIGURE PERL ON CYGWIN
81
82 The default options gathered by Configure with the assistance of
83 F<hints/cygwin.sh> will build a Perl that supports dynamic loading
84 (which requires a shared F<libperl.dll>).
85
86 This will run Configure and keep a record:
87
88   ./Configure 2>&1 | tee log.configure
89
90 If you are willing to accept all the defaults run Configure with B<-de>.
91 However, several useful customizations are available.
92
93 =head2 Stripping Perl Binaries on Cygwin
94
95 It is possible to strip the EXEs and DLLs created by the build process.
96 The resulting binaries will be significantly smaller.  If you want the
97 binaries to be stripped, you can either add a B<-s> option when Configure
98 prompts you,
99
100   Any additional ld flags (NOT including libraries)? [none] -s
101   Any special flags to pass to gcc to use dynamic linking? [none] -s
102   Any special flags to pass to ld2 to create a dynamically loaded library?
103   [none] -s
104
105 or you can edit F<hints/cygwin.sh> and uncomment the relevant variables
106 near the end of the file.
107
108 =head2 Optional Libraries for Perl on Cygwin
109
110 Several Perl functions and modules depend on the existence of
111 some optional libraries.  Configure will find them if they are
112 installed in one of the directories listed as being used for library
113 searches.  Pre-built packages for most of these are available from
114 the Cygwin installer.
115
116 =over 4
117
118 =item * C<-lcrypt>
119
120 The crypt package distributed with Cygwin is a Linux compatible 56-bit
121 DES crypt port by Corinna Vinschen.
122
123 Alternatively, the crypt libraries in GNU libc have been ported to Cygwin.
124
125 The DES based Ultra Fast Crypt port was done by Alexey Truhan:
126
127   ftp://ftp.uni-erlangen.de/pub/pc/gnuwin32/cygwin/porters/Okhapkin_Sergey/cw32crypt-dist-0.tgz
128
129 NOTE: There are various export restrictions on DES implementations,
130 see the glibc README for more details.
131
132 The MD5 port was done by Andy Piper:
133
134   ftp://ftp.uni-erlangen.de/pub/pc/gnuwin32/cygwin/porters/Okhapkin_Sergey/libcrypt.tgz
135
136 =item * C<-lgdbm> (C<use GDBM_File>)
137
138 GDBM is available for Cygwin.
139
140 NOTE: The GDBM library only works on NTFS partitions.
141
142 =item * C<-ldb> (C<use DB_File>)
143
144 BerkeleyDB is available for Cygwin.
145
146 NOTE: The BerkeleyDB library only completely works on NTFS partitions.
147
148 =item * C<-lcygipc> (C<use IPC::SysV>)
149
150 A port of SysV IPC is available for Cygwin.
151
152 NOTE: This has B<not> been extensively tested.  In particular,
153 C<d_semctl_semun> is undefined because it fails a Configure test
154 and on Win9x the I<shm*()> functions seem to hang.  It also creates
155 a compile time dependency because F<perl.h> includes F<<sys/ipc.h>>
156 and F<<sys/sem.h>> (which will be required in the future when compiling
157 CPAN modules). CURRENTLY NOT SUPPORTED!
158
159 =item * C<-lutil>
160
161 Included with the standard Cygwin netrelease is the inetutils package 
162 which includes libutil.a.
163
164 =back
165
166 =head2 Configure-time Options for Perl on Cygwin
167
168 The F<INSTALL> document describes several Configure-time options.  Some of
169 these will work with Cygwin, others are not yet possible.  Also, some of
170 these are experimental.  You can either select an option when Configure
171 prompts you or you can define (undefine) symbols on the command line.
172
173 =over 4
174
175 =item * C<-Uusedl>
176
177 Undefining this symbol forces Perl to be compiled statically.
178
179 =item * C<-Uusemymalloc>
180
181 By default Perl uses the C<malloc()> included with the Perl source.  If you
182 want to force Perl to build with the system C<malloc()> undefine this symbol.
183
184 =item * C<-Uuseperlio>
185
186 Undefining this symbol disables the PerlIO abstraction.  PerlIO is now the
187 default; it is not recommended to disable PerlIO.
188
189 =item * C<-Dusemultiplicity>
190
191 Multiplicity is required when embedding Perl in a C program and using
192 more than one interpreter instance.  This works with the Cygwin port.
193
194 =item * C<-Duse64bitint>
195
196 By default Perl uses 32 bit integers.  If you want to use larger 64
197 bit integers, define this symbol.
198
199 =item * C<-Duselongdouble>
200
201 I<gcc> supports long doubles (12 bytes).  However, several additional
202 long double math functions are necessary to use them within Perl
203 (I<{atan2, cos, exp, floor, fmod, frexp, isnan, log, modf, pow, sin, sqrt}l, 
204 strtold>).
205 These are B<not> yet available with Cygwin.
206
207 =item * C<-Dusethreads>
208
209 POSIX threads are implemented in Cygwin, define this symbol if you want
210 a threaded perl.
211
212 =item * C<-Duselargefiles>
213
214 Cygwin uses 64-bit integers for internal size and position calculations, 
215 this will be correctly detected and defined by Configure.
216
217 =item * C<-Dmksymlinks>
218
219 Use this to build perl outside of the source tree.  This works with Cygwin.
220 Details can be found in the F<INSTALL> document.  This is the recommended 
221 way to build perl from sources.
222
223 =back
224
225 =head2 Suspicious Warnings on Cygwin
226
227 You may see some messages during Configure that seem suspicious.
228
229 =over 4
230
231 =item * I<dlsym()>
232
233 I<ld2> is needed to build dynamic libraries, but it does not exist
234 when C<dlsym()> checking occurs (it is not created until C<make> runs).
235 You will see the following message:
236
237   Checking whether your C<dlsym()> needs a leading underscore ...
238   ld2: not found
239   I can't compile and run the test program.
240   I'm guessing that dlsym doesn't need a leading underscore.
241
242 Since the guess is correct, this is not a problem.
243
244 =item * Win9x and C<d_eofnblk>
245
246 Win9x does not correctly report C<EOF> with a non-blocking read on a
247 closed pipe.  You will see the following messages:
248
249   But it also returns -1 to signal EOF, so be careful!
250   WARNING: you can't distinguish between EOF and no data!
251
252   *** WHOA THERE!!! ***
253       The recommended value for $d_eofnblk on this machine was "define"!
254       Keep the recommended value? [y]
255
256 At least for consistency with WinNT, you should keep the recommended
257 value.
258
259 =item * Compiler/Preprocessor defines
260
261 The following error occurs because of the Cygwin C<#define> of
262 C<_LONG_DOUBLE>:
263
264   Guessing which symbols your C compiler and preprocessor define...
265   try.c:<line#>: missing binary operator
266
267 This failure does not seem to cause any problems.  With older gcc
268 versions, "parse error" is reported instead of "missing binary
269 operator".
270
271 =back
272
273 =head1 MAKE ON CYGWIN
274
275 Simply run I<make> and wait:
276
277   make 2>&1 | tee log.make
278
279 =head2 Errors on Cygwin
280
281 Errors like these are normal:
282
283   ...
284   make: [extra.pods] Error 1 (ignored)
285   ...
286   make: [extras.make] Error 1 (ignored)
287
288 =head2 ld2 on Cygwin
289
290 During C<make>, I<ld2> will be created and installed in your $installbin
291 directory (where you said to put public executables).  It does not
292 wait until the C<make install> process to install the I<ld2> script,
293 this is because the remainder of the C<make> refers to I<ld2> without
294 fully specifying its path and does this from multiple subdirectories.
295 The assumption is that $installbin is in your current C<PATH>.  If this
296 is not the case C<make> will fail at some point.  If this happens,
297 just manually copy I<ld2> from the source directory to somewhere in
298 your C<PATH>.
299
300 =head1 TEST ON CYGWIN
301
302 There are two steps to running the test suite:
303
304   make test 2>&1 | tee log.make-test
305
306   cd t;./perl harness 2>&1 | tee ../log.harness
307
308 The same tests are run both times, but more information is provided when
309 running as C<./perl harness>.
310
311 Test results vary depending on your host system and your Cygwin
312 configuration.  If a test can pass in some Cygwin setup, it is always
313 attempted and explainable test failures are documented.  It is possible
314 for Perl to pass all the tests, but it is more likely that some tests
315 will fail for one of the reasons listed below.
316
317 =head2 File Permissions on Cygwin
318
319 UNIX file permissions are based on sets of mode bits for
320 {read,write,execute} for each {user,group,other}.  By default Cygwin
321 only tracks the Win32 read-only attribute represented as the UNIX file
322 user write bit (files are always readable, files are executable if they
323 have a F<.{com,bat,exe}> extension or begin with C<#!>, directories are
324 always readable and executable).  On WinNT with the I<ntea> C<CYGWIN>
325 setting, the additional mode bits are stored as extended file attributes.
326 On WinNT with the I<ntsec> C<CYGWIN> setting, permissions use the standard
327 WinNT security descriptors and access control lists.  Without one of
328 these options, these tests will fail (listing not updated yet):
329
330   Failed Test           List of failed
331   ------------------------------------
332   io/fs.t               5, 7, 9-10
333   lib/anydbm.t          2
334   lib/db-btree.t        20
335   lib/db-hash.t         16
336   lib/db-recno.t        18
337   lib/gdbm.t            2
338   lib/ndbm.t            2
339   lib/odbm.t            2
340   lib/sdbm.t            2
341   op/stat.t             9, 20 (.tmp not an executable extension)
342
343 =head2 NDBM_File and ODBM_File do not work on FAT filesystems
344
345 Do not use NDBM_File or ODBM_File on FAT filesystem.  They can be
346 built on a FAT filesystem, but many tests will fail:
347
348  ../ext/NDBM_File/ndbm.t       13  3328    71   59  83.10%  1-2 4 16-71
349  ../ext/ODBM_File/odbm.t      255 65280    ??   ??       %  ??
350  ../lib/AnyDBM_File.t           2   512    12    2  16.67%  1 4
351  ../lib/Memoize/t/errors.t      0   139    11    5  45.45%  7-11
352  ../lib/Memoize/t/tie_ndbm.t   13  3328     4    4 100.00%  1-4
353  run/fresh_perl.t                          97    1   1.03%  91
354
355 If you intend to run only on FAT (or if using AnyDBM_File on FAT),
356 run Configure with the -Ui_ndbm and -Ui_dbm options to prevent
357 NDBM_File and ODBM_File being built.
358
359 With NTFS (and CYGWIN=ntsec), there should be no problems even if
360 perl was built on FAT.
361
362 =head2 C<fork()> failures in io_* tests
363
364 A C<fork()> failure may result in the following tests failing:
365
366   ext/IO/lib/IO/t/io_multihomed.t
367   ext/IO/lib/IO/t/io_sock.t
368   ext/IO/lib/IO/t/io_unix.t
369
370 See comment on fork in L<Miscellaneous> below.
371
372 =head1 Specific features of the Cygwin port
373
374 =head2 Script Portability on Cygwin
375
376 Cygwin does an outstanding job of providing UNIX-like semantics on top of
377 Win32 systems.  However, in addition to the items noted above, there are
378 some differences that you should know about.  This is a very brief guide
379 to portability, more information can be found in the Cygwin documentation.
380
381 =over 4
382
383 =item * Pathnames
384
385 Cygwin pathnames can be separated by forward (F</>) or backward (F<\\>)
386 slashes.  They may also begin with drive letters (F<C:>) or Universal
387 Naming Codes (F<//UNC>).  DOS device names (F<aux>, F<con>, F<prn>,
388 F<com*>, F<lpt?>, F<nul>) are invalid as base filenames.  However, they
389 can be used in extensions (e.g., F<hello.aux>).  Names may contain all
390 printable characters except these:
391
392   : * ? " < > |
393
394 File names are case insensitive, but case preserving.  A pathname that
395 contains a backslash or drive letter is a Win32 pathname (and not subject
396 to the translations applied to POSIX style pathnames).
397
398 =item * Text/Binary
399
400 When a file is opened it is in either text or binary mode.  In text mode
401 a file is subject to CR/LF/Ctrl-Z translations.  With Cygwin, the default
402 mode for an C<open()> is determined by the mode of the mount that underlies
403 the file.  Perl provides a C<binmode()> function to set binary mode on files
404 that otherwise would be treated as text.  C<sysopen()> with the C<O_TEXT>
405 flag sets text mode on files that otherwise would be treated as binary:
406
407     sysopen(FOO, "bar", O_WRONLY|O_CREAT|O_TEXT)
408
409 C<lseek()>, C<tell()> and C<sysseek()> only work with files opened in binary
410 mode.
411
412 The text/binary issue is covered at length in the Cygwin documentation.
413
414 =item * PerlIO
415
416 PerlIO overrides the default Cygwin Text/Binary behaviour.  A file will 
417 always treated as binary, regardless which mode of the mount it lives on,
418 just like it is in UNIX.  So CR/LF translation needs to be requested in 
419 either the C<open()> call like this:
420
421   open(FH, ">:crlf", "out.txt");
422
423 which will do conversion from LF to CR/LF on the output, or in the 
424 environment settings (add this to your .bashrc):
425
426   export PERLIO=crlf
427
428 which will pull in the crlf PerlIO layer which does LF -> CRLF conversion 
429 on every output generated by perl.
430
431 =item * F<.exe>
432
433 The Cygwin C<stat()>, C<lstat()> and C<readlink()> functions make the F<.exe>
434 extension transparent by looking for F<foo.exe> when you ask for F<foo>
435 (unless a F<foo> also exists).  Cygwin does not require a F<.exe>
436 extension, but I<gcc> adds it automatically when building a program.
437 However, when accessing an executable as a normal file (e.g., I<cp>
438 in a makefile) the F<.exe> is not transparent.  The I<install> included
439 with Cygwin automatically appends a F<.exe> when necessary.
440
441 =item * cygwin vs. windows process ids
442
443 Cygwin processes have their own pid, which is different from the
444 underlying windows pid.  Most posix compliant Proc functions expect
445 the cygwin pid, but several Win32::Process functions expect the
446 winpid. E.g. C<$$> is the cygwin pid of F</usr/bin/perl>, which is not
447 the winpid.  Use C<Cygwin::winpid_to_pid()> and C<Cygwin::winpid_to_pid()> 
448 to translate between them.
449
450 =item * C<chown()>
451
452 On WinNT C<chown()> can change a file's user and group IDs.  On Win9x C<chown()>
453 is a no-op, although this is appropriate since there is no security model.
454
455 =item * Miscellaneous
456
457 File locking using the C<F_GETLK> command to C<fcntl()> is a stub that
458 returns C<ENOSYS>.
459
460 Win9x can not C<rename()> an open file (although WinNT can).
461
462 The Cygwin C<chroot()> implementation has holes (it can not restrict file
463 access by native Win32 programs).
464
465 Inplace editing C<perl -i> of files doesn't work without doing a backup 
466 of the file being edited C<perl -i.bak> because of windowish restrictions,
467 therefore Perl adds the suffix C<.bak> automatically if you use C<perl -i> 
468 without specifying a backup extension.
469
470 Using C<fork()> after loading multiple dlls may fail with an internal cygwin
471 error like the following:
472
473   C:\CYGWIN\BIN\PERL.EXE: *** couldn't allocate memory 0x10000(4128768) for 'C:\CYGWIN\LIB\PERL5\5.6.1\CYGWIN-MULTI\AUTO\SOCKET\SOCKET.DLL' alignment, Win32 error 8
474
475     200 [main] perl 377147 sync_with_child: child -395691(0xB8) died before initialization with status code 0x1
476    1370 [main] perl 377147 sync_with_child: *** child state child loading dlls
477
478 Use the rebase utility to resolve the conflicting dll addresses.  The
479 rebase package is included in the Cygwin netrelease.  Use setup.exe from
480 F<http://www.cygwin.com/setup.exe> to install it and run rebaseall.
481
482 =back
483
484 =head2 Prebuilt methods:
485
486 =over 4
487
488 =item C<Cwd::cwd>
489
490 Returns current working directory.
491
492 =item C<Cygwin::pid_to_winpid>
493
494 Translates a cygwin pid to the corresponding Windows pid (which may or
495 may not be the same).
496
497 =item C<Cygwin::winpid_to_pid>
498
499 Translates a Windows pid to the corresponding cygwin pid (if any).
500
501 =back
502
503 =head1 INSTALL PERL ON CYGWIN
504
505 This will install Perl, including I<man> pages.
506
507   make install 2>&1 | tee log.make-install
508
509 NOTE: If C<STDERR> is redirected C<make install> will B<not> prompt
510 you to install I<perl> into F</usr/bin>.
511
512 You may need to be I<Administrator> to run C<make install>.  If you
513 are not, you must have write access to the directories in question.
514
515 Information on installing the Perl documentation in HTML format can be
516 found in the F<INSTALL> document.
517
518 =head1 MANIFEST ON CYGWIN
519
520 These are the files in the Perl release that contain references to Cygwin.
521 These very brief notes attempt to explain the reason for all conditional
522 code.  Hopefully, keeping this up to date will allow the Cygwin port to
523 be kept as clean as possible (listing not updated yet).
524
525 =over 4
526
527 =item Documentation
528
529   INSTALL README.cygwin README.win32 MANIFEST
530   Changes Changes5.005 Changes5.004 Changes5.6
531   pod/perl.pod pod/perlport.pod pod/perlfaq3.pod
532   pod/perldelta.pod pod/perl5004delta.pod pod/perl56delta.pod
533   pod/perlhist.pod pod/perlmodlib.pod perl/buildtoc pod/perltoc.pod
534
535 =item Build, Configure, Make, Install
536
537   cygwin/Makefile.SHs
538   cygwin/ld2.in
539   cygwin/perlld.in
540   ext/IPC/SysV/hints/cygwin.pl
541   ext/NDBM_File/hints/cygwin.pl
542   ext/ODBM_File/hints/cygwin.pl
543   hints/cygwin.sh
544   Configure             - help finding hints from uname,
545                           shared libperl required for dynamic loading
546   Makefile.SH           - linklibperl
547   Porting/patchls       - cygwin in port list
548   installman            - man pages with :: translated to .
549   installperl           - install dll/ld2/perlld, install to pods
550   makedepend.SH         - uwinfix
551
552 =item Tests
553
554   t/io/tell.t           - binmode
555   t/lib/b.t             - ignore Cwd from os_extras
556   t/lib/glob-basic.t    - Win32 directory list access differs from read mode
557   t/op/magic.t          - $^X/symlink WORKAROUND, s/.exe//
558   t/op/stat.t           - no /dev, skip Win32 ftCreationTime quirk
559                           (cache manager sometimes preserves ctime of file
560                           previously created and deleted), no -u (setuid)
561   t/lib/cygwin.t        - builtin cygwin function tests
562
563 =item Compiled Perl Source
564
565   EXTERN.h              - __declspec(dllimport)
566   XSUB.h                - __declspec(dllexport)
567   cygwin/cygwin.c       - os_extras (getcwd, spawn, Cygwin::winpid_to_pid, 
568                           Cygwin::pid_to_winpid)
569   perl.c                - os_extras
570   perl.h                - binmode
571   doio.c                - win9x can not rename a file when it is open
572   pp_sys.c              - do not define h_errno, pp_system with spawn
573   util.c                - use setenv
574
575 =item Compiled Module Source
576
577   ext/POSIX/POSIX.xs    - tzname defined externally
578   ext/SDBM_File/sdbm/pair.c
579                         - EXTCONST needs to be redefined from EXTERN.h
580   ext/SDBM_File/sdbm/sdbm.c
581                         - binary open
582
583 =item Perl Modules/Scripts
584
585   lib/Cwd.pm            - hook to internal Cwd::cwd
586   lib/ExtUtils/MakeMaker.pm
587                         - require MM_Cygwin.pm
588   lib/ExtUtils/MM_Cygwin.pm
589                         - canonpath, cflags, manifypods, perl_archive
590   lib/File/Find.pm      - on remote drives stat() always sets st_nlink to 1
591   lib/File/Spec/Unix.pm - preserve //unc
592   lib/File/Temp.pm      - no directory sticky bit
593   lib/perl5db.pl        - use stdin not /dev/tty
594   utils/perldoc.PL      - version comment
595
596 =back
597
598 =head1 BUGS ON CYGWIN
599
600 Support for swapping real and effective user and group IDs is incomplete.
601 On WinNT Cygwin provides C<setuid()>, C<seteuid()>, C<setgid()> and C<setegid()>.
602 However, additional Cygwin calls for manipulating WinNT access tokens
603 and security contexts are required.
604
605 =head1 AUTHORS
606
607 Charles Wilson <cwilson@ece.gatech.edu>,
608 Eric Fifer <egf7@columbia.edu>,
609 alexander smishlajev <als@turnhere.com>,
610 Steven Morlock <newspost@morlock.net>,
611 Sebastien Barre <Sebastien.Barre@utc.fr>,
612 Teun Burgers <burgers@ecn.nl>,
613 Gerrit P. Haase <gp@familiehaase.de>.
614
615 =head1 HISTORY
616
617 Last updated: 2005-02-11