| 1 |
PREFIX?=/usr/local |
| 2 |
BINDIR=$(DESTDIR)$(PREFIX)/bin |
| 3 |
|
| 4 |
override CFLAGS+=-Wall -Werror -Wformat=2 -g |
| 5 |
override LDFLAGS?= |
| 6 |
|
| 7 |
LDLIBS?= |
| 8 |
|
| 9 |
OS?=$(shell uname | tr 'A-Z' 'a-z' | sed 's?gnu/kfreebsd?freebsd?') |
| 10 |
INSTALL?=install |
| 11 |
PKG_CONFIG?=pkg-config |
| 12 |
|
| 13 |
ifeq ($(OS),sunos) |
| 14 |
override LDFLAGS += -lxnet -lsocket -lnsl |
| 15 |
endif |
| 16 |
|
| 17 |
VERS=$(shell ./vers.sh) |
| 18 |
TARG=beanstalkd |
| 19 |
MOFILE=main.o |
| 20 |
OFILES=\ |
| 21 |
$(OS).o\ |
| 22 |
conn.o\ |
| 23 |
file.o\ |
| 24 |
heap.o\ |
| 25 |
job.o\ |
| 26 |
ms.o\ |
| 27 |
net.o\ |
| 28 |
primes.o\ |
| 29 |
prot.o\ |
| 30 |
serv.o\ |
| 31 |
time.o\ |
| 32 |
tube.o\ |
| 33 |
util.o\ |
| 34 |
vers.o\ |
| 35 |
walg.o\ |
| 36 |
|
| 37 |
TOFILES=\ |
| 38 |
testheap.o\ |
| 39 |
testjobs.o\ |
| 40 |
testms.o\ |
| 41 |
testserv.o\ |
| 42 |
testutil.o\ |
| 43 |
|
| 44 |
HFILES=\ |
| 45 |
dat.h\ |
| 46 |
|
| 47 |
ifeq ($(OS),linux) |
| 48 |
LDLIBS+=-lrt |
| 49 |
endif |
| 50 |
|
| 51 |
# systemd support can be configured via USE_SYSTEMD: |
| 52 |
# no: disabled |
| 53 |
# yes: enabled, build fails if libsystemd is not found |
| 54 |
# otherwise: enabled if libsystemd is found |
| 55 |
ifneq ($(USE_SYSTEMD),no) |
| 56 |
ifeq ($(shell $(PKG_CONFIG) --exists libsystemd && echo $$?),0) |
| 57 |
LDLIBS+=$(shell $(PKG_CONFIG) --libs libsystemd) |
| 58 |
CPPFLAGS+=-DHAVE_LIBSYSTEMD |
| 59 |
else |
| 60 |
ifeq ($(USE_SYSTEMD),yes) |
| 61 |
$(error USE_SYSTEMD is set to "$(USE_SYSTEMD)", but $(PKG_CONFIG) cannot find libsystemd) |
| 62 |
endif |
| 63 |
endif |
| 64 |
endif |
| 65 |
|
| 66 |
CLEANFILES=\ |
| 67 |
vers.c\ |
| 68 |
$(wildcard *.gc*) |
| 69 |
|
| 70 |
.PHONY: all |
| 71 |
all: $(TARG) |
| 72 |
|
| 73 |
$(TARG): $(OFILES) $(MOFILE) |
| 74 |
$(LINK.o) -o $@ $^ $(LDLIBS) |
| 75 |
|
| 76 |
.PHONY: install |
| 77 |
install: $(BINDIR)/$(TARG) |
| 78 |
|
| 79 |
$(BINDIR)/%: % |
| 80 |
$(INSTALL) -d $(dir $@) |
| 81 |
$(INSTALL) $< $@ |
| 82 |
|
| 83 |
CLEANFILES+=$(TARG) |
| 84 |
|
| 85 |
$(OFILES) $(MOFILE): $(HFILES) |
| 86 |
|
| 87 |
CLEANFILES+=$(wildcard *.o) |
| 88 |
|
| 89 |
.PHONY: clean |
| 90 |
clean: |
| 91 |
rm -f $(CLEANFILES) |
| 92 |
|
| 93 |
.PHONY: check |
| 94 |
check: ct/_ctcheck |
| 95 |
ct/_ctcheck |
| 96 |
|
| 97 |
.PHONY: bench |
| 98 |
bench: ct/_ctcheck |
| 99 |
ct/_ctcheck -b |
| 100 |
|
| 101 |
ct/_ctcheck: ct/_ctcheck.o ct/ct.o $(OFILES) $(TOFILES) |
| 102 |
|
| 103 |
ct/_ctcheck.c: $(TOFILES) ct/gen |
| 104 |
ct/gen $(TOFILES) >[email protected] |
| 105 |
mv [email protected] $@ |
| 106 |
|
| 107 |
ct/ct.o ct/_ctcheck.o: ct/ct.h ct/internal.h |
| 108 |
|
| 109 |
$(TOFILES): $(HFILES) ct/ct.h |
| 110 |
|
| 111 |
CLEANFILES+=$(wildcard ct/_* ct/*.o ct/*.gc*) |
| 112 |
|
| 113 |
ifneq ($(shell ./verc.sh),$(shell cat vers.c 2>/dev/null)) |
| 114 |
.PHONY: vers.c |
| 115 |
endif |
| 116 |
vers.c: |
| 117 |
./verc.sh >vers.c |
| 118 |
|
| 119 |
doc/beanstalkd.1 doc/beanstalkd.1.html: doc/beanstalkd.ronn |
| 120 |
ronn $< |
| 121 |
|
| 122 |
freebsd.o: darwin.c |