Prefix/Cygwin

This article provides Article description::instructions for any poor soul attempting to bootstrap Gentoo Prefix on Cygwin.

Preface: Prefix on Cygwin
How to bootstrap Gentoo Prefix on Cygwin?

Overview
At the beginning you find some general advice and how to set up Cygwin. There are a few restrictions for your Cygwin setup you need to bear in mind, to actually have luck with Gentoo Prefix on Cygwin.

What is this?
There was also a project "Gentoo on Cygwin" which is unmaintained as of 2008. Note the difference to "Gentoo Prefix on Cygwin". "Gentoo Prefix on Cygwin" is not a project itself but simply a try to run the well maintained "Gentoo Prefix" sources on Cygwin.

Why do this?
Running Prefix on Cygwin provides the same runtime environment on Windows as possible on Linux or Mac. It brings much more options than a Java runtime environment and it requires less resources than a virtual machine. Additionally, any program can be compiled by using Gentoo's package manager. Finally, all this happens in the userspace which provides independence from the administrator acocunt. Nothing compares to this.

Restrictions
Unix/Linux based package managers usually do require the system call, which is not available in Windows in general. Nevertheless, Cygwin implements the system call using the  and  Windows calls, combined with sophisticated duplication of process memory, loaded libraries and open handles into the child process.

But this requires and  to locate the very same  (executable and dlls) as loaded in the parent process. Now imagine what happens when the package manager has replaced these binaries, while existing processes (including the package manager itself) still want to fork.

Fortunately, Cygwin 3.0 (not released yet -- April 2017) or newer provides an improved implementation of the system call, which is able to deal with removed or updated binaries. But this implementation imposes some additional requirements to your Cygwin setup to actually work.


 * An NTFS file system for the Cygwin installation to install into.
 * Use this very same NTFS file system for Gentoo Prefix to install into.

The reason here is that the original executables are hardlinked into the directory.

Installing Cygwin
Cygwin comes with a full featured installer that explains itself:
 * 64 bit: http://www.cygwin.org/setup-x86_64.exe
 * 32 bit: http://www.cygwin.org/setup-x86.exe (not officially supported by Gentoo Prefix yet)

Space and paths
Before installing Cygwin consider the pathname. Use (create) a windows user account without whitespace in the username. Not all scripts can handle whitespace in pathes. Have enough free space, minimum 4 GB, take 10 GB if available.

Let's assume you choose "prefix" as username and you install Cygwin on P:\cygwin (mnemo for Prefix Cygwin).

Windows perspective: P:\cygwin\home\prefix Cygwin perspective: /home/prefix

Remember to choose an  partition as the Cygwin installation directory.

User and permissions
Install Cygwin from the same windows account that you will use to run it. This way you avoid some trouble with user permissions and administration.

Additional packages
The Gentoo Prefix bootstrap aims to require as less as possible packages installed on the underlying operating system. However, a minimal set of compilation environment plus some download tool is required. Please install these additional packages using the Cygwin setup program:


 * gcc-g++
 * wget

Additional setup
The fork feature mentioned above is disabled by default, and you have to enable it manually:


 * Use Cygwin 3.0 (or higher), or a cygwin1.dll with the "forkables" patches applied.

Start the  console, and run: bash$ mkdir --mode=a=rwxt /var/run/cygfork
 * Create the Cygwin directory, as the Cygwin setup does not create that for you:


 * Finally, reboot your Windows, to make sure the initial Cygwin process started already finds the directory in place, to actually activate the fork handler for removed or replaced binaries for this Cygwin instance.

Install Gentoo Prefix
Simply follow the general bootstrap process.

External resources

 * Interix - A now deprecated, optional, POSIX-conformant Unix subsystem for Windows NT operating systems.