Contents
Introduction
Build variables like CFLAGS, LDFLAGS, CPUFLAGS etc. are used to override default build options and to take advantage of special compiler options available on some target hardware platforms. The build variables are usually supplied through shell variables, make options or mk.conf, so original build infrastructure can remain clean of hacks. Most build options can be applied globally to the whole NetBSD userspace or to some library, program or source file for example, but sometimes the special options need a few exception within the source tree. This is where per-source-file build options override comes in handy.
Per source file build option override
For example the CPUFLAGS build variable can be changed to depend on the source file being compiled:
CPUFLAGS_source_file_name_without_white_space_and_extension=-mnormal_arch \
DEF_CPUFLAGS=-mspecial_arch \
CPUFLAGS='${CPUFLAGS_${.IMPSRC:T:R}:U${DEF_CPUFLAGS}}' \
nbmake
When the BSD make builds a C file (or the build command uses the CPUFLAGS variable), a check is made if a variable named CPUFLAGS_source_file_name_without_white_space_and_extension exists. If this variable exists, its contents is used as CPUFLAGS, and if it does not exist, DEF_CPUFLAGS is used instead. See make manual for more variable name filters, regexp possibilities and other predifined make variables, which may all come in handy.
Example: libc cross-build for ARM/thumb, except for atomic_init_testset.c
$ cd lib/libc
$ CPUFLAGS_atomic_init_testset=-mthumb-interwork \
> DEF_CPUFLAGS='-mthumb -mthumb-interwork' \
> CPUFLAGS='${CPUFLAGS_${.IMPSRC:T:R}:U${DEF_CPUFLAGS}}' \
> $TOOLDIR/bin/nbmake-evbarm
Refences
- make(1)
- Per-source CFLAGS, discussion on freebsd-arch
- NetBSD Guide: Chapter 30. Crosscompiling NetBSD with build.sh
- share/mk/bsd.README
- BUILDING