FreeBASIC マニュアルのトップに戻る

FreeBASIC DevBootstrap

目次→FreeBASIC のハッキング→FreeBASIC でのハッキングのための情報Bootstrapping fbc on a new system←オリジナル・サイト

fbc を新しいシステムでブートストラップ/クロス・コンパイル



fbc は、FB 自体で書かれています。このため、新しい fbc を構築するためには、作業用の fbc が必要です。
まだ使える fbc が存在しないシステム上では、どのようにすればできるでしょうか?
2つの選択肢があります:fbc が動作しているシステム上で fbc ソースを事前コンパイルして(クロス・コンパイルで)、目標システムに結果を持って行きます。または、gcc クロス・コンパイラ・ツールチェーンを使って、完全クロス・コンパイルすることです。

Bootstrapping using the FreeBASIC-x.xx.x-source-bootstrap package (if available)

FreeBASIC-x.xx.x-source-bootstrap パッケージには、複数のターゲット用の FBソースと、プリコンパイルされたコンパイラソースが含まれています。
抽出後、既存の fbc を必要とせずにこれを構築できます。(パッケージに、ターゲットシステムの、プリコンパイル済みソースが含まれている場合):
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
  1. On a system with a working fbc compiler, create the bootstrap package:
    make bootstrap-dist

    creates FreeBASIC-x.xx.x-source-bootstrap.tar.xz

  2. 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 FreeBASIC-x.xx.x-source-bootstrap
    make bootstrap


  3. On the new system, assuming sources are in ~/fbc, use the bootstrap compiler to build fbc for the new system
    cd ~/fbc
    make 'FBC=~/FreeBASIC-x.xx.x-source-bootstrap/bin/fbc -i ~/FreeBASIC-x.xx.x-source-bootstrap/inc'


Doing make bootstrap-dist, taking the package to the target system, and then doing make bootstrap can replace the manual steps below, as long as the target is already supported by these commands in the FB makefile.

Bootstrapping by precompiling the compiler sources

  1. On Linux or Win32 (or another system where you have a working 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 <mytargetos> -arch <mytargetarch>
    		
    Some random examples:
    x86 Win32 -> x86 OpenBSD: -target openbsd [-arch 486]
    x86 Win32 -> x86_64 FreeBSD: -target freebsd -arch x86_64
    x86 Linux -> ARM Linux: -target arm-linux-gnueabihf, or just -arch armv6


  2. On the target system, compile FB's rtlib/gfxlib2 using the native C compiler as usual:
    make rtlib gfxlib2


  3. Take the .asm or .c files (produced in the first step) to the target system, and use the target system's native tools to build the final fbc executable:

Additional notes & tips
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:

  1. 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 rtlib gfxlib2 TARGET=<gcc-target-id>
    
    # Optionally, you can install everything into /usr/local:
    make install
    make install-rtlib install-gfxlib2 TARGET=<gcc-target-id>


  2. 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=<gcc-target-id>
    # (Specifying FBC=... is only needed if you did not install it globally)


Cross-compiling the 64bit version 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 support. The Win32 gcc toolchains from the MinGW-w64 project also have support for cross-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 gfxlib2 MULTILIB=64

# Now we have a new 32bit FB with 64bit libraries for cross-compiling.
# This can now be used to 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-compiling the 32bit FB on a 64bit system, just exchange 32 and 64 in the example above. For example, you have to specify MULTILIB=32 instead of MULTILIB=64.


FreeBASIC の開発者用情報 に戻る
目次に戻る
ページ歴史:2019-04-21 07:23:04
日本語翻訳:WATANABE Makoto、原文著作者:DkLwikki

ホームページのトップに戻る

表示-非営利-継承