As quoted from the LFS Optimization hint:
There are a few ways to change the default compiler options. One way is to edit
every Makefile file you can find in a package, look for the CFLAGS and CXXFLAGS
variables (a well designed package uses the CFLAGS variable to define gcc
compiler options and CXXFLAGS to define g++ compiler options) and change their
values. Packages like binutils, gcc, glibc and others have a lot of Makefile
files in a lot of subdirectories so this would take a lot of time to do.
Instead there's an easier way to do things: create the CFLAGS and CXXFLAGS
environment variables. Most configure scripts read the CFLAGS and CXXFLAGS
variables and use them in the Makefile files. A few packages don't follow this
convention and those package require manual editing.
To set those variables you can do the following commands in bash (or in your
.bashrc if you want them to be there all the time):
export CFLAGS="-O3 -march=<architecture>" &&
To read the full hint, you'll need to download it from a mirror:
Since the main site is down for now.