3. Configuring ports for custom version of GCC

Additional system configuration is required in order to use custom version of GCC installed from the FreeBSD ports tree.

3.1. Adjusting make.conf

Add the following lines to the /etc/make.conf file (or modify appropriately):

.if !empty(.CURDIR:M/usr/ports/*) && exists(/usr/local/bin/gcc44)
CC=gcc44
CXX=g++44
CPP=cpp44
.endif

Alternatively, it is possible to specify the ${CC} and ${CPP} variables manually.

Note:

The examples above are for GCC version 4.4. To use gcc43, replace "gcc44" with "gcc43" and "4.4" with "4.3" and so on.

3.2. Adjusting libmap.conf

Many of the ports' binaries and libraries link to libgcc_s or libstdc++. The base system already includes these libraries, but from an earlier version of GCC (version 4.2.1). To supply rtld (and ldd) with correct versions, add the following lines to the /etc/libmap.conf file (or modify appropriately):

libgcc_s.so.1   gcc44/libgcc_s.so.1
libgomp.so.1    gcc44/libgomp.so.1
libobjc.so.3    gcc44/libobjc.so.2
libssp.so.0     gcc44/libssp.so.0
libstdc++.so.6  gcc44/libstdc++.so.6

Note:

The examples above are for GCC version 4.4. To use gcc43, replace "gcc44" with "gcc43" and so on. Note also that all of these libraries are fully backwards compatible with base system libraries.

Warning:

Some C++ programs may refuse to work if these libraries are not mapped correctly. If it is not feasible to map them all, it is recommended to map at least libstdc++.so.

3.3. Custom CFLAGS for the ports tree

To add custom CFLAGS for the ports tree which are unsupported by the base system, adjust the /etc/make.conf according to the following example:

.if !empty(.CURDIR:M/usr/ports/*) && exists(/usr/local/bin/gcc44)
CC=gcc44
CXX=g++44
CPP=cpp44
CFLAGS+=-mssse3
.endif

It is possible to completely replace CFLAGS and/or define custom CPUTYPE as well. We recommend setting CPUTYPE because many ports decide their optimizations flags based on this variable.

3.4. Excluding ports that do not build with new version of GCC

To exclude ports that have problems with custom version of GCC, adjust the /etc/make.conf according to the following example:

.if !empty(.CURDIR:M/usr/ports/*) && exists(/usr/local/bin/gcc44)
.if empty(.CURDIR:M/usr/ports/net/openldap*)
CC=gcc44
CXX=g++44
CPP=cpp44
.endif
.endif

The example above excludes the forced use of gcc 4.4 for the net/openldap* ports. It is also possible to specify more ports on a single line:

.if empty(.CURDIR:M/usr/ports/net/openldap*) && empty(.CURDIR:M/usr/ports/xxx/yyy) && ...

All FreeBSD documents are available for download at http://ftp.FreeBSD.org/pub/FreeBSD/doc/

Questions that are not answered by the documentation may be sent to <freebsd-questions@FreeBSD.org>.
Send questions about this document to <freebsd-doc@FreeBSD.org>.