- 不用 [[http://www.mingw.org/|MinGW]],改用 [[http://mingw-w64.sourceforge.net/|Mingw-w64]]。 - 不用 [[http://www.mingw.org/wiki/MSYS|MSYS]],改用 [[http://sourceforge.net/projects/msys2/|MSYS2]] - 終端可選用 [[https://code.google.com/p/futty/|futty]] 或 [[https://conemu.github.io/|ConEmu]]。 ====== 使用 ====== - 安裝 [[https://cygwin.com/install.html|Cygwin]] - 安裝 [[https://code.google.com/p/futty/|futty]] - 升級安裝包 * setup-x86_64.exe -> Select Packages -> Curr & View (Pending) * 上述選項即可更新已安裝的套件,無須另外安裝套件管理器。 * [[http://stackoverflow.com/questions/9260014/how-do-i-install-cygwin-components-from-the-command-line|How do I install cygwin components from the command line?]] - 一般會保留安裝包,之後可以透過命令行直接安裝已下載的套件。 $ .\setup-x86_64.exe -P make flex bison automake pkg-config gettext-devel gcc-core mingw64-x86_64-gcc-core vim - 不建議使用 Mingw32,改採用 Mingw64。於 Cygwin 欲使用 MinGW 交叉編譯,使用底下命令行。[(https://cygwin.com/ml/cygwin/2014-12/msg00117.html)] # System types: # --build=BUILD configure for building on BUILD [guessed] # --host=HOST cross-compile to build programs to run on HOST [BUILD] $ ./configure --host=x86_64-w64-mingw32 $ ./configure --host=i686-w64-mingw32 * [[https://www.gnu.org/software/libtool/manual/html_node/Cygwin-to-MinGW-Cross.html|15.3.7.6 Cygwin to MinGW Cross]] * [[https://www.cygwin.com/ml/cygwin/2009-01/msg00808.html|RFD: cygwin + *native* MinGW compiler]] * [[https://cygwin.com/cygwin-ug-net/using-effectively.html|Using Cygwin effectively with Windows]] * [[http://stackoverflow.com/questions/9751845/apt-get-for-cygwin|apt-get for cygwin?]] * [[http://sourceforge.net/projects/cygwin-ports/|Cygwin Ports]] * 可以透過 cygport 自行編譯安裝包。 ===== 注意事項 ===== * [[https://cygwin.com/ml/cygwin/2013-10/msg00312.html|Re: g++ -m32 option causes an error]] * 64-bit Cygwin 的 GCC 不支援 -m32 選項,無法編譯出 32-bit 執行檔。 * [[https://www.cygwin.com/ml/cygwin/2012-04/msg00486.html|Re: Building for nocygwin]] * Cygwin GCC 不再支援 `-mno-cygwin`,另行安裝 mingw64 版本 GCC。 * [[http://superuser.com/questions/231590/running-rebaseall-on-cygwin|Running rebaseall on Cygwin]] * [[https://code.google.com/p/chromium/wiki/CygwinDllRemappingFailure|CygwinDllRemappingFailure]] * [[https://cygwin.com/faq/faq.html#faq.using.bloda|How do I fix fork() failures?]] * [[wp>GNU build system]] 需要 pkg-config 偵測已安裝的函式庫。 * Cygwin 和 mingw 的函式庫不可互通。 * [[http://stackoverflow.com/questions/771756/what-is-the-difference-between-cygwin-and-mingw|What is the difference between Cygwin and MinGW?]] * [[http://kaogold3.pixnet.net/blog/post/6178650-cygwin-v.s-mingw|Cygwin v.s MinGW]] * Cygwin 讓應用程序使用 POSIX 介面,再透過 Cygwin 提供的 DLL 轉呼叫 Windows API; MinGW 則是提供 GNU 工具鏈,讓使用者直接將應用程序編譯成 Windows 執行檔。 * [[http://eoffice.im.fju.edu.tw/phpbb/viewtopic.php?t=1895|MinGW 與 Cygwin 的不同處]] * [[https://www.cygwin.com/ml/cygwin/2008-11/msg00035.html|need some explanations about files ".a" ".la" ".dll.a"]] * [[MinGW]] ===== 移除 Cygwin ===== * [[https://cygwin.com/faq/faq.html#faq.setup.uninstall-all|How do I uninstall all of Cygwin?]] * [[http://superuser.com/questions/167219/how-to-completely-uninstall-remove-cygwin-from-windows-7|How to completely uninstall/remove cygwin from Windows 7]] * 一般情況下,直接移除 Cygwin 根目錄即可。 ===== 製作安裝包 ===== - 安裝 cygport 和 gettext-devel。 * [[https://cygwin.com/ml/cygwin/2003-09/msg00557.html|Re: autopoint]] - 撰寫 cygport 設定檔 (參考 [[https://raw.githubusercontent.com/azru0512/cygwin/master/hidapi/hidapi.cygport|hidapi.cygport]] 和 [[https://raw.githubusercontent.com/azru0512/cygwin/master/hidapi/mingw64-x86_64-hidapi.cygport|mingw64-x86_64-hidapi.cygport]])。 * [[https://cygwin.com/setup.html#making_srcpackage|Making a package with cygport]] * [[https://cygwin.com/cygport/README|cygport README]] * [[https://cygwin.com/ml/cygwin/2015-02/msg00008.html|Question about package version number]] - 製作安裝包。 # 下載源代碼和補丁。 $ cygport hidapi fetch # 打包。 $ cygport hidapi all - 檢查安裝包內容。 $ tar tvf hidapi.x86_64/dist/hidapi/libhidapi/libhidapi-hidapi-hidapi.tar.xz $ tar tvf hidapi.x86_64/dist/hidapi/libhidapi-devel/libhidapi-devel-hidapi-hidapi.tar.xz - 測試安裝包。 $ cd / $ tar xvf hidapi.x86_64/dist/hidapi/libhidapi/libhidapi-hidapi-hidapi.tar.xz $ tar xvf hidapi.x86_64/dist/hidapi/libhidapi-devel/libhidapi-devel-hidapi-hidapi.tar.xz * [[https://www.cygwin.com/ml/cygwin/2015-01/msg00425.html|How to verify a cygport package]] - 送審。 * 建議將整個目錄上傳,已利後續處理。 * [[https://cygwin.com/setup.html#postinstall|Submitting a package]] * [[https://cygwin.com/ml/cygwin-apps/2015-02/msg00070.html|[ITP] hidapi 0.8.0-rc1]] * [[http://stackoverflow.com/questions/10346370/what-is-the-best-practice-of-distributing-binaries-from-a-github-project|what is the best practice of distributing binaries from a github project?]] * [[https://help.github.com/articles/distributing-large-binaries/|Distributing large binaries]] * [[https://help.github.com/articles/generating-ssh-keys/|Generating SSH keys]] - 上傳套件。 * 啟動 [[wp>ssh-agent]] $ eval "$(ssh-agent -s)" $ ssh-add ~/.ssh/id_rsa * 登入伺服器 (不需要密碼)。 # 當前目錄已存在欲上傳套件之目錄。 $ lftp sftp://cygwin@cygwin.com lftp cygwin@cygwin.com:~> ls -rw-rw-rw- 1 cygwin cygwin 53 Feb 11 01:40 !packages drwxrwxr-x 4 cygwin cygstage 4096 Feb 10 16:10 . drwxrwsr-x 62 cygwin cygstage 4096 Feb 10 16:10 .. drwxrwxr-x 3 cygwin cygwin 4096 Feb 10 16:10 x86 drwxrwxr-x 3 cygwin cygwin 4096 Feb 10 16:10 x86_64 * 設定郵件通知。 # email 為本機端檔案,內存預收信的電郵地址。 $ put email -o !email * 上傳套件。 $ cd x86_64/release # 把本機端的 hidapi 上傳至 sftp。 $ mirror -eR hidapi $ ls drwxrwxr-x 3 cygwin cygwin 4096 Feb 11 01:54 . drwxrwxr-x 3 cygwin cygwin 4096 Feb 10 16:10 .. drwxr-xr-x 5 cygwin cygwin 4096 Feb 11 01:54 hidapi # 通知 upset 更新套件列表。 $ put /dev/null -o !ready * [[https://sourceware.org/cygwin-apps/package-upload.html|Uploading Packages to cygwin.com]] * [[https://forum.siteground.com/showthread.php?19951-Connect-securely-using-lftp|`ls' at 0 [Delaying before reconnect: 27] ]] ===== 編程相關 ===== * [[http://stackoverflow.com/questions/320001/using-a-stackdump-from-cygwin-executable|Using a stackdump from Cygwin executable]] * [[http://stackoverflow.com/questions/5225579/crash-reporting-for-mingw-applications|Crash reporting for MinGW applications]] ====== MSYS2 ====== * [[http://sourceforge.net/projects/msys2|MSYS2]] * [[http://sourceforge.net/p/msys2/wiki/MSYS2%20installation/|MSYS2 installation]] * [[http://sourceforge.net/p/msys2/wiki/Contributing%20to%20MSYS2/|Contributing to MSYS2]] * MSYS2 安裝包分為底下三類: * msys2: 近似於 cygwin * mingw32 * mingw64 * [[https://wiki.allegro.cc/index.php?title=Building_with_msys2|Building with msys2]] * [[https://wiki.archlinux.org/index.php/pacman|pacman]] * [[http://stackoverflow.com/questions/25019057/how-are-msys-msys2-and-msysgit-related-to-each-other|How are msys, msys2, and msysgit related to each other?]] # 更新套件庫 $ pacman -Sy $ pacman -S mingw-w64-x86_64-gcc # 以 usb 關鍵字搜尋套件庫 $ pacman -Ss usb # 安裝 mingw-w64-x86_64 版本的 openocd $ pacman -S mingw64/mingw-w64-x86_64-openocd-git * 必須開啟相映的 MSYS2/MinGW-w64 Win32/MinGW-w64 Win64 Shell Shell 才能找到 msys2、mingw32 和 mingw64 已安裝套件。 ====== 內部實現 ====== $ wget http://mirrors.163.com/cygwin/release/cygwin/cygwin-1.7.16-1-src.tar.bz2 $ tar xvf cygwin-1.7.16-1-src.tar.bz2 $ tar xvf winsup-1.7.16.tar.bz2 # src/winsup/cygwin 實現 cygwin1.dll。 # src/winsup/w32api 實現 w32 API。 $ cd src/winsup/cygwin # 或是透過 CVS。目錄底下不可以有 src 目錄,避免下載不了。 # 會有 how-to 文件。 $ export CVSROOT=:pserver:anoncvs@cygwin.com:/cvs/src $ cvs login (Logging in to anoncvs@cygwin.com) CVS password: anoncvs $ cvs checkout winsup $ mkdir build install; cd build $ ../src/configure --prefix=$INSTALL --enable-debugging $ make -j * [[http://cygwin.com/cvs.html|Cygwin in CVS]]
a DLL (cygwin1.dll) which acts as a Linux API layer providing substantial Linux API functionality.
cygwin1.dll 是 Linux 內核在 Windows 上的實現,它使用 Win32 API 實現 POSIX 系統呼叫。
Because we are trying to emulate a UNIX kernel which needs access to all processes running under it, the first Cygwin DLL to run creates shared memory areas that other processes using separate instances of the DLL can access. This is used to keep track of open file descriptors and assist fork and exec, among other purposes. In addition to the shared memory regions, every process also has a per_process structure that contains information such as process id, user id, signal masks, and other similar process-specific information.
* [[http://www.makelinux.net/books/ulk3/understandlk-CHP-10|Chapter 10. System Calls]] * [[wp>POSIX]] * 類 UNIX 的作業系統基本上都會提供符合 POSIX 規範的系統呼叫。 * [[http://stackoverflow.com/questions/12724397/why-cygwin-needs-recompile-application-but-wine-does-not|Why Cygwin needs recompile application but Wine does not?]] ===== 編譯 Cygwin ===== 參考 [[http://cygwin.com/install.html|Installing and Updating Cygwin]]。[[http://cygwin.com/setup.exe|setup.exe]] 用來初次安裝 cygwin 和其它套件。請安裝新版 GCC 以編譯 Cygwin。 * [[http://cygwin.com/ml/cygwin/2012-01/msg00048.html|Building cygwin1.dll]] * [[http://cygwin.wikia.com/wiki/How_to_install_a_newer_version_of_GCC|How to install a newer version of GCC]] * [[http://cygwin.com/ml/cygwin-announce/2012-05/msg00020.html|New package: cygwin-debug-1.7.15-1]] * [[http://cygwin.com/ml/cygwin/2000-11/msg01465.html|Debugging cygwin1.dll]] ===== 內部結構 ===== *[[http://cygwin.com/faq/faq-nochunks.html#faq.programming.building-cygwin|6.18. How do I build Cygwin on my own?]] * Devel: gcc4, make, cocom, cvs * Perl: perl * 下載 cvs 源碼進行編譯。 * [[http://xiaoxia.org/2010/03/29/cygwin-study-notes/|Cygwin学习笔记]] * [[http://blog.csdn.net/lights_joy/article/details/3084591|在vs2008下使用cygwin(1):前言]] * [[http://cygwin.com/cgi-bin/cvsweb.cgi/src/winsup/cygwin/how-startup-shutdown-works.txt?rev=1.1&content-type=text/x-cvsweb-markup&cvsroot=src|How startup and shutdown work]] * [[http://cygwin.com/faq/faq-nochunks.html#faq.programming.debugging-cygwin|6.19. I may have found a bug in Cygwin, how can I debug it (the symbols in gdb look funny)?]] * [[http://cygwin.com/cgi-bin/cvsweb.cgi/src/winsup/cygwin/how-to-debug-cygwin.txt?rev=1.12&content-type=text/x-cvsweb-markup&cvsroot=src|how-to-debug-cygwin.txt]] - mainCRTStartup (src/winsup/cygwin/crt0.c) - cygwin_crt0 (src/winsup/cygwin/lib/cygwin_crt0.c) - dll_crt0 (cygwin/dcrt0.cc) - dll_crt0_1 (winsup/cygwin/dcrt0.cc) (gdb) dll cygwin1 (gdb) b dll_crt0_1 * winsup/cygwin/syscalls.cc * 較簡單的系統呼叫在此實現。 * winsup/cygwin/* * 其它系統呼叫的實現。 ==== 實現 fork ==== - fork (winsup/cygwin/fork.cc) extern "C" int fork () { frok grouped; debug_printf ("entering"); grouped.load_dlls = 0; int res; bool ischild = false; myself->set_has_pgid_children (); // 創建子進程。 if (grouped.ch.parent == NULL) return -1; ... 略 ... } - frok::parent (winsup/cygwin/fork.cc) int __stdcall frok::parent (volatile char * volatile stack_here) { while (1) { hchild = NULL; rc = CreateProcessW (myself->progname, /* image to run */ myself->progname, /* what we send in arg0 */ &sec_none_nih, &sec_none_nih, TRUE, /* inherit handles from parent */ c_flags, NULL, /* environment filled in later */ 0, /* use current drive/directory */ &si, &pi); if (rc) debug_printf ("forked pid %u", pi.dwProcessId); else { this_errno = geterrno_from_win_error (); error ("CreateProcessW failed for '%W'", myself->progname); memset (&pi, 0, sizeof (pi)); goto cleanup; } * [[http://blog.csdn.net/lights_joy/article/details/4520862cygwin|关键技术:fork]] * [[http://blog.csdn.net/lights_joy/article/details/4531849|cygwin fork子进程对父进程数据的复制]] * [[http://blog.csdn.net/lights_joy/article/details/4532262|fork子进程的第一次跳转]] * [[http://cygwin.com/ml/cygwin/2006-01/msg00965.html|Need information about data and bss segment address access in cygwin]] ==== Heap ==== * [[http://blog.csdn.net/lights_joy/article/details/4513120|cygwin关键技术:cygheap]] * [[http://www.oschina.net/code/explore/cygwin-1.7.7-1/winsup/cygwin/how-cygheap-works.txt|http://www.oschina.net/code/explore/cygwin-1.7.7-1/winsup/cygwin/how-cygheap-works.txt]] ==== 實現 open ==== * [[http://blog.csdn.net/lights_joy/article/details/4518530|cygwin关键技术:设备模拟]] ====== 外部連結 ====== * [[http://www.cygwin.com/|Cygwin]] * [[http://cygwin.com/faq-nochunks.html#faq.api|5. Cygwin API Questions]] * [[http://cygwin.com/cygwin-ug-net/brief-history.html|A brief history of the Cygwin project]] * [[http://cygwin.com/cygwin-ug-net/highlights.html|Highlights of Cygwin Functionality]] * [[wp>Cygwin]] * [[http://linux.sns.it/cygwin/usenix-98/cygwin.html|Cygwin: A Free Win32 Porting Layer for UNIX® Applications]] * [[http://unix.stackexchange.com/questions/8381/is-cygwin-like-wine-but-for-linux-applications|Is cygwin like wine, but for linux applications?]] * [[http://www.oki-osk.jp/esc/utf8-cygwin/|UTF-8 Cygwin]] * [[http://cygwin.com/ml/cygwin/2012-10/msg00257.html|Any article talk about cygwin overall architecture]]