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