Home

DrV :: Blog

Blog home | RSS freebasic rss

08-22-2008

Building FreeBASIC on OpenBSD

fbgfx_flame on OpenBSD

Since someone asked, I decided to try porting FreeBASIC to OpenBSD. Luckily, it was not hard at all due to my previous work on porting to FreeBSD. After a couple of days, I have a basic working port.

Prerequisites

You'll need an i386 OpenBSD installation; I have only tested this on the latest release at this time, OpenBSD 4.3, but it will probably work on older releases as well. You will also need an existing fbc executable for OpenBSD, unless you would like to cross-compile and assemble and link the files by hand. Download this file and extract it in your home directory (it expands to fbc): fbc-openbsd-i386-r5084.gz.


Installing Dependencies

To build FreeBASIC on OpenBSD, you'll need to install some packages. This is how I installed the dependencies on OpenBSD 4.3:

export PKG_PATH=ftp://ftp.openbsd.org/pub/OpenBSD/4.3/packages/i386/
pkg_add -i gmake
pkg_add -i autoconf # pick the latest version; currently, it is autoconf-2.61p1
pkg_add -i automake # pick the latest version; currently, it is automake-1.9.6p2
pkg_add -i 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).

FBC_SRC=~/src/fbc/fbc-svn
mkdir -p ${FBC_SRC}
svn co https://fbc.svn.sourceforge.net/svnroot/fbc/trunk/FreeBASIC ${FBC_SRC}

Building FreeBASIC

This is much the same as building for Linux. Currently, I have not tested building with objinfo (bfd) enabled, because the bfd.h header shipped with OpenBSD seems to be broken, but it will probably work if you build and install your own copy of libbfd.

Runtime library:

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

To make things simpler, we will copy the runtime libraries to their proper location so we can link the compiler successfully later before running install.sh. Since the prebuilt fbc binary is configured with /usr as its prefix, we will copy the files to /usr/lib/freebasic/openbsd/.

su
mkdir /usr/lib/freebasic
mkdir /usr/lib/freebasic/openbsd
cp libfb*.a fbrt0.o /usr/lib/freebasic/openbsd/
exit

Graphics library (requires X):

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

Finally the compiler itself, using the existing OpenBSD compiler binary downloaded earlier:

cd ${FBC_SRC}/src/compiler/obj/openbsd
../../configure FBC=~/fbc --prefix=/usr --disable-objinfo
gmake
gmake install

Now we will do a full installation of FreeBASIC:

cd ${FBC_SRC}
su
./install.sh -i
exit
If all goes well, you should get a message stating that FreeBASIC has been successfully installed.

Note that this port has been very minimally tested; if you have any trouble, feel free to file a bug report or post questions on the FreeBASIC forums.

[category: /freebasic | permalink ]

02-10-2008

Building FreeBASIC on FreeBSD

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. :)

[category: /freebasic | permalink ]


Powered by Blosxom
Last updated: 2008-Nov-24
Contact: daniel@drv.nu