# This GNU Makefile supports different OS and CPU combinations.
#
# You should use it this way :
-# [g]make TARGET=os CPU=cpu USE_xxx=1 ...
+# [g]make TARGET=os ARCH=arch CPU=cpu USE_xxx=1 ...
#
# Valid USE_* options are the following. Most of them are automatically set by
# the TARGET, others have to be explictly specified :
# Variables useful for packagers :
# CC is set to "gcc" by default and is used for compilation only.
# LD is set to "gcc" by default and is used for linking only.
+# ARCH may be useful to force build of 32-bit binary on 64-bit systems
# CFLAGS is automatically set for the specified CPU and may be overridden.
# LDFLAGS is automatically set to -g and may be overridden.
# SMALL_OPTS may be used to specify some options to shrink memory usage.
# generic, i586, i686, ultrasparc, custom
CPU = generic
+#### Architecture, used when not building for native architecture
+# Use ARCH=<arch_name> to force build for a specific architecture. Known
+# architectures will lead to "-m32" or "-m64" being added to CFLAGS and
+# LDFLAGS. This can be required to build 32-bit binaries on 64-bit targets.
+# Currently, only x86_64, i386, i486, i586 and i686 are understood.
+ARCH =
+
#### Toolchain options.
# GCC is normally used both for compiling and linking.
CC = gcc
CPU_CFLAGS.ultrasparc = -O6 -mcpu=v9 -mtune=ultrasparc
CPU_CFLAGS = $(CPU_CFLAGS.$(CPU))
+#### ARCH dependant flags, may be overriden by CPU flags
+ARCH_FLAGS.i386 = -m32 -march=i386
+ARCH_FLAGS.i486 = -m32 -march=i486
+ARCH_FLAGS.i586 = -m32 -march=i586
+ARCH_FLAGS.i686 = -m32 -march=i686
+ARCH_FLAGS.x86_64 = -m64 -march=x86-64
+ARCH_FLAGS = $(ARCH_FLAGS.$(ARCH))
+
#### Common CFLAGS
# These CFLAGS contain general optimization options, CPU-specific optimizations
# and debug flags. They may be overridden by some distributions which prefer to
# set all of them at once instead of playing with the CPU and DEBUG variables.
-CFLAGS = $(CPU_CFLAGS) $(DEBUG_CFLAGS)
+CFLAGS = $(ARCH_FLAGS) $(CPU_CFLAGS) $(DEBUG_CFLAGS)
#### Common LDFLAGS
# These LDFLAGS are used as the first "ld" options, regardless of any library
# path or any other option. They may be changed to add any linker-specific
# option at the beginning of the ld command line.
-LDFLAGS = -g
+LDFLAGS = $(ARCH_FLAGS) -g
#### Target system options
# Depending on the target platform, some options are set, as well as some
src/haproxy.o: src/haproxy.c
$(CC) $(COPTS) \
-DBUILD_TARGET='"$(strip $(TARGET))"' \
+ -DBUILD_ARCH='"$(strip $(ARCH))"' \
-DBUILD_CPU='"$(strip $(CPU))"' \
-DBUILD_CC='"$(strip $(CC))"' \
-DBUILD_CFLAGS='"$(strip $(VERBOSE_CFLAGS))"' \
- linux22 for Linux 2.2
- linux24 for Linux 2.4 and above (default)
- linux24e for Linux 2.4 with support for a working epoll (> 0.21)
- - linux24eold for Linux 2.4 with support for a broken epoll (<= 0.21)
- linux26 for Linux 2.6 and above
- solaris for Solaris 8 or 10 (others untested)
- freebsd for FreeBSD 5 to 6.2 (others untested)
Alternatively, you may just set the CPU_CFLAGS value to the optimal GCC options
for your platform.
+You may want to build specific target binaries which do not match your native
+compiler's target. This is particularly true on 64-bit systems when you want
+to build a 32-bit binary. Use the ARCH variable for this purpose. Right now
+it only knows about a few x86 variants (i386,i486,i586,i686,x86_64) and sets
+-m32/-m64 as well as -march=<arch> accordingly.
+
If your system supports PCRE (Perl Compatible Regular Expressions), then you
really should build with libpcre which is between 2 and 10 times faster than
other libc implementations. Regex are used for header processing (deletion,
$ make -f Makefile.bsd REGEX=pcre DEBUG= COPTS.generic="-Os -fomit-frame-pointer -mgnu"
+In order to build a 32-bit binary on an x86_64 Linux system :
+
+ $ make TARGET=linux26 ARCH=i386
+
If you need to pass other defines, includes, libraries, etc... then please
check the Makefile to see which ones will be available in your case, and
use the USE_* variables in the GNU Makefile, or ADDINC, ADDLIB, and DEFINE