blob: 5fa8622a75f30375d3af308174034a42e0ecc498 [file] [log] [blame]
willy tarreaueedaa9f2005-12-17 14:08:03 +01001# This makefile supports different OS and CPU setups.
2# You should use it this way :
Willy Tarreau9bf6c6e2006-12-23 11:12:04 +01003# make TARGET=os CPU=cpu REGEX=lib
Willy Tarreauf2ef8c52007-07-11 09:19:31 +02004#
5# Some external components may be build with it, such dlmalloc :
6#
7# make DLMALLOC_SRC=/usr/local/src/dlmalloc.c
willy tarreaucee272f2006-03-19 21:16:26 +01008
willy tarreau750a4722005-12-17 13:21:24 +01009# Select target OS. TARGET must match a system for which COPTS and LIBS are
10# correctly defined below.
willy tarreau1c2ad212005-12-18 01:11:29 +010011#TARGET = linux26
willy tarreau750a4722005-12-17 13:21:24 +010012TARGET = linux24
willy tarreau64a3cc32005-12-18 01:13:11 +010013#TARGET = linux24e
willy tarreau750a4722005-12-17 13:21:24 +010014#TARGET = linux22
15#TARGET = solaris
willy tarreau750a4722005-12-17 13:21:24 +010016
Willy Tarreau4f60f162007-04-08 16:39:58 +020017USE_POLL = 1
18
19ifeq ($(TARGET),linux24e)
20USE_EPOLL = 1
Willy Tarreaude99e992007-04-16 00:53:59 +020021USE_SEPOLL = 1
Willy Tarreau4f60f162007-04-08 16:39:58 +020022endif
23
24ifeq ($(TARGET),linux26)
25USE_EPOLL = 1
Willy Tarreaude99e992007-04-16 00:53:59 +020026USE_SEPOLL = 1
Willy Tarreau4f60f162007-04-08 16:39:58 +020027endif
28
willy tarreaueedaa9f2005-12-17 14:08:03 +010029# pass CPU=<cpu_name> to make to optimize for a particular CPU
30CPU = generic
31#CPU = i586
32#CPU = i686
33#CPU = ultrasparc
willy tarreau0f7af912005-12-17 12:21:26 +010034
willy tarreau4373b962005-12-18 01:32:31 +010035# By default, we use libc's regex. WARNING! On Solaris 8/Sparc, group
36# references seem broken using libc ! Use pcre instead.
willy tarreau036e1ce2005-12-17 13:46:33 +010037REGEX=libc
38#REGEX=pcre
willy tarreau4373b962005-12-18 01:32:31 +010039#REGEX=static-pcre
willy tarreau036e1ce2005-12-17 13:46:33 +010040
willy tarreaueedaa9f2005-12-17 14:08:03 +010041# tools options
42CC = gcc
43LD = gcc
44
willy tarreau036e1ce2005-12-17 13:46:33 +010045# This is the directory hosting include/pcre.h and lib/libpcre.* when REGEX=pcre
willy tarreau2f6ba652005-12-17 13:57:42 +010046PCREDIR := $(shell pcre-config --prefix 2>/dev/null || :)
willy tarreau036e1ce2005-12-17 13:46:33 +010047#PCREDIR=/usr/local
48
Willy Tarreau6d1a9882007-01-07 02:03:04 +010049# This is the directory hosting libtcpsplice.[ah] when USE_TCPSPLICE is set
50TCPSPLICEDIR :=
51
willy tarreau64a3cc32005-12-18 01:13:11 +010052# This is for standard Linux 2.6 with netfilter and epoll()
Willy Tarreau4f60f162007-04-08 16:39:58 +020053COPTS.linux26 = -DNETFILTER
willy tarreau1c2ad212005-12-18 01:11:29 +010054LIBS.linux26 =
55
willy tarreaub952e1d2005-12-18 01:31:20 +010056# This is for enhanced Linux 2.4 with netfilter and epoll() patch.
57# Warning! If kernel is 2.4 with epoll-lt <= 0.21, then you must add
58# -DEPOLL_CTL_MOD_WORKAROUND to workaround a very rare bug.
Willy Tarreau4f60f162007-04-08 16:39:58 +020059#COPTS.linux24e = -DNETFILTER -DUSE_MY_EPOLL -DEPOLL_CTL_MOD_WORKAROUND
60COPTS.linux24e = -DNETFILTER -DUSE_MY_EPOLL
willy tarreau64a3cc32005-12-18 01:13:11 +010061LIBS.linux24e =
62
63# This is for standard Linux 2.4 with netfilter but without epoll()
Willy Tarreau4f60f162007-04-08 16:39:58 +020064COPTS.linux24 = -DNETFILTER
willy tarreau5cbea6f2005-12-17 12:48:26 +010065LIBS.linux24 =
willy tarreau0f7af912005-12-17 12:21:26 +010066
willy tarreau5cbea6f2005-12-17 12:48:26 +010067# This is for Linux 2.2
Willy Tarreau4f60f162007-04-08 16:39:58 +020068COPTS.linux22 = -DUSE_GETSOCKNAME
willy tarreau5cbea6f2005-12-17 12:48:26 +010069LIBS.linux22 =
70
71# This is for Solaris 8
Willy Tarreau2ee30412007-11-03 16:18:11 +010072COPTS.solaris = -fomit-frame-pointer -DFD_SETSIZE=65536 -D_REENTRANT
willy tarreau9da061b2005-12-17 12:29:56 +010073LIBS.solaris = -lnsl -lsocket
74
willy tarreaueedaa9f2005-12-17 14:08:03 +010075# CPU dependant optimizations
76COPTS.generic = -O2
Willy Tarreau390223b2006-10-15 23:43:42 +020077COPTS.i586 = -O2 -march=i586 -DCONFIG_HAP_USE_REGPARM
78COPTS.i686 = -O2 -march=i686 -DCONFIG_HAP_USE_REGPARM
willy tarreaueedaa9f2005-12-17 14:08:03 +010079COPTS.ultrasparc = -O6 -mcpu=v9 -mtune=ultrasparc
80
81# options for standard regex library
willy tarreau036e1ce2005-12-17 13:46:33 +010082COPTS.libc=
willy tarreaueedaa9f2005-12-17 14:08:03 +010083LIBS.libc=
willy tarreau036e1ce2005-12-17 13:46:33 +010084
willy tarreaueedaa9f2005-12-17 14:08:03 +010085# options for libpcre
willy tarreau036e1ce2005-12-17 13:46:33 +010086COPTS.pcre=-DUSE_PCRE -I$(PCREDIR)/include
87LIBS.pcre=-L$(PCREDIR)/lib -lpcreposix -lpcre
88
willy tarreau4373b962005-12-18 01:32:31 +010089# options for static libpcre
90COPTS.static-pcre=-DUSE_PCRE -I$(PCREDIR)/include
91LIBS.static-pcre=-L$(PCREDIR)/lib -Wl,-Bstatic -lpcreposix -lpcre -Wl,-Bdynamic
92
willy tarreaueedaa9f2005-12-17 14:08:03 +010093# you can enable debug arguments with "DEBUG=-g" or disable them with "DEBUG="
willy tarreaud38e72d2006-03-19 20:56:52 +010094#DEBUG = -g -DDEBUG_MEMORY -DDEBUG_FULL
willy tarreau5cbea6f2005-12-17 12:48:26 +010095DEBUG = -g
willy tarreau9da061b2005-12-17 12:29:56 +010096
willy tarreau0174f312005-12-18 01:02:42 +010097# if small memory footprint is required, you can reduce the buffer size. There
98# are 2 buffers per concurrent session, so 16 kB buffers will eat 32 MB memory
willy tarreau64a3cc32005-12-18 01:13:11 +010099# with 1000 concurrent sessions. Putting it slightly lower than a page size
willy tarreaud38e72d2006-03-19 20:56:52 +0100100# will avoid the additionnal paramters to overflow a page. 8030 bytes is
101# exactly 5.5 TCP segments of 1460 bytes.
102#SMALL_OPTS = -DBUFSIZE=8030 -DMAXREWRITE=1030 -DSYSTEM_MAXCONN=1024
willy tarreau0174f312005-12-18 01:02:42 +0100103SMALL_OPTS =
104
willy tarreau1c2ad212005-12-18 01:11:29 +0100105# redefine this if you want to add some special PATH to include/libs
106ADDINC =
107ADDLIB =
108
109# set some defines when needed.
willy tarreaud38e72d2006-03-19 20:56:52 +0100110# - use -DTPROXY to compile with transparent proxy support.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200111DEFINE = -DTPROXY
willy tarreau0174f312005-12-18 01:02:42 +0100112
Willy Tarreau9bf6c6e2006-12-23 11:12:04 +0100113# Now let's determine the version, sub-version and release date.
114# If we're in the GIT tree, we can use the last commit's version and date.
Willy Tarreau6620dbb2007-01-02 00:44:53 +0100115ifeq ($(IGNOREGIT),)
Willy Tarreauec692562007-09-09 23:31:11 +0200116VERSION := $(shell [ -d .git/. ] && ref=`(git-describe --tags) 2>/dev/null` && ref=$${ref%-g*} && echo "$${ref\#v}")
Willy Tarreau9bf6c6e2006-12-23 11:12:04 +0100117ifneq ($(VERSION),)
118# OK git is there and works.
Willy Tarreaua1973c42007-04-09 22:07:11 +0200119SUBVERS := $(shell comms=`git-log --no-merges v$(VERSION).. 2>/dev/null |grep -c ^commit `; [ $$comms -gt 0 ] && echo "-$$comms" )
120VERDATE := $(shell date +%Y/%m/%d -d "`git-log HEAD^.. 2>/dev/null | grep -m 1 ^Date: | cut -f2- -d: | cut -f1 -d+`" )
Willy Tarreauec692562007-09-09 23:31:11 +0200121endif
122endif
123
Willy Tarreau9bf6c6e2006-12-23 11:12:04 +0100124# Otherwise, use the hard-coded version of last tag, number of changes
125# since last tag, and release date.
Willy Tarreauec692562007-09-09 23:31:11 +0200126ifeq ($(VERSION),)
127VERSION := $(shell cat VERSION 2>/dev/null || touch VERSION)
128endif
129ifeq ($(SUBVERS),)
130SUBVERS := $(shell cat SUBVERS 2>/dev/null || touch SUBVERS)
131endif
132ifeq ($(VERDATE),)
133VERDATE := $(shell cat VERDATE 2>/dev/null || touch VERDATE)
Willy Tarreau9bf6c6e2006-12-23 11:12:04 +0100134endif
Willy Tarreau77074d52006-11-12 23:57:19 +0100135
136#### build options
137
138# do not change this one, enable USE_* variables instead.
139OPTIONS =
Willy Tarreaub38651a2007-03-24 17:24:39 +0100140OPT_OBJS =
Willy Tarreau77074d52006-11-12 23:57:19 +0100141
Willy Tarreau6d1a9882007-01-07 02:03:04 +0100142ifneq ($(USE_TCPSPLICE),)
143OPTIONS += -DCONFIG_HAP_TCPSPLICE
144endif
145
Willy Tarreaub38651a2007-03-24 17:24:39 +0100146# - set USE_CTTPROXY to enable full transparent proxy support
Willy Tarreau77074d52006-11-12 23:57:19 +0100147ifneq ($(USE_CTTPROXY),)
148OPTIONS += -DCONFIG_HAP_CTTPROXY
Willy Tarreaub38651a2007-03-24 17:24:39 +0100149OPT_OBJS += src/cttproxy.o
Willy Tarreau77074d52006-11-12 23:57:19 +0100150endif
151
152ifneq ($(USE_TPROXY),)
153OPTIONS += -DTPROXY
154endif
155
156ifneq ($(USE_POLL),)
157OPTIONS += -DENABLE_POLL
Willy Tarreau4f60f162007-04-08 16:39:58 +0200158OPT_OBJS += src/ev_poll.o
Willy Tarreau77074d52006-11-12 23:57:19 +0100159endif
160
161ifneq ($(USE_EPOLL),)
162OPTIONS += -DENABLE_EPOLL
Willy Tarreau4f60f162007-04-08 16:39:58 +0200163OPT_OBJS += src/ev_epoll.o
Willy Tarreau77074d52006-11-12 23:57:19 +0100164endif
165
Willy Tarreaude99e992007-04-16 00:53:59 +0200166ifneq ($(USE_SEPOLL),)
167OPTIONS += -DENABLE_SEPOLL
168OPT_OBJS += src/ev_sepoll.o
169endif
170
Willy Tarreau77074d52006-11-12 23:57:19 +0100171ifneq ($(USE_MY_EPOLL),)
172OPTIONS += -DUSE_MY_EPOLL
173endif
174
175ifneq ($(USE_NETFILTER),)
176OPTIONS += -DNETFILTER
177endif
178
179ifneq ($(USE_EPOLL_WORKAROUND),)
180OPTIONS += -DEPOLL_CTL_MOD_WORKAROUND
181endif
182
183ifneq ($(USE_GETSOCKNAME),)
184OPTIONS += -DUSE_GETSOCKNAME
185endif
186
187ifneq ($(USE_REGPARM),)
188OPTIONS += -DCONFIG_HAP_USE_REGPARM
189endif
190
Willy Tarreauf2ef8c52007-07-11 09:19:31 +0200191ifneq ($(DLMALLOC_SRC),)
192# May be changed to patch PAGE_SIZE on every platform
193DLMALLOC_THRES=4096
194OPT_OBJS += src/dlmalloc.o
195endif
196
Willy Tarreau79b34bf2006-12-22 15:28:43 +0100197ifneq ($(VERSION),)
198OPTIONS += -DCONFIG_HAPROXY_VERSION=\"$(VERSION)$(SUBVERS)\"
199endif
200
201ifneq ($(VERDATE),)
202OPTIONS += -DCONFIG_HAPROXY_DATE=\"$(VERDATE)\"
203endif
204
Willy Tarreau77074d52006-11-12 23:57:19 +0100205#### end of build options
206
207
willy tarreaueedaa9f2005-12-17 14:08:03 +0100208# global options
209TARGET_OPTS=$(COPTS.$(TARGET))
210REGEX_OPTS=$(COPTS.$(REGEX))
211CPU_OPTS=$(COPTS.$(CPU))
212
Willy Tarreau6d1a9882007-01-07 02:03:04 +0100213COPTS = -Iinclude $(CPU_OPTS) $(TARGET_OPTS) $(REGEX_OPTS) $(SMALL_OPTS) $(DEFINE) $(OPTIONS)
214LIBS=$(LIBS.$(TARGET)) $(LIBS.$(REGEX))
215
216ifneq ($(USE_TCPSPLICE),)
217COPTS += -I$(TCPSPLICEDIR)
218LIBS += -L$(TCPSPLICEDIR) -ltcpsplice
219endif
220
221COPTS += $(ADDINC)
222LIBS += $(ADDLIB)
willy tarreau0f7af912005-12-17 12:21:26 +0100223
willy tarreaud38e72d2006-03-19 20:56:52 +0100224CFLAGS = -Wall $(COPTS) $(DEBUG)
willy tarreau0f7af912005-12-17 12:21:26 +0100225LDFLAGS = -g
226
227all: haproxy
228
Willy Tarreaudd815982007-10-16 12:25:14 +0200229OBJS = src/haproxy.o src/sessionhash.o src/base64.o src/protocols.o \
Willy Tarreaubaaee002006-06-26 02:48:02 +0200230 src/uri_auth.o src/standard.o src/buffers.o src/log.o src/task.o \
231 src/time.o src/fd.o src/regex.o src/cfgparse.o src/server.o \
Willy Tarreau92fb9832007-10-16 17:34:28 +0200232 src/checks.o src/queue.o src/client.o src/proxy.o src/proto_uxst.o \
Willy Tarreaubaaee002006-06-26 02:48:02 +0200233 src/proto_http.o src/stream_sock.o src/appsession.o src/backend.o \
Willy Tarreau91861262007-10-17 17:06:05 +0200234 src/senddata.o src/dumpstats.o \
Willy Tarreau50e608d2007-05-13 18:26:08 +0200235 src/session.o src/hdr_idx.o src/ev_select.o src/acl.o src/memory.o
Willy Tarreaubaaee002006-06-26 02:48:02 +0200236
Willy Tarreaub38651a2007-03-24 17:24:39 +0100237haproxy: $(OBJS) $(OPT_OBJS)
willy tarreau0f7af912005-12-17 12:21:26 +0100238 $(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
239
Willy Tarreaubaaee002006-06-26 02:48:02 +0200240objsize: haproxy
241 @objdump -t $^|grep ' g '|grep -F '.text'|awk '{print $$5 FS $$6}'|sort
242
willy tarreau0f7af912005-12-17 12:21:26 +0100243%.o: %.c
244 $(CC) $(CFLAGS) -c -o $@ $<
245
Willy Tarreauf2ef8c52007-07-11 09:19:31 +0200246src/dlmalloc.o: $(DLMALLOC_SRC)
247 $(CC) $(CFLAGS) -DDEFAULT_MMAP_THRESHOLD=$(DLMALLOC_THRES) -c -o $@ $<
248
willy tarreau0f7af912005-12-17 12:21:26 +0100249clean:
Willy Tarreau1a587492006-10-15 23:40:58 +0200250 rm -f *.[oas] src/*.[oas] core haproxy test
251 for dir in . src include/* doc; do rm -f $$dir/*~ $$dir/*.rej;done
Willy Tarreau9bf6c6e2006-12-23 11:12:04 +0100252 rm -f haproxy-$(VERSION).tar.gz haproxy-$(VERSION)$(SUBVERS).tar.gz
253 rm -f haproxy-$(VERSION) nohup.out gmon.out
willy tarreauefae1842005-12-17 12:51:03 +0100254
willy tarreaue114bf92006-03-19 21:30:14 +0100255tar: clean
willy tarreaucee272f2006-03-19 21:16:26 +0100256 ln -s . haproxy-$(VERSION)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200257 tar --exclude=haproxy-$(VERSION)/.git \
258 --exclude=haproxy-$(VERSION)/haproxy-$(VERSION) \
259 --exclude=haproxy-$(VERSION)/haproxy-$(VERSION).tar.gz \
260 -cf - haproxy-$(VERSION)/* | gzip -c9 >haproxy-$(VERSION).tar.gz
willy tarreaucee272f2006-03-19 21:16:26 +0100261 rm -f haproxy-$(VERSION)
262
Willy Tarreau9f0a9012006-10-15 14:24:14 +0200263git-tar: clean
Willy Tarreau9bf6c6e2006-12-23 11:12:04 +0100264 git-tar-tree HEAD haproxy-$(VERSION) | gzip -9 > haproxy-$(VERSION)$(SUBVERS).tar.gz
Willy Tarreauec692562007-09-09 23:31:11 +0200265
266version:
267 @echo "VERSION: $(VERSION)"
268 @echo "SUBVERS: $(SUBVERS)"
269 @echo "VERDATE: $(VERDATE)"
270
271# never use this one if you don't know what it is used for.
272update-version:
273 @echo "Ready to update the following versions :"
274 @echo "VERSION: $(VERSION)"
275 @echo "SUBVERS: $(SUBVERS)"
276 @echo "VERDATE: $(VERDATE)"
277 @echo "Press [ENTER] to continue or Ctrl-C to abort now.";read
278 echo "$(VERSION)" > VERSION
279 echo "$(SUBVERS)" > SUBVERS
280 echo "$(VERDATE)" > VERDATE