File:  [NetBSD Developer Wiki] / wikisrc / tutorials / per_file_build_options_override.mdwn
Revision 1.1: download - view: text, annotated - select for diffs
Mon Nov 21 03:22:58 2011 UTC (6 years, 7 months ago) by mspo
Branches: MAIN
CVS tags: HEAD
finish importing the pages from my findings in the wiki


[[!toc levels=3]]

#  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 \

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' \
    > $TOOLDIR/bin/nbmake-evbarm

#  Refences 

  * man 1 make 
  * [Per-source CFLAGS, discussion on freebsd-arch](
  * [NetBSD Guide: Chapter 30. Crosscompiling NetBSD with](
  * share/mk/bsd.README 

CVSweb for NetBSD wikisrc <> software: FreeBSD-CVSweb