blob: d3d5c978932b2c40c4111fa296ff9c5246fb8f54 [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 tarreaueedaa9f2005-12-17 14:08:03 +01004
willy tarreaucee272f2006-03-19 21:16:26 +01005
willy tarreau750a4722005-12-17 13:21:24 +01006# Select target OS. TARGET must match a system for which COPTS and LIBS are
7# correctly defined below.
willy tarreau1c2ad212005-12-18 01:11:29 +01008#TARGET = linux26
willy tarreau750a4722005-12-17 13:21:24 +01009TARGET = linux24
willy tarreau64a3cc32005-12-18 01:13:11 +010010#TARGET = linux24e
willy tarreau750a4722005-12-17 13:21:24 +010011#TARGET = linux22
12#TARGET = solaris
willy tarreau750a4722005-12-17 13:21:24 +010013
Willy Tarreau4f60f162007-04-08 16:39:58 +020014USE_POLL = 1
15
16ifeq ($(TARGET),linux24e)
17USE_EPOLL = 1
18endif
19
20ifeq ($(TARGET),linux26)
21USE_EPOLL = 1
22endif
23
willy tarreaueedaa9f2005-12-17 14:08:03 +010024# pass CPU=<cpu_name> to make to optimize for a particular CPU
25CPU = generic
26#CPU = i586
27#CPU = i686
28#CPU = ultrasparc
willy tarreau0f7af912005-12-17 12:21:26 +010029
willy tarreau4373b962005-12-18 01:32:31 +010030# By default, we use libc's regex. WARNING! On Solaris 8/Sparc, group
31# references seem broken using libc ! Use pcre instead.
willy tarreau036e1ce2005-12-17 13:46:33 +010032REGEX=libc
33#REGEX=pcre
willy tarreau4373b962005-12-18 01:32:31 +010034#REGEX=static-pcre
willy tarreau036e1ce2005-12-17 13:46:33 +010035
willy tarreaueedaa9f2005-12-17 14:08:03 +010036# tools options
37CC = gcc
38LD = gcc
39
willy tarreau036e1ce2005-12-17 13:46:33 +010040# This is the directory hosting include/pcre.h and lib/libpcre.* when REGEX=pcre
willy tarreau2f6ba652005-12-17 13:57:42 +010041PCREDIR := $(shell pcre-config --prefix 2>/dev/null || :)
willy tarreau036e1ce2005-12-17 13:46:33 +010042#PCREDIR=/usr/local
43
Willy Tarreau6d1a9882007-01-07 02:03:04 +010044# This is the directory hosting libtcpsplice.[ah] when USE_TCPSPLICE is set
45TCPSPLICEDIR :=
46
willy tarreau64a3cc32005-12-18 01:13:11 +010047# This is for standard Linux 2.6 with netfilter and epoll()
Willy Tarreau4f60f162007-04-08 16:39:58 +020048COPTS.linux26 = -DNETFILTER
willy tarreau1c2ad212005-12-18 01:11:29 +010049LIBS.linux26 =
50
willy tarreaub952e1d2005-12-18 01:31:20 +010051# This is for enhanced Linux 2.4 with netfilter and epoll() patch.
52# Warning! If kernel is 2.4 with epoll-lt <= 0.21, then you must add
53# -DEPOLL_CTL_MOD_WORKAROUND to workaround a very rare bug.
Willy Tarreau4f60f162007-04-08 16:39:58 +020054#COPTS.linux24e = -DNETFILTER -DUSE_MY_EPOLL -DEPOLL_CTL_MOD_WORKAROUND
55COPTS.linux24e = -DNETFILTER -DUSE_MY_EPOLL
willy tarreau64a3cc32005-12-18 01:13:11 +010056LIBS.linux24e =
57
58# This is for standard Linux 2.4 with netfilter but without epoll()
Willy Tarreau4f60f162007-04-08 16:39:58 +020059COPTS.linux24 = -DNETFILTER
willy tarreau5cbea6f2005-12-17 12:48:26 +010060LIBS.linux24 =
willy tarreau0f7af912005-12-17 12:21:26 +010061
willy tarreau5cbea6f2005-12-17 12:48:26 +010062# This is for Linux 2.2
Willy Tarreau4f60f162007-04-08 16:39:58 +020063COPTS.linux22 = -DUSE_GETSOCKNAME
willy tarreau5cbea6f2005-12-17 12:48:26 +010064LIBS.linux22 =
65
66# This is for Solaris 8
Willy Tarreau4f60f162007-04-08 16:39:58 +020067COPTS.solaris = -fomit-frame-pointer -DFD_SETSIZE=65536
willy tarreau9da061b2005-12-17 12:29:56 +010068LIBS.solaris = -lnsl -lsocket
69
willy tarreaueedaa9f2005-12-17 14:08:03 +010070# CPU dependant optimizations
71COPTS.generic = -O2
Willy Tarreau390223b2006-10-15 23:43:42 +020072COPTS.i586 = -O2 -march=i586 -DCONFIG_HAP_USE_REGPARM
73COPTS.i686 = -O2 -march=i686 -DCONFIG_HAP_USE_REGPARM
willy tarreaueedaa9f2005-12-17 14:08:03 +010074COPTS.ultrasparc = -O6 -mcpu=v9 -mtune=ultrasparc
75
76# options for standard regex library
willy tarreau036e1ce2005-12-17 13:46:33 +010077COPTS.libc=
willy tarreaueedaa9f2005-12-17 14:08:03 +010078LIBS.libc=
willy tarreau036e1ce2005-12-17 13:46:33 +010079
willy tarreaueedaa9f2005-12-17 14:08:03 +010080# options for libpcre
willy tarreau036e1ce2005-12-17 13:46:33 +010081COPTS.pcre=-DUSE_PCRE -I$(PCREDIR)/include
82LIBS.pcre=-L$(PCREDIR)/lib -lpcreposix -lpcre
83
willy tarreau4373b962005-12-18 01:32:31 +010084# options for static libpcre
85COPTS.static-pcre=-DUSE_PCRE -I$(PCREDIR)/include
86LIBS.static-pcre=-L$(PCREDIR)/lib -Wl,-Bstatic -lpcreposix -lpcre -Wl,-Bdynamic
87
willy tarreaueedaa9f2005-12-17 14:08:03 +010088# you can enable debug arguments with "DEBUG=-g" or disable them with "DEBUG="
willy tarreaud38e72d2006-03-19 20:56:52 +010089#DEBUG = -g -DDEBUG_MEMORY -DDEBUG_FULL
willy tarreau5cbea6f2005-12-17 12:48:26 +010090DEBUG = -g
willy tarreau9da061b2005-12-17 12:29:56 +010091
willy tarreau0174f312005-12-18 01:02:42 +010092# if small memory footprint is required, you can reduce the buffer size. There
93# are 2 buffers per concurrent session, so 16 kB buffers will eat 32 MB memory
willy tarreau64a3cc32005-12-18 01:13:11 +010094# with 1000 concurrent sessions. Putting it slightly lower than a page size
willy tarreaud38e72d2006-03-19 20:56:52 +010095# will avoid the additionnal paramters to overflow a page. 8030 bytes is
96# exactly 5.5 TCP segments of 1460 bytes.
97#SMALL_OPTS = -DBUFSIZE=8030 -DMAXREWRITE=1030 -DSYSTEM_MAXCONN=1024
willy tarreau0174f312005-12-18 01:02:42 +010098SMALL_OPTS =
99
willy tarreau1c2ad212005-12-18 01:11:29 +0100100# redefine this if you want to add some special PATH to include/libs
101ADDINC =
102ADDLIB =
103
104# set some defines when needed.
willy tarreaud38e72d2006-03-19 20:56:52 +0100105# - use -DTPROXY to compile with transparent proxy support.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200106DEFINE = -DTPROXY
willy tarreau0174f312005-12-18 01:02:42 +0100107
Willy Tarreau9bf6c6e2006-12-23 11:12:04 +0100108# Now let's determine the version, sub-version and release date.
109# If we're in the GIT tree, we can use the last commit's version and date.
Willy Tarreau6620dbb2007-01-02 00:44:53 +0100110ifeq ($(IGNOREGIT),)
Willy Tarreau9bf6c6e2006-12-23 11:12:04 +0100111VERSION := $(shell [ -d .git/. ] && ref=$$(git-describe --tags 2>/dev/null) && ref=$${ref%-g*} && echo "$${ref\#v}" )
Willy Tarreau6620dbb2007-01-02 00:44:53 +0100112endif
Willy Tarreau9bf6c6e2006-12-23 11:12:04 +0100113
114ifneq ($(VERSION),)
115# OK git is there and works.
116SUBVERS := $(shell comms=$$(git-log --no-merges v$(VERSION).. 2>/dev/null |grep -c ^commit ); [ $$comms -gt 0 ] && echo "-$$comms" )
Willy Tarreau42afc3b2007-01-07 00:43:29 +0100117VERDATE := $(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 +0100118else
119# Otherwise, use the hard-coded version of last tag, number of changes
120# since last tag, and release date.
Willy Tarreau42c76592007-04-03 20:30:13 +0200121VERSION := 1.3.8.2
Willy Tarreau6620dbb2007-01-02 00:44:53 +0100122SUBVERS :=
Willy Tarreau42c76592007-04-03 20:30:13 +0200123VERDATE := 2007/04/03
Willy Tarreau9bf6c6e2006-12-23 11:12:04 +0100124endif
Willy Tarreau77074d52006-11-12 23:57:19 +0100125
126#### build options
127
128# do not change this one, enable USE_* variables instead.
129OPTIONS =
Willy Tarreaub38651a2007-03-24 17:24:39 +0100130OPT_OBJS =
Willy Tarreau77074d52006-11-12 23:57:19 +0100131
Willy Tarreau6d1a9882007-01-07 02:03:04 +0100132ifneq ($(USE_TCPSPLICE),)
133OPTIONS += -DCONFIG_HAP_TCPSPLICE
134endif
135
Willy Tarreaub38651a2007-03-24 17:24:39 +0100136# - set USE_CTTPROXY to enable full transparent proxy support
Willy Tarreau77074d52006-11-12 23:57:19 +0100137ifneq ($(USE_CTTPROXY),)
138OPTIONS += -DCONFIG_HAP_CTTPROXY
Willy Tarreaub38651a2007-03-24 17:24:39 +0100139OPT_OBJS += src/cttproxy.o
Willy Tarreau77074d52006-11-12 23:57:19 +0100140endif
141
142ifneq ($(USE_TPROXY),)
143OPTIONS += -DTPROXY
144endif
145
146ifneq ($(USE_POLL),)
147OPTIONS += -DENABLE_POLL
Willy Tarreau4f60f162007-04-08 16:39:58 +0200148OPT_OBJS += src/ev_poll.o
Willy Tarreau77074d52006-11-12 23:57:19 +0100149endif
150
151ifneq ($(USE_EPOLL),)
152OPTIONS += -DENABLE_EPOLL
Willy Tarreau4f60f162007-04-08 16:39:58 +0200153OPT_OBJS += src/ev_epoll.o
Willy Tarreau77074d52006-11-12 23:57:19 +0100154endif
155
156ifneq ($(USE_MY_EPOLL),)
157OPTIONS += -DUSE_MY_EPOLL
158endif
159
160ifneq ($(USE_NETFILTER),)
161OPTIONS += -DNETFILTER
162endif
163
164ifneq ($(USE_EPOLL_WORKAROUND),)
165OPTIONS += -DEPOLL_CTL_MOD_WORKAROUND
166endif
167
168ifneq ($(USE_GETSOCKNAME),)
169OPTIONS += -DUSE_GETSOCKNAME
170endif
171
172ifneq ($(USE_REGPARM),)
173OPTIONS += -DCONFIG_HAP_USE_REGPARM
174endif
175
Willy Tarreau79b34bf2006-12-22 15:28:43 +0100176ifneq ($(VERSION),)
177OPTIONS += -DCONFIG_HAPROXY_VERSION=\"$(VERSION)$(SUBVERS)\"
178endif
179
180ifneq ($(VERDATE),)
181OPTIONS += -DCONFIG_HAPROXY_DATE=\"$(VERDATE)\"
182endif
183
Willy Tarreau77074d52006-11-12 23:57:19 +0100184#### end of build options
185
186
willy tarreaueedaa9f2005-12-17 14:08:03 +0100187# global options
188TARGET_OPTS=$(COPTS.$(TARGET))
189REGEX_OPTS=$(COPTS.$(REGEX))
190CPU_OPTS=$(COPTS.$(CPU))
191
Willy Tarreau6d1a9882007-01-07 02:03:04 +0100192COPTS = -Iinclude $(CPU_OPTS) $(TARGET_OPTS) $(REGEX_OPTS) $(SMALL_OPTS) $(DEFINE) $(OPTIONS)
193LIBS=$(LIBS.$(TARGET)) $(LIBS.$(REGEX))
194
195ifneq ($(USE_TCPSPLICE),)
196COPTS += -I$(TCPSPLICEDIR)
197LIBS += -L$(TCPSPLICEDIR) -ltcpsplice
198endif
199
200COPTS += $(ADDINC)
201LIBS += $(ADDLIB)
willy tarreau0f7af912005-12-17 12:21:26 +0100202
willy tarreaud38e72d2006-03-19 20:56:52 +0100203CFLAGS = -Wall $(COPTS) $(DEBUG)
willy tarreau0f7af912005-12-17 12:21:26 +0100204LDFLAGS = -g
205
206all: haproxy
207
Willy Tarreaubaaee002006-06-26 02:48:02 +0200208OBJS = src/haproxy.o src/list.o src/chtbl.o src/hashpjw.o src/base64.o \
209 src/uri_auth.o src/standard.o src/buffers.o src/log.o src/task.o \
210 src/time.o src/fd.o src/regex.o src/cfgparse.o src/server.o \
211 src/checks.o src/queue.o src/capture.o src/client.o src/proxy.o \
212 src/proto_http.o src/stream_sock.o src/appsession.o src/backend.o \
Willy Tarreau4f60f162007-04-08 16:39:58 +0200213 src/session.o src/hdr_idx.o src/rbtree.o src/ev_select.o
Willy Tarreaubaaee002006-06-26 02:48:02 +0200214
Willy Tarreaub38651a2007-03-24 17:24:39 +0100215haproxy: $(OBJS) $(OPT_OBJS)
willy tarreau0f7af912005-12-17 12:21:26 +0100216 $(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
217
Willy Tarreaubaaee002006-06-26 02:48:02 +0200218objsize: haproxy
219 @objdump -t $^|grep ' g '|grep -F '.text'|awk '{print $$5 FS $$6}'|sort
220
willy tarreau0f7af912005-12-17 12:21:26 +0100221%.o: %.c
222 $(CC) $(CFLAGS) -c -o $@ $<
223
224clean:
Willy Tarreau1a587492006-10-15 23:40:58 +0200225 rm -f *.[oas] src/*.[oas] core haproxy test
226 for dir in . src include/* doc; do rm -f $$dir/*~ $$dir/*.rej;done
Willy Tarreau9bf6c6e2006-12-23 11:12:04 +0100227 rm -f haproxy-$(VERSION).tar.gz haproxy-$(VERSION)$(SUBVERS).tar.gz
228 rm -f haproxy-$(VERSION) nohup.out gmon.out
willy tarreauefae1842005-12-17 12:51:03 +0100229
willy tarreaue114bf92006-03-19 21:30:14 +0100230tar: clean
willy tarreaucee272f2006-03-19 21:16:26 +0100231 ln -s . haproxy-$(VERSION)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200232 tar --exclude=haproxy-$(VERSION)/.git \
233 --exclude=haproxy-$(VERSION)/haproxy-$(VERSION) \
234 --exclude=haproxy-$(VERSION)/haproxy-$(VERSION).tar.gz \
235 -cf - haproxy-$(VERSION)/* | gzip -c9 >haproxy-$(VERSION).tar.gz
willy tarreaucee272f2006-03-19 21:16:26 +0100236 rm -f haproxy-$(VERSION)
237
Willy Tarreau9f0a9012006-10-15 14:24:14 +0200238git-tar: clean
Willy Tarreau9bf6c6e2006-12-23 11:12:04 +0100239 git-tar-tree HEAD haproxy-$(VERSION) | gzip -9 > haproxy-$(VERSION)$(SUBVERS).tar.gz