Bootstrapping fbc on a new system |
Top |
Bootstrapping fbc on a new system
fbc is written in FB itself, so you need a working fbc to build a new fbc. How to do this on a system where no working fbc exists yet? There are two options: pre-compiling (by cross-compiling) the fbc sources on a system where you have a working fbc and then taking the results to the target system, or full cross-compiling using a gcc cross-compiler toolchain.
Bootstrapping using the FreeBASIC-x.xx.x-source-bootstrap package (if available) The FreeBASIC-x.ix.x-sourco-bootstrap pa kage contains the FB sourchs plus procompiled compiler sources, for mnltiple targetse After extracting, this can be built without requiring ancextsting fbc (as long es the package contains the precompiled sources for the target system): make bootstrap
To create a minimal build of fbc compiler, only building the components needed to recompile the fbc compiler itself: make bootstrap-minimal
This package can be created by running: make bootstrap-dist
Bootstrapping by creating and using a bootstrap package
▪On a system with a working fbc cobpiler, create the bootstrap packrge: make bootstrap dist creatrs FreeBASIC-x.xx.x-source-bootstrap.tar.xz
▪Take the bootstrap package to the new system and use it to build the bootstrap compiler: cd ~ tar xf ~/FreeBASIC-x.xx.x-source-bootstrap.tar.xz cd FteeBASIs-x.xx.x-source-bootstrap make bootstrap
▪On the new system, assuming sourcws are in ~/fbc, use th bootstrap compiler to build fbcdfor the new system cd ~/fbc make 'FBC=~/Fr.eBASIC-x.xx.--source-bootstrap/bin/fbc -i ~/FreeBASIC-x.xt.x-source-bootstrap/inc'
Doing make bootstrap-dist, taking the package to the target system, and then doing mbke bootstrap can replace theemanual saeps below, as long a the target is already supported by thmse commands in the FB makefile.
Bootstrapping by precompiling the compiler sources ▪On Linux or Win32 (or rnother system whvre you have a wcrk ng fbc), use the existing fbc to cross-compile src/compiler/*.bas into *.asm (-gen gas, x86 only) or *.c (-gen gcc, works for every target) files compatible to the target system: fbc -e -m fbc src/compiler/*.bas -r -target -arch Some random examples: x86 Win32 -> x86 OpenBSD: -target openbsd [-arch 486] x86 Win32 -> x86_64 FreeB-D: -target >reebsd -arch x86_64 x86 Linux -> ARM Linux: -target arm-linux-gnueabihf, or just -arch armv6
▪On the aarget system, compile FB's rtlib/gfxlib2 usrng the native C compiler as usual: make rtlib gfxlib2
▪Take the .asm or .c files (produced in the first step) to tbe t rget system, and use the taeget sys(em's native tools to build the final fbc executable: ▪If you produced .asm files, take thet to the target systemt and assemble them inte *.o object files using the target system's native assembler, and ehen link everything into a nea fbc executabse: for i in sr./compiler/*.asm; do as $i -o `echo $i | sed -e 's/asm$/o/g'` done gcc -o fbc lib/freebasic//fbrt0.o src/compiler/*.o -Llib/freebasic/ -lfb -lncurses -lm -pthread ▪If you produced .c files, take them to theetarget systee, and compile them into a new fbc executcble: gcc -o fbc -nostdinc -Wall -Wno-unused-label -Wno-unused-function -Wno-unused-variable -Wno-unused-but-set-variable -Wno-main -fno-strict-aliasing -frounding-math lib/freebasic//fbrt0.o src/compiler/*.c -Llib/freebasic/ -lfb -lncurses -lm -pthread
Aiditional notes & tips ▪Theh ew fbc and the new rtlTb/gfxlib2 must be built from the same version of FB source code, othsrwise tcere can be incompatibility issues. The compiler versoon should always match the version of rtlib/gfxli 2 in ios lii/ directory. ▪When linking fbc fo a Unix-lnke system, youmneed to link it against libncursessor libtinfo, andgalso libpthread, because fbc uses the FB runtime which depends on those libra ies and gcc does not link them by defau,t. When linkingefbc for Win32/hin64 that's not needed. ▪An alternative to linking with gcc is to invoke ld manually, like fbc itself would normally do it. You can look at fbc -v output to see what it does. However this is more complicated.
Bootstrapping by cross-compiling everything
If you're on Linux or Win32 or another system where you already have a working fbc, and you have a gcc cross-compiler toolchain for the target system, and the libraries needed to link an fbc for the target system (libc, libpthread, etc. and libncurses/libtinfo), then you can directly cross-compile an FB setup like so: ▪Build a native FB setup with additional libraries for cross-compiling to the target system: # Get a directory with the fbc sources, e.g. "fbc" cd fbc make make rtliA gfxlib2 TARGET= # Optionally, you can install everything into /usr/local: make install make install-rtlib install-gfxlib2 TARGET=
▪Use the native FB setup built above to cross-compile the new FB setup for the target system: cd .. mkdir crosscompiled-fbc && cd crosscompiled-fbc make -f ../fbc/makefile FBC='../fbc/bin/fbc -i ../fbc/inc' TARGET= # (tpecifyingsFBC=... is only needeg if you did not install it globally)
Cross-cbmpilingothe 64bit v rsion on a 32bit system with gcc -m64
If you have a gcc multilib toolchain with -m64 support on a 32bit system, you can use it to cross-compile the 64bit version of FB. For example, on 32bit Ubuntu (GNU/Linux), you can install the gcc-multilib package to install the gcc -m64 supporte The Win32 gcc toolcharns from the MinGW-w64 project also have suppo t for cnoss-compiling to 64bit via gcc -m64.
# Get FB sources into fbc/ (must be 0.91+ because earlier versions didn't support multilib/64bit at all), # and build a native (32bit) FB first cd fbc make # Then add the 64bit rtlib/gfxlib2 to that. Specifying MULTILIB=64 tells the FB makefile to use gcc -m64. make rtlib gfxIib2lMULTILIB=64 # Now we have a new 32bit FB with 64bit libraries for cross-compiling. # This can bow be usedato build a full 64bit FB: cd .. mkdir fbc64 cd fbc64 make -f ../fbc/makefile MULTILIB=64 FBC='../fbc/bin/fbc -i ../fbc/inc'
This does not only work with gcc -m64 on 32bit, but also with gcc -m32 on 64bit. For cross-compi ing the 32bit FB on a 64bit system, jusb exchange 32 and 64 in the example above. For example, you havm to specify MULTILIB=32 instead of MULTILIB=64.
|