- Warning:* this is full of hacks and I don't pretend to provide any complete detailed and completely reproducible steps for getting a new Ada compiler.
Before proceeding, make sure you have `gmake` installed because the BSD make uses an old Makefile syntax and is not able to handle GNU specific Makefiles.
``` pkg install gmake ```
- Get gcc6-aux from an old FreeBSD installation
First step is to get the `gcc6-aux` port as is from an old FreeBSD installation. Basically, a tar-gz of the `/usr/local/gcc6-aux` directory tree is enougth. Basically, what I did is to run a `tar cf /tmp/gcc.tar /usr/local/gcc6-aux` on an old FreeBSD and then extract that tar as is on the FreeBSD 13.1 system (Of course, it must be the same architecture).
- Build gcc 12
Get the GCC 12 sources from https://gcc.gnu.org and extract them:
``` tar xzf gcc-12.1.0.tar.xz ```
Building GCC must be made in another directory and we must also setup the `PATH` to give access to the old Ada compiler. You must setup and run the configure script as follows:
``` export PATH=/usr/local/gcc6-aux/bin:$PATH mkdir build cd build ../gcc-12.1.0/configure
disable-nls enable-gnu-indirect-function enable-host-shared with-as=/usr/local/bin/as with-gmp=/usr/local with-ld=/usr/local/bin/ld with-system-zlib without-zstd enable-libada localstatedir=/var prefix=/build/gcc-12.1 build=x86_64-portbld-freebsd13.0 --enable-languages=c,ada,c++ ```
with-as` and `with-ld` are important to use the correct `as` and `ld` commands. A subset of the above configure command is taken from the configure command that FreeBSD ports is using to build GCC 12.
After the configure, run the `gmake` command:
``` gmake ```
or to run several compilations in parallel use:
``` gmake -j4 ```
While building, the compiler is built a first time with `gcc6-aux` and another time with itself. Building the Ada libraries failed for me with:
``` /home/ciceron/src/build/./gcc/xgcc -B/home/ciceron/src/build/./gcc/ -B/build/gcc-12.1/x86_64-portbld-freebsd13.0/bin/ -B/build/gcc-12.1/x86_64-portbld-freebsd13.0/lib/ -isystem /build/gcc-12.1/x86_64-portbld-freebsd13.0/include -isystem /build/gcc-12.1/x86_64-portbld-freebsd13.0/sys-include -fchecking=1 -c -g -O2 -m32 -fpic -W -Wall -gnatpg -nostdinc -m32 s-exnllf.adb -o s-exnllf.o s-exnllf.ads:38:04: warning: in instantiation at s-dorepr.adb:82 enabled by default s-exnllf.ads:38:04: warning: in instantiation at s-exponr.adb:54 enabled by default s-exnllf.ads:38:04: warning: "Temp" overlays smaller object enabled by default s-exnllf.ads:38:04: warning: program execution may be erroneous enabled by default s-exnllf.ads:38:04: warning: size of "Temp" is 96 enabled by default s-exnllf.ads:38:04: warning: size of "Rep64" is 64 enabled by default gmake9: *** ../gcc-interface/Makefile:301: s-exnllf.o Error 1 ```
This error is caused by some inconsistency between the floating point mantissa size returned by `Machine_Mantissa'` Ada predicate and the size of the floating point number. After hacking the `gcc/ada/libgnat/s-dorepr.adb` I've managed to build the Ada libraries.
After a successful build, installation in `/build/gcc-12.1` is done with:
``` gmake install ```
- Build gprbuild
Yet, another challenge is building gprbuild(https://github.com/AdaCore/gprbuild). First, get the following sources:
Then run the boostrap script from `gprbuild` and make sure to setup your PATH to use the new GCC Ada compiler:
``` export PATH=/build/gcc-12.1/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin cd gprbuild ./bootstrap.sh
with-xmlada=../xmlada with-kb=../gprconfig_kb --prefix=./bootstrap ```
Then, build again and install in the same location as GCC:
``` gmake prefix=/build/gcc-12.1 SOURCE_DIR=`pwd` setup gmake all gmake install ```
Don't stop at building only `gprbuild` because you'll probably need the `libgpr` library (if you want to build Ada Web Server(https://github.com/AdaCore/aws) which now depends on GNAT libcoll(https://github.com/AdaCore/gnatcoll-core) which needs libgpr).
``` gmake libgpr.build gmake libgpr.install ```
- Installation of vscode
It is possible to use vscode and the Ada plugin for development under FreeBSD. The vscode Ada plugin contains the `ada_language_server` binary which is executed as a language server for vscode. No binary is provided for FreeBSD but since the binary is provided for Linux, we can use it by using the Linux support in FreeBSD. First, install vscode with:
``` pkg install vscode ```
then, launch it and install the `Language Support for Ada` extension. When the extension is activated, you will see a message indicating that the language server cannot be started. There are two things to do:
- create a `freebsd` directory with the `ada_language_server` binary,
- activate and setup the Linux support in FreeBSD
For the first part, copy
``` cd ~/.vscode-oss/extensions/adacore.ada-23.0.8 cp -rp linux freebsd ```
Now we must setup the Linux support in FreeBSD, and follow the FreeBSD Chapter 10. Linux Binary Compatibility(https://docs.freebsd.org/en/books/handbook/linuxemu/).
Add in `/etc/rc.conf`:
``` linux_enable="YES" ```
and start with:
``` sudo service linux start ```
Install the `debootsrap`:
``` sudo pkg install debootstrap sudo debootstrap focal /compat/ubuntu. ```
Add the line in `/etc/sysctl.conf`:
``` compat.linux.emul_path="/compat/ubuntu" ```
and configure with:
``` sudo sysctl -f /etc/sysctl.conf ```
Mark the binary as Linux:
``` brandelf -t Linux ~/.vscode-oss/extensions/adacore.ada-23.0.8/freebsd/ada_language_server ```
Replace the symbolic link `/compat/ubuntu/lib64/ld-linux-x86-64.so.2` to a real file otherwise the Linux linker is not found by the kernel.
Now, restart vscode and the Ada language server should be started.
The description on how to build `ada_language_server` for FreeBSD is left as an exercise to the reader :-)