內容

名稱

perlcygwin - Cygwin 的 Perl

摘要

本文檔將幫助您在 Cygwin 上配置、編譯、測試和安裝 Perl。本文還描述了影響 Perl 在運行時行為的 Cygwin 功能。

注意: Cygwin 提供了預先構建的 Perl 套件,並且在常規 Cygwin 安裝中提供了 Perl 的版本。如果您不需要自定義配置,請考慮使用其中一個套件。

在 Cygwin 上編譯 Perl 的先決條件

Cygwin = GNU+Cygnus+Windows(不要離開 UNIX 就沒有它)

Cygwin 工具是為 Win32 平台移植的流行 GNU 開發工具。它們

https://www.cygwin.com/

需要最新版本或商業版本的Cygwin。

在撰寫本文件時,Cygwin 3.0.7 是最新版本。

Cygwin 配置

在建置Perl時,可能需要對Cygwin進行一些更改,以便Perl能夠順利建置。這些更改對於正常使用Perl並不需要。

注意:建置的二進制檔可在所有Win32版本上運行。它們不依賴於您的主機系統或Cygwin配置(二進制/文本掛載、cygserver)。唯一的依賴來自硬編碼的路徑名稱,例如/usr/local。然而,您的主機系統和Cygwin配置將影響Perl的運行行為(請參見"TEST")。

在Cygwin上配置Perl

Configure在hints/cygwin.sh的幫助下收集的默認選項將建立支援動態加載的Perl(這需要一個共享的cygperl5_16.dll)。

這將運行Configure並保留記錄。

./Configure 2>&1 | tee log.configure

如果您願意接受所有默認值,請使用-de選項運行Configure。然而,有幾個有用的自定義選項可用。

在Cygwin上剝離Perl二進制文件

可以剝離構建過程創建的EXE和DLL文件。生成的二進制文件將會明顯更小。如果您希望剝離二進制文件,您可以在Configure提示時添加-s選項,

Any additional ld flags (NOT including libraries)? [none] -s
Any special flags to pass to g++ to create a dynamically loaded
library?
[none] -s
Any special flags to pass to gcc to use dynamic linking? [none] -s

或者您可以編輯hints/cygwin.sh,並取消文件末尾附近的相關變量的註釋。

Cygwin上Perl的可選庫

一些Perl功能和模組依賴於某些可選庫的存在。如果這些庫安裝在被列為用於庫搜索的目錄之一中,Configure將找到它們。大多數這些庫的預構建套件都可以從Cygwin安裝程式中獲得。

Perl 在 Cygwin 上的配置時間選項

INSTALL 文件描述了幾個配置時間選項。其中一些選項適用於 Cygwin,其他則尚不可行。此外,其中一些是實驗性的。您可以在 Configure 提示時選擇一個選項,也可以在命令行上定義(取消定義)符號。

在 CYGWIN 上進行編譯

只需運行 make,然後等待。

make -jn 2>&1 | tee log.make

其中 n 是您想要的最大同時編譯數量;省略此參數等同於指定 -j1

在 CYGWIN 上進行測試

運行測試套件有兩個步驟。

make test 2>&1 | tee log.make-test

cd t; ./perl harness 2>&1 | tee ../log.harness

兩次運行相同的測試,但以 ./perl harness 形式運行時提供更多信息,您也可以通過指定以下方式之一並行運行測試

cd t; TEST_JOBS=n ./perl harness 2>&1 | tee ../log.harness

其中 n 是要同時運行的最大測試數量。

測試結果因您的主機系統和您的 Cygwin 配置而異。如果測試在某些 Cygwin 設置中通過,則將始終嘗試並記錄可解釋的測試失敗。Perl 可能通過所有測試,但更可能是出於以下原因之一而失敗。

Cygwin 上的文件權限

