CPUFLAGS(1)

NAME
cpuflags - determine compiler flags to best target current CPU

SYNOPSIS
cpuflags [cc_pathname]

DESCRIPTION
cpuflags determines the current CPU type and gcc version, then outputs appropriate compiler options to best target code for that CPU. If no options exist to target the current CPU then nothing is output.

In the event of the CPU not being recognised, a warning is sent to stderr.

If cc_pathname is not specified it defaults to the first cc found in the path.

ENVIRONMENT
The BSD makefile fragment @PREFIX@/share/mk/cpuflags.mk will set the following make(1) variables, plus add CPU_FLAGS and CPU_DIR to .MAKEFLAGS for sub-makes.

CPU_FLAGS
    The output of cpuflags
CPU_DIR
    CPU_FLAGS with spaces stripped (eg: for use in PACKAGES)
CFLAGS
    Has CPU_FLAGS appended
CXXFLAGS
    Has CPU_FLAGS appended

FILES
@PREFIX@/share/mk/cpuflags.mk
    Set appropriate compiler flags based on the output from cpuflags. Suitable for inclusion in /etc/mk.conf
@PREFIX@/share/mk/optimize_gcc.mk
    Attempt to set additional -mXXX gcc flags based on gcc version and packages being compiled. Note: This is experimental and not supported.

EXAMPLES
cpuflags can be used to set default flags for building entries from pkgsrc and recompiling the NetBSD kernel or userland by adding the following to /etc/mk.conf:

     .sinclude "@PREFIX@/share/mk/cpuflags.mk"

To experiment with optimisations that can break generated code there is optimize_gcc.mk. This is unsupported, but for full effect add the following to /etc/mk.conf:

     .sinclude "@PREFIX@/share/mk/cpuflags.mk"
     .sinclude "@PREFIX@/share/mk/optimize_gcc.mk"

On all except low memory machines compilation can be speeded up by adding the following to /etc/mk.conf. (Note this will not affect the binaries produced)

    COPTS?= -pipe ${DEFCOPTS}
    CFLAGS+=-pipe

BUGS
cpuflags still needs to learn about more CPU types - updates welcomed to <abs@NetBSD.org>. Also the Makefile fragments and examples are BSD make specific - gmake examples welcomed.

Currently cpuflags is also gcc specific.

NOTES
cpuflags is based on input from many sources. I would like to thank them all, in particular Yakovetsky Vladimir.