[BUILD] make it possible to pass alternative arch at build time
When trying to build a 32-bit binary on a 64-bit platform, we generally need to pass "-m32" to gcc, which is not convenient with current makefile. Note that this option requires gcc >= 3. In order to ease parameter passing, a new ARCH= makefile option has been added. If it receives a target architecture, according "-m32"/"-m64" and "-march=xxxx" will be passed to gcc. Only the generic makefile has been changed to support this option right now as the need only appeared on Linux. The spec file now makes use of this option so that rpmbuild can automatically build with the proper architecture.
This commit is contained in:
parent
ff443f94c6
commit
ef7341dc3d
23
Makefile
23
Makefile
@ -1,7 +1,7 @@
|
||||
# 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 :
|
||||
@ -28,6 +28,7 @@
|
||||
# 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.
|
||||
@ -78,6 +79,13 @@ TARGET =
|
||||
# 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
|
||||
@ -129,17 +137,25 @@ CPU_CFLAGS.i686 = -O2 -march=i686
|
||||
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
|
||||
@ -458,6 +474,7 @@ objsize: haproxy
|
||||
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))"' \
|
||||
|
11
README
11
README
@ -22,7 +22,6 @@ and assign it to the TARGET variable :
|
||||
- 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)
|
||||
@ -42,6 +41,12 @@ one of the following choices to the CPU variable :
|
||||
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,
|
||||
@ -74,6 +79,10 @@ And I build it this way on OpenBSD or FreeBSD :
|
||||
|
||||
$ 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
|
||||
|
@ -33,7 +33,7 @@ risking the system's stability.
|
||||
%define __perl_requires /bin/true
|
||||
|
||||
%build
|
||||
%{__make} USE_PCRE=1 DEBUG="" TARGET=linux26
|
||||
%{__make} USE_PCRE=1 DEBUG="" ARCH=%{_target_cpu} TARGET=linux26
|
||||
|
||||
%install
|
||||
[ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot}
|
||||
|
Loading…
x
Reference in New Issue
Block a user