UNIX 文件權限基於每個 {用戶,組,其他} 的 {讀取,寫入,執行} 的一組模式位。默認情況下,Cygwin 只跟踪 Win32 只讀屬性,表示為 UNIX 文件用戶寫入位(文件始終可讀取,如果具有 .{com,bat,exe} 擴展名或以 #! 開頭,則文件可執行,目錄始終可讀取和可執行)。在具有 ntea CYGWIN 設置的 WinNT 上,額外的模式位存儲為擴展文件屬性。在具有默認 ntsec CYGWIN 設置的 WinNT 上,權限使用標準 WinNT 安全描述符和訪問控制列表。如果沒有這些選項之一,這些測試將失敗(列表尚未更新)。

Failed Test           List of failed
------------------------------------
io/fs.t               5, 7, 9-10
lib/anydbm.t          2
lib/db-btree.t        20
lib/db-hash.t         16
lib/db-recno.t        18
lib/gdbm.t            2
lib/ndbm.t            2
lib/odbm.t            2
lib/sdbm.t            2
op/stat.t             9, 20 (.tmp not an executable extension)

NDBM_File 和 ODBM_File 在 FAT 文件系統上無法使用

不要在 FAT 文件系統上使用 NDBM_File 或 ODBM_File。它們可以在 FAT 文件系統上構建,但許多測試將失敗。

../ext/NDBM_File/ndbm.t       13  3328    71   59  83.10%  1-2 4 16-71
../ext/ODBM_File/odbm.t      255 65280    ??   ??       %  ??
../lib/AnyDBM_File.t           2   512    12    2  16.67%  1 4
../lib/Memoize/t/errors.t      0   139    11    5  45.45%  7-11
../lib/Memoize/t/tie_ndbm.t   13  3328     4    4 100.00%  1-4
run/fresh_perl.t                          97    1   1.03%  91

如果您打算僅在 FAT 上運行(或者在 FAT 上使用 AnyDBM_File),請使用 -Ui_ndbm 和 -Ui_dbm 選項運行 Configure 以防止構建 NDBM_File 和 ODBM_File。

在 NTFS(沒有 CYGWIN=nontsec)上,即使 Perl 是在 FAT 上構建的,也不應該出現問題。

io_* 測試中的 fork() 失敗

一個 fork() 失敗可能導致以下測試失敗

ext/IO/lib/IO/t/io_multihomed.t
ext/IO/lib/IO/t/io_sock.t
ext/IO/lib/IO/t/io_unix.t

請參閱下方的 "雜項" 中對 fork 的註解。

Cygwin 版本的特定功能

Cygwin 上的腳本可移植性

Cygwin 在 Win32 系統上提供了類似 UNIX 的語意,但除了上述提及的項目外,還有一些您應該了解的差異。這是一個非常簡要的可移植性指南,更多信息可以在 Cygwin 文件中找到。

預建方法

Cwd::cwd

回傳目前的工作目錄。

Cygwin::pid_to_winpid

將 cygwin 的 pid 轉換為對應的 Windows pid(可能相同,也可能不同)。

Cygwin::winpid_to_pid

將 Windows pid 轉換為對應的 cygwin pid(如果有的話)。

Cygwin::win_to_posix_path

將 Windows 路徑轉換為對應的 cygwin 路徑,尊重當前的掛載點。如果有第二個非空引數,則返回絕對路徑。雙字節字符將不會被轉換。

Cygwin::posix_to_win_path

將 cygwin 路徑轉換為對應的 Windows 路徑,尊重當前的掛載點。如果有第二個非空引數,則返回絕對路徑。雙字節字符將不會被轉換。

Cygwin::mount_table()

返回一個 [mnt_dir, mnt_fsname, mnt_type, mnt_opts] 的陣列。

perl -e 'for $i (Cygwin::mount_table) {print join(" ",@$i),"\n";}'
/bin c:\cygwin\bin system binmode,cygexec
/usr/bin c:\cygwin\bin system binmode
/usr/lib c:\cygwin\lib system binmode
/ c:\cygwin system binmode
/cygdrive/c c: system binmode,noumount
/cygdrive/d d: system binmode,noumount
/cygdrive/e e: system binmode,noumount
Cygwin::mount_flags

返回指定掛載點的掛載類型和標誌。一個以逗號分隔的字符串,其中包含 mntent->mnt_type(始終為 "system" 或 "user"),然後是 mntent->mnt_opts,第一個始終為 "binmode" 或 "textmode"。

system|user,binmode|textmode,exec,cygexec,cygdrive,mixed,
notexec,managed,nosuid,devfs,proc,noumount

如果參數為 "/cygdrive",則只返回卷掛載設置和 cygdrive 掛載前綴。

用戶掛載會覆蓋系統掛載。

$ perl -e 'print Cygwin::mount_flags "/usr/bin"'
system,binmode,cygexec
$ perl -e 'print Cygwin::mount_flags "/cygdrive"'
binmode,cygdrive,/cygdrive
Cygwin::is_binmount

如果給定的 cygwin 路徑是二進制掛載,則返回 true,如果該路徑以 textmode 掛載則返回 false。

Cygwin::sync_winenv

Cygwin 不會初始化所有原始的 Win32 環境變量。請參見本頁底部的“受限制的 Win32 環境”:https://cygwin.com/cygwin-ug-net/setup-env.html

從 cygwin 程式呼叫的某些 Win32 程式可能需要一些環境變數,例如 ADODB 需要 %COMMONPROGRAMFILES%。呼叫 Cygwin::sync_winenv() 將所有 Win32 環境變數複製到您的進程中,請注意 cygwin 將對每個非 POSIX 路徑的遇到發出警告。

在 CYGWIN 上安裝 PERL

這將安裝 Perl,包括 man 頁面。

make install 2>&1 | tee log.make-install

注意:如果 STDERR 被重定向,make install 將不會提示您將 perl 安裝到 /usr/bin 中。

您可能需要以 管理員 身份運行 make install。如果您不是,則必須對相應目錄具有寫入許可權。

有關以 HTML 格式安裝 Perl 文件的信息,請參閱 INSTALL 文件。

在 CYGWIN 上 MANIFEST

這些是 Perl 發行版中包含對 Cygwin 的引用的文件。這些非常簡短的注釋試圖解釋所有條件代碼的原因。希望保持此信息的最新將使 Cygwin 端口保持盡可能清潔。

文檔
INSTALL README.cygwin README.win32 MANIFEST
pod/perl.pod pod/perlport.pod pod/perlfaq3.pod
pod/perldelta.pod pod/perl5004delta.pod pod/perl56delta.pod
pod/perl561delta.pod pod/perl570delta.pod pod/perl572delta.pod
pod/perl573delta.pod pod/perl58delta.pod pod/perl581delta.pod
pod/perl590delta.pod pod/perlhist.pod pod/perlmodlib.pod
pod/perltoc.pod Porting/Glossary pod/perlgit.pod
Porting/updateAUTHORS.pl
dist/Cwd/Changes ext/Compress-Raw-Zlib/Changes
dist/Time-HiRes/Changes
ext/Compress-Raw-Zlib/README ext/Compress-Zlib/Changes
ext/DB_File/Changes ext/Encode/Changes ext/Sys-Syslog/Changes
ext/Win32API-File/Changes
lib/ExtUtils/CBuilder/Changes lib/ExtUtils/Changes
lib/ExtUtils/NOTES lib/ExtUtils/PATCHING lib/ExtUtils/README
lib/Net/Ping/Changes lib/Test/Harness/Changes
lib/Term/ANSIColor/ChangeLog lib/Term/ANSIColor/README
構建、配置、製作、安裝
cygwin/Makefile.SHs
ext/IPC/SysV/hints/cygwin.pl
ext/NDBM_File/hints/cygwin.pl
ext/ODBM_File/hints/cygwin.pl
hints/cygwin.sh
Configure             - help finding hints from uname,
                        shared libperl required for dynamic loading
Makefile.SH Cross/Makefile-cross-SH
                      - linklibperl
Porting/patchls       - cygwin in port list
installman            - man pages with :: translated to .
installperl           - install dll, install to 'pods'
makedepend.SH         - uwinfix
regen_lib.pl          - file permissions

plan9/mkfile
vms/descrip_mms.template
win32/Makefile
測試
t/io/fs.t             - no file mode checks if not ntsec
                        skip rename() check when not
                        check_case:relaxed
t/io/tell.t           - binmode
t/lib/cygwin.t        - builtin cygwin function tests
t/op/groups.t         - basegroup has ID = 0
t/op/magic.t          - $^X/symlink WORKAROUND, s/.exe//
t/op/stat.t           - no /dev, skip Win32 ftCreationTime quirk
                        (cache manager sometimes preserves ctime of
                        file previously created and deleted), no -u
                        (setuid)
t/op/taint.t          - can't use empty path under Cygwin Perl
t/op/time.t           - no tzset()
編譯的 Perl 源代碼
EXTERN.h              - __declspec(dllimport)
XSUB.h                - __declspec(dllexport)
cygwin/cygwin.c       - os_extras (getcwd, spawn, and several
                        Cygwin:: functions)
perl.c                - os_extras, -i.bak
perl.h                - binmode
doio.c                - win9x can not rename a file when it is open
pp_sys.c              - do not define h_errno, init
                        _pwent_struct.pw_comment
util.c                - use setenv
util.h                - PERL_FILE_IS_ABSOLUTE macro
pp.c                  - Comment about Posix vs IEEE math under
                        Cygwin
perlio.c              - CR/LF mode
perliol.c             - Comment about EXTCONST under Cygwin
編譯的模塊源代碼
ext/Compress-Raw-Zlib/Makefile.PL
                      - Can't install via CPAN shell under Cygwin
ext/Compress-Raw-Zlib/zlib-src/zutil.h
                      - Cygwin is Unix-like and has vsnprintf
ext/Errno/Errno_pm.PL - Special handling for Win32 Perl under
                        Cygwin
ext/POSIX/POSIX.xs    - tzname defined externally
ext/SDBM_File/sdbm/pair.c
                      - EXTCONST needs to be redefined from
                        EXTERN.h
ext/SDBM_File/sdbm/sdbm.c
                      - binary open
ext/Sys/Syslog/Syslog.xs
                      - Cygwin has syslog.h
ext/Sys/Syslog/win32/compile.pl
                      - Convert paths to Windows paths
ext/Time-HiRes/HiRes.xs
                      - Various timers not available
ext/Time-HiRes/Makefile.PL
                      - Find w32api/windows.h
ext/Win32/Makefile.PL - Use various libraries under Cygwin
ext/Win32/Win32.xs    - Child dir and child env under Cygwin
ext/Win32API-File/File.xs
                      - _open_osfhandle not implemented under
                        Cygwin
ext/Win32CORE/Win32CORE.c
                      - __declspec(dllexport)
Perl 模塊/腳本
ext/B/t/OptreeCheck.pm - Comment about stderr/stdout order under
                         Cygwin
ext/Digest-SHA/bin/shasum
                      - Use binary mode under Cygwin
ext/Sys/Syslog/win32/Win32.pm
                      - Convert paths to Windows paths
ext/Time-HiRes/HiRes.pm
                      - Comment about various timers not available
ext/Win32API-File/File.pm
                      - _open_osfhandle not implemented under
                        Cygwin
ext/Win32CORE/Win32CORE.pm
                      - History of Win32CORE under Cygwin
lib/Cwd.pm            - hook to internal Cwd::cwd
lib/ExtUtils/CBuilder/Platform/cygwin.pm
                      - use gcc for ld, and link to libperl.dll.a
lib/ExtUtils/CBuilder.pm
                      - Cygwin is Unix-like
lib/ExtUtils/Install.pm - Install and rename issues under Cygwin
lib/ExtUtils/MM.pm    - OS classifications
lib/ExtUtils/MM_Any.pm - Example for Cygwin
lib/ExtUtils/MakeMaker.pm
                      - require MM_Cygwin.pm
lib/ExtUtils/MM_Cygwin.pm
                      - canonpath, cflags, manifypods, perl_archive
lib/File/Fetch.pm     - Comment about quotes using a Cygwin example
lib/File/Find.pm      - on remote drives stat() always sets
                        st_nlink to 1
lib/File/Spec/Cygwin.pm - case_tolerant
lib/File/Spec/Unix.pm - preserve //unc
lib/File/Spec/Win32.pm - References a message on cygwin.com
lib/File/Spec.pm      - Pulls in lib/File/Spec/Cygwin.pm
lib/File/Temp.pm      - no directory sticky bit
lib/Module/CoreList.pm - List of all module files and versions
lib/Net/Domain.pm     - No domainname command under Cygwin
lib/Net/Netrc.pm      - Bypass using stat() under Cygwin
lib/Net/Ping.pm       - ECONREFUSED is EAGAIN under Cygwin
lib/Pod/Find.pm       - Set 'pods' dir
lib/Pod/Perldoc/ToMan.pm - '-c' switch for pod2man
lib/Pod/Perldoc.pm    - Use 'less' pager, and use .exe extension
lib/Term/ANSIColor.pm - Cygwin terminal info
lib/perl5db.pl        - use stdin not /dev/tty
utils/perlbug.PL      - Add CYGWIN environment variable to report
Perl 模塊測試
dist/Cwd/t/cwd.t
ext/Compress-Zlib/t/14gzopen.t
ext/DB_File/t/db-btree.t
ext/DB_File/t/db-hash.t
ext/DB_File/t/db-recno.t
ext/DynaLoader/t/DynaLoader.t
ext/File-Glob/t/basic.t
ext/GDBM_File/t/gdbm.t
ext/POSIX/t/sysconf.t
ext/POSIX/t/time.t
ext/SDBM_File/t/sdbm.t
ext/Sys/Syslog/t/syslog.t
ext/Time-HiRes/t/HiRes.t
ext/Win32/t/Unicode.t
ext/Win32API-File/t/file.t
ext/Win32CORE/t/win32core.t
lib/AnyDBM_File.t
lib/Archive/Extract/t/01_Archive-Extract.t
lib/Archive/Tar/t/02_methods.t
lib/ExtUtils/t/Embed.t
lib/ExtUtils/t/eu_command.t
lib/ExtUtils/t/MM_Cygwin.t
lib/ExtUtils/t/MM_Unix.t
lib/File/Compare.t
lib/File/Copy.t
lib/File/Find/t/find.t
lib/File/Path.t
lib/File/Spec/t/crossplatform.t
lib/File/Spec/t/Spec.t
lib/Net/hostent.t
lib/Net/Ping/t/110_icmp_inst.t
lib/Net/Ping/t/500_ping_icmp.t
lib/Net/t/netrc.t
lib/Pod/Simple/t/perlcyg.pod
lib/Pod/Simple/t/perlcygo.txt
lib/Pod/Simple/t/perlfaq.pod
lib/Pod/Simple/t/perlfaqo.txt
lib/User/grent.t
lib/User/pwent.t

在 CYGWIN 上的 BUGS

對於交換真實和有效用戶和組 ID 的支持是不完整的。在 WinNT 上,Cygwin 提供 setuid()seteuid()setgid()setegid()。但是,還需要其他 Cygwin 調用來操作 WinNT 訪問令牌和安全上下文。

作者

Charles Wilson <cwilson@ece.gatech.edu>, Eric Fifer <egf7@columbia.edu>, alexander smishlajev <als@turnhere.com>, Steven Morlock <newspost@morlock.net>, Sebastien Barre <Sebastien.Barre@utc.fr>, Teun Burgers <burgers@ecn.nl>, Gerrit P. Haase <gp@familiehaase.de>, Reini Urban <rurban@cpan.org>, Jan Dubois <jand@activestate.com>, Jerry D. Hedden <jdhedden@cpan.org>。

歷史

上次更新:2019-11-14