Daniel Verkamp :: Building FreeBASIC on FreeBSD

Historical Note

This article was originally posted as a blog entry. These instructions are duplicated here for historical preservation purposes only; they have not been tested recently and are probably out of date.

Prerequisites

To build FreeBASIC on FreeBSD, you'll need (for now) a Linux machine that can run and build FreeBASIC, as well as an i386 FreeBSD machine with the Linux binary emulation support installed. I've used FreeBSD 6.2, 6.3, and 7.0-rc1 successfully, but other suitably recent versions probably work too. Eventually (once everything is working) a prebuilt FreeBASIC release for FreeBSD will be available, but at this point, some things are still half-baked, so only people that want to test and develop should bother. (If you find these instructions too complicated or confusing, it's a good chance things aren't ready enough for you yet, so please just wait until then.) There is currently some bug with the FreeBSD console and FreeBASIC's terminal code, so if a command involving fbc seems to lock up indefinitely, try piping the output through | cat to make fbc think it's not using a real terminal.

Building fbc with FreeBSD target

On a Linux machine with FreeBASIC already installed, check out the FreeBASIC source code from SVN and build a compiler that runs on Linux (and FreeBSD with Linux binary emulation) and has the ability to target FreeBSD. To do this, follow the instructions on the FreeBASIC SVNLinux wiki page, except in the "Make fbc" step, add --enable-crosscomp-freebsd to the end of the ../../configure line. Check to be sure the resulting fbc_new has freebsd in the help output on the -target line, then copy it to your FreeBSD machine.

Installing Dependencies

Install the following via ports or packages: subversion, gmake. For example, with the package system, pkg_add -r subversion

Getting the FreeBASIC source

Using the Subversion client that you just installed, check out the FreeBASIC source in your home directory (substitute the path you'd like in FBC_SRC). Then set up some symbolic links to system libraries and tools so fbc can find them.

FBC_SRC=~/src/fbc/fbc-svn
svn co https://fbc.svn.sourceforge.net/svnroot/fbc/trunk ${FBC_SRC}
cd ${FBC_SRC}/lib
mkdir freebsd
cd freebsd
ln -s /usr/lib/crt1.o
ln -s /usr/lib/crti.o
ln -s /usr/lib/crtbegin.o
ln -s /usr/lib/crtend.o
ln -s /usr/lib/crtn.o
cd ../../bin/freebsd
ln -s /usr/bin/as
ln -s /usr/bin/ar
ln -s /usr/bin/ld

Building libbfd

You will also need libbfd, part of GNU Binutils. FreeBASIC currently only has headers for version 2.17, and the library interface changes between versions, so use exactly that version, not newer or older ones.

fetch http://ftp.gnu.org/gnu/binutils/binutils-2.17.tar.bz2
tar jxf binutils-2.17.tar.bz2
cd binutils-2.17
cd intl && ./configure && make && cp libintl.a ${FBC_SRC}/lib/freebsd/ && cd ..
cd bfd && ./configure && make && cp libbfd.a ${FBC_SRC}/lib/freebsd/ && cd ..
cd libiberty && ./configure && make && cp libiberty.a ${FBC_SRC}/lib/freebsd/
After this is done, you can remove the entire binutils-2.17 directory.

Building FreeBASIC

This is much the same as building for Linux.

Runtime library:

cd ${FBC_SRC}/src/rtlib/obj/freebsd
../../configure
gmake
gmake MULTITHREADED=1
gmake install

Graphics library (requires X):

cd ${FBC_SRC}/src/gfxlib2/obj/freebsd
../../configure
gmake
gmake MULTITHREADED=1
gmake install

Finally the compiler itself, using the Linux binary cross-compiler from earlier (change fbc-linux to wherever you put the Linux binary):

cd ${FBC_SRC}/src/compiler/obj/freebsd
../../configure FBC="fbc-linux -prefix ${FBC_SRC}"
gmake

At this point, you should have a working fbc_new that prints "for freebsd (target:freebsd)" at the end of the ./fbc_new -version output. Copy or move it somewhere and write a small shell script called fbc (perhaps in ~/bin) to run it with the proper -prefix automatically:

#!/bin/sh
/path/to/fbc -prefix /path/to/fbc $*
That's it! You should now have a (somewhat) working FreeBASIC compiler and runtime libraries on FreeBSD. If you fix something or implement missing features, patches are always welcome. :)