blob: d607e5cdf0d9b529484c08613f05daeb15d1ea58 [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 Tarreau4f60f162007-04-08 16:39:58 +020072COPTS.solaris = -fomit-frame-pointer -DFD_SETSIZE=65536
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 Tarreaua1973c42007-04-09 22:07:11 +0200116VERSION := $(shell [ -d .git/. ] && ref=`git-describe --tags 2>/dev/null` && ref=$${ref%-g*} && echo "$${ref\#v}" )
Willy Tarreau6620dbb2007-01-02 00:44:53 +0100117endif
Willy Tarreau9bf6c6e2006-12-23 11:12:04 +0100118
119ifneq ($(VERSION),)
120# OK git is there and works.
Willy Tarreaua1973c42007-04-09 22:07:11 +0200121SUBVERS := $(shell comms=`git-log --no-merges v$(VERSION).. 2>/dev/null |grep -c ^commit `; [ $$comms -gt 0 ] && echo "-$$comms" )
122VERDATE := $(shell date +%Y/%m/%d -d "`git-log HEAD^.. 2>/dev/null | grep -m 1 ^Date: | cut -f2- -d: | cut -f1 -d+`" )
Willy Tarreau9bf6c6e2006-12-23 11:12:04 +0100123else
124# Otherwise, use the hard-coded version of last tag, number of changes
125# since last tag, and release date.
Willy Tarreaub21152b2007-06-17 23:41:40 +0200126VERSION := 1.3.12
Willy Tarreau6620dbb2007-01-02 00:44:53 +0100127SUBVERS :=
Willy Tarreaub21152b2007-06-17 23:41:40 +0200128VERDATE := 2007/06/17
Willy Tarreau9bf6c6e2006-12-23 11:12:04 +0100129endif
Willy Tarreau77074d52006-11-12 23:57:19 +0100130
131#### build options
132
133# do not change this one, enable USE_* variables instead.
134OPTIONS =
Willy Tarreaub38651a2007-03-24 17:24:39 +0100135OPT_OBJS =
Willy Tarreau77074d52006-11-12 23:57:19 +0100136
Willy Tarreau6d1a9882007-01-07 02:03:04 +0100137ifneq ($(USE_TCPSPLICE),)
138OPTIONS += -DCONFIG_HAP_TCPSPLICE
139endif
140
Willy Tarreaub38651a2007-03-24 17:24:39 +0100141# - set USE_CTTPROXY to enable full transparent proxy support
Willy Tarreau77074d52006-11-12 23:57:19 +0100142ifneq ($(USE_CTTPROXY),)
143OPTIONS += -DCONFIG_HAP_CTTPROXY
Willy Tarreaub38651a2007-03-24 17:24:39 +0100144OPT_OBJS += src/cttproxy.o
Willy Tarreau77074d52006-11-12 23:57:19 +0100145endif
146
147ifneq ($(USE_TPROXY),)
148OPTIONS += -DTPROXY
149endif
150
151ifneq ($(USE_POLL),)
152OPTIONS += -DENABLE_POLL
Willy Tarreau4f60f162007-04-08 16:39:58 +0200153OPT_OBJS += src/ev_poll.o
Willy Tarreau77074d52006-11-12 23:57:19 +0100154endif
155
156ifneq ($(USE_EPOLL),)
157OPTIONS += -DENABLE_EPOLL
Willy Tarreau4f60f162007-04-08 16:39:58 +0200158OPT_OBJS += src/ev_epoll.o
Willy Tarreau77074d52006-11-12 23:57:19 +0100159endif
160
Willy Tarreaude99e992007-04-16 00:53:59 +0200161ifneq ($(USE_SEPOLL),)
162OPTIONS += -DENABLE_SEPOLL
163OPT_OBJS += src/ev_sepoll.o
164endif
165
Willy Tarreau77074d52006-11-12 23:57:19 +0100166ifneq ($(USE_MY_EPOLL),)
167OPTIONS += -DUSE_MY_EPOLL
168endif
169
170ifneq ($(USE_NETFILTER),)
171OPTIONS += -DNETFILTER
172endif
173
174ifneq ($(USE_EPOLL_WORKAROUND),)
175OPTIONS += -DEPOLL_CTL_MOD_WORKAROUND
176endif
177
178ifneq ($(USE_GETSOCKNAME),)
179OPTIONS += -DUSE_GETSOCKNAME
180endif
181
182ifneq ($(USE_REGPARM),)
183OPTIONS += -DCONFIG_HAP_USE_REGPARM
184endif
185
Willy Tarreauf2ef8c52007-07-11 09:19:31 +0200186ifneq ($(DLMALLOC_SRC),)
187# May be changed to patch PAGE_SIZE on every platform
188DLMALLOC_THRES=4096
189OPT_OBJS += src/dlmalloc.o
190endif
191
Willy Tarreau79b34bf2006-12-22 15:28:43 +0100192ifneq ($(VERSION),)
193OPTIONS += -DCONFIG_HAPROXY_VERSION=\"$(VERSION)$(SUBVERS)\"
194endif
195
196ifneq ($(VERDATE),)
197OPTIONS += -DCONFIG_HAPROXY_DATE=\"$(VERDATE)\"
198endif
199
Willy Tarreau77074d52006-11-12 23:57:19 +0100200#### end of build options
201
202
willy tarreaueedaa9f2005-12-17 14:08:03 +0100203# global options
204TARGET_OPTS=$(COPTS.$(TARGET))
205REGEX_OPTS=$(COPTS.$(REGEX))
206CPU_OPTS=$(COPTS.$(CPU))
207
Willy Tarreau6d1a9882007-01-07 02:03:04 +0100208COPTS = -Iinclude $(CPU_OPTS) $(TARGET_OPTS) $(REGEX_OPTS) $(SMALL_OPTS) $(DEFINE) $(OPTIONS)
209LIBS=$(LIBS.$(TARGET)) $(LIBS.$(REGEX))
210
211ifneq ($(USE_TCPSPLICE),)
212COPTS += -I$(TCPSPLICEDIR)
213LIBS += -L$(TCPSPLICEDIR) -ltcpsplice
214endif
215
216COPTS += $(ADDINC)
217LIBS += $(ADDLIB)
willy tarreau0f7af912005-12-17 12:21:26 +0100218
willy tarreaud38e72d2006-03-19 20:56:52 +0100219CFLAGS = -Wall $(COPTS) $(DEBUG)
willy tarreau0f7af912005-12-17 12:21:26 +0100220LDFLAGS = -g
221
222all: haproxy
223
Willy Tarreau51041c72007-09-09 21:56:53 +0200224OBJS = src/haproxy.o src/sessionhash.o src/base64.o \
Willy Tarreaubaaee002006-06-26 02:48:02 +0200225 src/uri_auth.o src/standard.o src/buffers.o src/log.o src/task.o \
226 src/time.o src/fd.o src/regex.o src/cfgparse.o src/server.o \
Willy Tarreau086b3b42007-05-13 21:45:51 +0200227 src/checks.o src/queue.o src/client.o src/proxy.o \
Willy Tarreaubaaee002006-06-26 02:48:02 +0200228 src/proto_http.o src/stream_sock.o src/appsession.o src/backend.o \
Willy Tarreau50e608d2007-05-13 18:26:08 +0200229 src/session.o src/hdr_idx.o src/ev_select.o src/acl.o src/memory.o
Willy Tarreaubaaee002006-06-26 02:48:02 +0200230
Willy Tarreaub38651a2007-03-24 17:24:39 +0100231haproxy: $(OBJS) $(OPT_OBJS)
willy tarreau0f7af912005-12-17 12:21:26 +0100232 $(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
233
Willy Tarreaubaaee002006-06-26 02:48:02 +0200234objsize: haproxy
235 @objdump -t $^|grep ' g '|grep -F '.text'|awk '{print $$5 FS $$6}'|sort
236
willy tarreau0f7af912005-12-17 12:21:26 +0100237%.o: %.c
238 $(CC) $(CFLAGS) -c -o $@ $<
239
Willy Tarreauf2ef8c52007-07-11 09:19:31 +0200240src/dlmalloc.o: $(DLMALLOC_SRC)
241 $(CC) $(CFLAGS) -DDEFAULT_MMAP_THRESHOLD=$(DLMALLOC_THRES) -c -o $@ $<
242
willy tarreau0f7af912005-12-17 12:21:26 +0100243clean:
Willy Tarreau1a587492006-10-15 23:40:58 +0200244 rm -f *.[oas] src/*.[oas] core haproxy test
245 for dir in . src include/* doc; do rm -f $$dir/*~ $$dir/*.rej;done
Willy Tarreau9bf6c6e2006-12-23 11:12:04 +0100246 rm -f haproxy-$(VERSION).tar.gz haproxy-$(VERSION)$(SUBVERS).tar.gz
247 rm -f haproxy-$(VERSION) nohup.out gmon.out
willy tarreauefae1842005-12-17 12:51:03 +0100248
willy tarreaue114bf92006-03-19 21:30:14 +0100249tar: clean
willy tarreaucee272f2006-03-19 21:16:26 +0100250 ln -s . haproxy-$(VERSION)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200251 tar --exclude=haproxy-$(VERSION)/.git \
252 --exclude=haproxy-$(VERSION)/haproxy-$(VERSION) \
253 --exclude=haproxy-$(VERSION)/haproxy-$(VERSION).tar.gz \
254 -cf - haproxy-$(VERSION)/* | gzip -c9 >haproxy-$(VERSION).tar.gz
willy tarreaucee272f2006-03-19 21:16:26 +0100255 rm -f haproxy-$(VERSION)
256
Willy Tarreau9f0a9012006-10-15 14:24:14 +0200257git-tar: clean
Willy Tarreau9bf6c6e2006-12-23 11:12:04 +0100258 git-tar-tree HEAD haproxy-$(VERSION) | gzip -9 > haproxy-$(VERSION)$(SUBVERS).tar.gz