commit:     d29682528a767c6fb033f121730b9b4bb946cba0
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Sat Mar  7 05:40:17 2026 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sun Mar 15 22:21:10 2026 +0000
URL:        https://gitweb.gentoo.org/proj/crossdev.git/commit/?id=d2968252

crossdev: initial GNU Hurd support

Introduce GNU Hurd support which needs the following new packages:
* dev-util/mig
* sys-kernel/hurd
* sys-kernel/gnumach

We have to build a few packages twice because of dependencies between
headers:
1) sys-kernel/gnumach[headers-only]
2) dev-util/mig
3) sys-kernel/gnumach[-headers-only] (which uses GNU MIG)
4) sys-kernel/hurd[headers-only]
5) sys-libs/glibc

These are handled as K{2,3}PKG with some hacks. I'm not completely happy
with this but I don't see a better way of doing it.

As a TODO, there's still an issue I think with the final headers-only
state in package.use but need to poke at that.

Also had to fix a few minor *-gnu => Linux assumptions (now match *-linux-gnu*
first).

`crossdev i686-gnu` gets me a working toolchain now on x86_64-pc-linux-gnu:
```
$ file /tmp/a
/tmp/a: ELF 32-bit LSB pie executable, Intel i386, version 1 (SYSV), 
dynamically linked, interpreter /lib/ld.so, for GNU/Hurd 0.0.0, not stripped
```

More to do surely, but a start. I've also built bash with
`i686-gnu-emerge app-shells/bash`.

Some honourable mentions to prior art from Sergei Trofimovich <slyich <AT> 
gmail.com>
at https://trofi.github.io/posts/208-crossdev-and-gnu-hurd.html and
Matija Skala <mskala <AT> gmx.com> at https://github.com/matijaskala/hurd.
Alexey Shvetsov <alexxy <AT> gentoo.org> also shared with me his past work
on it at https://github.com/alexxy/gentoo-hurd. In the end, I've gone for
a different approach than those.

Signed-off-by: Sam James <sam <AT> gentoo.org>

 crossdev | 52 ++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 48 insertions(+), 4 deletions(-)

diff --git a/crossdev b/crossdev
index 3c4666d..07e3f5e 100755
--- a/crossdev
+++ b/crossdev
@@ -419,7 +419,8 @@ parse_target() {
                        LPKG="dietlibc"
                        LCAT="dev-libs"
                        ;;
-               *-gnu*)
+
+               *-linux*gnu*)
                        LPKG="glibc"
                        # gcc would not find -lpthread without static libraries 
while building
                        # its copy of libgomp.
@@ -461,6 +462,24 @@ parse_target() {
                        WITH_DEF_HEADERS="no"
                        ;;
 
+               # GNU Hurd
+               *-gnu)
+                       LPKG="glibc"
+
+                       # GNU Mach first has to be built w/ headers-only
+                       KPKG="gnumach"
+                       # GNU MIG needs those initial GNU Mach headers
+                       K2CAT="dev-util"
+                       K2PKG="mig"
+                       # We need GNU Hurd headers for glibc too
+                       K3CAT="sys-kernel"
+                       K3PKG="hurd"
+
+                       # gcc would not find -lpthread without static libraries 
while building
+                       # its copy of libgomp.
+                       LUSE+=" static-libs"
+                       ;;
+
                # Now for the BSDs ...
                *-freebsd*)
                        LCAT="sys-freebsd" LPKG="freebsd-lib"
@@ -1645,7 +1664,7 @@ for f in package.{accept_keywords,env,mask,use} 
env/${CROSSDEV_OVERLAY_CATEGORY}
        rm -f "${f}/${CROSSDEV_OVERLAY_CATEGORY}"
 done
 
-pkglist=( K L )
+pkglist=( K K2 K3 L )
 if [[ ${LLVM} == "yes" ]] ; then
        pkglist+=( R C A P U )
 else
@@ -1924,9 +1943,34 @@ if ! ex_fast ; then
        if is_s2 ; then
                set_eopts_on_pkg_status ${KPKG} crosscompile_opts_headers-only 
headers-only
 
-               USE="${KUSE} ${USE}" \
-               CROSSCOMPILE_OPTS="" \
+               USE="${KUSE} ${USE} headers-only" \
+               CROSSCOMPILE_OPTS="headers-only" \
                        doemerge ${KPKG}
+
+               if [[ -n ${K2PKG} ]] ; then
+                       # KPKG may need K2PKG to install everything, so
+                       # build it as a dependency first.
+                       set_eopts_on_pkg_status ${K2PKG} crosscompile_opts
+
+                       USE="${KUSE} ${USE} headers-only" \
+                       CROSSCOMPILE_OPTS="headers-only" \
+                               doemerge ${K2PKG}
+
+                       # Go again now we have it.
+                       USE="${KUSE} ${USE}" \
+                       CROSSCOMPILE_OPTS="" \
+                               doemerge ${KPKG}
+               fi
+
+               if [[ -n ${K3PKG} ]] ; then
+                       # LPKG may need K3PKG to install everything, so
+                       # build it as a dependency first.
+                       set_eopts_on_pkg_status ${K3PKG} 
crosscompile_opts_headers-only headers-only
+
+                       USE="${KUSE} ${USE} headers-only" \
+                       CROSSCOMPILE_OPTS="headers-only" \
+                               doemerge ${K3PKG}
+               fi
        fi
 
        # stage3: full C library (headers/libs/etc...)

Reply via email to