User:Maffblaster/Drafts/Prefix Cygwin

From Gentoo Wiki
Jump to: navigation, search
Important
I am keeping this article for personal reference as I have run with a Cygwin Prefix. Please see the actual Prefix/Cygwin article. --Maffblaster (talk) 20:21, 13 April 2017 (UTC)

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

Contents

Windows, and the fork system call

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

But this requires CreateProcess() and LoadLibrary() to locate the very same binaries (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.

Requirements

Fortunately, Cygwin 3.0 (not released yet -- April 2017) or newer provides an improved implementation of the fork() system call, which is able to deal with removed or updated binaries. As this implementation uses hardlinks, the binaries are required to reside on the very same file system as the /var/run/cygfork/ Cygwin directory, and this file system to be of type NTFS, as other Windows file systems do not support hardlinks.

However, this fork feature is disabled by default.

So this is what you need to provide for Gentoo Prefix:

bash$ mkdir --mode=a=rwxt /var/run/cygfork
  • Reboot your Windows, to make sure the initial Cygwin process started already finds the /var/run/cygfork/ 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.

Old Instructions, to be removed

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. Those chapters that cover the bootstrapping process are divided into a "Walkthrough" followed by "Issue" handling in case if something goes wrong.

As recommended by the Prefix team follow the manual bootstrap process. Be advised to follow that document in parallel in a second browser view. This wiki page is kind of an overlay to that guide.

Sadly as of 2014 unless you are running Windows [version] Ultimate, Windows [server edition version], or < Windows 7 Interix or SFU(Services for UNIX) is not available for your environment.

What is this?

For the beginning this is rather a log of a single users efforts to install Gentoo Prefix on Cygwin. There is no report that anybody has done that successfully before, but Nimish Pachapurkar got quite far. Maybe he did it, we don't know.

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.

So this is a work of progress by nature. If the little pioneer gives up half the way, his experiences should not fully be lost. Hence, here they go in the hope that they may be of use for others that follow his trail.

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.

General issue handling

Before you start with bootstrapping have a look a this general strategies when you run into trouble. Having this strategies in mind will save you a lot of time.

First aid

Try this as far as the directories or files are already installed:

  • Assure the Windows editor files are all set to Unix format.
  • Close open files while emerging.
  • source ~/bootstrap.rc
  • env-update && source ~/gentoo/etc/profile
  • hash -r
  • Cygwin: rebaseall

Cygwin and DLLs

Rebasing packages

If you know how to use ldd great! it has been said that DLLs referencing memory lower than about 0x60000000 need to be rebased.

If you start not seeing your files or things start acting funny, close all your Cygwin terminals and do these commands. Try what you were doing again. Then, ask for help.

Open a windows command shell (cmd.exe):

C:\> path_to_cygwin\bin\ash /bin/rebaseall

This only rebases DLL installed with setup.exe but, it is good enough to get you started again if you happen to need to wipe your prefix and start over.

Windows/Cygwin have often troubles with memory addresses of moved DLL See PE. Especially with those of Perl and Python. As you may know emerge uses Python to do its grunt work and will fail if one or more of its libraries have moved without every involved DLL knowing.

The "rebaseall" script was made just for this purpose. It hides the (most) gory details of non-global-offset-style executable.

For more information view README file:

user $less /usr/share/doc/rebase/README

Creating a DLL list for the rebase program

Create a script to generate rebase.lst:

FILE /home/prefix/makeRebaseList.sh
MRL='/home/prefix/makeRebaseList.sh'
touch $MRL && chmod +x $MRL
echo '#/bin/bash' >> $MRL
echo 'BASE=/home/prefix' >> $MRL
echo 'rm ${BASE}/rebase.lst' >> $MRL
echo 'find ${BASE}/gentoo/bin/ -name *.dll -o -name *.so >> ${BASE}/rebase.lst' >> $MRL
echo 'find ${BASE}/gentoo/lib/ -name *.dll -o -name *.so >> ${BASE}/rebase.lst' >> $MRL
echo 'find ${BASE}/gentoo/usr/bin -name *.dll -o -name *.so >> ${BASE}/rebase.lst' >> $MRL
echo 'find ${BASE}/gentoo/usr/lib -name *.dll -o -name *.so >> ${BASE}/rebase.lst' >> $MRL

Alternatively, open a new file and put this in it (assuming you have a BASE variable} already set in the env):

FILE rebase.sh
#!/bin/bash

# Note the single bracket redirection in the first line removes the previous file.
find ${BASE}/gentoo/tmp/bin/ -name *.dll -o -name *.so > ${BASE}/rebase.lst
find ${BASE}/gentoo/tmp/lib/ -name *.dll -o -name *.so >> ${BASE}/rebase.lst
find ${BASE}/gentoo/tmp/usr/bin -name *.dll -o -name *.so >> ${BASE}/rebase.lst
find ${BASE}/gentoo/tmp/usr/lib -name *.dll -o -name *.so >> ${BASE}/rebase.lst

