1# This GNU Makefile supports different OS and CPU combinations.
2#
3# You should use it this way :
4#   [g]make TARGET=os ARCH=arch CPU=cpu USE_xxx=1 ...
5#
6# By default the detailed commands are hidden for a cleaner output, but you may
7# see them by appending "V=1" to the make command.
8#
9# Valid USE_* options are the following. Most of them are automatically set by
10# the TARGET, others have to be explicitly specified :
11#   USE_DLMALLOC         : enable use of dlmalloc (see DLMALLOC_SRC)
12#   USE_EPOLL            : enable epoll() on Linux 2.6. Automatic.
13#   USE_KQUEUE           : enable kqueue() on BSD. Automatic.
14#   USE_MY_EPOLL         : redefine epoll_* syscalls. Automatic.
15#   USE_MY_SPLICE        : redefine the splice syscall if build fails without.
16#   USE_NETFILTER        : enable netfilter on Linux. Automatic.
17#   USE_PCRE             : enable use of libpcre for regex. Recommended.
18#   USE_PCRE_JIT         : enable JIT for faster regex on libpcre >= 8.32
19#   USE_PCRE2            : enable use of libpcre2 for regex.
20#   USE_PCRE2_JIT        : enable JIT for faster regex on libpcre2
21#   USE_POLL             : enable poll(). Automatic.
22#   USE_PRIVATE_CACHE    : disable shared memory cache of ssl sessions.
23#   USE_THREAD           : enable threads support.
24#   USE_PTHREAD_PSHARED  : enable pthread process shared mutex on sslcache.
25#   USE_REGPARM          : enable regparm optimization. Recommended on x86.
26#   USE_STATIC_PCRE      : enable static libpcre. Recommended.
27#   USE_STATIC_PCRE2     : enable static libpcre2.
28#   USE_TPROXY           : enable transparent proxy. Automatic.
29#   USE_LINUX_TPROXY     : enable full transparent proxy. Automatic.
30#   USE_LINUX_SPLICE     : enable kernel 2.6 splicing. Automatic.
31#   USE_LIBCRYPT         : enable crypted passwords using -lcrypt
32#   USE_CRYPT_H          : set it if your system requires including crypt.h
33#   USE_VSYSCALL         : enable vsyscall on Linux x86, bypassing libc
34#   USE_GETADDRINFO      : use getaddrinfo() to resolve IPv6 host names.
35#   USE_OPENSSL          : enable use of OpenSSL. Recommended, but see below.
36#   USE_LUA              : enable Lua support.
37#   USE_FUTEX            : enable use of futex on kernel 2.6. Automatic.
38#   USE_ACCEPT4          : enable use of accept4() on linux. Automatic.
39#   USE_MY_ACCEPT4       : use own implemention of accept4() if glibc < 2.10.
40#   USE_PRCTL            : enable use of prctl(). Automatic.
41#   USE_ZLIB             : enable zlib library support.
42#   USE_SLZ              : enable slz library instead of zlib (pick at most one).
43#   USE_CPU_AFFINITY     : enable pinning processes to CPU on Linux. Automatic.
44#   USE_TFO              : enable TCP fast open. Supported on Linux >= 3.7.
45#   USE_NS               : enable network namespace support. Supported on Linux >= 2.6.24.
46#   USE_DL               : enable it if your system requires -ldl. Automatic on Linux.
47#   USE_RT               : enable it if your system requires -lrt. Automatic on Linux.
48#   USE_DEVICEATLAS      : enable DeviceAtlas api.
49#   USE_51DEGREES        : enable third party device detection library from 51Degrees
50#   USE_WURFL            : enable WURFL detection library from Scientiamobile
51#   USE_SYSTEMD          : enable sd_notify() support.
52#   USE_OBSOLETE_LINKER  : use when the linker fails to emit __start_init/__stop_init
53#
54# Options can be forced by specifying "USE_xxx=1" or can be disabled by using
55# "USE_xxx=" (empty string).
56#
57# Variables useful for packagers :
58#   CC is set to "gcc" by default and is used for compilation only.
59#   LD is set to "gcc" by default and is used for linking only.
60#   ARCH may be useful to force build of 32-bit binary on 64-bit systems
61#   CFLAGS is automatically set for the specified CPU and may be overridden.
62#   LDFLAGS is automatically set to -g and may be overridden.
63#   DEP may be cleared to ignore changes to include files during development
64#   SMALL_OPTS may be used to specify some options to shrink memory usage.
65#   DEBUG may be used to set some internal debugging options.
66#   ERR may be set to non-empty to pass -Werror to the compiler
67#   ADDINC may be used to complete the include path in the form -Ipath.
68#   ADDLIB may be used to complete the library list in the form -Lpath -llib.
69#   DEFINE may be used to specify any additional define, which will be reported
70#          by "haproxy -vv" in CFLAGS.
71#   SILENT_DEFINE may be used to specify other defines which will not be
72#     reported by "haproxy -vv".
73#   EXTRA   is used to force building or not building some extra tools.
74#   DESTDIR is not set by default and is used for installation only.
75#           It might be useful to set DESTDIR if you want to install haproxy
76#           in a sandbox.
77#   PREFIX  is set to "/usr/local" by default and is used for installation only.
78#   SBINDIR is set to "$(PREFIX)/sbin" by default and is used for installation
79#           only.
80#   MANDIR  is set to "$(PREFIX)/share/man" by default and is used for
81#           installation only.
82#   DOCDIR  is set to "$(PREFIX)/doc/haproxy" by default and is used for
83#           installation only.
84#
85# Other variables :
86#   DLMALLOC_SRC   : build with dlmalloc, indicate the location of dlmalloc.c.
87#   DLMALLOC_THRES : should match PAGE_SIZE on every platform (default: 4096).
88#   PCRE_CONFIG    : force the binary path to get pcre config (by default
89#                                                              pcre-config)
90#   PCREDIR        : force the path to libpcre.
91#   PCRE_LIB       : force the lib path to libpcre (defaults to $PCREDIR/lib).
92#   PCRE_INC       : force the include path to libpcre ($PCREDIR/inc)
93#   PCRE2_CONFIG   : force the binary path to get pcre2 config (by default
94#                                                               pcre2-config)
95#   SSL_LIB        : force the lib path to libssl/libcrypto
96#   SSL_INC        : force the include path to libssl/libcrypto
97#   LUA_LIB        : force the lib path to lua
98#   LUA_INC        : force the include path to lua
99#   LUA_LIB_NAME   : force the lib name (or automatically evaluated, by order of
100#                                        priority : lua5.3, lua53, lua).
101#   IGNOREGIT      : ignore GIT commit versions if set.
102#   VERSION        : force haproxy version reporting.
103#   SUBVERS        : add a sub-version (eg: platform, model, ...).
104#   VERDATE        : force haproxy's release date.
105#
106#   VTEST_PROGRAM : location of the vtest program to run reg-tests.
107
108# verbosity: pass V=1 for verbose shell invocation
109V = 0
110Q = @
111ifeq ($V,1)
112Q=
113endif
114
115# Function used to detect support of a given option by the compiler.
116# Usage: CFLAGS += $(call cc-opt,option). Eg: $(call cc-opt,-fwrapv)
117# Note: ensure the referencing variable is assigned using ":=" and not "=" to
118#       call it only once.
119cc-opt = $(shell set -e; if $(CC) $(1) -E -xc - -o /dev/null </dev/null >&0 2>&0; then echo "$(1)"; fi;)
120
121# same but emits $2 if $1 is not supported
122cc-opt-alt = $(shell set -e; if $(CC) $(1) -E -xc - -o /dev/null </dev/null >&0 2>&0; then echo "$(1)"; else echo "$(2)"; fi;)
123
124# Disable a warning when supported by the compiler. Don't put spaces around the
125# warning! And don't use cc-opt which doesn't always report an error until
126# another one is also returned.
127# Usage: CFLAGS += $(call cc-nowarn,warning). Eg: $(call cc-opt,format-truncation)
128cc-nowarn = $(shell set -e; if $(CC) -W$(1) -E -xc - -o /dev/null </dev/null >&0 2>&0; then echo "-Wno-$(1)"; fi;)
129
130#### Installation options.
131DESTDIR =
132PREFIX = /usr/local
133SBINDIR = $(PREFIX)/sbin
134MANDIR = $(PREFIX)/share/man
135DOCDIR = $(PREFIX)/doc/haproxy
136
137#### TARGET system
138# Use TARGET=<target_name> to optimize for a specifc target OS among the
139# following list (use the default "generic" if uncertain) :
140#    generic, linux22, linux24, linux24e, linux26, solaris,
141#    freebsd, openbsd, netbsd, cygwin, haiku, custom, aix51, aix52
142TARGET =
143
144#### TARGET CPU
145# Use CPU=<cpu_name> to optimize for a particular CPU, among the following
146# list :
147#    generic, native, i586, i686, ultrasparc, custom
148CPU = generic
149
150#### Architecture, used when not building for native architecture
151# Use ARCH=<arch_name> to force build for a specific architecture. Known
152# architectures will lead to "-m32" or "-m64" being added to CFLAGS and
153# LDFLAGS. This can be required to build 32-bit binaries on 64-bit targets.
154# Currently, only 32, 64, x86_64, i386, i486, i586 and i686 are understood.
155ARCH =
156
157#### Toolchain options.
158# GCC is normally used both for compiling and linking.
159CC = gcc
160LD = $(CC)
161
162#### Debug flags (typically "-g").
163# Those flags only feed CFLAGS so it is not mandatory to use this form.
164DEBUG_CFLAGS = -g
165
166#### Add -Werror when set to non-empty
167ERR =
168
169#### May be used to force running a specific set of reg-tests
170REG_TEST_FILES =
171
172#### Compiler-specific flags that may be used to disable some negative over-
173# optimization or to silence some warnings. -fno-strict-aliasing is needed with
174# gcc >= 4.4.
175# We rely on signed integer wraparound on overflow, however clang think it
176# can do whatever it wants since it's an undefined behavior, so use -fwrapv
177# to be sure we get the intended behavior.
178SPEC_CFLAGS := -fno-strict-aliasing -Wdeclaration-after-statement
179SPEC_CFLAGS += $(call cc-opt-alt,-fwrapv,$(call cc-opt,-fno-strict-overflow))
180SPEC_CFLAGS += $(call cc-nowarn,address-of-packed-member)
181SPEC_CFLAGS += $(call cc-nowarn,unused-label)
182SPEC_CFLAGS += $(call cc-nowarn,sign-compare)
183SPEC_CFLAGS += $(call cc-nowarn,unused-parameter)
184SPEC_CFLAGS += $(call cc-nowarn,old-style-declaration)
185SPEC_CFLAGS += $(call cc-nowarn,ignored-qualifiers)
186SPEC_CFLAGS += $(call cc-nowarn,clobbered)
187SPEC_CFLAGS += $(call cc-nowarn,missing-field-initializers)
188SPEC_CFLAGS += $(call cc-nowarn,implicit-fallthrough)
189SPEC_CFLAGS += $(call cc-nowarn,stringop-overflow)
190SPEC_CFLAGS += $(call cc-nowarn,cast-function-type)
191SPEC_CFLAGS += $(call cc-opt,-Wtype-limits)
192SPEC_CFLAGS += $(call cc-opt,-Wshift-negative-value)
193SPEC_CFLAGS += $(call cc-opt,-Wshift-overflow=2)
194SPEC_CFLAGS += $(call cc-opt,-Wduplicated-cond)
195SPEC_CFLAGS += $(call cc-opt,-Wnull-dereference)
196
197#### Memory usage tuning
198# If small memory footprint is required, you can reduce the buffer size. There
199# are 2 buffers per concurrent session, so 16 kB buffers will eat 32 MB memory
200# with 1000 concurrent sessions. Putting it slightly lower than a page size
201# will prevent the additional parameters to go beyond a page. 8030 bytes is
202# exactly 5.5 TCP segments of 1460 bytes and is generally good. Useful tuning
203# macros include :
204#    SYSTEM_MAXCONN, BUFSIZE, MAXREWRITE, REQURI_LEN, CAPTURE_LEN.
205# Example: SMALL_OPTS = -DBUFSIZE=8030 -DMAXREWRITE=1030 -DSYSTEM_MAXCONN=1024
206SMALL_OPTS =
207
208#### Debug settings
209# You can enable debugging on specific code parts by setting DEBUG=-DDEBUG_xxx.
210# Currently defined DEBUG macros include DEBUG_FULL, DEBUG_MEMORY, DEBUG_FSM,
211# DEBUG_HASH, DEBUG_AUTH, DEBUG_SPOE, DEBUG_UAF and DEBUG_THREAD. Please check
212# sources for exact meaning or do not use at all.
213DEBUG =
214
215#### Trace options
216# Use TRACE=1 to trace function calls to file "trace.out" or to stderr if not
217# possible.
218TRACE =
219
220#### Additional include and library dirs
221# Redefine this if you want to add some special PATH to include/libs
222ADDINC =
223ADDLIB =
224
225#### Specific macro definitions
226# Use DEFINE=-Dxxx to set any tunable macro. Anything declared here will appear
227# in the build options reported by "haproxy -vv". Use SILENT_DEFINE if you do
228# not want to pollute the report with complex defines.
229# The following settings might be of interest when SSL is enabled :
230#   LISTEN_DEFAULT_CIPHERS is a cipher suite string used to set the default SSL
231#           ciphers on "bind" lines instead of using OpenSSL's defaults.
232#   CONNECT_DEFAULT_CIPHERS is a cipher suite string used to set the default
233#           SSL ciphers on "server" lines instead of using OpenSSL's defaults.
234DEFINE =
235SILENT_DEFINE =
236
237#### extra programs to build
238# Force this to enable building extra programs or to disable them.
239# It's automatically appended depending on the targets.
240EXTRA =
241
242#### CPU dependant optimizations
243# Some CFLAGS are set by default depending on the target CPU. Those flags only
244# feed CPU_CFLAGS, which in turn feed CFLAGS, so it is not mandatory to use
245# them. You should not have to change these options. Better use CPU_CFLAGS or
246# even CFLAGS instead.
247CPU_CFLAGS.generic    = -O2
248CPU_CFLAGS.native     = -O2 -march=native
249CPU_CFLAGS.i586       = -O2 -march=i586
250CPU_CFLAGS.i686       = -O2 -march=i686
251CPU_CFLAGS.ultrasparc = -O6 -mcpu=v9 -mtune=ultrasparc
252CPU_CFLAGS            = $(CPU_CFLAGS.$(CPU))
253
254#### ARCH dependant flags, may be overridden by CPU flags
255ARCH_FLAGS.32     = -m32
256ARCH_FLAGS.64     = -m64
257ARCH_FLAGS.i386   = -m32 -march=i386
258ARCH_FLAGS.i486   = -m32 -march=i486
259ARCH_FLAGS.i586   = -m32 -march=i586
260ARCH_FLAGS.i686   = -m32 -march=i686
261ARCH_FLAGS.x86_64 = -m64 -march=x86-64
262ARCH_FLAGS        = $(ARCH_FLAGS.$(ARCH))
263
264#### Common CFLAGS
265# These CFLAGS contain general optimization options, CPU-specific optimizations
266# and debug flags. They may be overridden by some distributions which prefer to
267# set all of them at once instead of playing with the CPU and DEBUG variables.
268CFLAGS = $(ARCH_FLAGS) $(CPU_CFLAGS) $(DEBUG_CFLAGS) $(SPEC_CFLAGS)
269
270#### Common LDFLAGS
271# These LDFLAGS are used as the first "ld" options, regardless of any library
272# path or any other option. They may be changed to add any linker-specific
273# option at the beginning of the ld command line.
274LDFLAGS = $(ARCH_FLAGS) -g
275
276#### Target system options
277# Depending on the target platform, some options are set, as well as some
278# CFLAGS and LDFLAGS. The USE_* values are set to "implicit" so that they are
279# not reported in the build options string. You should not have to change
280# anything there. poll() is always supported, unless explicitly disabled by
281# passing USE_POLL="" on the make command line.
282USE_POLL   = default
283
284# Always enable threads support by default and let the Makefile detect if
285# HAProxy can be compiled with threads or not.
286
287ifeq ($(TARGET),generic)
288  # generic system target has nothing specific
289  USE_POLL   = implicit
290  USE_TPROXY = implicit
291else
292ifeq ($(TARGET),haiku)
293  # For Haiku
294  TARGET_LDFLAGS = -lnetwork
295  USE_POLL = implicit
296  USE_TPROXY = implicit
297else
298ifeq ($(TARGET),linux22)
299  # This is for Linux 2.2
300  USE_POLL        = implicit
301  USE_TPROXY      = implicit
302  USE_LIBCRYPT    = implicit
303  USE_DL          = implicit
304  USE_RT          = implicit
305else
306ifeq ($(TARGET),linux24)
307  # This is for standard Linux 2.4 with netfilter but without epoll()
308  USE_NETFILTER   = implicit
309  USE_POLL        = implicit
310  USE_TPROXY      = implicit
311  USE_CRYPT_H     = implicit
312  USE_LIBCRYPT    = implicit
313  USE_DL          = implicit
314  USE_RT          = implicit
315else
316ifeq ($(TARGET),linux24e)
317  # This is for enhanced Linux 2.4 with netfilter and epoll() patch > 0.21
318  USE_NETFILTER   = implicit
319  USE_POLL        = implicit
320  USE_EPOLL       = implicit
321  USE_MY_EPOLL    = implicit
322  USE_TPROXY      = implicit
323  USE_CRYPT_H     = implicit
324  USE_LIBCRYPT    = implicit
325  USE_DL          = implicit
326  USE_RT          = implicit
327else
328ifeq ($(TARGET),linux26)
329  # This is for standard Linux 2.6 with netfilter and standard epoll()
330  USE_NETFILTER   = implicit
331  USE_POLL        = implicit
332  USE_EPOLL       = implicit
333  USE_TPROXY      = implicit
334  USE_CRYPT_H     = implicit
335  USE_LIBCRYPT    = implicit
336  USE_FUTEX       = implicit
337  USE_PRCTL       = implicit
338  USE_DL          = implicit
339  USE_RT          = implicit
340else
341ifeq ($(TARGET),linux2628)
342  # This is for standard Linux >= 2.6.28 with netfilter, epoll, tproxy and splice
343  USE_NETFILTER   = implicit
344  USE_POLL        = implicit
345  USE_EPOLL       = implicit
346  USE_TPROXY      = implicit
347  USE_CRYPT_H     = implicit
348  USE_LIBCRYPT    = implicit
349  USE_LINUX_SPLICE= implicit
350  USE_LINUX_TPROXY= implicit
351  USE_ACCEPT4     = implicit
352  USE_FUTEX       = implicit
353  USE_CPU_AFFINITY= implicit
354  USE_PRCTL       = implicit
355  ASSUME_SPLICE_WORKS= implicit
356  USE_DL          = implicit
357  USE_RT          = implicit
358  USE_THREAD      = implicit
359else
360ifeq ($(TARGET),solaris)
361  # This is for Solaris 8
362  # We also enable getaddrinfo() which works since solaris 8.
363  USE_POLL       = implicit
364  TARGET_CFLAGS  = -DFD_SETSIZE=65536 -D_REENTRANT -D_XOPEN_SOURCE=500 -D__EXTENSIONS__
365  TARGET_LDFLAGS = -lnsl -lsocket
366  USE_TPROXY     = implicit
367  USE_LIBCRYPT    = implicit
368  USE_CRYPT_H     = implicit
369  USE_GETADDRINFO = implicit
370  USE_THREAD      = implicit
371  USE_OBSOLETE_LINKER = implicit
372else
373ifeq ($(TARGET),freebsd)
374  # This is for FreeBSD
375  USE_POLL       = implicit
376  USE_KQUEUE     = implicit
377  USE_TPROXY     = implicit
378  USE_LIBCRYPT   = implicit
379  USE_THREAD     = implicit
380  USE_CPU_AFFINITY= implicit
381else
382ifeq ($(TARGET),osx)
383  # This is for Mac OS/X
384  USE_POLL       = implicit
385  USE_KQUEUE     = implicit
386  USE_TPROXY     = implicit
387  EXPORT_SYMBOL  = -export_dynamic
388else
389ifeq ($(TARGET),openbsd)
390  # This is for OpenBSD >= 5.7
391  USE_POLL       = implicit
392  USE_KQUEUE     = implicit
393  USE_TPROXY     = implicit
394  USE_ACCEPT4    = implicit
395  USE_THREAD     = implicit
396else
397ifeq ($(TARGET),netbsd)
398  # This is for NetBSD
399  USE_POLL       = implicit
400  USE_KQUEUE     = implicit
401  USE_TPROXY     = implicit
402else
403ifeq ($(TARGET),aix51)
404  # This is for AIX 5.1
405  USE_POLL        = implicit
406  USE_LIBCRYPT    = implicit
407  USE_OBSOLETE_LINKER = implicit
408  USE_PRIVATE_CACHE = implicit
409  TARGET_CFLAGS   = -Dss_family=__ss_family -Dip6_hdr=ip6hdr -DSTEVENS_API -D_LINUX_SOURCE_COMPAT -Dunsetenv=my_unsetenv
410  DEBUG_CFLAGS    =
411else
412ifeq ($(TARGET),aix52)
413  # This is for AIX 5.2 and later
414  USE_POLL        = implicit
415  USE_LIBCRYPT    = implicit
416  USE_OBSOLETE_LINKER = implicit
417  TARGET_CFLAGS   = -D_MSGQSUPPORT
418  DEBUG_CFLAGS    =
419else
420ifeq ($(TARGET),cygwin)
421  # This is for Cygwin
422  # Cygwin adds IPv6 support only in version 1.7 (in beta right now).
423  USE_POLL   = implicit
424  USE_TPROXY = implicit
425  USE_OBSOLETE_LINKER = implicit
426  TARGET_CFLAGS  = $(if $(filter 1.5.%, $(shell uname -r)), -DUSE_IPV6 -DAF_INET6=23 -DINET6_ADDRSTRLEN=46, )
427endif # cygwin
428endif # aix52
429endif # aix51
430endif # netbsd
431endif # openbsd
432endif # osx
433endif # freebsd
434endif # solaris
435endif # linux2628
436endif # linux26
437endif # linux24e
438endif # linux24
439endif # linux22
440endif # haiku
441endif # generic
442
443
444#### Old-style REGEX library settings for compatibility with previous setups.
445# It is still possible to use REGEX=<regex_lib> to select an alternative regex
446# library. By default, we use libc's regex. On Solaris 8/Sparc, grouping seems
447# to be broken using libc, so consider using pcre instead. Supported values are
448# "libc", "pcre", and "static-pcre". Use of this method is deprecated in favor
449# of "USE_PCRE" and "USE_STATIC_PCRE" (see build options below).
450REGEX = libc
451
452ifeq ($(REGEX),pcre)
453USE_PCRE = 1
454$(warning WARNING! use of "REGEX=pcre" is deprecated, consider using "USE_PCRE=1" instead.)
455endif
456
457ifeq ($(REGEX),static-pcre)
458USE_STATIC_PCRE = 1
459$(warning WARNING! use of "REGEX=pcre-static" is deprecated, consider using "USE_STATIC_PCRE=1" instead.)
460endif
461
462#### Old-style TPROXY settings
463ifneq ($(findstring -DTPROXY,$(DEFINE)),)
464USE_TPROXY = 1
465$(warning WARNING! use of "DEFINE=-DTPROXY" is deprecated, consider using "USE_TPROXY=1" instead.)
466endif
467
468
469#### Determine version, sub-version and release date.
470# If GIT is found, and IGNOREGIT is not set, VERSION, SUBVERS and VERDATE are
471# extracted from the last commit. Otherwise, use the contents of the files
472# holding the same names in the current directory.
473
474ifeq ($(IGNOREGIT),)
475VERSION := $(shell [ -d .git/. ] && (git describe --tags --match 'v*' --abbrev=0 | cut -c 2-) 2>/dev/null)
476ifneq ($(VERSION),)
477# OK git is there and works.
478SUBVERS := $(shell comms=`git log --format=oneline --no-merges v$(VERSION).. 2>/dev/null | wc -l | tr -d '[:space:]'`; commit=`(git log -1 --pretty=%h --abbrev=6) 2>/dev/null`; [ $$comms -gt 0 ] && echo "-$$commit-$$comms")
479VERDATE := $(shell git log -1 --pretty=format:%ci | cut -f1 -d' ' | tr '-' '/')
480endif
481endif
482
483# Last commit version not found, take it from the files.
484ifeq ($(VERSION),)
485VERSION := $(shell cat VERSION 2>/dev/null || touch VERSION)
486endif
487ifeq ($(SUBVERS),)
488SUBVERS := $(shell (grep -v '\$$Format' SUBVERS 2>/dev/null || touch SUBVERS) | head -n 1)
489endif
490ifeq ($(VERDATE),)
491VERDATE := $(shell (grep -v '^\$$Format' VERDATE 2>/dev/null || touch VERDATE) | head -n 1 | cut -f1 -d' ' | tr '-' '/')
492endif
493
494#### Build options
495# Do not change these ones, enable USE_* variables instead.
496OPTIONS_CFLAGS  =
497OPTIONS_LDFLAGS =
498OPTIONS_OBJS    =
499
500# This variable collects all USE_* values except those set to "implicit". This
501# is used to report a list of all flags which were used to build this version.
502# Do not assign anything to it.
503BUILD_OPTIONS =
504
505# Return USE_xxx=$(USE_xxx) unless $(USE_xxx) = "implicit"
506# Usage:
507#   BUILD_OPTIONS += $(call ignore_implicit,USE_xxx)
508ignore_implicit = $(patsubst %=implicit,,$(1)=$($(1)))
509
510ifneq ($(USE_TCPSPLICE),)
511$(error experimental option USE_TCPSPLICE has been removed, check USE_LINUX_SPLICE)
512endif
513
514ifneq ($(USE_LINUX_SPLICE),)
515OPTIONS_CFLAGS += -DCONFIG_HAP_LINUX_SPLICE
516BUILD_OPTIONS  += $(call ignore_implicit,USE_LINUX_SPLICE)
517endif
518
519ifneq ($(USE_TPROXY),)
520OPTIONS_CFLAGS += -DTPROXY
521BUILD_OPTIONS  += $(call ignore_implicit,USE_TPROXY)
522endif
523
524ifneq ($(USE_LINUX_TPROXY),)
525OPTIONS_CFLAGS += -DCONFIG_HAP_LINUX_TPROXY
526BUILD_OPTIONS  += $(call ignore_implicit,USE_LINUX_TPROXY)
527endif
528
529ifneq ($(USE_LIBCRYPT),)
530OPTIONS_CFLAGS  += -DCONFIG_HAP_CRYPT
531BUILD_OPTIONS   += $(call ignore_implicit,USE_LIBCRYPT)
532OPTIONS_LDFLAGS += -lcrypt
533endif
534
535ifneq ($(USE_CRYPT_H),)
536OPTIONS_CFLAGS  += -DNEED_CRYPT_H
537BUILD_OPTIONS   += $(call ignore_implicit,USE_CRYPT_H)
538endif
539
540ifneq ($(USE_GETADDRINFO),)
541OPTIONS_CFLAGS  += -DUSE_GETADDRINFO
542BUILD_OPTIONS   += $(call ignore_implicit,USE_GETADDRINFO)
543endif
544
545ifneq ($(USE_OBSOLETE_LINKER),)
546OPTIONS_CFLAGS  += -DUSE_OBSOLETE_LINKER
547BUILD_OPTIONS   += $(call ignore_implicit,USE_OBSOLETE_LINKER)
548endif
549
550ifneq ($(USE_SLZ),)
551# Use SLZ_INC and SLZ_LIB to force path to zlib.h and libz.{a,so} if needed.
552SLZ_INC =
553SLZ_LIB =
554OPTIONS_CFLAGS  += -DUSE_SLZ $(if $(SLZ_INC),-I$(SLZ_INC))
555BUILD_OPTIONS   += $(call ignore_implicit,USE_SLZ)
556OPTIONS_LDFLAGS += $(if $(SLZ_LIB),-L$(SLZ_LIB)) -lslz
557endif
558
559ifneq ($(USE_ZLIB),)
560# Use ZLIB_INC and ZLIB_LIB to force path to zlib.h and libz.{a,so} if needed.
561ZLIB_INC =
562ZLIB_LIB =
563OPTIONS_CFLAGS  += -DUSE_ZLIB $(if $(ZLIB_INC),-I$(ZLIB_INC))
564BUILD_OPTIONS   += $(call ignore_implicit,USE_ZLIB)
565OPTIONS_LDFLAGS += $(if $(ZLIB_LIB),-L$(ZLIB_LIB)) -lz
566endif
567
568ifneq ($(USE_POLL),)
569OPTIONS_CFLAGS += -DENABLE_POLL
570OPTIONS_OBJS   += src/ev_poll.o
571BUILD_OPTIONS  += $(call ignore_implicit,USE_POLL)
572endif
573
574ifneq ($(USE_EPOLL),)
575OPTIONS_CFLAGS += -DENABLE_EPOLL
576OPTIONS_OBJS   += src/ev_epoll.o
577BUILD_OPTIONS  += $(call ignore_implicit,USE_EPOLL)
578endif
579
580ifneq ($(USE_MY_EPOLL),)
581OPTIONS_CFLAGS += -DUSE_MY_EPOLL
582BUILD_OPTIONS  += $(call ignore_implicit,USE_MY_EPOLL)
583endif
584
585ifneq ($(USE_KQUEUE),)
586OPTIONS_CFLAGS += -DENABLE_KQUEUE
587OPTIONS_OBJS   += src/ev_kqueue.o
588BUILD_OPTIONS  += $(call ignore_implicit,USE_KQUEUE)
589endif
590
591ifneq ($(USE_VSYSCALL),)
592OPTIONS_OBJS   += src/i386-linux-vsys.o
593OPTIONS_CFLAGS += -DCONFIG_HAP_LINUX_VSYSCALL
594BUILD_OPTIONS  += $(call ignore_implicit,USE_VSYSCALL)
595endif
596
597ifneq ($(USE_CPU_AFFINITY),)
598OPTIONS_CFLAGS += -DUSE_CPU_AFFINITY
599BUILD_OPTIONS  += $(call ignore_implicit,USE_CPU_AFFINITY)
600endif
601
602ifneq ($(USE_MY_SPLICE),)
603OPTIONS_CFLAGS += -DUSE_MY_SPLICE
604BUILD_OPTIONS  += $(call ignore_implicit,USE_MY_SPLICE)
605endif
606
607ifneq ($(ASSUME_SPLICE_WORKS),)
608OPTIONS_CFLAGS += -DASSUME_SPLICE_WORKS
609BUILD_OPTIONS  += $(call ignore_implicit,ASSUME_SPLICE_WORKS)
610endif
611
612ifneq ($(USE_ACCEPT4),)
613OPTIONS_CFLAGS += -DUSE_ACCEPT4
614BUILD_OPTIONS  += $(call ignore_implicit,USE_ACCEPT4)
615endif
616
617ifneq ($(USE_MY_ACCEPT4),)
618OPTIONS_CFLAGS += -DUSE_MY_ACCEPT4
619BUILD_OPTIONS  += $(call ignore_implicit,USE_MY_ACCEPT4)
620endif
621
622ifneq ($(USE_NETFILTER),)
623OPTIONS_CFLAGS += -DNETFILTER
624BUILD_OPTIONS  += $(call ignore_implicit,USE_NETFILTER)
625endif
626
627ifneq ($(USE_PRCTL),)
628OPTIONS_CFLAGS += -DUSE_PRCTL
629endif
630
631ifneq ($(USE_REGPARM),)
632OPTIONS_CFLAGS += -DCONFIG_REGPARM=3
633BUILD_OPTIONS  += $(call ignore_implicit,USE_REGPARM)
634endif
635
636ifneq ($(USE_DL),)
637BUILD_OPTIONS   += $(call ignore_implicit,USE_DL)
638OPTIONS_LDFLAGS += -ldl
639endif
640
641ifneq ($(USE_THREAD),)
642BUILD_OPTIONS   += $(call ignore_implicit,USE_THREAD)
643OPTIONS_CFLAGS  += -DUSE_THREAD
644OPTIONS_LDFLAGS += -lpthread
645endif
646
647ifneq ($(USE_RT),)
648BUILD_OPTIONS   += $(call ignore_implicit,USE_RT)
649OPTIONS_LDFLAGS += -lrt
650endif
651
652# report DLMALLOC_SRC only if explicitly specified
653ifneq ($(DLMALLOC_SRC),)
654BUILD_OPTIONS += DLMALLOC_SRC=$(DLMALLOC_SRC)
655endif
656
657ifneq ($(USE_DLMALLOC),)
658BUILD_OPTIONS  += $(call ignore_implicit,USE_DLMALLOC)
659ifeq ($(DLMALLOC_SRC),)
660DLMALLOC_SRC=src/dlmalloc.c
661endif
662endif
663
664ifneq ($(DLMALLOC_SRC),)
665# DLMALLOC_THRES may be changed to match PAGE_SIZE on every platform
666DLMALLOC_THRES = 4096
667OPTIONS_OBJS  += src/dlmalloc.o
668endif
669
670ifneq ($(USE_OPENSSL),)
671# OpenSSL is packaged in various forms and with various dependencies.
672# In general -lssl is enough, but on some platforms, -lcrypto may be needed,
673# reason why it's added by default. Some even need -lz, then you'll need to
674# pass it in the "ADDLIB" variable if needed. If your SSL libraries are not
675# in the usual path, use SSL_INC=/path/to/inc and SSL_LIB=/path/to/lib.
676BUILD_OPTIONS   += $(call ignore_implicit,USE_OPENSSL)
677OPTIONS_CFLAGS  += -DUSE_OPENSSL $(if $(SSL_INC),-I$(SSL_INC))
678OPTIONS_LDFLAGS += $(if $(SSL_LIB),-L$(SSL_LIB)) -lssl -lcrypto
679ifneq ($(USE_DL),)
680OPTIONS_LDFLAGS += -ldl
681endif
682OPTIONS_OBJS  += src/ssl_sock.o
683endif
684
685# The private cache option affect the way the shctx is built
686ifneq ($(USE_PRIVATE_CACHE),)
687OPTIONS_CFLAGS  += -DUSE_PRIVATE_CACHE
688else
689ifneq ($(USE_PTHREAD_PSHARED),)
690OPTIONS_CFLAGS  += -DUSE_PTHREAD_PSHARED
691OPTIONS_LDFLAGS += -lpthread
692else
693ifneq ($(USE_FUTEX),)
694OPTIONS_CFLAGS  += -DUSE_SYSCALL_FUTEX
695endif
696endif
697endif
698
699ifneq ($(USE_LUA),)
700check_lua_lib = $(shell echo "int main(){}" | $(CC) -o /dev/null -x c - $(2) -l$(1) 2>/dev/null && echo $(1))
701check_lua_inc = $(shell if [ -d $(2)$(1) ]; then echo $(2)$(1); fi;)
702
703BUILD_OPTIONS   += $(call ignore_implicit,USE_LUA)
704OPTIONS_CFLAGS  += -DUSE_LUA $(if $(LUA_INC),-I$(LUA_INC))
705LUA_LD_FLAGS := -Wl,$(if $(EXPORT_SYMBOL),$(EXPORT_SYMBOL),--export-dynamic) $(if $(LUA_LIB),-L$(LUA_LIB))
706ifeq ($(LUA_LIB_NAME),)
707# Try to automatically detect the Lua library
708LUA_LIB_NAME := $(firstword $(foreach lib,lua5.3 lua53 lua,$(call check_lua_lib,$(lib),$(LUA_LD_FLAGS))))
709ifeq ($(LUA_LIB_NAME),)
710$(error unable to automatically detect the Lua library name, you can enforce its name with LUA_LIB_NAME=<name> (where <name> can be lua5.3, lua53, lua, ...))
711endif
712LUA_INC := $(firstword $(foreach lib,lua5.3 lua53 lua,$(call check_lua_inc,$(lib),"/usr/include/")))
713ifneq ($(LUA_INC),)
714OPTIONS_CFLAGS  += -I$(LUA_INC)
715endif
716endif
717
718OPTIONS_LDFLAGS += $(LUA_LD_FLAGS) -l$(LUA_LIB_NAME) -lm
719ifneq ($(USE_DL),)
720OPTIONS_LDFLAGS += -ldl
721endif
722OPTIONS_OBJS    += src/hlua.o src/hlua_fcn.o
723endif
724
725ifneq ($(USE_DEVICEATLAS),)
726ifeq ($(USE_PCRE),)
727$(error the DeviceAtlas module needs the PCRE library in order to compile)
728endif
729# Use DEVICEATLAS_SRC and possibly DEVICEATLAS_INC and DEVICEATLAS_LIB to force path
730# to DeviceAtlas headers and libraries if needed.
731DEVICEATLAS_SRC =
732DEVICEATLAS_INC = $(DEVICEATLAS_SRC)
733DEVICEATLAS_LIB = $(DEVICEATLAS_SRC)
734ifeq ($(DEVICEATLAS_SRC),)
735OPTIONS_LDFLAGS += -lda
736else
737OPTIONS_OBJS	+= $(DEVICEATLAS_LIB)/json.o
738OPTIONS_OBJS	+= $(DEVICEATLAS_LIB)/dac.o
739endif
740OPTIONS_OBJS	+= src/da.o
741OPTIONS_CFLAGS += -DUSE_DEVICEATLAS $(if $(DEVICEATLAS_INC),-I$(DEVICEATLAS_INC))
742BUILD_OPTIONS  += $(call ignore_implicit,USE_DEVICEATLAS)
743endif
744
745ifneq ($(USE_51DEGREES),)
746# Use 51DEGREES_SRC and possibly 51DEGREES_INC and 51DEGREES_LIB to force path
747# to 51degrees headers and libraries if needed.
74851DEGREES_SRC =
74951DEGREES_INC = $(51DEGREES_SRC)
75051DEGREES_LIB = $(51DEGREES_SRC)
751OPTIONS_OBJS    += $(51DEGREES_LIB)/../cityhash/city.o
752OPTIONS_OBJS    += $(51DEGREES_LIB)/51Degrees.o
753OPTIONS_OBJS    += src/51d.o
754OPTIONS_CFLAGS  += -DUSE_51DEGREES $(if $(51DEGREES_INC),-I$(51DEGREES_INC))
755ifeq ($(USE_THREAD),)
756OPTIONS_CFLAGS  += -DFIFTYONEDEGREES_NO_THREADING
757else
758OPTIONS_OBJS    += $(51DEGREES_LIB)/../threading.o
759endif
760
761BUILD_OPTIONS   += $(call ignore_implicit,USE_51DEGREES)
762OPTIONS_LDFLAGS += $(if $(51DEGREES_LIB),-L$(51DEGREES_LIB)) -lm
763endif
764
765ifneq ($(USE_WURFL),)
766# Use WURFL_SRC and possibly WURFL_INC and WURFL_LIB to force path
767# to WURFL headers and libraries if needed.
768WURFL_SRC =
769WURFL_INC = $(WURFL_SRC)
770WURFL_LIB = $(WURFL_SRC)
771OPTIONS_OBJS    += src/wurfl.o
772OPTIONS_CFLAGS  += -DUSE_WURFL $(if $(WURFL_INC),-I$(WURFL_INC))
773ifneq ($(WURFL_DEBUG),)
774OPTIONS_CFLAGS  += -DWURFL_DEBUG
775endif
776ifneq ($(WURFL_HEADER_WITH_DETAILS),)
777OPTIONS_CFLAGS  += -DWURFL_HEADER_WITH_DETAILS
778endif
779BUILD_OPTIONS   += $(call ignore_implicit,USE_WURFL)
780OPTIONS_LDFLAGS += $(if $(WURFL_LIB),-L$(WURFL_LIB)) -lwurfl
781endif
782
783ifneq ($(USE_SYSTEMD),)
784BUILD_OPTIONS   += $(call ignore_implicit,USE_SYSTEMD)
785OPTIONS_CFLAGS  += -DUSE_SYSTEMD
786OPTIONS_LDFLAGS += -lsystemd
787endif
788
789ifneq ($(USE_PCRE)$(USE_STATIC_PCRE)$(USE_PCRE_JIT),)
790ifneq ($(USE_PCRE2)$(USE_STATIC_PCRE2)$(USE_PCRE2_JIT),)
791$(error cannot compile both PCRE and PCRE2 support)
792endif
793# PCREDIR is used to automatically construct the PCRE_INC and PCRE_LIB paths,
794# by appending /include and /lib respectively. If your system does not use the
795# same sub-directories, simply force these variables instead of PCREDIR. It is
796# automatically detected but can be forced if required (for cross-compiling).
797# Forcing PCREDIR to an empty string will let the compiler use the default
798# locations.
799
800PCRE_CONFIG    	:= pcre-config
801PCREDIR	        := $(shell $(PCRE_CONFIG) --prefix 2>/dev/null || echo /usr/local)
802ifneq ($(PCREDIR),)
803PCRE_INC        := $(PCREDIR)/include
804PCRE_LIB        := $(PCREDIR)/lib
805endif
806
807ifeq ($(USE_STATIC_PCRE),)
808# dynamic PCRE
809OPTIONS_CFLAGS  += -DUSE_PCRE $(if $(PCRE_INC),-I$(PCRE_INC))
810OPTIONS_LDFLAGS += $(if $(PCRE_LIB),-L$(PCRE_LIB)) -lpcreposix -lpcre
811BUILD_OPTIONS   += $(call ignore_implicit,USE_PCRE)
812else
813# static PCRE
814OPTIONS_CFLAGS  += -DUSE_PCRE $(if $(PCRE_INC),-I$(PCRE_INC))
815OPTIONS_LDFLAGS += $(if $(PCRE_LIB),-L$(PCRE_LIB)) -Wl,-Bstatic -lpcreposix -lpcre -Wl,-Bdynamic
816BUILD_OPTIONS   += $(call ignore_implicit,USE_STATIC_PCRE)
817endif
818# JIT PCRE
819ifneq ($(USE_PCRE_JIT),)
820OPTIONS_CFLAGS  += -DUSE_PCRE_JIT
821BUILD_OPTIONS   += $(call ignore_implicit,USE_PCRE_JIT)
822endif
823endif
824
825ifneq ($(USE_PCRE2)$(USE_STATIC_PCRE2)$(USE_PCRE2_JIT),)
826PCRE2_CONFIG 	:= pcre2-config
827PCRE2DIR	:= $(shell $(PCRE2_CONFIG) --prefix 2>/dev/null || echo /usr/local)
828ifneq ($(PCRE2DIR),)
829PCRE2_INC       := $(PCRE2DIR)/include
830PCRE2_LIB       := $(PCRE2DIR)/lib
831
832ifeq ($(PCRE2_WIDTH),)
833PCRE2_WIDTH	= 8
834endif
835
836ifneq ($(PCRE2_WIDTH),8)
837ifneq ($(PCRE2_WIDTH),16)
838ifneq ($(PCRE2_WIDTH),32)
839$(error PCRE2_WIDTH needs to be set to either 8,16 or 32)
840endif
841endif
842endif
843
844
845PCRE2_LDFLAGS	:= $(shell $(PCRE2_CONFIG) --libs$(PCRE2_WIDTH) 2>/dev/null || echo -L/usr/local/lib -lpcre2-$(PCRE2_WIDTH))
846
847ifeq ($(PCRE2_LDFLAGS),)
848$(error libpcre2-$(PCRE2_WIDTH) not found)
849else
850ifeq ($(PCRE2_WIDTH),8)
851PCRE2_LDFLAGS	+= -lpcre2-posix
852endif
853endif
854
855OPTIONS_CFLAGS	+= -DUSE_PCRE2 -DPCRE2_CODE_UNIT_WIDTH=$(PCRE2_WIDTH)
856OPTIONS_CFLAGS  += $(if $(PCRE2_INC), -I$(PCRE2_INC))
857
858ifneq ($(USE_STATIC_PCRE2),)
859OPTIONS_LDFLAGS += $(if $(PCRE2_LIB),-L$(PCRE2_LIB)) -Wl,-Bstatic -L$(PCRE2_LIB) $(PCRE2_LDFLAGS) -Wl,-Bdynamic
860BUILD_OPTIONS   += $(call ignore_implicit,USE_STATIC_PCRE2)
861else
862OPTIONS_LDFLAGS += $(if $(PCRE2_LIB),-L$(PCRE2_LIB)) -L$(PCRE2_LIB) $(PCRE2_LDFLAGS)
863BUILD_OPTIONS   += $(call ignore_implicit,USE_PCRE2)
864endif
865
866ifneq ($(USE_PCRE2_JIT),)
867OPTIONS_CFLAGS  += -DUSE_PCRE2_JIT
868BUILD_OPTIONS   += $(call ignore_implicit,USE_PCRE2_JIT)
869endif
870
871endif
872endif
873
874# TCP Fast Open
875ifneq ($(USE_TFO),)
876OPTIONS_CFLAGS  += -DUSE_TFO
877BUILD_OPTIONS   += $(call ignore_implicit,USE_TFO)
878endif
879
880# This one can be changed to look for ebtree files in an external directory
881EBTREE_DIR := ebtree
882
883#### Global compile options
884VERBOSE_CFLAGS = $(CFLAGS) $(TARGET_CFLAGS) $(SMALL_OPTS) $(DEFINE)
885COPTS  = -Iinclude -I$(EBTREE_DIR) -Wall -Wextra
886
887ifneq ($(ERR),)
888COPTS += -Werror
889endif
890
891COPTS += $(CFLAGS) $(TARGET_CFLAGS) $(SMALL_OPTS) $(DEFINE) $(SILENT_DEFINE)
892COPTS += $(DEBUG) $(OPTIONS_CFLAGS) $(ADDINC)
893
894ifneq ($(VERSION)$(SUBVERS),)
895COPTS += -DCONFIG_HAPROXY_VERSION=\"$(VERSION)$(SUBVERS)\"
896endif
897
898ifneq ($(VERDATE),)
899COPTS += -DCONFIG_HAPROXY_DATE=\"$(VERDATE)\"
900endif
901
902ifneq ($(TRACE),)
903# if tracing is enabled, we want it to be as fast as possible
904TRACE_COPTS := $(filter-out -O0 -O1 -O2 -pg -finstrument-functions,$(COPTS)) -O3 -fomit-frame-pointer
905COPTS += -finstrument-functions
906endif
907
908ifneq ($(USE_NS),)
909OPTIONS_CFLAGS += -DCONFIG_HAP_NS
910BUILD_OPTIONS  += $(call ignore_implicit,USE_NS)
911OPTIONS_OBJS  += src/namespace.o
912endif
913
914#### Global link options
915# These options are added at the end of the "ld" command line. Use LDFLAGS to
916# add options at the beginning of the "ld" command line if needed.
917LDOPTS = $(TARGET_LDFLAGS) $(OPTIONS_LDFLAGS) $(ADDLIB)
918
919ifeq ($V,1)
920cmd_CC = $(CC)
921cmd_LD = $(LD)
922cmd_AR = $(AR)
923else
924cmd_CC = $(Q)echo "  CC      $@";$(CC)
925cmd_LD = $(Q)echo "  LD      $@";$(LD)
926cmd_AR = $(Q)echo "  AR      $@";$(AR)
927endif
928
929ifeq ($(TARGET),)
930all:
931	@echo
932	@echo "Due to too many reports of suboptimized setups, building without"
933	@echo "specifying the target is no longer supported. Please specify the"
934	@echo "target OS in the TARGET variable, in the following form:"
935	@echo
936	@echo "   $ make TARGET=xxx"
937	@echo
938	@echo "Please choose the target among the following supported list :"
939	@echo
940	@echo "   linux2628, linux26, linux24, linux24e, linux22, solaris,"
941	@echo "   freebsd, netbsd, osx, openbsd, aix51, aix52, cygwin, haiku,"
942	@echo "   generic, custom"
943	@echo
944	@echo "Use \"generic\" if you don't want any optimization, \"custom\" if you"
945	@echo "want to precisely tweak every option, or choose the target which"
946	@echo "matches your OS the most in order to gain the maximum performance"
947	@echo "out of it. Please check the Makefile in case of doubts."
948	@echo
949	@exit 1
950else
951all: haproxy $(EXTRA)
952endif
953
954OBJS = src/proto_http.o src/cfgparse-listen.o src/proto_htx.o src/stream.o    \
955       src/mux_h2.o src/stats.o src/flt_spoe.o src/server.o src/checks.o      \
956       src/haproxy.o src/cfgparse.o src/flt_http_comp.o src/http_fetch.o      \
957       src/dns.o src/stick_table.o src/mux_h1.o src/peers.o src/standard.o    \
958       src/proxy.o src/cli.o src/log.o src/backend.o src/pattern.o            \
959       src/sample.o src/stream_interface.o src/proto_tcp.o src/listener.o     \
960       src/h1.o src/cfgparse-global.o src/cache.o src/http_rules.o            \
961       src/http_act.o src/tcp_rules.o src/filters.o src/connection.o          \
962       src/session.o src/acl.o src/vars.o src/raw_sock.o src/map.o            \
963       src/proto_uxst.o src/payload.o src/fd.o src/queue.o src/flt_trace.o    \
964       src/task.o src/lb_chash.o src/frontend.o src/applet.o src/mux_pt.o     \
965       src/signal.o src/ev_select.o src/proto_sockpair.o src/compression.o    \
966       src/http_conv.o src/memory.o src/lb_fwrr.o src/channel.o src/htx.o     \
967       src/uri_auth.o src/regex.o src/chunk.o src/pipe.o src/lb_fas.o         \
968       src/lb_map.o src/lb_fwlc.o src/auth.o src/time.o src/hathreads.o       \
969       src/http_htx.o src/buffer.o src/hpack-tbl.o src/shctx.o src/sha1.o     \
970       src/http.o src/hpack-dec.o src/action.o src/proto_udp.o src/http_acl.o \
971       src/xxhash.o src/hpack-enc.o src/h2.o src/freq_ctr.o src/lru.o         \
972       src/protocol.o src/arg.o src/hpack-huff.o src/hdr_idx.o src/base64.o   \
973       src/hash.o src/mailers.o src/activity.o src/http_msg.o
974
975EBTREE_OBJS = $(EBTREE_DIR)/ebtree.o $(EBTREE_DIR)/eb32sctree.o \
976              $(EBTREE_DIR)/eb32tree.o $(EBTREE_DIR)/eb64tree.o \
977              $(EBTREE_DIR)/ebmbtree.o $(EBTREE_DIR)/ebsttree.o \
978              $(EBTREE_DIR)/ebimtree.o $(EBTREE_DIR)/ebistree.o
979
980ifneq ($(TRACE),)
981OBJS += src/trace.o
982endif
983
984
985# Not used right now
986LIB_EBTREE = $(EBTREE_DIR)/libebtree.a
987
988# Used only for forced dependency checking. May be cleared during development.
989INCLUDES = $(wildcard include/*/*.h ebtree/*.h)
990DEP = $(INCLUDES) .build_opts
991
992help:
993	$(Q)sed -ne "/^[^#]*$$/q;s/^# \{0,1\}\(.*\)/\1/;p" Makefile
994
995# Used only to force a rebuild if some build options change
996build_opts = $(shell rm -f .build_opts.new; echo \'$(TARGET) $(BUILD_OPTIONS) $(VERBOSE_CFLAGS)\' > .build_opts.new; if cmp -s .build_opts .build_opts.new; then rm -f .build_opts.new; else mv -f .build_opts.new .build_opts; fi)
997.build_opts: $(build_opts)
998
999haproxy: $(OPTIONS_OBJS) $(OBJS) $(EBTREE_OBJS)
1000	$(cmd_LD) $(LDFLAGS) -o $@ $^ $(LDOPTS)
1001
1002$(LIB_EBTREE): $(EBTREE_OBJS)
1003	$(cmd_AR) rv $@ $^
1004
1005objsize: haproxy
1006	$(Q)objdump -t $^|grep ' g '|grep -F '.text'|awk '{print $$5 FS $$6}'|sort
1007
1008%.o:	%.c $(DEP)
1009	$(cmd_CC) $(COPTS) -c -o $@ $<
1010
1011src/trace.o: src/trace.c $(DEP)
1012	$(cmd_CC) $(TRACE_COPTS) -c -o $@ $<
1013
1014src/haproxy.o:	src/haproxy.c $(DEP)
1015	$(cmd_CC) $(COPTS) \
1016	      -DBUILD_TARGET='"$(strip $(TARGET))"' \
1017	      -DBUILD_ARCH='"$(strip $(ARCH))"' \
1018	      -DBUILD_CPU='"$(strip $(CPU))"' \
1019	      -DBUILD_CC='"$(strip $(CC))"' \
1020	      -DBUILD_CFLAGS='"$(strip $(VERBOSE_CFLAGS))"' \
1021	      -DBUILD_OPTIONS='"$(strip $(BUILD_OPTIONS))"' \
1022	       -c -o $@ $<
1023
1024src/dlmalloc.o: $(DLMALLOC_SRC) $(DEP)
1025	$(cmd_CC) $(COPTS) -DDEFAULT_MMAP_THRESHOLD=$(DLMALLOC_THRES) -c -o $@ $<
1026
1027install-man:
1028	$(Q)install -v -d "$(DESTDIR)$(MANDIR)"/man1
1029	$(Q)install -v -m 644 doc/haproxy.1 "$(DESTDIR)$(MANDIR)"/man1
1030
1031EXCLUDE_DOCUMENTATION = lgpl gpl coding-style
1032DOCUMENTATION = $(filter-out $(EXCLUDE_DOCUMENTATION),$(patsubst doc/%.txt,%,$(wildcard doc/*.txt)))
1033
1034install-doc:
1035	$(Q)install -v -d "$(DESTDIR)$(DOCDIR)"
1036	$(Q)for x in $(DOCUMENTATION); do \
1037		install -v -m 644 doc/$$x.txt "$(DESTDIR)$(DOCDIR)" ; \
1038	done
1039
1040install-bin:
1041	$(Q)for i in haproxy $(EXTRA); do \
1042		if ! [ -e "$$i" ]; then \
1043			echo "Please run 'make' before 'make install'."; \
1044			exit 1; \
1045		fi; \
1046	done
1047	$(Q)install -v -d "$(DESTDIR)$(SBINDIR)"
1048	$(Q)install -v haproxy $(EXTRA) "$(DESTDIR)$(SBINDIR)"
1049
1050install: install-bin install-man install-doc
1051
1052uninstall:
1053	$(Q)rm -f "$(DESTDIR)$(MANDIR)"/man1/haproxy.1
1054	$(Q)for x in $(DOCUMENTATION); do \
1055		rm -f "$(DESTDIR)$(DOCDIR)"/$$x.txt ; \
1056	done
1057	$(Q)-rmdir "$(DESTDIR)$(DOCDIR)"
1058	$(Q)rm -f "$(DESTDIR)$(SBINDIR)"/haproxy
1059
1060clean:
1061	$(Q)rm -f *.[oas] src/*.[oas] ebtree/*.[oas] haproxy test .build_opts .build_opts.new
1062	$(Q)for dir in . src include/* doc ebtree; do rm -f $$dir/*~ $$dir/*.rej $$dir/core; done
1063	$(Q)rm -f haproxy-$(VERSION).tar.gz haproxy-$(VERSION)$(SUBVERS).tar.gz
1064	$(Q)rm -f haproxy-$(VERSION) haproxy-$(VERSION)$(SUBVERS) nohup.out gmon.out
1065
1066tags:
1067	$(Q)find src include \( -name '*.c' -o -name '*.h' \) -print0 | \
1068	   xargs -0 etags --declarations --members
1069
1070cscope:
1071	$(Q)find src include -name "*.[ch]" -print | cscope -q -b -i -
1072
1073tar:	clean
1074	$(Q)ln -s . haproxy-$(VERSION)$(SUBVERS)
1075	$(Q)tar --exclude=haproxy-$(VERSION)$(SUBVERS)/.git \
1076	    --exclude=haproxy-$(VERSION)$(SUBVERS)/haproxy-$(VERSION)$(SUBVERS) \
1077	    --exclude=haproxy-$(VERSION)$(SUBVERS)/haproxy-$(VERSION)$(SUBVERS).tar.gz \
1078	    -cf - haproxy-$(VERSION)$(SUBVERS)/* | gzip -c9 >haproxy-$(VERSION)$(SUBVERS).tar.gz
1079	$(Q)echo haproxy-$(VERSION)$(SUBVERS).tar.gz
1080	$(Q)rm -f haproxy-$(VERSION)$(SUBVERS)
1081
1082git-tar:
1083	$(Q)git archive --format=tar --prefix="haproxy-$(VERSION)$(SUBVERS)/" HEAD | gzip -9 > haproxy-$(VERSION)$(SUBVERS).tar.gz
1084	$(Q)echo haproxy-$(VERSION)$(SUBVERS).tar.gz
1085
1086version:
1087	@echo "VERSION: $(VERSION)"
1088	@echo "SUBVERS: $(SUBVERS)"
1089	@echo "VERDATE: $(VERDATE)"
1090
1091# never use this one if you don't know what it is used for.
1092update-version:
1093	@echo "Ready to update the following versions :"
1094	@echo "VERSION: $(VERSION)"
1095	@echo "SUBVERS: $(SUBVERS)"
1096	@echo "VERDATE: $(VERDATE)"
1097	@echo "Press [ENTER] to continue or Ctrl-C to abort now.";read
1098	echo "$(VERSION)" > VERSION
1099	echo "$(SUBVERS)" > SUBVERS
1100	echo "$(VERDATE)" > VERDATE
1101
1102# just display the build options
1103opts:
1104	@echo -n 'Using: '
1105	@echo -n 'TARGET="$(strip $(TARGET))" '
1106	@echo -n 'ARCH="$(strip $(ARCH))" '
1107	@echo -n 'CPU="$(strip $(CPU))" '
1108	@echo -n 'CC="$(strip $(CC))" '
1109	@echo -n 'ARCH_FLAGS="$(strip $(ARCH_FLAGS))" '
1110	@echo -n 'CPU_CFLAGS="$(strip $(CPU_CFLAGS))" '
1111	@echo -n 'DEBUG_CFLAGS="$(strip $(DEBUG_CFLAGS))" '
1112	@echo "$(strip $(BUILD_OPTIONS))"
1113	@echo 'COPTS="$(strip $(COPTS))"'
1114	@echo 'LDFLAGS="$(strip $(LDFLAGS))"'
1115	@echo 'LDOPTS="$(strip $(LDOPTS))"'
1116	@echo 'OPTIONS_OBJS="$(strip $(OPTIONS_OBJS))"'
1117	@echo 'OBJS="$(strip $(OBJS))"'
1118
1119ifeq (reg-tests, $(firstword $(MAKECMDGOALS)))
1120  REGTEST_ARGS := $(wordlist 2, $(words $(MAKECMDGOALS)), $(MAKECMDGOALS))
1121  $(eval $(REGTEST_ARGS):;@true)
1122endif
1123
1124# Target to run the regression testing script files.
1125reg-tests:
1126	$(Q)./scripts/run-regtests.sh --LEVEL "$(LEVEL)" $(REGTEST_ARGS) $(REG_TEST_FILES)
1127.PHONY: $(REGTEST_ARGS)
1128
1129reg-tests-help:
1130	@echo
1131	@echo "To launch the reg tests for haproxy, first export to your environment VTEST_PROGRAM variable to point to your vtest program:"
1132	@echo "    $$ export VTEST_PROGRAM=/opt/local/bin/vtest"
1133	@echo "or"
1134	@echo "    $$ setenv VTEST_PROGRAM /opt/local/bin/vtest"
1135	@echo
1136	@echo "The same thing may be done to set your haproxy program with HAPROXY_PROGRAM but with ./haproxy as default value."
1137	@echo
1138	@echo "To run all the tests:"
1139	@echo "    $$ make reg-tests"
1140	@echo
1141	@echo "You can also set the programs to be used on the command line:"
1142	@echo "    $$ VTEST_PROGRAM=<...> HAPROXY_PROGRAM=<...> make reg-tests"
1143	@echo
1144	@echo "To run tests with specific levels:"
1145	@echo "    $$ LEVEL=1,3,4   make reg-tests  #list of levels"
1146	@echo "    $$ LEVEL=1-3,5-6 make reg-tests  #list of range of levels"
1147	@echo
1148	@echo "About the levels:"
1149	@echo "    LEVEL 1 scripts are dedicated to pure haproxy compliance tests (prefixed with 'h' letter)."
1150	@echo "    LEVEL 2 scripts are slow scripts (prefixed with 's' letter)."
1151	@echo "    LEVEL 3 scripts are low interest scripts (prefixed with 'l' letter)."
1152	@echo "    LEVEL 4 scripts are in relation with bugs they help to reproduce (prefixed with 'b' letter)."
1153	@echo "    LEVEL 5 scripts are scripts triggering known broken behaviors for which there is still no fix (prefixed with 'k' letter)."
1154	@echo "    LEVEL 6 scripts are experimental, typically used to develop new scripts (prefixed with 'e' lettre)."
1155
1156.PHONY: reg-tests reg-tests-help
1157