blob: 7958b89d67b0902dcbd41d99a8ba72285bd124f4 [file] [log] [blame]
Willy Tarreau9f2b7302008-01-02 20:48:34 +01001# This GNU Makefile supports different OS and CPU combinations.
2#
willy tarreaueedaa9f2005-12-17 14:08:03 +01003# You should use it this way :
Willy Tarreau50b1aae2019-06-14 15:52:01 +02004# [g]make TARGET=os [ARCH=arch] [CPU=cpu] USE_xxx=1 ...
5#
6# When in doubt, invoke help, possibly with a known target :
7# [g]make help
Willy Tarreau61cf0dc2019-06-14 16:32:09 +02008# [g]make help TARGET=linux-glibc
Willy Tarreauf2ef8c52007-07-11 09:19:31 +02009#
Willy Tarreau16119652018-11-19 08:15:54 +010010# By default the detailed commands are hidden for a cleaner output, but you may
11# see them by appending "V=1" to the make command.
12#
Willy Tarreau05fd82d2019-03-27 10:57:49 +010013# Valid USE_* options are enumerated in the "use_opts" variable and are listed
14# below. Most of them are automatically set by the TARGET, others have to be
15# explicitly specified :
Willy Tarreau9f2b7302008-01-02 20:48:34 +010016# USE_EPOLL : enable epoll() on Linux 2.6. Automatic.
Willy Tarreau9f2b7302008-01-02 20:48:34 +010017# USE_KQUEUE : enable kqueue() on BSD. Automatic.
Emmanuel Hocdet0ba4f482019-04-08 16:53:32 +000018# USE_EVPORTS : enable event ports on SunOS systems. Automatic.
Willy Tarreau9f2b7302008-01-02 20:48:34 +010019# USE_NETFILTER : enable netfilter on Linux. Automatic.
20# USE_PCRE : enable use of libpcre for regex. Recommended.
Willy Tarreau91418062013-04-04 23:05:32 +020021# USE_PCRE_JIT : enable JIT for faster regex on libpcre >= 8.32
David Carlierf2592b22016-11-21 21:25:58 +000022# USE_PCRE2 : enable use of libpcre2 for regex.
23# USE_PCRE2_JIT : enable JIT for faster regex on libpcre2
Willy Tarreau9f2b7302008-01-02 20:48:34 +010024# USE_POLL : enable poll(). Automatic.
Emeric Brun9faf0712012-09-25 11:11:16 +020025# USE_PRIVATE_CACHE : disable shared memory cache of ssl sessions.
Christopher Fauleta1ae7e82017-10-25 17:55:27 +020026# USE_THREAD : enable threads support.
Emeric Bruncd1a5262014-05-07 23:11:42 +020027# USE_PTHREAD_PSHARED : enable pthread process shared mutex on sslcache.
Willy Tarreau9f2b7302008-01-02 20:48:34 +010028# USE_STATIC_PCRE : enable static libpcre. Recommended.
David Carlierf2592b22016-11-21 21:25:58 +000029# USE_STATIC_PCRE2 : enable static libpcre2.
Willy Tarreau9f2b7302008-01-02 20:48:34 +010030# USE_TPROXY : enable transparent proxy. Automatic.
Willy Tarreaue0c623d2012-06-04 00:42:09 +020031# USE_LINUX_TPROXY : enable full transparent proxy. Automatic.
32# USE_LINUX_SPLICE : enable kernel 2.6 splicing. Automatic.
Willy Tarreau890a33e2010-03-04 19:10:14 +010033# USE_LIBCRYPT : enable crypted passwords using -lcrypt
34# USE_CRYPT_H : set it if your system requires including crypt.h
Willy Tarreau64bc40b2011-03-23 20:00:53 +010035# USE_GETADDRINFO : use getaddrinfo() to resolve IPv6 host names.
Emeric Brun7444f012012-05-18 15:48:30 +020036# USE_OPENSSL : enable use of OpenSSL. Recommended, but see below.
Thierry FOURNIER6f1fd482015-01-23 14:06:13 +010037# USE_LUA : enable Lua support.
Emeric Brun3e541d12012-09-03 11:14:36 +020038# USE_FUTEX : enable use of futex on kernel 2.6. Automatic.
Willy Tarreau1bc4aab2012-10-08 20:11:03 +020039# USE_ACCEPT4 : enable use of accept4() on linux. Automatic.
Brad Smith5018aac2020-09-30 01:04:48 -040040# USE_CLOSEFROM : enable use of closefrom() on *bsd, solaris. Automatic.
Willy Tarreau636848a2019-04-15 19:38:50 +020041# USE_PRCTL : enable use of prctl(). Automatic.
William Lallemand82fe75c2012-10-23 10:25:10 +020042# USE_ZLIB : enable zlib library support.
Willy Tarreau418b8c02015-03-29 03:32:06 +020043# USE_SLZ : enable slz library instead of zlib (pick at most one).
Willy Tarreaufc6c0322012-11-16 16:12:27 +010044# USE_CPU_AFFINITY : enable pinning processes to CPU on Linux. Automatic.
Lukas Tribus0999f762013-04-02 16:43:24 +020045# USE_TFO : enable TCP fast open. Supported on Linux >= 3.7.
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +010046# USE_NS : enable network namespace support. Supported on Linux >= 2.6.24.
Willy Tarreau71b99ef2015-03-17 14:33:22 +010047# USE_DL : enable it if your system requires -ldl. Automatic on Linux.
Willy Tarreau58e90cb2018-10-18 16:28:54 +020048# USE_RT : enable it if your system requires -lrt. Automatic on Linux.
Willy Tarreauf5b4e062020-03-03 15:40:23 +010049# USE_BACKTRACE : enable backtrace(). Automatic on Linux.
David Carliera03fb142015-06-01 14:00:07 +020050# USE_DEVICEATLAS : enable DeviceAtlas api.
Dragan Dosen93b38d92015-06-29 16:43:25 +020051# USE_51DEGREES : enable third party device detection library from 51Degrees
Willy Tarreaub3cc9f22019-04-19 16:03:32 +020052# USE_WURFL : enable WURFL detection library from Scientiamobile
Tim Duesterhusd6942c82017-11-20 15:58:35 +010053# USE_SYSTEMD : enable sd_notify() support.
Willy Tarreau7b5654f2019-03-29 21:30:17 +010054# USE_OBSOLETE_LINKER : use when the linker fails to emit __start_init/__stop_init
Willy Tarreauc7091d82019-05-17 10:08:49 +020055# USE_THREAD_DUMP : use the more advanced thread state dump system. Automatic.
Willy Tarreauf2ef8c52007-07-11 09:19:31 +020056#
Willy Tarreau9f2b7302008-01-02 20:48:34 +010057# Options can be forced by specifying "USE_xxx=1" or can be disabled by using
Willy Tarreau50b1aae2019-06-14 15:52:01 +020058# "USE_xxx=" (empty string). The list of enabled and disabled options for a
59# given TARGET is enumerated at the end of "make help".
Willy Tarreau9f2b7302008-01-02 20:48:34 +010060#
61# Variables useful for packagers :
Brad Smith94636432020-09-13 02:53:06 -040062# CC is set to "cc" by default and is used for compilation only.
63# LD is set to "cc" by default and is used for linking only.
Willy Tarreauef7341d2009-04-11 19:45:50 +020064# ARCH may be useful to force build of 32-bit binary on 64-bit systems
Willy Tarreau9f2b7302008-01-02 20:48:34 +010065# CFLAGS is automatically set for the specified CPU and may be overridden.
66# LDFLAGS is automatically set to -g and may be overridden.
Willy Tarreaub26835d2016-05-30 13:39:32 +020067# DEP may be cleared to ignore changes to include files during development
Willy Tarreau9f2b7302008-01-02 20:48:34 +010068# SMALL_OPTS may be used to specify some options to shrink memory usage.
69# DEBUG may be used to set some internal debugging options.
Willy Tarreau23cd43e2018-10-22 06:22:46 +020070# ERR may be set to non-empty to pass -Werror to the compiler
Willy Tarreau9f2b7302008-01-02 20:48:34 +010071# ADDINC may be used to complete the include path in the form -Ipath.
72# ADDLIB may be used to complete the library list in the form -Lpath -llib.
73# DEFINE may be used to specify any additional define, which will be reported
74# by "haproxy -vv" in CFLAGS.
75# SILENT_DEFINE may be used to specify other defines which will not be
76# reported by "haproxy -vv".
William Lallemanda6cfa902017-06-01 17:38:58 +020077# EXTRA is used to force building or not building some extra tools.
Christian Wiesea184aa22008-03-12 15:25:35 +020078# DESTDIR is not set by default and is used for installation only.
79# It might be useful to set DESTDIR if you want to install haproxy
80# in a sandbox.
81# PREFIX is set to "/usr/local" by default and is used for installation only.
82# SBINDIR is set to "$(PREFIX)/sbin" by default and is used for installation
83# only.
Christian Wiese19b50292008-03-12 15:57:54 +020084# MANDIR is set to "$(PREFIX)/share/man" by default and is used for
85# installation only.
Christian Wiesebf34eb42008-03-12 17:24:49 +020086# DOCDIR is set to "$(PREFIX)/doc/haproxy" by default and is used for
87# installation only.
Tim Duesterhus541fe1e2020-01-12 13:55:41 +010088# HLUA_PREPEND_PATH may be used to prepend a folder to Lua's default package.path.
89# HLUA_PREPEND_CPATH may be used to prepend a folder to Lua's default package.cpath.
Willy Tarreau9f2b7302008-01-02 20:48:34 +010090#
91# Other variables :
Fabrice Fontaine7b4c8c32018-09-28 19:21:26 +020092# PCRE_CONFIG : force the binary path to get pcre config (by default
93# pcre-config)
Willy Tarreau9f2b7302008-01-02 20:48:34 +010094# PCREDIR : force the path to libpcre.
Willy Tarreau39793092013-02-13 12:39:06 +010095# PCRE_LIB : force the lib path to libpcre (defaults to $PCREDIR/lib).
96# PCRE_INC : force the include path to libpcre ($PCREDIR/inc)
Fabrice Fontaine7b4c8c32018-09-28 19:21:26 +020097# PCRE2_CONFIG : force the binary path to get pcre2 config (by default
98# pcre2-config)
Willy Tarreau9a059452013-09-17 15:26:39 +020099# SSL_LIB : force the lib path to libssl/libcrypto
100# SSL_INC : force the include path to libssl/libcrypto
Thierry FOURNIER6f1fd482015-01-23 14:06:13 +0100101# LUA_LIB : force the lib path to lua
102# LUA_INC : force the include path to lua
Cyril Bontéc21adb52015-03-03 23:13:03 +0100103# LUA_LIB_NAME : force the lib name (or automatically evaluated, by order of
Thierry FOURNIERf90838b2015-03-06 13:48:32 +0100104# priority : lua5.3, lua53, lua).
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100105# IGNOREGIT : ignore GIT commit versions if set.
106# VERSION : force haproxy version reporting.
107# SUBVERS : add a sub-version (eg: platform, model, ...).
Willy Tarreauac32b4b2020-10-01 04:05:39 +0200108# EXTRAVERSION : local version string to append (e.g. build number etc)
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100109# VERDATE : force haproxy's release date.
Willy Tarreau648fa9d2019-06-14 15:52:01 +0200110# VTEST_PROGRAM : location of the vtest program to run reg-tests.
Ilya Shipitsin4a034f22020-09-12 11:24:48 +0500111# DEBUG_USE_ABORT: use abort() for program termination, see include/haproxy/bug.h for details
Willy Tarreau4f60f162007-04-08 16:39:58 +0200112
Willy Tarreaub42233a2018-11-19 07:44:42 +0100113# verbosity: pass V=1 for verbose shell invocation
114V = 0
115Q = @
116ifeq ($V,1)
117Q=
118endif
119
Willy Tarreaud3a7f402017-09-13 16:54:28 +0200120# Function used to detect support of a given option by the compiler.
121# Usage: CFLAGS += $(call cc-opt,option). Eg: $(call cc-opt,-fwrapv)
122# Note: ensure the referencing variable is assigned using ":=" and not "=" to
123# call it only once.
Willy Tarreauf11ca5e2018-10-03 09:52:51 +0200124cc-opt = $(shell set -e; if $(CC) $(1) -E -xc - -o /dev/null </dev/null >&0 2>&0; then echo "$(1)"; fi;)
Willy Tarreaud3a7f402017-09-13 16:54:28 +0200125
Willy Tarreau0d7a2ae2018-10-16 18:11:34 +0200126# same but emits $2 if $1 is not supported
127cc-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;)
128
Willy Tarreaub7801662017-09-14 19:05:45 +0200129# Disable a warning when supported by the compiler. Don't put spaces around the
130# warning! And don't use cc-opt which doesn't always report an error until
131# another one is also returned.
132# Usage: CFLAGS += $(call cc-nowarn,warning). Eg: $(call cc-opt,format-truncation)
Willy Tarreauf11ca5e2018-10-03 09:52:51 +0200133cc-nowarn = $(shell set -e; if $(CC) -W$(1) -E -xc - -o /dev/null </dev/null >&0 2>&0; then echo "-Wno-$(1)"; fi;)
Willy Tarreaub7801662017-09-14 19:05:45 +0200134
Christian Wiesea184aa22008-03-12 15:25:35 +0200135#### Installation options.
136DESTDIR =
137PREFIX = /usr/local
138SBINDIR = $(PREFIX)/sbin
Jeremy Hinegardneref3b4032008-11-15 17:29:03 -0700139MANDIR = $(PREFIX)/share/man
Christian Wiesebf34eb42008-03-12 17:24:49 +0200140DOCDIR = $(PREFIX)/doc/haproxy
Willy Tarreau4f60f162007-04-08 16:39:58 +0200141
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100142#### TARGET system
Ilya Shipitsin2a950d02020-03-06 13:07:38 +0500143# Use TARGET=<target_name> to optimize for a specific target OS among the
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100144# following list (use the default "generic" if uncertain) :
Willy Tarreau39b2fda2020-04-16 15:14:17 +0200145# linux-glibc, linux-glibc-legacy, linux-musl, solaris, freebsd, openbsd,
146# netbsd, cygwin, haiku, aix51, aix52, aix72-gcc, osx, generic, custom
Willy Tarreaue4208cb2008-03-11 06:37:39 +0100147TARGET =
Willy Tarreau4f60f162007-04-08 16:39:58 +0200148
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100149#### TARGET CPU
150# Use CPU=<cpu_name> to optimize for a particular CPU, among the following
151# list :
Christian Lachnerc1322302020-02-10 10:29:13 +0100152# generic, native, i586, i686, ultrasparc, power8, power9, custom
willy tarreaueedaa9f2005-12-17 14:08:03 +0100153CPU = generic
willy tarreau036e1ce2005-12-17 13:46:33 +0100154
Willy Tarreauef7341d2009-04-11 19:45:50 +0200155#### Architecture, used when not building for native architecture
156# Use ARCH=<arch_name> to force build for a specific architecture. Known
157# architectures will lead to "-m32" or "-m64" being added to CFLAGS and
158# LDFLAGS. This can be required to build 32-bit binaries on 64-bit targets.
Willy Tarreaua5899aa2010-11-28 07:41:00 +0100159# Currently, only 32, 64, x86_64, i386, i486, i586 and i686 are understood.
Willy Tarreauef7341d2009-04-11 19:45:50 +0200160ARCH =
161
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100162#### Toolchain options.
Brad Smith94636432020-09-13 02:53:06 -0400163CC = cc
Christian Wiesef6308302008-03-17 18:23:12 +0100164LD = $(CC)
willy tarreaueedaa9f2005-12-17 14:08:03 +0100165
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100166#### Debug flags (typically "-g").
167# Those flags only feed CFLAGS so it is not mandatory to use this form.
168DEBUG_CFLAGS = -g
willy tarreau036e1ce2005-12-17 13:46:33 +0100169
Willy Tarreau23cd43e2018-10-22 06:22:46 +0200170#### Add -Werror when set to non-empty
171ERR =
172
Willy Tarreaudb863332018-11-23 08:29:15 +0100173#### May be used to force running a specific set of reg-tests
174REG_TEST_FILES =
Frédéric Lécailledc1a3bd2019-03-29 15:07:24 +0100175REG_TEST_SCRIPT=./scripts/run-regtests.sh
Willy Tarreaudb863332018-11-23 08:29:15 +0100176
Willy Tarreau3c9a3fb2010-11-28 08:28:15 +0100177#### Compiler-specific flags that may be used to disable some negative over-
Willy Tarreaud1c847a2020-02-25 10:10:47 +0100178# optimization or to silence some warnings.
Olivier Houchard73bdb322017-04-19 11:34:10 +0200179# We rely on signed integer wraparound on overflow, however clang think it
180# can do whatever it wants since it's an undefined behavior, so use -fwrapv
181# to be sure we get the intended behavior.
Willy Tarreau4b61e692020-03-10 09:37:08 +0100182SPEC_CFLAGS := -Wall -Wextra -Wdeclaration-after-statement
Willy Tarreau0d7a2ae2018-10-16 18:11:34 +0200183SPEC_CFLAGS += $(call cc-opt-alt,-fwrapv,$(call cc-opt,-fno-strict-overflow))
Willy Tarreaub7801662017-09-14 19:05:45 +0200184SPEC_CFLAGS += $(call cc-nowarn,address-of-packed-member)
Willy Tarreaueff9a9e2017-10-27 11:06:11 +0200185SPEC_CFLAGS += $(call cc-nowarn,unused-label)
Willy Tarreauf7db9302018-09-20 10:38:08 +0200186SPEC_CFLAGS += $(call cc-nowarn,sign-compare)
187SPEC_CFLAGS += $(call cc-nowarn,unused-parameter)
Willy Tarreauf7db9302018-09-20 10:38:08 +0200188SPEC_CFLAGS += $(call cc-nowarn,clobbered)
189SPEC_CFLAGS += $(call cc-nowarn,missing-field-initializers)
Olivier Houchard73bce432018-11-27 14:47:58 +0100190SPEC_CFLAGS += $(call cc-nowarn,cast-function-type)
Willy Tarreauc77c2d42019-09-24 09:43:34 +0200191SPEC_CFLAGS += $(call cc-nowarn,string-plus-int)
Willy Tarreauf7db9302018-09-20 10:38:08 +0200192SPEC_CFLAGS += $(call cc-opt,-Wtype-limits)
193SPEC_CFLAGS += $(call cc-opt,-Wshift-negative-value)
194SPEC_CFLAGS += $(call cc-opt,-Wshift-overflow=2)
195SPEC_CFLAGS += $(call cc-opt,-Wduplicated-cond)
196SPEC_CFLAGS += $(call cc-opt,-Wnull-dereference)
Willy Tarreau3c9a3fb2010-11-28 08:28:15 +0100197
Willy Tarreau4b61e692020-03-10 09:37:08 +0100198ifneq ($(ERR),)
199SPEC_CFLAGS += -Werror
200endif
201
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100202#### Memory usage tuning
203# If small memory footprint is required, you can reduce the buffer size. There
204# are 2 buffers per concurrent session, so 16 kB buffers will eat 32 MB memory
205# with 1000 concurrent sessions. Putting it slightly lower than a page size
206# will prevent the additional parameters to go beyond a page. 8030 bytes is
207# exactly 5.5 TCP segments of 1460 bytes and is generally good. Useful tuning
208# macros include :
209# SYSTEM_MAXCONN, BUFSIZE, MAXREWRITE, REQURI_LEN, CAPTURE_LEN.
210# Example: SMALL_OPTS = -DBUFSIZE=8030 -DMAXREWRITE=1030 -DSYSTEM_MAXCONN=1024
211SMALL_OPTS =
Willy Tarreau6d1a9882007-01-07 02:03:04 +0100212
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100213#### Debug settings
214# You can enable debugging on specific code parts by setting DEBUG=-DDEBUG_xxx.
Willy Tarreau4c442b02020-07-04 12:43:46 +0200215# Use quotes and spaces if multiple options are needed (the DEBUG variables is
216# passed as-is to CFLAGS). Please check sources for their exact meaning or do
217# not use them at all. Some even more obscure ones might also be available
218# without appearing here. Currently defined DEBUG macros include DEBUG_FULL,
219# DEBUG_MEM_STATS, DEBUG_DONT_SHARE_POOLS, DEBUG_NO_LOCKLESS_POOLS, DEBUG_FD,
220# DEBUG_NO_LOCAL_POOLS, DEBUG_FAIL_ALLOC, DEBUG_STRICT_NOCRASH, DEBUG_HPACK,
221# DEBUG_AUTH, DEBUG_SPOE, DEBUG_UAF, DEBUG_THREAD, DEBUG_STRICT, DEBUG_DEV.
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100222DEBUG =
willy tarreau1c2ad212005-12-18 01:11:29 +0100223
Willy Tarreau7de211c2012-05-25 23:53:16 +0200224#### Trace options
225# Use TRACE=1 to trace function calls to file "trace.out" or to stderr if not
226# possible.
227TRACE =
228
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100229#### Additional include and library dirs
230# Redefine this if you want to add some special PATH to include/libs
231ADDINC =
232ADDLIB =
willy tarreau64a3cc32005-12-18 01:13:11 +0100233
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100234#### Specific macro definitions
235# Use DEFINE=-Dxxx to set any tunable macro. Anything declared here will appear
236# in the build options reported by "haproxy -vv". Use SILENT_DEFINE if you do
237# not want to pollute the report with complex defines.
Emeric Brun76d88952012-10-05 15:47:31 +0200238# The following settings might be of interest when SSL is enabled :
239# LISTEN_DEFAULT_CIPHERS is a cipher suite string used to set the default SSL
240# ciphers on "bind" lines instead of using OpenSSL's defaults.
241# CONNECT_DEFAULT_CIPHERS is a cipher suite string used to set the default
242# SSL ciphers on "server" lines instead of using OpenSSL's defaults.
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100243DEFINE =
244SILENT_DEFINE =
willy tarreau0f7af912005-12-17 12:21:26 +0100245
William Lallemanda6cfa902017-06-01 17:38:58 +0200246#### extra programs to build
Willy Tarreaubc289da2014-05-10 12:16:21 +0200247# Force this to enable building extra programs or to disable them.
248# It's automatically appended depending on the targets.
249EXTRA =
willy tarreau5cbea6f2005-12-17 12:48:26 +0100250
Ilya Shipitsin2a950d02020-03-06 13:07:38 +0500251#### CPU dependent optimizations
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100252# Some CFLAGS are set by default depending on the target CPU. Those flags only
253# feed CPU_CFLAGS, which in turn feed CFLAGS, so it is not mandatory to use
254# them. You should not have to change these options. Better use CPU_CFLAGS or
255# even CFLAGS instead.
256CPU_CFLAGS.generic = -O2
Willy Tarreaua5899aa2010-11-28 07:41:00 +0100257CPU_CFLAGS.native = -O2 -march=native
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100258CPU_CFLAGS.i586 = -O2 -march=i586
259CPU_CFLAGS.i686 = -O2 -march=i686
260CPU_CFLAGS.ultrasparc = -O6 -mcpu=v9 -mtune=ultrasparc
Christian Lachnerc1322302020-02-10 10:29:13 +0100261CPU_CFLAGS.power8 = -O2 -mcpu=power8 -mtune=power8
262CPU_CFLAGS.power9 = -O2 -mcpu=power9 -mtune=power9
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100263CPU_CFLAGS = $(CPU_CFLAGS.$(CPU))
willy tarreau9da061b2005-12-17 12:29:56 +0100264
Ilya Shipitsin2a950d02020-03-06 13:07:38 +0500265#### ARCH dependent flags, may be overridden by CPU flags
Willy Tarreaua5899aa2010-11-28 07:41:00 +0100266ARCH_FLAGS.32 = -m32
267ARCH_FLAGS.64 = -m64
Willy Tarreauef7341d2009-04-11 19:45:50 +0200268ARCH_FLAGS.i386 = -m32 -march=i386
269ARCH_FLAGS.i486 = -m32 -march=i486
270ARCH_FLAGS.i586 = -m32 -march=i586
271ARCH_FLAGS.i686 = -m32 -march=i686
272ARCH_FLAGS.x86_64 = -m64 -march=x86-64
273ARCH_FLAGS = $(ARCH_FLAGS.$(ARCH))
274
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100275#### Common CFLAGS
276# These CFLAGS contain general optimization options, CPU-specific optimizations
277# and debug flags. They may be overridden by some distributions which prefer to
278# set all of them at once instead of playing with the CPU and DEBUG variables.
Willy Tarreau3c9a3fb2010-11-28 08:28:15 +0100279CFLAGS = $(ARCH_FLAGS) $(CPU_CFLAGS) $(DEBUG_CFLAGS) $(SPEC_CFLAGS)
willy tarreaueedaa9f2005-12-17 14:08:03 +0100280
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100281#### Common LDFLAGS
282# These LDFLAGS are used as the first "ld" options, regardless of any library
283# path or any other option. They may be changed to add any linker-specific
284# option at the beginning of the ld command line.
Willy Tarreauef7341d2009-04-11 19:45:50 +0200285LDFLAGS = $(ARCH_FLAGS) -g
willy tarreau036e1ce2005-12-17 13:46:33 +0100286
Willy Tarreau05fd82d2019-03-27 10:57:49 +0100287#### list of all "USE_*" options. These ones must be updated if new options are
288# added, so that the relevant options are properly added to the CFLAGS and to
289# the reported build options.
Willy Tarreau06c63ae2020-03-10 07:20:10 +0100290use_opts = USE_EPOLL USE_KQUEUE USE_NETFILTER \
Willy Tarreau05fd82d2019-03-27 10:57:49 +0100291 USE_PCRE USE_PCRE_JIT USE_PCRE2 USE_PCRE2_JIT USE_POLL \
Willy Tarreauf5b4e062020-03-03 15:40:23 +0100292 USE_PRIVATE_CACHE USE_THREAD USE_PTHREAD_PSHARED USE_BACKTRACE \
Willy Tarreau05fd82d2019-03-27 10:57:49 +0100293 USE_STATIC_PCRE USE_STATIC_PCRE2 USE_TPROXY USE_LINUX_TPROXY \
Willy Tarreauc3e926b2020-03-10 06:48:17 +0100294 USE_LINUX_SPLICE USE_LIBCRYPT USE_CRYPT_H \
Willy Tarreau05fd82d2019-03-27 10:57:49 +0100295 USE_GETADDRINFO USE_OPENSSL USE_LUA USE_FUTEX USE_ACCEPT4 \
Brad Smith5018aac2020-09-30 01:04:48 -0400296 USE_CLOSEFROM USE_ZLIB USE_SLZ USE_CPU_AFFINITY USE_TFO USE_NS \
Willy Tarreau14261982019-04-23 10:57:09 +0200297 USE_DL USE_RT USE_DEVICEATLAS USE_51DEGREES USE_WURFL USE_SYSTEMD \
Emmanuel Hocdet0ba4f482019-04-08 16:53:32 +0000298 USE_OBSOLETE_LINKER USE_PRCTL USE_THREAD_DUMP USE_EVPORTS
Willy Tarreau05fd82d2019-03-27 10:57:49 +0100299
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100300#### Target system options
301# Depending on the target platform, some options are set, as well as some
Willy Tarreau05fd82d2019-03-27 10:57:49 +0100302# CFLAGS and LDFLAGS. All variables pre-set here will not appear in the build
303# options string. They may be set to any value, but are historically set to
304# "implicit" which eases debugging. You should not have to change anything
305# there unless you're adding support for a new platform.
Willy Tarreauf6bf8e92019-03-27 11:30:47 +0100306default_opts = $(foreach name,$(1),$(eval $(name)=implicit))
Willy Tarreau05fd82d2019-03-27 10:57:49 +0100307
308# poll() is always supported, unless explicitly disabled by passing USE_POLL=""
309# on the make command line.
Willy Tarreau32e65ef2013-04-02 08:14:29 +0200310USE_POLL = default
311
Christopher Fauleta1ae7e82017-10-25 17:55:27 +0200312# Always enable threads support by default and let the Makefile detect if
313# HAProxy can be compiled with threads or not.
314
Willy Tarreau39f19922019-03-27 11:44:19 +0100315# generic system target has nothing specific
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100316ifeq ($(TARGET),generic)
Willy Tarreau57c99ec2019-03-29 20:55:54 +0100317 set_target_defaults = $(call default_opts,USE_POLL USE_TPROXY)
Willy Tarreau39f19922019-03-27 11:44:19 +0100318endif
319
320# Haiku
Jerome Duval38932c32015-10-19 23:01:16 +0000321ifeq ($(TARGET),haiku)
Jerome Duval38932c32015-10-19 23:01:16 +0000322 TARGET_LDFLAGS = -lnetwork
Willy Tarreau57c99ec2019-03-29 20:55:54 +0100323 set_target_defaults = $(call default_opts,USE_POLL USE_TPROXY)
Willy Tarreau39f19922019-03-27 11:44:19 +0100324endif
325
Willy Tarreau61cf0dc2019-06-14 16:32:09 +0200326# For linux >= 2.6.28 and glibc
327ifeq ($(TARGET),linux-glibc)
Willy Tarreau57c99ec2019-03-29 20:55:54 +0100328 set_target_defaults = $(call default_opts, \
Willy Tarreauf6bf8e92019-03-27 11:30:47 +0100329 USE_POLL USE_TPROXY USE_LIBCRYPT USE_DL USE_RT USE_CRYPT_H USE_NETFILTER \
330 USE_CPU_AFFINITY USE_THREAD USE_EPOLL USE_FUTEX USE_LINUX_TPROXY \
Willy Tarreau364d6f52019-06-14 18:33:56 +0200331 USE_ACCEPT4 USE_LINUX_SPLICE USE_PRCTL USE_THREAD_DUMP USE_NS USE_TFO \
Willy Tarreauf5b4e062020-03-03 15:40:23 +0100332 USE_GETADDRINFO USE_BACKTRACE)
Willy Tarreau48e86032020-03-18 08:20:45 +0100333ifneq ($(shell echo __arm__/__aarch64__ | $(CC) -E -xc - | grep '^[^\#]'),__arm__/__aarch64__)
David Carlierd93e6ec2020-03-15 10:30:51 +0000334 TARGET_LDFLAGS=-latomic
335endif
Willy Tarreau39f19922019-03-27 11:44:19 +0100336endif
337
Lukas Tribuscc1eb162019-09-01 16:48:36 +0200338# For linux >= 2.6.28, glibc without new features
339ifeq ($(TARGET),linux-glibc-legacy)
340 set_target_defaults = $(call default_opts, \
341 USE_POLL USE_TPROXY USE_LIBCRYPT USE_DL USE_RT USE_CRYPT_H USE_NETFILTER \
342 USE_CPU_AFFINITY USE_THREAD USE_EPOLL USE_FUTEX USE_LINUX_TPROXY \
343 USE_ACCEPT4 USE_LINUX_SPLICE USE_PRCTL USE_THREAD_DUMP USE_GETADDRINFO)
344endif
345
Willy Tarreau39b2fda2020-04-16 15:14:17 +0200346# For linux >= 2.6.28 and musl
347ifeq ($(TARGET),linux-musl)
348 set_target_defaults = $(call default_opts, \
349 USE_POLL USE_TPROXY USE_LIBCRYPT USE_DL USE_RT USE_CRYPT_H USE_NETFILTER \
350 USE_CPU_AFFINITY USE_THREAD USE_EPOLL USE_FUTEX USE_LINUX_TPROXY \
351 USE_ACCEPT4 USE_LINUX_SPLICE USE_PRCTL USE_THREAD_DUMP USE_NS USE_TFO \
352 USE_GETADDRINFO)
353ifneq ($(shell echo __arm__/__aarch64__ | $(CC) -E -xc - | grep '^[^\#]'),__arm__/__aarch64__)
354 TARGET_LDFLAGS=-latomic
355endif
356endif
357
Brad Smith7c503bb2020-09-30 15:46:16 -0400358# Solaris 10 and above
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100359ifeq ($(TARGET),solaris)
Willy Tarreau57c99ec2019-03-29 20:55:54 +0100360 set_target_defaults = $(call default_opts, \
Emmanuel Hocdet7093c192019-05-21 09:12:03 +0000361 USE_POLL USE_TPROXY USE_LIBCRYPT USE_CRYPT_H USE_GETADDRINFO USE_THREAD \
Brad Smith7c503bb2020-09-30 15:46:16 -0400362 USE_RT USE_OBSOLETE_LINKER USE_EVPORTS USE_CLOSEFROM)
Emmanuel Hocdet3c0edfa2019-05-17 15:32:21 +0000363 TARGET_CFLAGS = -DFD_SETSIZE=65536 -D_REENTRANT -D_XOPEN_SOURCE=500 -D__EXTENSIONS__
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100364 TARGET_LDFLAGS = -lnsl -lsocket
Willy Tarreau39f19922019-03-27 11:44:19 +0100365endif
366
Brad Smith9d85eb02020-09-15 03:10:04 -0400367# FreeBSD 10 and above
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100368ifeq ($(TARGET),freebsd)
Willy Tarreau57c99ec2019-03-29 20:55:54 +0100369 set_target_defaults = $(call default_opts, \
Willy Tarreauf6bf8e92019-03-27 11:30:47 +0100370 USE_POLL USE_TPROXY USE_LIBCRYPT USE_THREAD USE_CPU_AFFINITY USE_KQUEUE \
Brad Smith9d85eb02020-09-15 03:10:04 -0400371 USE_ACCEPT4 USE_CLOSEFROM USE_GETADDRINFO)
Willy Tarreau39f19922019-03-27 11:44:19 +0100372endif
373
374# Mac OS/X
Willy Tarreau8624cab2013-04-02 08:17:43 +0200375ifeq ($(TARGET),osx)
Willy Tarreau57c99ec2019-03-29 20:55:54 +0100376 set_target_defaults = $(call default_opts, \
David Carlier5e4c8e22019-09-13 05:12:58 +0100377 USE_POLL USE_TPROXY USE_LIBCRYPT USE_THREAD USE_CPU_AFFINITY USE_KQUEUE)
Willy Tarreaub684e7a2018-03-05 15:37:04 +0100378 EXPORT_SYMBOL = -export_dynamic
Willy Tarreau39f19922019-03-27 11:44:19 +0100379endif
380
Brad Smith90c9d782020-09-26 23:05:25 -0400381# OpenBSD 6.3 and above
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100382ifeq ($(TARGET),openbsd)
Willy Tarreau57c99ec2019-03-29 20:55:54 +0100383 set_target_defaults = $(call default_opts, \
Brad Smith90c9d782020-09-26 23:05:25 -0400384 USE_POLL USE_TPROXY USE_THREAD USE_KQUEUE USE_ACCEPT4 USE_CLOSEFROM \
385 USE_GETADDRINFO)
Willy Tarreau39f19922019-03-27 11:44:19 +0100386endif
387
388# NetBSD
David Carlierb5714da2015-07-02 06:58:22 +0000389ifeq ($(TARGET),netbsd)
Willy Tarreau57c99ec2019-03-29 20:55:54 +0100390 set_target_defaults = $(call default_opts, \
Willy Tarreauf6bf8e92019-03-27 11:30:47 +0100391 USE_POLL USE_TPROXY USE_KQUEUE)
Willy Tarreau39f19922019-03-27 11:44:19 +0100392endif
393
394# AIX 5.1 only
Willy Tarreau50abe302014-04-02 20:44:43 +0200395ifeq ($(TARGET),aix51)
Willy Tarreau57c99ec2019-03-29 20:55:54 +0100396 set_target_defaults = $(call default_opts, \
Willy Tarreau13d9b022019-03-29 18:56:54 +0100397 USE_POLL USE_LIBCRYPT USE_OBSOLETE_LINKER USE_PRIVATE_CACHE)
Willy Tarreau0aed6ac2019-03-29 18:56:00 +0100398 TARGET_CFLAGS = -Dss_family=__ss_family -Dip6_hdr=ip6hdr -DSTEVENS_API -D_LINUX_SOURCE_COMPAT -Dunsetenv=my_unsetenv
Willy Tarreau50abe302014-04-02 20:44:43 +0200399 DEBUG_CFLAGS =
Willy Tarreau39f19922019-03-27 11:44:19 +0100400endif
401
Christian Lachnerc1322302020-02-10 10:29:13 +0100402# AIX 5.2
Willy Tarreau7dec9652012-06-06 16:15:03 +0200403ifeq ($(TARGET),aix52)
Willy Tarreau57c99ec2019-03-29 20:55:54 +0100404 set_target_defaults = $(call default_opts, \
Willy Tarreau7b5654f2019-03-29 21:30:17 +0100405 USE_POLL USE_LIBCRYPT USE_OBSOLETE_LINKER)
Willy Tarreau7dec9652012-06-06 16:15:03 +0200406 TARGET_CFLAGS = -D_MSGQSUPPORT
407 DEBUG_CFLAGS =
Willy Tarreau39f19922019-03-27 11:44:19 +0100408endif
409
Christian Lachnerc1322302020-02-10 10:29:13 +0100410# AIX 7.2 and above
411ifeq ($(TARGET),aix72-gcc)
412 set_target_defaults = $(call default_opts, \
413 USE_POLL USE_THREAD USE_LIBCRYPT USE_OBSOLETE_LINKER USE_GETADDRINFO)
414 TARGET_CFLAGS = -D_H_XMEM -D_H_VAR
415 TARGET_LDFLAGS = -latomic
416endif
417
Willy Tarreau39f19922019-03-27 11:44:19 +0100418# Cygwin
Yitzhak Sapir32087312009-06-14 18:27:54 +0200419ifeq ($(TARGET),cygwin)
Willy Tarreau7b5654f2019-03-29 21:30:17 +0100420 set_target_defaults = $(call default_opts, \
421 USE_POLL USE_TPROXY USE_OBSOLETE_LINKER)
Willy Tarreau39f19922019-03-27 11:44:19 +0100422 # Cygwin adds IPv6 support only in version 1.7 (in beta right now).
Yitzhak Sapir32087312009-06-14 18:27:54 +0200423 TARGET_CFLAGS = $(if $(filter 1.5.%, $(shell uname -r)), -DUSE_IPV6 -DAF_INET6=23 -DINET6_ADDRSTRLEN=46, )
Willy Tarreau39f19922019-03-27 11:44:19 +0100424endif
willy tarreau4373b962005-12-18 01:32:31 +0100425
Willy Tarreau57c99ec2019-03-29 20:55:54 +0100426# set the default settings according to the target above
427$(set_target_defaults)
428
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100429#### Determine version, sub-version and release date.
430# If GIT is found, and IGNOREGIT is not set, VERSION, SUBVERS and VERDATE are
431# extracted from the last commit. Otherwise, use the contents of the files
432# holding the same names in the current directory.
willy tarreau0174f312005-12-18 01:02:42 +0100433
Willy Tarreau6620dbb2007-01-02 00:44:53 +0100434ifeq ($(IGNOREGIT),)
Willy Tarreau3c55efb2019-06-22 08:24:16 +0200435VERSION := $(shell [ -d .git/. ] && (git describe --tags --match 'v*' --abbrev=0 | cut -c 2-) 2>/dev/null)
Willy Tarreau9bf6c6e2006-12-23 11:12:04 +0100436ifneq ($(VERSION),)
437# OK git is there and works.
Willy Tarreau30a6f642019-06-22 07:51:02 +0200438SUBVERS := $(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")
Willy Tarreau689e4d72013-12-10 09:31:06 +0100439VERDATE := $(shell git log -1 --pretty=format:%ci | cut -f1 -d' ' | tr '-' '/')
Willy Tarreauec692562007-09-09 23:31:11 +0200440endif
441endif
442
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100443# Last commit version not found, take it from the files.
Willy Tarreauec692562007-09-09 23:31:11 +0200444ifeq ($(VERSION),)
445VERSION := $(shell cat VERSION 2>/dev/null || touch VERSION)
446endif
447ifeq ($(SUBVERS),)
Willy Tarreau6173bbe2013-12-16 01:34:39 +0100448SUBVERS := $(shell (grep -v '\$$Format' SUBVERS 2>/dev/null || touch SUBVERS) | head -n 1)
Willy Tarreauec692562007-09-09 23:31:11 +0200449endif
450ifeq ($(VERDATE),)
Willy Tarreauf1ed3272014-01-26 00:39:22 +0100451VERDATE := $(shell (grep -v '^\$$Format' VERDATE 2>/dev/null || touch VERDATE) | head -n 1 | cut -f1 -d' ' | tr '-' '/')
Willy Tarreau9bf6c6e2006-12-23 11:12:04 +0100452endif
Willy Tarreau77074d52006-11-12 23:57:19 +0100453
Willy Tarreauac32b4b2020-10-01 04:05:39 +0200454# this one is always empty by default and appended verbatim
455EXTRAVERSION =
456
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100457#### Build options
458# Do not change these ones, enable USE_* variables instead.
459OPTIONS_CFLAGS =
460OPTIONS_LDFLAGS =
461OPTIONS_OBJS =
Willy Tarreau77074d52006-11-12 23:57:19 +0100462
Willy Tarreauada5d092019-01-10 10:01:03 +0100463#### Extra objects to be built and integrated (used only for development)
464EXTRA_OBJS =
465
Willy Tarreau09fe5662019-03-27 10:36:35 +0100466# Return USE_xxx=$(USE_xxx) if the variable was set from the environment or the
467# command line.
468# Usage:
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100469# BUILD_OPTIONS += $(call ignore_implicit,USE_xxx)
Willy Tarreau09fe5662019-03-27 10:36:35 +0100470ignore_implicit = $(if $(subst environment,,$(origin $(1))), \
471 $(if $(subst command line,,$(origin $(1))),, \
472 $(1)=$($(1))), \
473 $(1)=$($(1))) \
Willy Tarreau77074d52006-11-12 23:57:19 +0100474
Willy Tarreau05fd82d2019-03-27 10:57:49 +0100475# This variable collects all USE_* values except those set to "implicit". This
476# is used to report a list of all flags which were used to build this version.
477# Do not assign anything to it.
Willy Tarreau7728ed32019-03-27 13:20:08 +0100478BUILD_OPTIONS := $(foreach opt,$(use_opts),$(call ignore_implicit,$(opt)))
479BUILD_FEATURES := $(foreach opt,$(patsubst USE_%,%,$(use_opts)),$(if $(USE_$(opt)),+$(opt),-$(opt)))
Willy Tarreau05fd82d2019-03-27 10:57:49 +0100480
Willy Tarreau824cd002019-03-27 14:44:14 +0100481# All USE_* options have their equivalent macro defined in the code (some might
482# possibly be unused though)
483OPTIONS_CFLAGS += $(foreach opt,$(use_opts),$(if $($(opt)),-D$(opt),))
484
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +0100485ifneq ($(USE_LIBCRYPT),)
David Carlier6c00eba2019-09-01 14:59:10 +0100486ifneq ($(TARGET),osx)
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +0100487OPTIONS_LDFLAGS += -lcrypt
488endif
David Carlier6c00eba2019-09-01 14:59:10 +0100489endif
Krzysztof Piotr Oledzki96105042010-01-29 17:50:44 +0100490
Willy Tarreau418b8c02015-03-29 03:32:06 +0200491ifneq ($(USE_SLZ),)
492# Use SLZ_INC and SLZ_LIB to force path to zlib.h and libz.{a,so} if needed.
493SLZ_INC =
494SLZ_LIB =
Willy Tarreau824cd002019-03-27 14:44:14 +0100495OPTIONS_CFLAGS += $(if $(SLZ_INC),-I$(SLZ_INC))
Willy Tarreau418b8c02015-03-29 03:32:06 +0200496OPTIONS_LDFLAGS += $(if $(SLZ_LIB),-L$(SLZ_LIB)) -lslz
497endif
498
William Lallemand82fe75c2012-10-23 10:25:10 +0200499ifneq ($(USE_ZLIB),)
Willy Tarreaue2f49442012-02-10 20:37:26 +0100500# Use ZLIB_INC and ZLIB_LIB to force path to zlib.h and libz.{a,so} if needed.
501ZLIB_INC =
502ZLIB_LIB =
Willy Tarreau824cd002019-03-27 14:44:14 +0100503OPTIONS_CFLAGS += $(if $(ZLIB_INC),-I$(ZLIB_INC))
Willy Tarreaue2f49442012-02-10 20:37:26 +0100504OPTIONS_LDFLAGS += $(if $(ZLIB_LIB),-L$(ZLIB_LIB)) -lz
William Lallemand82fe75c2012-10-23 10:25:10 +0200505endif
506
Willy Tarreau77074d52006-11-12 23:57:19 +0100507ifneq ($(USE_POLL),)
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100508OPTIONS_OBJS += src/ev_poll.o
Willy Tarreau77074d52006-11-12 23:57:19 +0100509endif
510
511ifneq ($(USE_EPOLL),)
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100512OPTIONS_OBJS += src/ev_epoll.o
Willy Tarreau77074d52006-11-12 23:57:19 +0100513endif
514
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100515ifneq ($(USE_KQUEUE),)
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100516OPTIONS_OBJS += src/ev_kqueue.o
Willy Tarreau77074d52006-11-12 23:57:19 +0100517endif
518
Emmanuel Hocdet0ba4f482019-04-08 16:53:32 +0000519ifneq ($(USE_EVPORTS),)
Emmanuel Hocdet0ba4f482019-04-08 16:53:32 +0000520OPTIONS_OBJS += src/ev_evports.o
521endif
522
Willy Tarreau71b99ef2015-03-17 14:33:22 +0100523ifneq ($(USE_DL),)
Willy Tarreau71b99ef2015-03-17 14:33:22 +0100524OPTIONS_LDFLAGS += -ldl
525endif
526
Willy Tarreau58e90cb2018-10-18 16:28:54 +0200527ifneq ($(USE_RT),)
Willy Tarreau58e90cb2018-10-18 16:28:54 +0200528OPTIONS_LDFLAGS += -lrt
529endif
530
Willy Tarreauc0bbdc12020-03-04 08:31:47 +0100531ifneq ($(USE_THREAD),)
532OPTIONS_LDFLAGS += -lpthread
533endif
534
Willy Tarreauf5b4e062020-03-03 15:40:23 +0100535ifneq ($(USE_BACKTRACE),)
536OPTIONS_LDFLAGS += -Wl,$(if $(EXPORT_SYMBOL),$(EXPORT_SYMBOL),--export-dynamic)
537endif
538
Emeric Brun7444f012012-05-18 15:48:30 +0200539ifneq ($(USE_OPENSSL),)
Ilya Shipitsinf21023e2020-08-04 15:36:24 +0500540SSL_INC =
541SSL_LIB =
David CARLIER7385f652015-11-06 15:13:06 +0000542# OpenSSL is packaged in various forms and with various dependencies.
Emeric Brun7444f012012-05-18 15:48:30 +0200543# In general -lssl is enough, but on some platforms, -lcrypto may be needed,
Willy Tarreau8f182d92012-09-10 09:11:22 +0200544# reason why it's added by default. Some even need -lz, then you'll need to
Willy Tarreau9a059452013-09-17 15:26:39 +0200545# pass it in the "ADDLIB" variable if needed. If your SSL libraries are not
546# in the usual path, use SSL_INC=/path/to/inc and SSL_LIB=/path/to/lib.
Willy Tarreau824cd002019-03-27 14:44:14 +0100547OPTIONS_CFLAGS += $(if $(SSL_INC),-I$(SSL_INC))
Willy Tarreaucd360ce2014-10-31 07:36:51 +0100548OPTIONS_LDFLAGS += $(if $(SSL_LIB),-L$(SSL_LIB)) -lssl -lcrypto
Dirkjan Bussink1866d6d2016-08-29 13:26:37 +0200549ifneq ($(USE_DL),)
550OPTIONS_LDFLAGS += -ldl
551endif
William Lallemand6a66a5e2020-05-15 12:01:17 +0200552OPTIONS_OBJS += src/ssl_sample.o src/ssl_sock.o src/ssl_crtlist.o src/ssl_ckch.o src/ssl_utils.o src/cfgparse-ssl.o
William Lallemandb620e982017-11-02 16:00:51 +0100553endif
554
555# The private cache option affect the way the shctx is built
Willy Tarreau824cd002019-03-27 14:44:14 +0100556ifeq ($(USE_PRIVATE_CACHE),)
Emeric Bruncd1a5262014-05-07 23:11:42 +0200557ifneq ($(USE_PTHREAD_PSHARED),)
Emeric Bruncd1a5262014-05-07 23:11:42 +0200558OPTIONS_LDFLAGS += -lpthread
Emeric Bruncd1a5262014-05-07 23:11:42 +0200559endif
Emeric Brun3e541d12012-09-03 11:14:36 +0200560endif
Olivier Houchard2292edf2019-02-25 14:26:54 +0100561
Thierry FOURNIER6f1fd482015-01-23 14:06:13 +0100562ifneq ($(USE_LUA),)
Cyril Bontéc21adb52015-03-03 23:13:03 +0100563check_lua_lib = $(shell echo "int main(){}" | $(CC) -o /dev/null -x c - $(2) -l$(1) 2>/dev/null && echo $(1))
Nan Liub286fff2017-06-09 15:57:45 +0800564check_lua_inc = $(shell if [ -d $(2)$(1) ]; then echo $(2)$(1); fi;)
Cyril Bontéc21adb52015-03-03 23:13:03 +0100565
Willy Tarreau824cd002019-03-27 14:44:14 +0100566OPTIONS_CFLAGS += $(if $(LUA_INC),-I$(LUA_INC))
Thierry Fournier13113d62018-02-26 09:25:56 +0100567LUA_LD_FLAGS := -Wl,$(if $(EXPORT_SYMBOL),$(EXPORT_SYMBOL),--export-dynamic) $(if $(LUA_LIB),-L$(LUA_LIB))
Cyril Bontéc21adb52015-03-03 23:13:03 +0100568ifeq ($(LUA_LIB_NAME),)
569# Try to automatically detect the Lua library
Thierry FOURNIER463119c2015-03-10 00:35:36 +0100570LUA_LIB_NAME := $(firstword $(foreach lib,lua5.3 lua53 lua,$(call check_lua_lib,$(lib),$(LUA_LD_FLAGS))))
Cyril Bontéc21adb52015-03-03 23:13:03 +0100571ifeq ($(LUA_LIB_NAME),)
Thierry FOURNIER463119c2015-03-10 00:35:36 +0100572$(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, ...))
Cyril Bontéc21adb52015-03-03 23:13:03 +0100573endif
Nan Liub286fff2017-06-09 15:57:45 +0800574LUA_INC := $(firstword $(foreach lib,lua5.3 lua53 lua,$(call check_lua_inc,$(lib),"/usr/include/")))
575ifneq ($(LUA_INC),)
576OPTIONS_CFLAGS += -I$(LUA_INC)
577endif
Tim Duesterhus541fe1e2020-01-12 13:55:41 +0100578ifneq ($(HLUA_PREPEND_PATH),)
579OPTIONS_CFLAGS += -DHLUA_PREPEND_PATH=$(HLUA_PREPEND_PATH)
580BUILD_OPTIONS += HLUA_PREPEND_PATH=$(HLUA_PREPEND_PATH)
581endif
582ifneq ($(HLUA_PREPEND_CPATH),)
583OPTIONS_CFLAGS += -DHLUA_PREPEND_CPATH=$(HLUA_PREPEND_CPATH)
584BUILD_OPTIONS += HLUA_PREPEND_CPATH=$(HLUA_PREPEND_CPATH)
585endif
Cyril Bontéc21adb52015-03-03 23:13:03 +0100586endif
587
Willy Tarreau71b99ef2015-03-17 14:33:22 +0100588OPTIONS_LDFLAGS += $(LUA_LD_FLAGS) -l$(LUA_LIB_NAME) -lm
Vincent Bernate192cbb2015-07-16 20:52:51 +0200589ifneq ($(USE_DL),)
590OPTIONS_LDFLAGS += -ldl
591endif
Thierry Fournierfb0b5462016-01-21 09:28:58 +0100592OPTIONS_OBJS += src/hlua.o src/hlua_fcn.o
Thierry FOURNIER6f1fd482015-01-23 14:06:13 +0100593endif
594
David Carliera03fb142015-06-01 14:00:07 +0200595ifneq ($(USE_DEVICEATLAS),)
David CARLIER7385f652015-11-06 15:13:06 +0000596ifeq ($(USE_PCRE),)
597$(error the DeviceAtlas module needs the PCRE library in order to compile)
598endif
Willy Tarreau82bd42e2015-06-02 14:10:28 +0200599# Use DEVICEATLAS_SRC and possibly DEVICEATLAS_INC and DEVICEATLAS_LIB to force path
Dragan Dosen93b38d92015-06-29 16:43:25 +0200600# to DeviceAtlas headers and libraries if needed.
Willy Tarreau82bd42e2015-06-02 14:10:28 +0200601DEVICEATLAS_SRC =
602DEVICEATLAS_INC = $(DEVICEATLAS_SRC)
603DEVICEATLAS_LIB = $(DEVICEATLAS_SRC)
Bertrand Jacquin3a2661d2016-10-06 00:32:39 +0100604ifeq ($(DEVICEATLAS_SRC),)
605OPTIONS_LDFLAGS += -lda
606else
David Carliera03fb142015-06-01 14:00:07 +0200607OPTIONS_OBJS += $(DEVICEATLAS_LIB)/json.o
608OPTIONS_OBJS += $(DEVICEATLAS_LIB)/dac.o
Bertrand Jacquin3a2661d2016-10-06 00:32:39 +0100609endif
David Carliera03fb142015-06-01 14:00:07 +0200610OPTIONS_OBJS += src/da.o
Willy Tarreau824cd002019-03-27 14:44:14 +0100611OPTIONS_CFLAGS += $(if $(DEVICEATLAS_INC),-I$(DEVICEATLAS_INC))
David Carliera03fb142015-06-01 14:00:07 +0200612endif
613
Thomas Holmes0ca65f82015-05-12 15:06:21 +0100614ifneq ($(USE_51DEGREES),)
Willy Tarreauc7203c72015-06-01 11:12:35 +0200615# Use 51DEGREES_SRC and possibly 51DEGREES_INC and 51DEGREES_LIB to force path
616# to 51degrees headers and libraries if needed.
61751DEGREES_SRC =
61851DEGREES_INC = $(51DEGREES_SRC)
61951DEGREES_LIB = $(51DEGREES_SRC)
James Rosewell3670eb12015-09-18 17:24:29 +0100620OPTIONS_OBJS += $(51DEGREES_LIB)/../cityhash/city.o
Dragan Dosen93b38d92015-06-29 16:43:25 +0200621OPTIONS_OBJS += $(51DEGREES_LIB)/51Degrees.o
622OPTIONS_OBJS += src/51d.o
Willy Tarreau824cd002019-03-27 14:44:14 +0100623OPTIONS_CFLAGS += $(if $(51DEGREES_INC),-I$(51DEGREES_INC))
Ben51Degrees4ddf59d2019-02-05 13:24:00 +0000624ifeq ($(USE_THREAD),)
625OPTIONS_CFLAGS += -DFIFTYONEDEGREES_NO_THREADING
626else
627OPTIONS_OBJS += $(51DEGREES_LIB)/../threading.o
628endif
629
James Rosewell3670eb12015-09-18 17:24:29 +0100630OPTIONS_LDFLAGS += $(if $(51DEGREES_LIB),-L$(51DEGREES_LIB)) -lm
Thomas Holmes0ca65f82015-05-12 15:06:21 +0100631endif
632
Willy Tarreaub3cc9f22019-04-19 16:03:32 +0200633ifneq ($(USE_WURFL),)
634# Use WURFL_SRC and possibly WURFL_INC and WURFL_LIB to force path
635# to WURFL headers and libraries if needed.
636WURFL_SRC =
637WURFL_INC = $(WURFL_SRC)
638WURFL_LIB = $(WURFL_SRC)
639OPTIONS_OBJS += src/wurfl.o
Willy Tarreau14261982019-04-23 10:57:09 +0200640OPTIONS_CFLAGS += $(if $(WURFL_INC),-I$(WURFL_INC))
Willy Tarreaub3cc9f22019-04-19 16:03:32 +0200641ifneq ($(WURFL_DEBUG),)
642OPTIONS_CFLAGS += -DWURFL_DEBUG
643endif
644ifneq ($(WURFL_HEADER_WITH_DETAILS),)
645OPTIONS_CFLAGS += -DWURFL_HEADER_WITH_DETAILS
646endif
Willy Tarreaub3cc9f22019-04-19 16:03:32 +0200647OPTIONS_LDFLAGS += $(if $(WURFL_LIB),-L$(WURFL_LIB)) -lwurfl
648endif
649
Tim Duesterhusd6942c82017-11-20 15:58:35 +0100650ifneq ($(USE_SYSTEMD),)
Tim Duesterhusd6942c82017-11-20 15:58:35 +0100651OPTIONS_LDFLAGS += -lsystemd
652endif
653
Hiroaki Nakamura70351322013-01-13 15:00:42 +0900654ifneq ($(USE_PCRE)$(USE_STATIC_PCRE)$(USE_PCRE_JIT),)
David Carlierf2592b22016-11-21 21:25:58 +0000655ifneq ($(USE_PCRE2)$(USE_STATIC_PCRE2)$(USE_PCRE2_JIT),)
656$(error cannot compile both PCRE and PCRE2 support)
657endif
Willy Tarreau39793092013-02-13 12:39:06 +0100658# PCREDIR is used to automatically construct the PCRE_INC and PCRE_LIB paths,
659# by appending /include and /lib respectively. If your system does not use the
660# same sub-directories, simply force these variables instead of PCREDIR. It is
661# automatically detected but can be forced if required (for cross-compiling).
662# Forcing PCREDIR to an empty string will let the compiler use the default
663# locations.
664
Fabrice Fontaine7b4c8c32018-09-28 19:21:26 +0200665PCRE_CONFIG := pcre-config
666PCREDIR := $(shell $(PCRE_CONFIG) --prefix 2>/dev/null || echo /usr/local)
Willy Tarreau39793092013-02-13 12:39:06 +0100667ifneq ($(PCREDIR),)
668PCRE_INC := $(PCREDIR)/include
669PCRE_LIB := $(PCREDIR)/lib
Willy Tarreau79b34bf2006-12-22 15:28:43 +0100670endif
Willy Tarreau39793092013-02-13 12:39:06 +0100671
Christian Wiesec8203002008-11-20 14:47:04 +0100672ifeq ($(USE_STATIC_PCRE),)
Willy Tarreau39793092013-02-13 12:39:06 +0100673# dynamic PCRE
674OPTIONS_CFLAGS += -DUSE_PCRE $(if $(PCRE_INC),-I$(PCRE_INC))
675OPTIONS_LDFLAGS += $(if $(PCRE_LIB),-L$(PCRE_LIB)) -lpcreposix -lpcre
Willy Tarreau39793092013-02-13 12:39:06 +0100676else
677# static PCRE
678OPTIONS_CFLAGS += -DUSE_PCRE $(if $(PCRE_INC),-I$(PCRE_INC))
679OPTIONS_LDFLAGS += $(if $(PCRE_LIB),-L$(PCRE_LIB)) -Wl,-Bstatic -lpcreposix -lpcre -Wl,-Bdynamic
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100680endif
Willy Tarreau39793092013-02-13 12:39:06 +0100681endif
Willy Tarreau77074d52006-11-12 23:57:19 +0100682
David Carlierf2592b22016-11-21 21:25:58 +0000683ifneq ($(USE_PCRE2)$(USE_STATIC_PCRE2)$(USE_PCRE2_JIT),)
Fabrice Fontaine7b4c8c32018-09-28 19:21:26 +0200684PCRE2_CONFIG := pcre2-config
685PCRE2DIR := $(shell $(PCRE2_CONFIG) --prefix 2>/dev/null || echo /usr/local)
David Carlierf2592b22016-11-21 21:25:58 +0000686ifneq ($(PCRE2DIR),)
687PCRE2_INC := $(PCRE2DIR)/include
688PCRE2_LIB := $(PCRE2DIR)/lib
689
690ifeq ($(PCRE2_WIDTH),)
691PCRE2_WIDTH = 8
692endif
693
694ifneq ($(PCRE2_WIDTH),8)
695ifneq ($(PCRE2_WIDTH),16)
696ifneq ($(PCRE2_WIDTH),32)
697$(error PCRE2_WIDTH needs to be set to either 8,16 or 32)
698endif
699endif
700endif
701
702
Fabrice Fontaine7b4c8c32018-09-28 19:21:26 +0200703PCRE2_LDFLAGS := $(shell $(PCRE2_CONFIG) --libs$(PCRE2_WIDTH) 2>/dev/null || echo -L/usr/local/lib -lpcre2-$(PCRE2_WIDTH))
David Carlierf2592b22016-11-21 21:25:58 +0000704
705ifeq ($(PCRE2_LDFLAGS),)
706$(error libpcre2-$(PCRE2_WIDTH) not found)
707else
708ifeq ($(PCRE2_WIDTH),8)
709PCRE2_LDFLAGS += -lpcre2-posix
710endif
711endif
712
713OPTIONS_CFLAGS += -DUSE_PCRE2 -DPCRE2_CODE_UNIT_WIDTH=$(PCRE2_WIDTH)
714OPTIONS_CFLAGS += $(if $(PCRE2_INC), -I$(PCRE2_INC))
715
716ifneq ($(USE_STATIC_PCRE2),)
717OPTIONS_LDFLAGS += $(if $(PCRE2_LIB),-L$(PCRE2_LIB)) -Wl,-Bstatic -L$(PCRE2_LIB) $(PCRE2_LDFLAGS) -Wl,-Bdynamic
David Carlierf2592b22016-11-21 21:25:58 +0000718else
719OPTIONS_LDFLAGS += $(if $(PCRE2_LIB),-L$(PCRE2_LIB)) -L$(PCRE2_LIB) $(PCRE2_LDFLAGS)
David Carlierf2592b22016-11-21 21:25:58 +0000720endif
721
David Carlierf2592b22016-11-21 21:25:58 +0000722endif
723endif
724
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100725#### Global compile options
726VERBOSE_CFLAGS = $(CFLAGS) $(TARGET_CFLAGS) $(SMALL_OPTS) $(DEFINE)
Willy Tarreaufc80e302020-05-27 11:05:33 +0200727COPTS = -Iinclude
Willy Tarreau23cd43e2018-10-22 06:22:46 +0200728
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100729COPTS += $(CFLAGS) $(TARGET_CFLAGS) $(SMALL_OPTS) $(DEFINE) $(SILENT_DEFINE)
730COPTS += $(DEBUG) $(OPTIONS_CFLAGS) $(ADDINC)
willy tarreaueedaa9f2005-12-17 14:08:03 +0100731
Willy Tarreauac32b4b2020-10-01 04:05:39 +0200732ifneq ($(VERSION)$(SUBVERS)$(EXTRAVERSION),)
733COPTS += -DCONFIG_HAPROXY_VERSION=\"$(VERSION)$(SUBVERS)$(EXTRAVERSION)\"
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100734endif
Willy Tarreau6d1a9882007-01-07 02:03:04 +0100735
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100736ifneq ($(VERDATE),)
737COPTS += -DCONFIG_HAPROXY_DATE=\"$(VERDATE)\"
Willy Tarreau6d1a9882007-01-07 02:03:04 +0100738endif
739
Willy Tarreau7de211c2012-05-25 23:53:16 +0200740ifneq ($(TRACE),)
741# if tracing is enabled, we want it to be as fast as possible
742TRACE_COPTS := $(filter-out -O0 -O1 -O2 -pg -finstrument-functions,$(COPTS)) -O3 -fomit-frame-pointer
743COPTS += -finstrument-functions
744endif
745
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +0100746ifneq ($(USE_NS),)
Willy Tarreau7520e4f2018-11-11 14:38:09 +0100747OPTIONS_OBJS += src/namespace.o
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +0100748endif
749
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100750#### Global link options
751# These options are added at the end of the "ld" command line. Use LDFLAGS to
752# add options at the beginning of the "ld" command line if needed.
753LDOPTS = $(TARGET_LDFLAGS) $(OPTIONS_LDFLAGS) $(ADDLIB)
willy tarreau0f7af912005-12-17 12:21:26 +0100754
Willy Tarreau16119652018-11-19 08:15:54 +0100755ifeq ($V,1)
756cmd_CC = $(CC)
757cmd_LD = $(LD)
758cmd_AR = $(AR)
759else
760cmd_CC = $(Q)echo " CC $@";$(CC)
761cmd_LD = $(Q)echo " LD $@";$(LD)
762cmd_AR = $(Q)echo " AR $@";$(AR)
763endif
764
Willy Tarreaue4208cb2008-03-11 06:37:39 +0100765ifeq ($(TARGET),)
766all:
767 @echo
768 @echo "Due to too many reports of suboptimized setups, building without"
769 @echo "specifying the target is no longer supported. Please specify the"
770 @echo "target OS in the TARGET variable, in the following form:"
771 @echo
772 @echo " $ make TARGET=xxx"
773 @echo
774 @echo "Please choose the target among the following supported list :"
775 @echo
Willy Tarreau39b2fda2020-04-16 15:14:17 +0200776 @echo " linux-glibc, linux-glibc-legacy, linux-musl, solaris, freebsd, openbsd, "
777 @echo " netbsd, cygwin, haiku, aix51, aix52, aix72-gcc, osx, generic, custom"
Willy Tarreaue4208cb2008-03-11 06:37:39 +0100778 @echo
779 @echo "Use \"generic\" if you don't want any optimization, \"custom\" if you"
780 @echo "want to precisely tweak every option, or choose the target which"
781 @echo "matches your OS the most in order to gain the maximum performance"
782 @echo "out of it. Please check the Makefile in case of doubts."
783 @echo
784 @exit 1
Willy Tarreauc31e5a52019-06-16 17:53:39 +0200785else
786ifneq ($(filter $(TARGET), linux linux22 linux24 linux24e linux26 linux2628),)
Willy Tarreau99e49e92019-06-14 16:44:49 +0200787all:
788 @echo
789 @echo "Target '$(TARGET)' was removed from HAProxy 2.0 due to being irrelevant and"
790 @echo "often wrong. Please use 'linux-glibc' instead or define your custom target"
791 @echo "by checking available options using 'make help TARGET=<your-target>'."
792 @echo
793 @exit 1
Willy Tarreaue4208cb2008-03-11 06:37:39 +0100794else
Willy Tarreaubc289da2014-05-10 12:16:21 +0200795all: haproxy $(EXTRA)
Willy Tarreaue4208cb2008-03-11 06:37:39 +0100796endif
Willy Tarreauc31e5a52019-06-16 17:53:39 +0200797endif
willy tarreau0f7af912005-12-17 12:21:26 +0100798
Willy Tarreau920214e2020-06-05 20:04:36 +0200799OBJS = src/mux_fcgi.o src/mux_h1.o src/mux_h2.o src/backend.o \
800 src/cfgparse.o src/cli.o src/cfgparse-listen.o src/stats.o \
801 src/http_ana.o src/stream.o src/check.o src/sample.o \
802 src/tools.o src/server.o src/listener.o src/tcpcheck.o \
803 src/pattern.o src/log.o src/stick_table.o src/flt_spoe.o \
804 src/stream_interface.o src/filters.o src/http_fetch.o \
805 src/map.o src/session.o src/sink.o src/flt_http_comp.o \
806 src/debug.o src/tcp_rules.o src/haproxy.o src/peers.o \
807 src/flt_trace.o src/queue.o src/proxy.o src/http_htx.o \
808 src/dns.o src/raw_sock.o src/pool.o src/http_act.o \
809 src/http_rules.o src/compression.o src/cfgparse-global.o \
810 src/payload.o src/signal.o src/activity.o src/mworker.o \
811 src/cache.o src/proto_uxst.o src/lb_chash.o src/connection.o \
812 src/proto_tcp.o src/http_conv.o src/arg.o src/lb_fas.o \
813 src/xprt_handshake.o src/fcgi-app.o src/applet.o src/acl.o \
814 src/task.o src/ring.o src/vars.o src/trace.o src/mux_pt.o \
815 src/xxhash.o src/mworker-prog.o src/h1_htx.o src/frontend.o \
816 src/extcheck.o src/channel.o src/action.o src/mailers.o \
Willy Tarreauaeae66c2020-08-28 11:03:28 +0200817 src/tcp_act.o src/proto_sockpair.o src/ebmbtree.o src/thread.o \
Willy Tarreau8987e7a2020-08-28 11:37:21 +0200818 src/tcp_sample.o src/lb_fwrr.o src/time.o src/regex.o src/lb_fwlc.o \
Willy Tarreau920214e2020-06-05 20:04:36 +0200819 src/htx.o src/h2.o src/hpack-tbl.o src/lru.o src/wdt.o \
820 src/lb_map.o src/eb32sctree.o src/ebistree.o src/h1.o \
821 src/sha1.o src/http.o src/fd.o src/ev_select.o src/chunk.o \
822 src/hash.o src/hpack-dec.o src/freq_ctr.o src/http_acl.o \
Willy Tarreau739879a2020-06-29 09:26:59 +0200823 src/dynbuf.o src/uri_auth.o src/protocol.o src/auth.o \
Willy Tarreau920214e2020-06-05 20:04:36 +0200824 src/ebsttree.o src/pipe.o src/hpack-enc.o src/fcgi.o \
825 src/eb64tree.o src/dict.o src/shctx.o src/ebimtree.o \
Emeric Brun3835c0d2020-07-07 09:46:09 +0200826 src/eb32tree.o src/ebtree.o src/dgram.o src/proto_udp.o \
Willy Tarreau13180342020-08-28 11:54:59 +0200827 src/hpack-huff.o src/cfgparse-tcp.o src/base64.o src/version.o \
Willy Tarreau0d06df62020-08-28 15:10:11 +0200828 src/cfgparse-unix.o src/sock.o src/sock_inet.o src/sock_unix.o
Willy Tarreaubaaee002006-06-26 02:48:02 +0200829
Willy Tarreau7de211c2012-05-25 23:53:16 +0200830ifneq ($(TRACE),)
Willy Tarreau9eebd8a2019-08-08 16:53:40 +0200831OBJS += src/calltrace.o
Willy Tarreau7de211c2012-05-25 23:53:16 +0200832endif
833
Willy Tarreauada5d092019-01-10 10:01:03 +0100834ifneq ($(EXTRA_OBJS),)
835OBJS += $(EXTRA_OBJS)
836endif
Marc-Antoine Perennoued9803e2013-02-12 10:53:53 +0100837
Willy Tarreaub26835d2016-05-30 13:39:32 +0200838# Used only for forced dependency checking. May be cleared during development.
Willy Tarreaufc80e302020-05-27 11:05:33 +0200839INCLUDES = $(wildcard include/*/*.h)
Willy Tarreau8225bb42016-05-30 15:16:10 +0200840DEP = $(INCLUDES) .build_opts
841
William Lallemandf1b60f72018-12-13 14:02:25 +0100842help:
Willy Tarreaue8d07192019-06-22 08:13:24 +0200843 $(Q)sed -ne "/^[^#]*$$/q;s/^# \{0,1\}\(.*\)/\1/;p" Makefile
Willy Tarreau50b1aae2019-06-14 15:52:01 +0200844 $(Q)echo; \
845 if [ -n "$(TARGET)" ]; then \
Willy Tarreau5fb76032019-06-16 19:26:18 +0200846 if [ -n "$(set_target_defaults)" ]; then \
847 echo "Current TARGET: $(TARGET)"; \
848 else \
849 echo "Current TARGET: $(TARGET) (custom target)"; \
850 fi; \
Willy Tarreau50b1aae2019-06-14 15:52:01 +0200851 else \
Willy Tarreau648fa9d2019-06-14 15:52:01 +0200852 echo "TARGET not set, you may pass 'TARGET=xxx' to set one among :";\
Lukas Tribuscc1eb162019-09-01 16:48:36 +0200853 echo " linux-glibc, linux-glibc-legacy, solaris, freebsd, netbsd, osx,"; \
Christian Lachnerc1322302020-02-10 10:29:13 +0100854 echo " openbsd, aix51, aix52, aix72-gcc, cygwin, haiku, generic, custom"; \
Willy Tarreau648fa9d2019-06-14 15:52:01 +0200855 fi
Willy Tarreau50b1aae2019-06-14 15:52:01 +0200856 $(Q)echo;echo "Enabled features for TARGET '$(TARGET)' (disable with 'USE_xxx=') :"
857 $(Q)set -- $(foreach opt,$(patsubst USE_%,%,$(use_opts)),$(if $(USE_$(opt)),$(opt),)); echo " $$*" | (fmt || cat) 2>/dev/null
858 $(Q)echo;echo "Disabled features for TARGET '$(TARGET)' (enable with 'USE_xxx=1') :"
859 $(Q)set -- $(foreach opt,$(patsubst USE_%,%,$(use_opts)),$(if $(USE_$(opt)),,$(opt))); echo " $$*" | (fmt || cat) 2>/dev/null
William Lallemandf1b60f72018-12-13 14:02:25 +0100860
Willy Tarreau6f6d96d2020-03-04 16:21:06 +0100861# Used only to force a rebuild if some build options change, but we don't do
862# it for certain targets which take no build options
863ifneq (reg-tests, $(firstword $(MAKECMDGOALS)))
Willy Tarreau509a0092019-03-29 17:17:52 +0100864build_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)
865.build_opts: $(build_opts)
Willy Tarreau6f6d96d2020-03-04 16:21:06 +0100866else
867.build_opts:
868endif
Willy Tarreaub26835d2016-05-30 13:39:32 +0200869
Willy Tarreauff0e8a42020-05-27 10:43:24 +0200870haproxy: $(OPTIONS_OBJS) $(OBJS)
Willy Tarreau16119652018-11-19 08:15:54 +0100871 $(cmd_LD) $(LDFLAGS) -o $@ $^ $(LDOPTS)
willy tarreau0f7af912005-12-17 12:21:26 +0100872
Willy Tarreaubaaee002006-06-26 02:48:02 +0200873objsize: haproxy
Willy Tarreaub42233a2018-11-19 07:44:42 +0100874 $(Q)objdump -t $^|grep ' g '|grep -F '.text'|awk '{print $$5 FS $$6}'|sort
Willy Tarreaubaaee002006-06-26 02:48:02 +0200875
Willy Tarreaub26835d2016-05-30 13:39:32 +0200876%.o: %.c $(DEP)
Willy Tarreau16119652018-11-19 08:15:54 +0100877 $(cmd_CC) $(COPTS) -c -o $@ $<
willy tarreau0f7af912005-12-17 12:21:26 +0100878
Willy Tarreau909b9d82019-01-04 18:20:32 +0100879# rebuild it every time
880.PHONY: src/version.c
881
Willy Tarreau9eebd8a2019-08-08 16:53:40 +0200882src/calltrace.o: src/calltrace.c $(DEP)
Willy Tarreau16119652018-11-19 08:15:54 +0100883 $(cmd_CC) $(TRACE_COPTS) -c -o $@ $<
Willy Tarreau7de211c2012-05-25 23:53:16 +0200884
Willy Tarreaub26835d2016-05-30 13:39:32 +0200885src/haproxy.o: src/haproxy.c $(DEP)
Willy Tarreau16119652018-11-19 08:15:54 +0100886 $(cmd_CC) $(COPTS) \
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100887 -DBUILD_TARGET='"$(strip $(TARGET))"' \
Willy Tarreauef7341d2009-04-11 19:45:50 +0200888 -DBUILD_ARCH='"$(strip $(ARCH))"' \
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100889 -DBUILD_CPU='"$(strip $(CPU))"' \
890 -DBUILD_CC='"$(strip $(CC))"' \
891 -DBUILD_CFLAGS='"$(strip $(VERBOSE_CFLAGS))"' \
892 -DBUILD_OPTIONS='"$(strip $(BUILD_OPTIONS))"' \
Willy Tarreau7728ed32019-03-27 13:20:08 +0100893 -DBUILD_FEATURES='"$(strip $(BUILD_FEATURES))"' \
Willy Tarreau9f2b7302008-01-02 20:48:34 +0100894 -c -o $@ $<
Willy Tarreau7b066db2007-12-02 11:28:59 +0100895
Christian Wiese19b50292008-03-12 15:57:54 +0200896install-man:
Willy Tarreau4ab5d032018-11-19 07:51:04 +0100897 $(Q)install -v -d "$(DESTDIR)$(MANDIR)"/man1
898 $(Q)install -v -m 644 doc/haproxy.1 "$(DESTDIR)$(MANDIR)"/man1
Christian Wiese19b50292008-03-12 15:57:54 +0200899
Vincent Bernat5c5147f2015-10-13 22:20:55 +0200900EXCLUDE_DOCUMENTATION = lgpl gpl coding-style
901DOCUMENTATION = $(filter-out $(EXCLUDE_DOCUMENTATION),$(patsubst doc/%.txt,%,$(wildcard doc/*.txt)))
902
Christian Wiesebf34eb42008-03-12 17:24:49 +0200903install-doc:
Willy Tarreau4ab5d032018-11-19 07:51:04 +0100904 $(Q)install -v -d "$(DESTDIR)$(DOCDIR)"
905 $(Q)for x in $(DOCUMENTATION); do \
906 install -v -m 644 doc/$$x.txt "$(DESTDIR)$(DOCDIR)" ; \
Christian Wiesebf34eb42008-03-12 17:24:49 +0200907 done
908
Willy Tarreau13d67bb2016-06-24 18:30:22 +0200909install-bin:
Willy Tarreaub42233a2018-11-19 07:44:42 +0100910 $(Q)for i in haproxy $(EXTRA); do \
Willy Tarreau13d67bb2016-06-24 18:30:22 +0200911 if ! [ -e "$$i" ]; then \
912 echo "Please run 'make' before 'make install'."; \
913 exit 1; \
914 fi; \
915 done
Willy Tarreau4ab5d032018-11-19 07:51:04 +0100916 $(Q)install -v -d "$(DESTDIR)$(SBINDIR)"
917 $(Q)install -v haproxy $(EXTRA) "$(DESTDIR)$(SBINDIR)"
Christian Wiesea184aa22008-03-12 15:25:35 +0200918
Christian Wiesedb5238d2008-03-12 18:28:13 +0200919install: install-bin install-man install-doc
Christian Wiese4cf5d572008-03-12 16:21:05 +0200920
Ilyas Bakirovdfb124f2015-02-04 17:14:26 +0600921uninstall:
Willy Tarreau4ab5d032018-11-19 07:51:04 +0100922 $(Q)rm -f "$(DESTDIR)$(MANDIR)"/man1/haproxy.1
923 $(Q)for x in $(DOCUMENTATION); do \
Ilyas Bakirovdfb124f2015-02-04 17:14:26 +0600924 rm -f "$(DESTDIR)$(DOCDIR)"/$$x.txt ; \
925 done
Willy Tarreau4ab5d032018-11-19 07:51:04 +0100926 $(Q)-rmdir "$(DESTDIR)$(DOCDIR)"
927 $(Q)rm -f "$(DESTDIR)$(SBINDIR)"/haproxy
Ilyas Bakirovdfb124f2015-02-04 17:14:26 +0600928
willy tarreau0f7af912005-12-17 12:21:26 +0100929clean:
Willy Tarreauff0e8a42020-05-27 10:43:24 +0200930 $(Q)rm -f *.[oas] src/*.[oas] haproxy test .build_opts .build_opts.new
Willy Tarreaufc80e302020-05-27 11:05:33 +0200931 $(Q)for dir in . src include/* doc; do rm -f $$dir/*~ $$dir/*.rej $$dir/core; done
Willy Tarreauac32b4b2020-10-01 04:05:39 +0200932 $(Q)rm -f haproxy-$(VERSION).tar.gz haproxy-$(VERSION)$(SUBVERS)$(EXTRAVERSION).tar.gz
933 $(Q)rm -f haproxy-$(VERSION) haproxy-$(VERSION)$(SUBVERS)$(EXTRAVERSION) nohup.out gmon.out
willy tarreauefae1842005-12-17 12:51:03 +0100934
Willy Tarreauebe0af42009-10-10 22:20:44 +0200935tags:
Willy Tarreau6db82662018-11-19 08:14:40 +0100936 $(Q)find src include \( -name '*.c' -o -name '*.h' \) -print0 | \
Willy Tarreauebe0af42009-10-10 22:20:44 +0200937 xargs -0 etags --declarations --members
938
William Lallemand9e5cc8d2013-10-18 16:26:39 +0200939cscope:
Willy Tarreau6db82662018-11-19 08:14:40 +0100940 $(Q)find src include -name "*.[ch]" -print | cscope -q -b -i -
William Lallemand9e5cc8d2013-10-18 16:26:39 +0200941
willy tarreaue114bf92006-03-19 21:30:14 +0100942tar: clean
Willy Tarreauac32b4b2020-10-01 04:05:39 +0200943 $(Q)ln -s . haproxy-$(VERSION)$(SUBVERS)$(EXTRAVERSION)
944 $(Q)tar --exclude=haproxy-$(VERSION)$(SUBVERS)$(EXTRAVERSION)/.git \
945 --exclude=haproxy-$(VERSION)$(SUBVERS)$(EXTRAVERSION)/haproxy-$(VERSION)$(SUBVERS)$(EXTRAVERSION) \
946 --exclude=haproxy-$(VERSION)$(SUBVERS)$(EXTRAVERSION)/haproxy-$(VERSION)$(SUBVERS)$(EXTRAVERSION).tar.gz \
947 -cf - haproxy-$(VERSION)$(SUBVERS)$(EXTRAVERSION)/* | gzip -c9 >haproxy-$(VERSION)$(SUBVERS)$(EXTRAVERSION).tar.gz
948 $(Q)echo haproxy-$(VERSION)$(SUBVERS)$(EXTRAVERSION).tar.gz
949 $(Q)rm -f haproxy-$(VERSION)$(SUBVERS)$(EXTRAVERSION)
willy tarreaucee272f2006-03-19 21:16:26 +0100950
Willy Tarreau05ed29c2012-12-20 15:00:44 +0100951git-tar:
Willy Tarreauac32b4b2020-10-01 04:05:39 +0200952 $(Q)git archive --format=tar --prefix="haproxy-$(VERSION)$(SUBVERS)$(EXTRAVERSION)/" HEAD | gzip -9 > haproxy-$(VERSION)$(SUBVERS)$(EXTRAVERSION).tar.gz
953 $(Q)echo haproxy-$(VERSION)$(SUBVERS)$(EXTRAVERSION).tar.gz
Willy Tarreauec692562007-09-09 23:31:11 +0200954
955version:
956 @echo "VERSION: $(VERSION)"
957 @echo "SUBVERS: $(SUBVERS)"
958 @echo "VERDATE: $(VERDATE)"
959
960# never use this one if you don't know what it is used for.
961update-version:
962 @echo "Ready to update the following versions :"
963 @echo "VERSION: $(VERSION)"
964 @echo "SUBVERS: $(SUBVERS)"
965 @echo "VERDATE: $(VERDATE)"
966 @echo "Press [ENTER] to continue or Ctrl-C to abort now.";read
967 echo "$(VERSION)" > VERSION
968 echo "$(SUBVERS)" > SUBVERS
969 echo "$(VERDATE)" > VERDATE
Frédéric Lécaille153b2b62018-06-18 19:32:10 +0200970
Willy Tarreaua8b12c62018-10-03 09:40:22 +0200971# just display the build options
972opts:
973 @echo -n 'Using: '
974 @echo -n 'TARGET="$(strip $(TARGET))" '
975 @echo -n 'ARCH="$(strip $(ARCH))" '
976 @echo -n 'CPU="$(strip $(CPU))" '
977 @echo -n 'CC="$(strip $(CC))" '
978 @echo -n 'ARCH_FLAGS="$(strip $(ARCH_FLAGS))" '
979 @echo -n 'CPU_CFLAGS="$(strip $(CPU_CFLAGS))" '
980 @echo -n 'DEBUG_CFLAGS="$(strip $(DEBUG_CFLAGS))" '
981 @echo "$(strip $(BUILD_OPTIONS))"
982 @echo 'COPTS="$(strip $(COPTS))"'
983 @echo 'LDFLAGS="$(strip $(LDFLAGS))"'
984 @echo 'LDOPTS="$(strip $(LDOPTS))"'
985 @echo 'OPTIONS_OBJS="$(strip $(OPTIONS_OBJS))"'
986 @echo 'OBJS="$(strip $(OBJS))"'
987
Frédéric Lécaillea3b4cbf2018-12-19 16:27:47 +0100988ifeq (reg-tests, $(firstword $(MAKECMDGOALS)))
989 REGTEST_ARGS := $(wordlist 2, $(words $(MAKECMDGOALS)), $(MAKECMDGOALS))
990 $(eval $(REGTEST_ARGS):;@true)
991endif
992
Frédéric Lécaille99316342018-08-22 10:41:33 +0200993# Target to run the regression testing script files.
Frédéric Lécaille153b2b62018-06-18 19:32:10 +0200994reg-tests:
Frédéric Lécailledc1a3bd2019-03-29 15:07:24 +0100995 $(Q)$(REG_TEST_SCRIPT) --type "$(REGTESTS_TYPES)" $(REGTEST_ARGS) $(REG_TEST_FILES)
Frédéric Lécaillea3b4cbf2018-12-19 16:27:47 +0100996.PHONY: $(REGTEST_ARGS)
Frederic Lecailled4f36e32018-12-13 22:15:05 +0100997
998reg-tests-help:
999 @echo
Frédéric Lécailledc1a3bd2019-03-29 15:07:24 +01001000 @echo "To launch the reg tests for haproxy, first export to your environment "
1001 @echo "VTEST_PROGRAM variable to point to your vtest program:"
Frédéric Lécaille43361232019-01-11 10:10:21 +01001002 @echo " $$ export VTEST_PROGRAM=/opt/local/bin/vtest"
Frederic Lecailled4f36e32018-12-13 22:15:05 +01001003 @echo "or"
Frédéric Lécaille43361232019-01-11 10:10:21 +01001004 @echo " $$ setenv VTEST_PROGRAM /opt/local/bin/vtest"
Frederic Lecailled4f36e32018-12-13 22:15:05 +01001005 @echo
Frédéric Lécailledc1a3bd2019-03-29 15:07:24 +01001006 @echo "The same thing may be done to set your haproxy program with HAPROXY_PROGRAM "
1007 @echo "but with ./haproxy as default value."
Frederic Lecailled4f36e32018-12-13 22:15:05 +01001008 @echo
1009 @echo "To run all the tests:"
1010 @echo " $$ make reg-tests"
1011 @echo
1012 @echo "You can also set the programs to be used on the command line:"
Frédéric Lécaille43361232019-01-11 10:10:21 +01001013 @echo " $$ VTEST_PROGRAM=<...> HAPROXY_PROGRAM=<...> make reg-tests"
Frederic Lecailled4f36e32018-12-13 22:15:05 +01001014 @echo
Frédéric Lécailledc1a3bd2019-03-29 15:07:24 +01001015 @echo "To run tests with specific types:"
1016 @echo " $$ REGTESTS_TYPES=slow,default make reg-tests"
1017 @echo
1018 @echo "with 'any' as default value for REGTESTS_TYPES variable."
1019 @echo
1020 @echo "About the reg test types:"
1021 @echo " any : all the tests without distinction (this is the default"
1022 @echo " value of REGTESTS_TYPES."
1023 @echo " default : dedicated to pure haproxy compliance tests."
1024 @echo " slow : scripts which take non negligible time to run."
1025 @echo " bug : scripts in relation with bugs they help to reproduce."
1026 @echo " broken : scripts triggering known broken behaviors for which"
1027 @echo " there is still no fix."
1028 @echo " experimental: for scripts which are experimental, typically used to"
1029 @echo " develop new scripts."
Frederic Lecailled4f36e32018-12-13 22:15:05 +01001030 @echo
Frédéric Lécailledc1a3bd2019-03-29 15:07:24 +01001031 @echo "Note that 'reg-tests' target run '"$(REG_TEST_SCRIPT)"' script"
1032 @echo "(see --help option of this script for more information)."
Frederic Lecailled4f36e32018-12-13 22:15:05 +01001033
1034.PHONY: reg-tests reg-tests-help