Hello, It'd be useful that all these small cross-compilation howtos here and there be merged into the corresponding wiki page where it belongs,
./toolchain/cross-gnu.mdwn https://darnassus.sceen.net/~hurd-web/toolchain/cross-gnu/ Samuel Sergey Bugaev, le mar. 24 janv. 2023 22:29:15 +0300, a ecrit: > On Tue, Jan 24, 2023 at 8:23 PM Ryan Raymond <rjraym...@oakland.edu> wrote: > > > > Hello, > > I was reading the install instructions and I saw that they were incomplete. > > The system can't build right now I guess, but I wanted to fix that. I was > > wondering if the last person who built could point me in the general > > direction of how they think hurd is supposed to build? > > Hello! > > I'm unlikely to be the *last* person who compiled the Hurd, but I have > cross-compiled it from GNU/Linux just recently, and importantly I have > written some notes on how to do so. Dumping them below, hope this will > be useful. If you don't need to cross-compile, i.e. if you already > have a working Hurd installation; it's even easier, it's just > ./configure && make. > > Sergey > > ---- > > Install dependencies: bison, flex, the three libraries GCC needs. > > Set up the basic directory structure: > > $ export PREFIX=~/dev/crosshurd > $ export PATH=$PREFIX/bin:$PATH > $ mkdir $PREFIX && cd $PREFIX > $ mkdir src include i686-gnu > $ ln -s ../include i686-gnu/sys-include > $ ln -s ../lib i686-gnu/lib > $ cd src > > Build binutils: > > $ wget https://ftp.gnu.org/gnu/binutils/binutils-2.39.tar.gz > $ tar xf binutils-2.39.tar.gz > $ cd binutils-2.39 > $ mkdir build && cd build > $ ../configure --target=i686-gnu --prefix=$PREFIX --with-lib-path=$PREFIX/lib > $ make -j8 > $ make install > > Verify that e.g. `$PREFIX/bin/i686-gnu-nm -v` works. > > Now build GCC: > > $ wget https://ftp.gnu.org/gnu/gcc/gcc-12.2.0/gcc-12.2.0.tar.gz > $ tar xf gcc-12.2.0.tar.gz > $ cd gcc-12.2.0 > $ mkdir build && cd build > $ ../configure --prefix=$PREFIX --target=i686-gnu > --with-lib-path=$PREFIX/lib --disable-multilib --enable-languages=c > $ make -j8 all-gcc > $ make install-gcc > > Note that at this step we're only building GCC itself, not libgcc -- > that will have to wait until we install glibc headers. > > Next, we want to build MIG. MIG needs Mach headers, but we can't build > GNU Mach without MIG. So what we do is we 'make' GNU Mach twice, once > to install the headers, and later on once more to actually build it. > > $ git clone git://git.savannah.gnu.org/hurd/gnumach.git > $ cd gnumach > $ autoreconf -i > $ mkdir build && cd build > $ CC=gcc ../configure --prefix=$PREFIX --host=i686-gnu > $ make install-data > > At configuring step, it will warn that "mig was not found, we will not > be able to build a kernel, only install headers. Install or build mig > against them, and run configure again". This is exactly how we want it > at this first step. > > The trick here is to tell configure to use host's GCC instead of our > previously built i686-gnu-gcc. This is because we are not yet building > GNU Mach for real, we're only doing this to install the headers. But > we need to appease configure into generating a Makefile for us, hence > CC=gcc. > > Now we should have $PREFIX/include/mach/message.h, > $PREFIX/include/mach/i386/machine_types.defs and suchlike. > > Now, onto building MIG: > $ git clone git://git.savannah.gnu.org/hurd/mig.git > $ cd mig > $ autoreconf -i > $ mkdir build && cd build > $ ../configure --target=i686-gnu --prefix=$PREFIX > $ make -j8 > $ make install > > Now, before we build glibc, we should install Hurd headers similarly > to how we've installed Mach headers above: > > $ git clone git://git.savannah.gnu.org/hurd/hurd.git > $ cd hurd > $ autoreconf -i > $ mkdir build && cd build > $ CC=gcc ../configure --host=i686-gnu --without-parted > --without-libcrypt --without-libbz2 --without-libz --without-rump > $ make no_deps=t prefix=$PREFIX install-headers > > Now, it's finally glibc time: > > $ git clone https://sourceware.org/git/glibc.git > $ mkdir build && cd build > $ ../configure --build=$(../scripts/config.guess) --host=i686-gnu > --prefix=$PREFIX --with-headers=$PREFIX/include > $ make install-headers > > We also need to do some hacky things manually in order for this to > start looking enough like a real glibc installation: > > $ touch $PREFIX/include/gnu/stubs.h $PREFIX/lib/libc.so > $ make csu/subdir_lib && install csu/crt1.o csu/crti.o csu/crtn.o $PREFIX/lib > > Now we can go back to GCC and build libgcc: > > $ make configure-target-libgcc > $ make -j8 all-target-libgcc > $ make install-target-libgcc > > And now we can once again go to glibc and build it for real: > > $ make PARALLELMFLAGS=-j8 > $ make install > > At this point it should be possible to cross-compile a C hello world > for the Hurd with no ceremony: > > $ $PREFIX/bin/i686-gnu-gcc hello.c -o hello > > Now we can rebuild Mach and Hurd properly, if we want to: > > $ make distclean > $ ../configure --prefix=$PREFIX --host=i686-gnu > $ make -j8 > $ make install > > $ make distclean > $ ../configure --host=i686-gnu --without-parted --without-libcrypt > --without-libbz2 --without-libz --without-rump > $ make -j8 DESTDIR=$PREFIX install > -- Samuel --- Pour une évaluation indépendante, transparente et rigoureuse ! Je soutiens la Commission d'Évaluation de l'Inria.