Building a Package by Adding Ada Support to GCC14 in FreeBSD Ports
Last updated on
This guide explains the entire process of modifying the lang/gcc14 port in FreeBSD to enable Ada language support, compiling it, and finally generating an installable package file.
This process requires bootstrapping. That is, a working Ada compiler must already be installed on the system to build the Ada frontend (GNAT) of GCC 14.
Step 1: Install Bootstrap Compiler
First, install the gnat13 compiler to serve as the bootstrap for building GCC14. Without this step, the compilation of the GCC14 Ada frontend will fail.
sudo pkg install gnat13
Step 2: Set Environment Variables
Add the path of gnat13 to the beginning of the PATH environment variable so that the build system locates the compiler of the recently installed gnat13 before other GCC versions on the system.
# Add gnat13 path to the current shell session
export PATH=/usr/local/gnat13/bin:$PATH
# Verify that PATH is set correctly
echo $PATH
# Example output: /usr/local/gnat13/bin:/sbin:/bin:/usr/sbin:/usr/bin...
Set the CC and CXX environment variables to gcc and g++, respectively.
export CC=gcc
export CXX=g++
Step 3: Modify Port Files
Navigate to the lang/gcc14 port directory and modify the relevant files to ensure Ada-related files are included in the package.
cd /usr/ports/lang/gcc14
Refer to the following diff content to modify three files: Makefile, pkg-descr, and pkg-plist.
diff --git a/lang/gcc14/Makefile b/lang/gcc14/Makefile
index 3f2d7cf484..89ffefc12e 100644
--- a/lang/gcc14/Makefile
+++ b/lang/gcc14/Makefile
@@ -3,7 +3,7 @@ PORTVERSION= 14.2.0
PORTREVISION= 4
CATEGORIES= lang
MASTER_SITES= GCC
-PKGNAMESUFFIX= ${SUFFIX}
+PKGNAMESUFFIX= ${SUFFIX}-ada
MAINTAINER= salvadore@FreeBSD.org
COMMENT= GNU Compiler Collection 14
@@ -80,7 +80,7 @@ CONFIGURE_TARGET= x86_64-portbld-${OPSYS:tl}${OSREL}
CONFIGURE_ARGS+= --with-abi=elfv2
.endif
-LANGUAGES= c,c++,objc,fortran
+LANGUAGES= c,c++,objc,fortran,ada
.if ${ARCH} != i386 && !empty(PORT_OPTIONS:M*BOOTSTRAP)
LANGUAGES:= ${LANGUAGES},jit
.endif
@@ -134,6 +134,9 @@ INFO= gcc${SUFFIX}/cpp \
gcc${SUFFIX}/gccinstall \
gcc${SUFFIX}/gccint \
gcc${SUFFIX}/gfortran \
+ gcc${SUFFIX}/gnat-style \
+ gcc${SUFFIX}/gnat_rm \
+ gcc${SUFFIX}/gnat_ugn \
gcc${SUFFIX}/libgccjit \
gcc${SUFFIX}/libgomp
# Release tarballs (as opposed to snapshots) always carry this.
diff --git a/lang/gcc14/pkg-descr b/lang/gcc14/pkg-descr
index 4802e1f26c..5987959593 100644
--- a/lang/gcc14/pkg-descr
+++ b/lang/gcc14/pkg-descr
@@ -1,3 +1,3 @@
GCC, the GNU Compiler Collection, supports a number of languages.
-This port installs the C, C++, and Fortran front ends as gcc14, g++14,
-and gfortran14, respectively.
+This port installs the C, C++, Fortran, and Ada front ends as gcc14, g++14,
+gfortran14, and gnat14 respectively.
diff --git a/lang/gcc14/pkg-plist b/lang/gcc14/pkg-plist
index 8dcc98c6dd..26c9ba393d 100644
--- a/lang/gcc14/pkg-plist
+++ b/lang/gcc14/pkg-plist
@@ -17,6 +17,16 @@ bin/gcov%%SUFFIX%%
bin/gcov-dump%%SUFFIX%%
bin/gcov-tool%%SUFFIX%%
bin/gfortran%%SUFFIX%%
+bin/gnat%%SUFFIX%%
+bin/gnatbind%%SUFFIX%%
+bin/gnatchop%%SUFFIX%%
+bin/gnatclean%%SUFFIX%%
+bin/gnatkr%%SUFFIX%%
+bin/gnatlink%%SUFFIX%%
+bin/gnatls%%SUFFIX%%
+bin/gnatmake%%SUFFIX%%
+bin/gnatname%%SUFFIX%%
+bin/gnatprep%%SUFFIX%%
bin/lto-dump%%SUFFIX%%
include/gcc%%SUFFIX%%/ISO_Fortran_binding.h
share/man/man1/cpp%%SUFFIX%%.1.gz
Step 4: Compile and Packaging
Since all file modifications are complete, proceed with compilation and packaging using the make package command.
# Proceed with compilation and package generation simultaneously
make package
- Compilation Time: This process may take anywhere from tens of minutes to several hours, depending on system specifications.
makeBehavior: If the source code is not yet compiled,make packageautomatically executes the compilation (build) phase first before generating the package.
Step 5: Package Verification, Installation, and Validation
Once compilation is complete, this step involves installing the built package onto the system and verifying it is applied correctly.
Verify Build Artifacts: Package File Inspection
First, verify that the package file has been created correctly.
The generated package is located in work/pkg/ under the port directory.
ls -l work/pkg/
You should see a file with a name similar to gcc14-14.2.0_4.pkg.
Before installation, you can verify whether gnat related files are actually included in the package using the following command. This is an effective way to validate if the build successfully included Ada.
pkg info -l -F work/pkg/gcc14-14.2.0_4.pkg | grep gnat
/usr/local/bin/gnat14
/usr/local/bin/gnatbind14
/usr/local/bin/gnatchop14
/usr/local/bin/gnatclean14
/usr/local/bin/gnatkr14
/usr/local/bin/gnatlink14
/usr/local/bin/gnatls14
/usr/local/bin/gnatmake14
/usr/local/bin/gnatname14
/usr/local/bin/gnatprep14
/usr/local/lib/gcc14/gcc/x86_64-portbld-freebsd14.3/14.2.0/adainclude/gnat.ads
/usr/local/lib/gcc14/gcc/x86_64-portbld-freebsd14.3/14.2.0/adalib/libgnat.a
/usr/local/lib/gcc14/gcc/x86_64-portbld-freebsd14.3/14.2.0/adalib/libgnat-14.so
/usr/local/lib/gcc14/gcc/x86_64-portbld-freebsd14.3/14.2.0/adalib/gnat.ali
/usr/local/lib/gcc14/gcc/x86_64-portbld-freebsd14.3/14.2.0/adalib/libgnat.so
/usr/local/lib/gcc14/gcc/x86_64-portbld-freebsd14.3/14.2.0/adalib/libgnat_pic.a
/usr/local/libexec/gcc14/gcc/x86_64-portbld-freebsd14.3/14.2.0/gnat1
/usr/local/share/info/gcc14/gnat-style.info
/usr/local/share/info/gcc14/gnat_rm.info
/usr/local/share/info/gcc14/gnat_ugn.info
If paths such as .../bin/gnat14 and .../bin/gnatmake14 are displayed as shown above, the Ada components have been correctly included.
Installation Options: make reinstall vs. pkg add
There are two methods to install the package on the system. In most cases, the first method, make reinstall, is recommended.
-
Method 1: Using
make reinstallSituation: It is highly likely that
gcc14is already installed on the FreeBSD system because many other programs depend on it. In this case, themake installcommand will fail due to conflicts with the existing package.Solution: The
make reinstallcommand first safely removes the existinggcc14installation and then installs the newly built Ada-supported version in its place. This command handles removal and installation automatically, simplifying the procedure.# Remove the existing package and reinstall the newly built version make reinstall -
Method 2: Using
pkg add(Manual Installation and Archiving)Purpose: This method is used when transferring the generated
.pkgfile to another system or keeping it for backup purposes.# Install directly using the pkg add command (requires root privileges) $ sudo pkg add ./work/pkg/gcc14-14.2.0_4.pkg Installing gcc14-14.2.0_4... the most recent version of gcc14-14.2.0_4 is already installedThis method may also fail if
gcc14is already installed on the system. In this case, you can use the-f(force) option to forcibly overwrite the existing installed package.$ sudo pkg add -f work/pkg/gcc14-14.2.0_4.pkg Installing gcc14-14.2.0_4... package gcc14 is already installed, forced install
Final Installation Verification
After installation is complete, open a new terminal and verify that the Ada compiler is correctly recognized.
# Check gnat version
gnat14 --version
GNAT 14.2.0
Copyright 1996-2024, Free Software Foundation, Inc.
To list Ada build switches use --help-ada
List of available commands
gnat bind gnatbind14
gnat chop gnatchop14
gnat clean gnatclean14
gnat compile gnatmake14 -f -u -c
gnat check gnatcheck14
gnat elim gnatelim14
gnat krunch gnatkr14
gnat link gnatlink14
gnat list gnatls14
gnat make gnatmake14
gnat metric gnatmetric14
gnat name gnatname14
gnat preprocess gnatprep14
gnat pretty gnatpp14
gnat stack gnatstack14
gnat stub gnatstub14
gnat test gnattest14
# Check gcc detailed information
gcc14 -v
Using built-in specs.
COLLECT_GCC=gcc14
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc14/gcc/x86_64-portbld-freebsd14.3/14.2.0/lto-wrapper
Target: x86_64-portbld-freebsd14.3
Configured with: /usr/ports/lang/gcc14/work/gcc-14.2.0/configure --disable-multilib --without-isl --with-build-config=bootstrap-debug --disable-nls --disable-libssp --enable-gnu-indirect-function --enable-host-shared --enable-plugin --libdir=/usr/local/lib/gcc14 --libexecdir=/usr/local/libexec/gcc14 --program-suffix=14 --with-as=/usr/local/bin/as --with-gmp=/usr/local --with-gxx-include-dir=/usr/local/lib/gcc14/include/c++/ --with-gxx-libcxx-include-dir=/usr/include/c++/v1 --with-ld=/usr/local/bin/ld --with-pkgversion='FreeBSD Ports Collection' --with-system-zlib --without-zstd --enable-languages=c,c++,objc,fortran,jit,ada --prefix=/usr/local --localstatedir=/var --mandir=/usr/local/share/man --infodir=/usr/local/share/info/gcc14 --build=x86_64-portbld-freebsd14.3
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.2.0 (FreeBSD Ports Collection)
If you see ada included in the Configured with: section of the gcc14 -v command output, such as --enable-languages=...ada..., the build has been completed correctly.