#remove these bottom lines after you are finished bootstraping
find ${BASE}/gentoo/tmp/bin/ -name *.dll -o -name *.so >> ${BASE}/rebase.lst
find ${BASE}/gentoo/tmp/lib/ -name *.dll -o -name *.so >> ${BASE}/rebase.lst
find ${BASE}/gentoo/tmp/usr/bin -name *.dll -o -name *.so >> ${BASE}/rebase.lst
find ${BASE}/gentoo/tmp/usr/lib -name *.dll -o -name *.so >> ${BASE}/rebase.lst

Running the script:

user $~/makeRebaseList.sh

Result is a file called rebase.lst.

Rebase all with user list

Use the -T option to set the user list. Open a windows command shell (cmd):

C:\> path_to_cygwin\bin\ash /bin/rebaseall -T /home/prefix/rebase.lst

Or make a insertmemehere.bat with the above plus PAUSE on the next line.

Gentoo issues

Strategies to debug

  • Emerge packages one-by-one:
root #emerge --oneshot --ask xxx-yyy/zzz
  • Execute single emerge steps:
root #ebuild path/to/ebuild [configure
root #compile
root #install
root #merge]
  • Go to work directory and try:
./configure followed by {{c|make and make install

QA complaints: explicit EPREFIX but target not found

Symptom:

QA Notice: the following files use invalid (possible non-prefixed) shebangs:
some/path:/shebang/path (explicit EPREFIX but target not found)

Reason: This was a meanwhile fixed bug. Reason is nano -w /home/prefix/gentoo/usr/lib/portage/bin/misc-functions.sh in function install_qa_check_prefix():

# does the shebang start with ${EPREFIX}, and does it exist?
if [[ ${line[0]} == ${EPREFIX}/* ]] ; then
  if [[ ! -e ${ROOT}${line[0]} && ! -e ${D}${line[0]} ]] ; then                   ## <---- This line. ##
    # hmm, refers explicitly to $EPREFIX, but doesn't exist,
    # if it's in PATH that's wrong in any case

Solution: Fabian Groffen writes: Ok, I see, ${ROOT%/} is probably the right thing to use here. Same for ${D}, should be ${D%/}.

QA complaints: in PATH but target not found

Symptom:

QA Notice: the following files use invalid (possible non-prefixed) shebangs:
some/path:/shebang/path (in PATH but target not found)
...

Reason: A package has missing ${EPREFIX} in the first line of some bash scripts.
Workaround: Disable death penalty for shebang issues. Interpreters are usually found in PATH.
End of nano -w ~/gentoo/usr/lib/portage/bin/misc-functions.sh function install_qa_check_prefix():

install_qa_check_prefix() {
[...]
#           die "Aborting due to QA concerns: invalid shebangs found"
    fi
}

QA complaints of missing gen_usr_ldscript

* QA Notice: Missing gen_usr_ldscript for libbz2.so
[...]
*      [[

Workaround: Disable this quality check. We don't need gen_usr_ldscript at all on windows.
Lines 438 of ~/gentoo/usr/lib/portage/bin/misc-functions.sh:

# [[ ${abort} == "yes" ]] && die "add those ldscripts"

unable to read SONAME

Symptom:

gen_usr_ldscript: unable to read SONAME from libiconv.so

Reason: gen_usr_ldscript doesn't cover cygwin and the default case doesn't work.

Solution: Don't use this for Cygwin. Simply return for now. Edit nano -w /home/prefix/gentoo/usr/portage/eclass/toolchain-funcs.eclass line 518:

gen_usr_ldscript() {
   return 0
}
XXXgen_usr_ldscript() {

Collisions

Sympton: Collisions while installing a package.

Reason: Often a previous installation did break.

Solution:

env FEATURES="-collision-protect" CHOST="i686-pc-cygwin" emerge --oneshot --nodeps libiconv

Cannot find *.so or *.dll

Symptom: a package can't find it's library

Reason: On windows shared libraries have to be in PATH.

Solution: Extend the PATH. See #extend_PATH_for_shared_libries and #Profile_setup.

Warnings you can ignore

* QA Notice: Package has poor programming practices which may compile
*            fine but exhibit random runtime failures.
* src/pch.c:116: warning: implicit declaration of function "setmode"
/home/prefix/gentoo/usr/lib/portage/bin/ebuild-helpers/prepstrip: line 98: scanelf: command not found
/home/prefix/gentoo/usr/lib/portage/bin/ebuild-helpers/prepstrip: line 186: scanelf: command not found
gcc: unrecognized option '-R/home/prefix/gentoo/usr/lib'
gcc: unrecognized option '-R/home/prefix/gentoo/lib'
[something] seems to ignore the --datarootdir setting

Installing Cygwin

Cygwin comes with a full featured installer that explains itself. http://www.cygwin.org/setup.exe

Space and paths

Before installing Cygwin consider the pathname. 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

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.

Basic packages

gcc4, wget, make, patch, python

For fast edits from the shell install an editor of choice:

vim, nano, pico, ... 

Install a terminal that supports copy and paste:

mintty
Note
Have a native windows editor available. ALWAYS set format to unix or your scriprts will break mysteriously! For example use Notepad++ and in the menu set "Format > Convert to unix".

Initial bootstrapping

Walkthrough Part I

BASE, EPREFIX, and OVERLAY variables

Define directories:

user $export BASE=${HOME}
user $export EPREFIX=${BASE}/gentoo
user $export OVERLAY=${BASE}/overlay

You can play with this.

.bashrc setup

Append the following code to the bottom of ~/.bashrc file:

FILE ~/.bashrc
alias ls="ls -hF --color=tty"
export BASE="${HOME}"
export EPREFIX="${BASE}/gentoo"
export OVERLAY="${BASE}/overlay"
export PATH="${EPREFIX}/lib:${EPREFIX}/usr/lib:${EPREFIX}/usr/bin:${EPREFIX}/bin:${EPREFIX}/tmp/usr/bin:${EPREFIX}/tmp/bin:/usr/bin:/bin"

Then source the newly edited ~/.bashrc file:

user $source ~/.bashrc

Download bootstrap-prefix.sh

The initial bootstrapping is done by bootstrap-prefix.sh. Fetch it and make it executable.

user $chmod +x ${BASE}/bootstrap-prefix.sh

Easy mode

Run the bootstrap-prefix.sh script without any options and it goes into interactive mode doing the hard work for you. If you would like to do it on your own ignore this step:

user $${BASE}/bootstrap-prefix.sh

Main Gentoo repository

Setup the main Gentoo repository:

user $${BASE}/bootstrap-prefix.sh ${EPREFIX} tree

Portage

Download and install Portage:

user $${BASE}/bootstrap-prefix.sh ${EPREFIX} portage

After this completes, the emerge command will be available for use in the ${EPREFIX}/tmp/usr/bin directory. First set the PYTHONPATH variable so that the python interpreter will be able to find the Portage modules:

user $export PYTHONPATH="${EPREFIX}/tmp/usr/lib/portage/pym/"

It should be possible to run the emerge command now:

user $${EPREFIX}/tmp/usr/bin/emerge

Be sure to sync to get the latest updates:

user $${EPREFIX}/tmp/usr/bin/emerge --sync

Build customization

${EPREFIX}/tmp/etc/make.globals
Prepare this file for bootstraping.
${EPREFIX}/tmp/etc/</code>
Make a symlink named make.profile here to ${EPREFIX}/usr/portage/profiles/prefix/windows/cygwin/1.7/x86
${OVERLAY}/profiles/prefix/cygwin/make.defaults
Some values have automatically been added for: CPPFLAGS, LDFLAGS, USE, and FEATURES variables.

Profile setup

FILE ${EPREFIX}/etc/portage/make.conf
CFLAGS="-O2 -pipe"
CXXFLAGS="${CFLAGS}"
MAKEOPTS="-j3"
# Extend PATH to find libraries on Windows
DEFAULT_PATH="${DEFAULT_PATH}:${EPREFIX}/lib:${EPREFIX}/usr/lib"
# The base profile sets ACCEPT_KEYWORDS=x86 and we don't have that in prefix.
ACCEPT_KEYWORDS="-x86 ~x86-linux"
# Fix -R warnings
LDFLAGS="-L${EPREFIX}/usr/lib -L${EPREFIX}/lib"
Note
There is no RPATH on Windows. See [Bug 336653].

Overlay setup

To customize some ebuilds create an overlay.

user $mkdir -p ${OVERLAY}/profiles
user $echo "Cygwin overlay" > ${OVERLAY}/profiles/repo_name
user $mkdir -p ${EPREFIX}/etc

Issues

There are never not issues =)

Oneshot emergings

Walkthrough part II

Cygwin installations

Run setup.exe to install following packages:

* automake (autoconf and perl will be included)
* sources of coreutils
* libiconv

Fix QA complaints

See: #QA_complaints:_explicit_EPREFIX_but_target_not_found, #QA_complaints:_in_PATH_but_target_not_found, #QA_complaints_of_missing_gen_usr_ldscript

 file=${EPREFIX}/usr/lib/portage/bin/misc-functions.sh

 sed -i 's/${ROOT}${line/${ROOT%\/}${line/' $file
 sed -i 's/${D}${line/${D%\/}${line/' $file

 sed -i 's/\(.*die.*invalid shebangs.*\)/#\1/' $file

 sed -i 's/\(.*add those ldscripts.*\)/#\1/' $file

Disable gen_usr_ldscript

Edit the toolchain-funcs.eclass file (line 518):

FILE ${EPREFIX}/usr/portage/eclass/toolchain-funcs.eclass
gen_usr_ldscript() {
       return 0;
}
XXXgen_usr_ldscript() {

emerge sed

The magic sauce needed to get emerge to run without bootstrap-prefix.sh isexport PYTHONPATH="${EPREFIX}/tmp/usr/lib/portage/pym/" without this you will be left high and dry when you do your emerge. if you would like to keep your configs out of the ${EPREFIX}/tmp dir then set:

root #export PORTAGE_CONFIGROOT=${EPREFIX}
root #emerge --oneshot sed

Here is where you begin filtering your ebuild blockages

You should have done rebaseall after you have installed python. If not do it now to be able to run emerge. results:

bin/sed.exe

emerge ncurses

the program cmp is needed for ether this build or the previous it is avalable through cygwin as diff-tools? this particular build also requires a pid command for the ${EPREFIX}/tmp/usr/lib/portage/bin/helper-functions.sh

script.
emerge --oneshot ncurses
</per>

results:

<pre>
usr/lib/libform.a
usr/lib/libform.dll.a
usr/lib/libmenu.a
usr/lib/libmenu.dll.a
usr/lib/libncurses++.a
usr/lib/libncurses.a
usr/lib/libncurses.dll.a
usr/lib/libpanel.a
usr/lib/libpanel.dll.a
usr/bin/captoinfo.exe -> tic.exe*
usr/bin/clear.exe*
usr/bin/cygform5.dll*
usr/bin/cygmenu5.dll*
usr/bin/cygncurses5.dll*
usr/bin/cygpanel5.dll*
usr/bin/infocmp.exe*
usr/bin/infotocap.exe -> tic.exe*
usr/bin/ncurses5-config*
usr/bin/reset.exe -> tset.exe*
usr/bin/tic.exe*
usr/bin/toe.exe*
usr/bin/tput.exe*
usr/bin/tset.exe*

emerge bash

emerge --oneshot bash

results:

bin/bash.exe

emerge wget

emerge --oneshot wget

results:

usr/bin/wget.exe

emerge baselayout-prefix

emerge --oneshot --nodeps baselayout-prefix

results:

sbin/depscan.sh  
sbin/env-update.sh  
sbin/functions.sh  
sbin/runscript.sh
etc/env.d/00basic
etc/env.d/99basic
etc/profile

update ~/.bashrc

Now we source ${EPREFIX}/etc/profile when entering a shell.

echo "source ${EPREFIX}/etc/profile" >> ${HOME}/.bashrc
source ${HOME}/.bashrc

extend PATH for shared libraries

In windows shared libraries are searched in PATH.

echo "PATH=\"${EPREFIX}/usr/lib:${EPREFIX}/lib:${EPREFIX}/opt/bin:${EPREFIX}/usr/sbin:${EPREFIX}/sbin\"" >> ${EPREFIX}/etc/env.d/00basic
env-update && source ${EPREFIX}/etc/profile
echo "PATH: $PATH"

The DEFAULT_PATH has already been set in #Profile_setup

emerge xz-utils

emerge --oneshot xz-utils

results:

usr/lib/liblzma.dll.a
usr/lib/liblzma.la
usr/bin/cyglzma-0.dll
usr/bin/lz*
usr/bin/xz*

Note: Only few installed programs have an .exe suffix.

emerge m4

emerge --oneshot m4

results:

/usr/bin/m4.exe

emerge flex

emerge --oneshot flex

results:

usr/bin/flex.exe
usr/bin/lex
usr/lib/libfl.a
usr/lib/libfl_pic.a
usr/include/FlexLexer.h

emerge bison

emerge --oneshot bison

results:

usr/bin/bison.exe
usr/bin/yacc
usr/bin/yacc.bison

emerge gnuconfig

emerge --oneshot gnuconfig

results:

usr/share/gnuconfig/config.guess
usr/share/gnuconfig/config.sub

emerge binutils-config

emerge --oneshot --nodeps binutils-config

results:

usr/bin/binutils-config
usr/lib/misc/binutils-config/binutils-config.h
usr/lib/misc/binutils-config/create-ldwrapper
usr/lib/misc/binutils-config/libbinutils-config.a

emerge binutils

Check Cygwins libiconv is already installed.

ls /usr/lib/libiconv.la && emerge --oneshot binutils

results:

usr/i686-pc-cygwin1.7/binutils-bin/2.20.51.0.8/addr2line.exe
usr/i686-pc-cygwin1.7/binutils-bin/2.20.51.0.8/ar.exe
usr/i686-pc-cygwin1.7/binutils-bin/2.20.51.0.8/as.exe
usr/i686-pc-cygwin1.7/binutils-bin/2.20.51.0.8/c++filt.exe
usr/i686-pc-cygwin1.7/binutils-bin/2.20.51.0.8/dlltool.exe
usr/i686-pc-cygwin1.7/binutils-bin/2.20.51.0.8/dllwrap.exe
usr/i686-pc-cygwin1.7/binutils-bin/2.20.51.0.8/elfedit.exe
usr/i686-pc-cygwin1.7/binutils-bin/2.20.51.0.8/gprof.exe
usr/i686-pc-cygwin1.7/binutils-bin/2.20.51.0.8/ld.bfd.exe
usr/i686-pc-cygwin1.7/binutils-bin/2.20.51.0.8/ld.exe
usr/i686-pc-cygwin1.7/binutils-bin/2.20.51.0.8/nm.exe
usr/i686-pc-cygwin1.7/binutils-bin/2.20.51.0.8/objcopy.exe
usr/i686-pc-cygwin1.7/binutils-bin/2.20.51.0.8/objdump.exe
usr/i686-pc-cygwin1.7/binutils-bin/2.20.51.0.8/ranlib.exe
usr/i686-pc-cygwin1.7/binutils-bin/2.20.51.0.8/readelf.exe
usr/i686-pc-cygwin1.7/binutils-bin/2.20.51.0.8/size.exe
usr/i686-pc-cygwin1.7/binutils-bin/2.20.51.0.8/strings.exe
usr/i686-pc-cygwin1.7/binutils-bin/2.20.51.0.8/strip.exe
usr/i686-pc-cygwin1.7/binutils-bin/2.20.51.0.8/windmc.exe
usr/i686-pc-cygwin1.7/binutils-bin/2.20.51.0.8/windres.exe
usr/lib/binutils/i686-pc-cygwin1.7/2.20.51.0.8/include/ansidecl.h
usr/lib/binutils/i686-pc-cygwin1.7/2.20.51.0.8/include/bfd.h
usr/lib/binutils/i686-pc-cygwin1.7/2.20.51.0.8/include/bfdlink.h
usr/lib/binutils/i686-pc-cygwin1.7/2.20.51.0.8/include/dis-asm.h
usr/lib/binutils/i686-pc-cygwin1.7/2.20.51.0.8/include/libiberty.h
usr/lib/binutils/i686-pc-cygwin1.7/2.20.51.0.8/include/symcat.h
usr/lib/binutils/i686-pc-cygwin1.7/2.20.51.0.8/ldscripts/i386pe.x
usr/lib/binutils/i686-pc-cygwin1.7/2.20.51.0.8/ldscripts/i386pe.xa
usr/lib/binutils/i686-pc-cygwin1.7/2.20.51.0.8/ldscripts/i386pe.xbn
usr/lib/binutils/i686-pc-cygwin1.7/2.20.51.0.8/ldscripts/i386pe.xn
usr/lib/binutils/i686-pc-cygwin1.7/2.20.51.0.8/ldscripts/i386pe.xr
usr/lib/binutils/i686-pc-cygwin1.7/2.20.51.0.8/ldscripts/i386pe.xu
usr/lib/binutils/i686-pc-cygwin1.7/2.20.51.0.8/libbfd.a
usr/lib/binutils/i686-pc-cygwin1.7/2.20.51.0.8/libbfd.la
usr/lib/binutils/i686-pc-cygwin1.7/2.20.51.0.8/libiberty.a
usr/lib/binutils/i686-pc-cygwin1.7/2.20.51.0.8/libopcodes.a
usr/lib/binutils/i686-pc-cygwin1.7/2.20.51.0.8/libopcodes.la

emerge gmp

emerge --oneshot gmp

results:

usr/include/gmp.h
usr/include/gmpxx.h
usr/lib/libgmp.a
usr/lib/libgmp.la
usr/lib/libgmpxx.a
usr/lib/libgmpxx.la

emerge mpfr

emerge --oneshot mpfr

results:

usr/include/mpf2mpfr.h
usr/include/mpfr.h
usr/lib/libmpfr.a
usr/lib/libmpfr.la

emerge gcc-config

emerge --oneshot gcc-config

results:

usr/bin/gcc-config
usr/lib/misc/gcc-config.exe

emerge gcc

If GCC doesn't emerge here use Cygwins for now and wait for a new version of GCC.

emerge coreutils

Check Cygwins automake, autoconf, perl and the sources of coreutils (8.5-2) are already installed.

ls /usr/bin/ | grep automake
ls /usr/bin/ | grep autoconf
ls /usr/bin/ | grep perl

Create overlay first:

mkdir -p ${OVERLAY}/sys-apps/coreutils/
cp ${EPREFIX}/usr/portage/sys-apps/coreutils/coreutils-8.5.ebuild ${OVERLAY}/sys-apps/coreutils/
ln -s ${EPREFIX}/usr/portage/sys-apps/coreutils/files/ ${OVERLAY}/sys-apps/coreutils/files

Adapt nano -w ${OVERLAY}/sys-apps/coreutils/coreutils-8.5.ebuild.

src_unpack() {
 unpack ${A}
 cd "${S}"
 # apply the cygwin patch
 epatch /usr/src/coreutils-8.5-2.src.patch
 einfo "Running autoreconf:"
 autoreconf
 [... patches go here ... ]
 # disable this interix patch as it conflicts:
 # epatch "${FILESDIR}"/${PN}-8.5-interix-warn-mount.patch
 [... patches go here ... ]
 mkdir -p man/install.td/
 cp /bin/install.exe.manifest man/install.td/install.exe.manifest
 mkdir src
 cp /bin/install.exe.manifest src/ginstall.exe.manifest
 cp /bin/install.exe.manifest ${EPREFIX}/usr/bin/install.exe.manifest
}

Alternative use sed expressions for this.

file=${OVERLAY}/sys-apps/coreutils/coreutils-8.5.ebuild
# apply the cygwin patch
sed -i '/cd "${S}"/a\\n\tepatch /usr/src/coreutils-8.5-2.src.patch\n\tautoreconf\n' $file
# disable interix patch as it conflicts
sed -i 's/\(.*interix-warn-mount.patch.*\)/#\1/' $file
# install exe.minifests (yes, sed is in reverse order here with intent)
sed -i '/cross-compiler && touch/a\\tcp /bin/install.exe.manifest ${EPREFIX}/usr/bin/install.exe.manifest' $file
sed -i '/cross-compiler && touch/a\\tcp /bin/install.exe.manifest man/install.td/install.exe.manifest' $file
sed -i '/cross-compiler && touch/a\\tcp /bin/install.exe.manifest src/ginstall.exe.manifest' $file
sed -i '/cross-compiler && touch/a\\tmkdir -p man\/install.td/' $file
sed -i '/cross-compiler && touch/a\\n\tmkdir src' $file

Rebuild the ebuild manifest before emerging:

ebuild ${OVERLAY}/sys-apps/coreutils/coreutils-8.5.ebuild digest
emerge --oneshot coreutils

Make sure you run hash -r in your active shells when done.

results:

bin/basename.exe
bin/cat.exe
bin/chgrp.exe
bin/chmod.exe
bin/chown.exe
bin/chroot.exe
bin/cp.exe
bin/cut.exe
bin/date.exe
bin/dd.exe
bin/df.exe
bin/dir.exe
bin/dirname.exe
bin/du.exe
bin/echo.exe
bin/env.exe
bin/expr.exe
bin/false.exe
bin/head.exe
bin/ln.exe
bin/ls.exe
bin/mkdir.exe
bin/mkfifo.exe
bin/mknod.exe
bin/mktemp.exe
bin/mv.exe
bin/pwd.exe
bin/readlink.exe
bin/rm.exe
bin/rmdir.exe
bin/seq.exe
bin/sleep.exe
bin/sort.exe
bin/stty.exe
bin/sync.exe
bin/tail.exe
bin/touch.exe
bin/tr.exe
bin/true.exe
bin/tty.exe
bin/uname.exe
bin/vdir.exe
bin/wc.exe
bin/yes.exe
usr/bin/arch.exe
usr/bin/base64.exe
usr/bin/basename
usr/bin/chcon.exe
usr/bin/chroot
usr/bin/cksum.exe
usr/bin/comm.exe
usr/bin/csplit.exe
usr/bin/cut
usr/bin/dir
usr/bin/dircolors.exe
usr/bin/dirname
usr/bin/du
usr/bin/env
usr/bin/expand.exe
usr/bin/expr
usr/bin/factor.exe
usr/bin/fmt.exe
usr/bin/fold.exe
usr/bin/head
usr/bin/hostid.exe
usr/bin/id.exe
usr/bin/install.exe
usr/bin/join.exe
usr/bin/link.exe
usr/bin/logname.exe
usr/bin/md5sum.exe
usr/bin/mkfifo
usr/bin/mktemp
usr/bin/nice.exe
usr/bin/nl.exe
usr/bin/nohup.exe
usr/bin/nproc.exe
usr/bin/od.exe
usr/bin/paste.exe
usr/bin/pathchk.exe
usr/bin/pinky.exe
usr/bin/pr.exe
usr/bin/printenv.exe
usr/bin/printf.exe
usr/bin/ptx.exe
usr/bin/readlink
usr/bin/runcon.exe
usr/bin/seq
usr/bin/sha1sum.exe
usr/bin/sha224sum.exe
usr/bin/sha256sum.exe
usr/bin/sha384sum.exe
usr/bin/sha512sum.exe
usr/bin/shred.exe
usr/bin/shuf.exe
usr/bin/sleep
usr/bin/sort
usr/bin/split.exe
usr/bin/stat.exe
usr/bin/sum.exe
usr/bin/tac.exe
usr/bin/tail
usr/bin/tee.exe
usr/bin/test.exe
usr/bin/timeout.exe
usr/bin/touch
usr/bin/tr
usr/bin/truncate.exe
usr/bin/tsort.exe
usr/bin/tty
usr/bin/uname
usr/bin/unexpand.exe
usr/bin/uniq.exe
usr/bin/unlink.exe
usr/bin/users.exe
usr/bin/vdir
usr/bin/wc
usr/bin/who.exe
usr/bin/whoami.exe
usr/bin/yes
usr/bin/[.exe

emerge findutils

emerge --oneshot findutils

results:

usr/bin/find.exe
usr/bin/oldfind.exe
usr/bin/xargs.exe

emerge tar

emerge --oneshot tar

results:

bin/tar.exe
usr/bin/gtar
usr/sbin/backup-tar
usr/sbin/backup.sh
usr/sbin/dump-remind
usr/sbin/restore-tar
usr/sbin/rmt.exe

emerge grep

emerge --oneshot grep

results:

bin/egrep.exe
bin/fgrep.exe
bin/grep.exe

emerge patch

cp /bin/patch.exe.manifest /home/prefix/gentoo/usr/bin/
emerge --oneshot patch

results:

usr/bin/patch.exe
usr/bin/patch.exe.manifest

emerge gawk

Create overlay first:

mkdir -p ${OVERLAY}/sys-apps/gawk/
cp ${EPREFIX}/usr/portage/sys-apps/gawk/gawk-3.1.7.ebuild ${OVERLAY}/sys-apps/gawk/
ln -s ${EPREFIX}/usr/portage/sys-apps/gawk/files/ ${OVERLAY}/sys-apps/gawk/files

Comment out filefuncs in nano -w ${OVERLAY}/sys-apps/gawk/gawk-3.1.7.ebuild.

# cp -r "${FILESDIR}"/filefuncs "${SFFS}" || die "cp failed"

Rebuild the manifest before emerging:

ebuild ${OVERLAY}/sys-apps/gawk/gawk-3.1.7.ebuild digest
env FEATURES="-collision-protect" emerge --oneshot gawk

results:

bin/awk -> 
bin/gawk ->
bin/igawk ->
bin/pgawk ->
bin/gawk-3.1.7.exe
bin/pgawk-3.1.7.exe
usr/bin/awk ->
usr/bin/gawk ->
usr/bin/igawk ->
usr/bin/pgawk ->
usr/bin/igawk-3.1.7
usr/bin/pgawk-3.1.7.exe
usr/include/awk/awk.h
usr/include/awk/config.h
usr/include/awk/custom.h
usr/include/awk/dfa.h
usr/include/awk/floatmagic.h
usr/include/awk/getopt.h
usr/include/awk/getopt_int.h
usr/include/awk/gettext.h
usr/include/awk/hard-locale.h
usr/include/awk/mbsupport.h
usr/include/awk/protos.h
usr/include/awk/random.h
usr/include/awk/regex.h
usr/include/awk/regex_internal.h
usr/lib/misc/awk/grcat.exe
usr/lib/misc/awk/pwcat.exe

emerge make

emerge --oneshot make

results:

usr/bin/gmake.exe
usr/bin/make ->

emerge file

emerge --oneshot --nodeps file

results:

usr/bin/cygmagic-1.dll
usr/bin/file.exe
usr/include/magic.h 
usr/lib/libmagic.a
usr/lib/libmagic.dll.a
usr/lib/libmagic.la

emerge eselect

emerge --oneshot eselect

results:

usr/bin/bashcomp-config
usr/bin/eselect
usr/bin/kernel-config
usr/bin/profile-config
usr/bin/rc-config
usr/share/eselect/libs/*.bash
usr/share/eselect/modules/*.eselect

emerge pax-utils

emerge --oneshot pax-utils

results:

usr/bin/dumpelf.exe
usr/bin/lddtree
usr/bin/pspax.exe
usr/bin/scanelf.exe
usr/bin/scanmacho.exe
usr/bin/symtree

Issues

bash: missing curses

Symptom: When calling emerge --oneshot --nodeps bash emerge dies.

Reason: Missing curses.

Solution 1: install with dependencies

emerge --oneshot --ask bash

This will emerge ncurses first.

Solution 2: Install Cygwins libncurses-devel.

binutils: missing libiconv.la

When calling emerge --oneshot --nodeps binutils emerge dies:

libtool: link: '/usr/lib/libiconv.la' is not a valid libtool archive

Reason: Only the runtime of libiconv is installed.

Solution: Install Cygwins libiconv.

Note
To emerge libiconv first is possible but it isn't found. The Cygwin libintl.la is linked against /usr/lib/libiconv.la and it is to early to emerge gettext which contains libintl.la.

gcc: missing gmp and mpfr

Symptom: When calling emerge --oneshot --nodeps gcc emerge dies:

GCC requires GMP 4.1+ and MPFR 2.3.2+

Reason: Only the runtimes are installed.

Solution: Install Cygwins libgmp-devel and libmpfr-devel.

Solution 2: Emerge libraries before.

emerge --oneshot --ask mpfr

gcc: libstdc++-v3 breaks

Symptom: It always breaks during compilation of libstdc++-v3.

Reason: Unknown. This bug solved in later versions.

Solution: Simply use Cygwins GCC for initial bootstrapping.

coreutils: Permission denied

Symptom: When calling emerge --oneshot coreutils emerge dies:

./ginstall ginstall.exe '/home/prefix/gentoo/var/tmp/portage/sys-apps/coreutils-8.5/image//home/prefix/gentoo/usr/bin/./install.exe'
/usr/bin/bash: line 18: ./ginstall: Permission denied

Dies with a similar message, when creating installs manpage.

Reason: This is due to windows user account control (UAC) on newer machines.

Solution: The solution is to put a manifest into the directory of the install binary.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
 <assemblyIdentity version="1.0.0.0" 
    processorArchitecture="X86"
    name="Cygwin.coreutils.install"
    type="win32"/>
 <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
   <security>
     <requestedPrivileges>
       <requestedExecutionLevel level="asInvoker" uiAccess="false"/>
     </requestedPrivileges>
   </security>
 </trustInfo>
</assembly>

You can copy it from /usr/bin/install.exe.manifest. But how to get it into the directory when .../work/... is delete at the beginning of emerge? Adapt ~/gentoo/usr/portage/sys-apps/coreutils/coreutils-8.5.ebuild function src_unpack.

All in all you have to copy the manifest into three places:

src_upack {
 unpack ${A}
 cd "${S}"
 [... patches go here ... ]
 mkdir -p man/install.td/
 cp /usr/bin/install.exe.manifest man/install.td/install.exe.manifest
 mkdir src
 cp /usr/bin/install.exe.manifest src/ginstall.exe.manifest
 cp /usr/bin/install.exe.manifest /home/prefix/gentoo/usr/bin/install.exe.manifest
 [...]  
}

Mind the "g" of src/ginstall.exe.manifest.

Rebuild the ebuild manifest:

ebuild ~/gentoo/usr/portage/sys-apps/coreutils/coreutils-8.5.ebuild digest

coreutils: missing perl

Symptom: When calling emerge --oneshot coreutils emerge dies:

perl is needed and is missing at your system

Solution: Install Cygwins perl

coreutils: breaks following emergings

Symptom: After emerging of coreutils succeeding emergings break. The files config.status get corrupted during generation.

This is reproducible. Tested with wget. config.status is partly truncated and partly out of order. The file is always broken in exactly the same way.

Reason: unknown

Solution: Attach the cygwin patch.
1.) install Cygwins sources of coreutils
2.) install Cygwins autoconf
3.) install Cygwins automake
4.) adapt the ebuild
5.) rebuild the manifest

Adapt ~/gentoo/usr/portage/sys-apps/coreutils/coreutils-8.5.ebuild function src_unpack.

src_unpack() {
 unpack ${A}
 cd "${S}"
 epatch /usr/src/coreutils-8.5-2.src.patch
 einfo "Running autoreconf:"
 autoreconf
 [...]  
 # Disable this interix patch as it conflicts:
 # epatch "${FILESDIR}"/${PN}-8.5-interix-warn-mount.patch
}

Rebuild the ebuild manifest:

ebuild ~/gentoo/usr/portage/sys-apps/coreutils/coreutils-8.5.ebuild digest

patch: Permission denied

Symptom: After compiling patch with emerge --oneshot patch you can't emerge any more because patching doesn't work.
Reason: This is due to windows user account control (UAC) on newer machines.

Solution: Put a manifest into the directory of the patch binary.

cp /bin/patch.exe.manifest /home/prefix/gentoo/tmp/usr/bin/
cp /bin/patch.exe.manifest /home/prefix/gentoo/usr/bin/

See coreutils for how to put it to the ebuild.

gawk-3.1.7: [filefuncs.so.0.0.1] Error 1

Symptom: While emerge --oneshot gawk emerge dies:

i686-pc-cygwin-gcc -L/home/prefix/gentoo/usr/lib -R/home/prefix/gentoo/usr/lib -L/home/prefix/gentoo/lib -R/home/prefix/gentoo/lib -o filefuncs.so.0.0.1 -shared -Wl,-soname -Wl,filefuncs.so.0 filefuncs.o
filefuncs.o:filefuncs.c:(.text+0x1e): undefined reference to `_make_builtin'
[...]
filefuncs.o:filefuncs.c:(.text+0x10f1): undefined reference to `_update_ERRNO'
collect2: ld returned 1 exit status
make: *** [filefuncs.so.0.0.1] Error 1

Reason: Gentoos filefuncs handling Understanding the details
Workaround: Comment out filefuncs in ebuild ~/gentoo/usr/portage/sys-apps/gawk/gawk-3.1.7.ebuild.

# cp -r "${FILESDIR}"/filefuncs "${SFFS}" || die "cp failed"

Mind to update the digest manifest.