I am not entirely sure how it is solved on other OS (i only recall it seemed to be a huge hack, which needed a second set of libraries and headers, and a target specific compiler).
If you build x86 Haiku on 64 bit Haiku, you have to use the buildtools repo, which is essentially a crosscompiler, which targets 32 bit. MAybe that’s what you are searching for.
The buildtools compiler is not available in the Depot, you have to build it.
I don’t need “external” libs, only the basic C runtime and pthread library.
Publishing the sources is no problem, but “write a recipe to let the buildbots build the program” is beyond my knowledge at this point. I have quite some background in Linux, various BSDs (and macOS). On all these platforms, I just fire up my Makefile and that’s it - provided we have the “correct” GCC or Clang installed for the target platform. But, most important: For the Average Joe user, it is more convenient to just grab a pre-compiled binary, just as you would get it from your “native” package manager. So that is why I prefer to provide pre-compiled binaries for each supported platform (in addition to source code).
As said before, on Linux we can easily install “cross-build” version of GCC from the package manager, so I can build for x86_64, i686 and even aarch64 targets all from a single x86_64 machine. On FreeBSD, we can use -m32 and -m64 options of GCC to build for 32-Bit and 64-Bit systems from a single 64-Bit machine. And, on macOS, we can use -target option to build for x86_64 and aarch64 (Apple Silicon) from a single x86_64 MacBook. So, I was just hoping it would be somewhat similar on Haiku too
(my favorite platform is GNU/Hurd, because no fancy stuff like 64-Bit or multiple-processor support!)
After several hours, the i586-pc-haiku-gcc has now been created from the sources!
Command used to build was:
./configure --cross-tools-source ../buildtools --build-cross-tools x86
But the resulting i586-pc-haiku-gcc fails to find the fundamental header file:
make -B CC=/boot/home/Desktop/haiku/generated/cross-tools-x86/bin/i586-pc-haiku-gcc
/boot/home/Desktop/haiku/generated/cross-tools-x86/bin/i586-pc-haiku-gcc -Ilib/include -std=gnu99 -Wall -O3 -DNDEBUG -c frontend/src/utils.c -o frontend/obj/utils.o
In file included from frontend/src/utils.h:9,
frontend/src/platform.h:9:10: fatal error: stdlib.h: No such file or directory
9 | #include <stdlib.h>
Makefile:128: recipe for target 'frontend/obj/utils.o' failed
I see. Anyway, the required header files are there, somewhere in the generated/cross-tools-x86 directory. It’s just that the i586-pc-haiku-gcc binary doesn’t seem to be configured correctly to look for the headers in the right directory. I tried to explicitly add the directory where stdlib.h is located to the search path, with -I option, but it only resulted in additional errors. It seems like more “include” directories are needed, probably in a specific order. Not so easy to figure out. When I use cross-compiler like i686-linux-gnu-gcc on Linux machine, this binary “knows” how to find the headers for the target platform by itself. Can this be accomplished in Haiku system with the buildtools in a similar fashion?
At this point I have almost given up on the idea to cross-build for 32-Bit Haiku from 64-Bit Haiku system and will probably have to keep a separate 32-Bit system around. But Haiku has a package repository, where binary packages can be downloaded from (via pkgman tool). How do the package maintainers normally approach this? They always have to keep separate machines for providing 32-Bit and 64-Bit packages?
As mentionned above: we use haikuporter build servers. When we write a recipe and put it on the github repository, it is automatically compiled on our servers for all currently supported architectures. If there is a failure there, it can be fixed later in an update commit.
It is possible in theory but no one has written the needed procedure yet. So I don’t know how to do it.