BUILD: makefile: get rid of the CPU variable
The CPU variable, when used, is almost always exclusively used with "generic" to disable any CPU-specific optimizations, or "native" to enable "-march=native". Other options are not used and are just making CPU_CFLAGS more confusing. This commit just drops all pre-configured variants and replaces them with documentation about examples of supported options. CPU_CFLAGS is preserved as it appears that it's mostly used as a proxy to inject the distro's CFLAGS, and it's just empty by default. The CPU variable is checked, and if set to anything but "generic", it emits a warning about its deprecation and invites the user to read INSTALL. Users who would just set CPU_CFLAGS will be able to continue to do so, those who were using CPU=native will have to pass CPU_CFLAGS=-march=native and those who were passing one of the other options will find it in the doc as well. Note that this also removes the "CPU=" line from haproxy -vv, that most users got used to seeing set to "generic" or occasionally "native" anyway, thus that didn't provide any useful information.
This commit is contained in:
parent
8194499bec
commit
018443b8a1
46
INSTALL
46
INSTALL
|
@ -45,7 +45,7 @@ are a few build examples :
|
|||
CC=/opt/cross/gcc730-arm/bin/gcc ADDLIB=-latomic
|
||||
|
||||
- Build with static PCRE on Solaris / UltraSPARC :
|
||||
$ make TARGET=solaris CPU=ultrasparc USE_STATIC_PCRE2=1
|
||||
$ make TARGET=solaris CPU_CFLAGS="-mcpu=v9" USE_STATIC_PCRE2=1
|
||||
|
||||
For more advanced build options or if a command above reports an error, please
|
||||
read the following sections.
|
||||
|
@ -558,27 +558,6 @@ and assign it to the TARGET variable :
|
|||
- generic for any other OS or version.
|
||||
- custom to manually adjust every setting
|
||||
|
||||
You may also choose your CPU to benefit from some optimizations. This is
|
||||
particularly important on UltraSparc machines. For this, you can assign
|
||||
one of the following choices to the CPU variable :
|
||||
|
||||
- i686 for intel PentiumPro, Pentium 2 and above, AMD Athlon (32 bits)
|
||||
- i586 for intel Pentium, AMD K6, VIA C3.
|
||||
- ultrasparc : Sun UltraSparc I/II/III/IV processor
|
||||
- power8 : IBM POWER8 processor
|
||||
- power9 : IBM POWER9 processor
|
||||
- armv81 : modern ARM cores (Cortex A55/A75/A76/A78/X1, Neoverse, Graviton2)
|
||||
- a72 : ARM Cortex-A72 or A73 (e.g. RPi4, Odroid N2, AWS Graviton)
|
||||
- a53 : ARM Cortex-A53 or any of its successors in 64-bit mode (e.g. RPi3)
|
||||
- armv8-auto : support both older and newer armv8 cores with a minor penalty,
|
||||
thanks to gcc 10's outline atomics (default with gcc 10.2).
|
||||
- native : use the build machine's specific processor optimizations. Use with
|
||||
extreme care, and never in virtualized environments (known to break).
|
||||
- generic : any other processor or no CPU-specific optimization. (default)
|
||||
|
||||
Alternatively, you may just set the CPU_CFLAGS value to the optimal GCC options
|
||||
for your platform.
|
||||
|
||||
A generic CFLAGS variable may be set to append any option to pass to the C
|
||||
compiler. These flags are passed last so the variable may be used to override
|
||||
other options such as warnings, optimization levels, include paths etc.
|
||||
|
@ -587,6 +566,29 @@ A default optimization level of -O2 is set by variable OPT_CFLAGS which may be
|
|||
overridden if desired. It's used early in the list of CFLAGS so that any other
|
||||
set of CFLAGS providing a different value may easily override it.
|
||||
|
||||
Some platforms may benefit from some CPU-specific options that will enable
|
||||
certain instruction sets, word size or endianness for example. One of them is
|
||||
the common "-march=native" that indicates to modern compilers that they need to
|
||||
optimize for the machine the compiler is running on. Such options may be either
|
||||
passed in the CPU_CFLAGS or in the CFLAGS variable, either will work though
|
||||
one may be more convenient for certain methods of packaging and the other one
|
||||
for other methods. Among the many possible options, the following ones are
|
||||
known for having successfully been used:
|
||||
|
||||
- "-march=native" for a native build
|
||||
- "-march=armv8-a+crc" for older ARM Cortex A53/A72/A73 (such as RPi 3B/4B)
|
||||
- "-march=armv8.1-a" for modern ARM Cortex A55/A76, Graviton2+, RPi 5
|
||||
- "-march=armv8-a+crc -moutline-atomics" to support older ARM with better
|
||||
support of modern cores with gcc-10+
|
||||
- "-mavx", "-mavx2", "-mavx512", to enable certain x86 SIMD instruction sets
|
||||
- "-march=i586" to support almost all 32-bit x86 systems
|
||||
- "-march=i686" to support only the latest 32-bit x86 systems
|
||||
- "-march=i386" to support even the oldest 32-bit x86 systems
|
||||
- "-mlittle-endian -march=armv5te" for some little-endian ARMv5 systems
|
||||
- "-mcpu=v9 -mtune=ultrasparc -m64" for a 64-bit Solaris SPARC build
|
||||
- "-march=1004kc -mtune=1004kc" for some multi-core 32-bit MIPS 1004Kc
|
||||
- "-march=24kc -mtune=24kc" for some single-core 32-bit MIPS 24Kc
|
||||
|
||||
If you are building for a different system than the one you're building on,
|
||||
this is called "cross-compiling". HAProxy supports cross-compilation pretty
|
||||
well and tries to ease it by letting you adjust paths to all libraries (please
|
||||
|
|
42
Makefile
42
Makefile
|
@ -1,7 +1,7 @@
|
|||
# This GNU Makefile supports different OS and CPU combinations.
|
||||
#
|
||||
# You should use it this way :
|
||||
# [g]make TARGET=os [ARCH=arch] [CPU=cpu] USE_xxx=1 ...
|
||||
# [g]make TARGET=os [ARCH=arch] [CFLAGS=...] USE_xxx=1 ...
|
||||
#
|
||||
# When in doubt, invoke help, possibly with a known target :
|
||||
# [g]make help
|
||||
|
@ -152,12 +152,16 @@ DOCDIR = $(PREFIX)/doc/haproxy
|
|||
# custom
|
||||
TARGET =
|
||||
|
||||
#### TARGET CPU
|
||||
# Use CPU=<cpu_name> to optimize for a particular CPU, among the following
|
||||
# list :
|
||||
# generic, native, i586, i686, ultrasparc, power8, power9, custom,
|
||||
# a53, a72, armv81, armv8-auto
|
||||
CPU = generic
|
||||
#### No longer used
|
||||
CPU =
|
||||
ifneq ($(CPU),)
|
||||
ifneq ($(CPU),generic)
|
||||
$(warning Warning: the "CPU" variable was forced to "$(CPU)" but is no longer \
|
||||
used and will be ignored. For native builds, modern compilers generally \
|
||||
prefer that the string "-march=native" is passed in CPU_CFLAGS or CFLAGS. \
|
||||
For other CPU-specific options, please read suggestions in the INSTALL file.)
|
||||
endif
|
||||
endif
|
||||
|
||||
#### Architecture, used when not building for native architecture
|
||||
# Use ARCH=<arch_name> to force build for a specific architecture. Known
|
||||
|
@ -260,22 +264,12 @@ SILENT_DEFINE =
|
|||
EXTRA =
|
||||
|
||||
#### CPU dependent optimizations
|
||||
# Some CFLAGS are set by default depending on the target CPU. Those flags only
|
||||
# feed CPU_CFLAGS, which in turn feed CFLAGS, so it is not mandatory to use
|
||||
# them. You should not have to change these options. Better use CPU_CFLAGS or
|
||||
# even CFLAGS instead.
|
||||
CPU_CFLAGS.generic =
|
||||
CPU_CFLAGS.native = -march=native
|
||||
CPU_CFLAGS.i586 = -march=i586
|
||||
CPU_CFLAGS.i686 = -march=i686
|
||||
CPU_CFLAGS.ultrasparc = -mcpu=v9 -mtune=ultrasparc
|
||||
CPU_CFLAGS.power8 = -mcpu=power8 -mtune=power8
|
||||
CPU_CFLAGS.power9 = -mcpu=power9 -mtune=power9
|
||||
CPU_CFLAGS.a53 = -mcpu=cortex-a53
|
||||
CPU_CFLAGS.a72 = -mcpu=cortex-a72
|
||||
CPU_CFLAGS.armv81 = -march=armv8.1-a
|
||||
CPU_CFLAGS.armv8-auto = -march=armv8-a+crc -moutline-atomics
|
||||
CPU_CFLAGS = $(CPU_CFLAGS.$(CPU))
|
||||
# This may optionally be used to pass CPU-specific optimizations such as
|
||||
# -march=native, -mcpu=something, -m64 etc independently of CFLAGS if it is
|
||||
# considered more convenient. Historically, the optimization level was also
|
||||
# passed there. This is still supported but not recommended though; OPT_CFLAGS
|
||||
# is better suited. The default is empty.
|
||||
CPU_CFLAGS =
|
||||
|
||||
#### ARCH dependent flags, may be overridden by CPU flags
|
||||
ARCH_FLAGS.32 = -m32
|
||||
|
@ -1049,7 +1043,6 @@ src/haproxy.o: src/haproxy.c $(DEP)
|
|||
$(cmd_CC) $(COPTS) \
|
||||
-DBUILD_TARGET='"$(strip $(TARGET))"' \
|
||||
-DBUILD_ARCH='"$(strip $(ARCH))"' \
|
||||
-DBUILD_CPU='"$(strip $(CPU))"' \
|
||||
-DBUILD_CC='"$(strip $(CC))"' \
|
||||
-DBUILD_CFLAGS='"$(strip $(VERBOSE_CFLAGS))"' \
|
||||
-DBUILD_OPTIONS='"$(strip $(BUILD_OPTIONS))"' \
|
||||
|
@ -1152,7 +1145,6 @@ opts:
|
|||
@echo -n 'Using: '
|
||||
@echo -n 'TARGET="$(strip $(TARGET))" '
|
||||
@echo -n 'ARCH="$(strip $(ARCH))" '
|
||||
@echo -n 'CPU="$(strip $(CPU))" '
|
||||
@echo -n 'CC="$(strip $(CC))" '
|
||||
@echo -n 'OPT_CFLAGS="$(strip $(OPT_CFLAGS))" '
|
||||
@echo -n 'ARCH_FLAGS="$(strip $(ARCH_FLAGS))" '
|
||||
|
|
|
@ -565,9 +565,6 @@ static void display_build_opts()
|
|||
#ifdef BUILD_TARGET
|
||||
"\n TARGET = " BUILD_TARGET
|
||||
#endif
|
||||
#ifdef BUILD_CPU
|
||||
"\n CPU = " BUILD_CPU
|
||||
#endif
|
||||
#ifdef BUILD_CC
|
||||
"\n CC = " BUILD_CC
|
||||
#endif
|
||||
|
@ -2808,9 +2805,6 @@ static void init(int argc, char **argv)
|
|||
#ifdef BUILD_TARGET
|
||||
chunk_appendf(&trash, "TARGET='%s'", BUILD_TARGET);
|
||||
#endif
|
||||
#ifdef BUILD_CPU
|
||||
chunk_appendf(&trash, " CPU='%s'", BUILD_CPU);
|
||||
#endif
|
||||
#ifdef BUILD_OPTIONS
|
||||
chunk_appendf(&trash, " %s", BUILD_OPTIONS);
|
||||
#endif
|
||||
|
@ -3367,9 +3361,6 @@ int main(int argc, char **argv)
|
|||
#ifdef BUILD_TARGET
|
||||
"\n TARGET = " BUILD_TARGET
|
||||
#endif
|
||||
#ifdef BUILD_CPU
|
||||
"\n CPU = " BUILD_CPU
|
||||
#endif
|
||||
#ifdef BUILD_CC
|
||||
"\n CC = " BUILD_CC
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue