Makefile 4.93 KB
Newer Older
Jordan Sissel's avatar
Jordan Sissel committed
1
VERSION=0.0.30
Jordan Sissel's avatar
Jordan Sissel committed
2

3 4 5 6 7 8 9 10 11
# By default, all dependencies (zeromq, etc) will be downloaded and installed
# locally. You can change this if you are deploying your own.
VENDOR?=zeromq jemalloc openssl zlib

# Where to install to.
PREFIX?=/opt/lumberjack

FETCH=sh fetch.sh

Jordan Sissel's avatar
Jordan Sissel committed
12 13
CFLAGS+=-D_POSIX_C_SOURCE=199309 -std=c99 -Wall -Wextra -Werror -pipe
CFLAGS+=-g
Jordan Sissel's avatar
Jordan Sissel committed
14
CFLAGS+=-Wno-unused-function
15
LDFLAGS+=-pthread
Jordan Sissel's avatar
Jordan Sissel committed
16
LIBS=-lzmq -ljemalloc -lssl -lcrypto -luuid -lz
Jordan Sissel's avatar
Jordan Sissel committed
17

18 19
MAKE?=make

20 21
CFLAGS+=-Ibuild/include 
LDFLAGS+=-Lbuild/lib -Wl,-rpath,'$$ORIGIN/../lib'
Jordan Sissel's avatar
Jordan Sissel committed
22

23 24
default: build-all
build-all: build/bin/lumberjack build/bin/lumberjack.sh
25 26
include Makefile.ext

Jordan Sissel's avatar
Jordan Sissel committed
27 28 29 30 31
ifeq ($(UNAME),Linux)
# clock_gettime is in librt on linux.
LIBS+=-lrt
endif

Jordan Sissel's avatar
Jordan Sissel committed
32
clean:
Jordan Sissel's avatar
Jordan Sissel committed
33
	-@rm -fr lumberjack unixsock *.o build
Jordan Sissel's avatar
Jordan Sissel committed
34 35

vendor-clean:
36 37 38 39 40 41 42
	-$(MAKE) -C vendor/msgpack/ clean
	-$(MAKE) -C vendor/jansson/ clean
	-$(MAKE) -C vendor/jemalloc/ clean
	-$(MAKE) -C vendor/libuuid/ clean
	-$(MAKE) -C vendor/zeromq/ clean
	-$(MAKE) -C vendor/zlib/ clean
	-$(MAKE) -C vendor/apr/ clean
Jordan Sissel's avatar
Jordan Sissel committed
43

44
rpm deb: | build-all
Jordan Sissel's avatar
Jordan Sissel committed
45
	fpm -s dir -t $@ -n lumberjack -v $(VERSION) --prefix /opt/lumberjack \
Jordan Sissel's avatar
Jordan Sissel committed
46 47 48
		--exclude '*.a' --exclude 'lib/pkgconfig/zlib.pc' -C build \
		--description "a log shipping tool" \
		--url "https://github.com/jordansissel/lumberjack" \
49
		bin/lumberjack bin/lumberjack.sh lib
50

Jordan Sissel's avatar
Jordan Sissel committed
51 52 53 54
#install: build/bin/lumberjack build/lib/libzmq.$(LIBEXT)
# install -d -m 755 build/bin/* $(PREFIX)/bin/lumberjack
# install -d build/lib/* $(PREFIX)/lib

Jordan Sissel's avatar
Jordan Sissel committed
55
flog.o: flog.c flog.h
Jordan Sissel's avatar
Jordan Sissel committed
56 57
strlist.o: strlist.h
emitter.o: strlist.h
58
backoff.o: backoff.c backoff.h
Jordan Sissel's avatar
Jordan Sissel committed
59 60 61
harvester.o: harvester.c harvester.h proto.h str.h sleepdefs.h flog.h
emitter.o: emitter.c emitter.h ring.h sleepdefs.h flog.h
lumberjack.o: lumberjack.c backoff.h harvester.h emitter.h flog.h
62
str.o: str.c str.h
Jordan Sissel's avatar
Jordan Sissel committed
63
proto.o: proto.c proto.h str.h sleepdefs.h flog.h
64 65 66 67
ring.o: ring.c ring.h

harvester.o: build/include/insist.h 
lumberjack.o: build/include/insist.h 
Jordan Sissel's avatar
Jordan Sissel committed
68

Jordan Sissel's avatar
Jordan Sissel committed
69
# Vendor'd dependencies
70 71
# If VENDOR contains 'zeromq' download and build it.
ifeq ($(filter zeromq,$(VENDOR)),zeromq)
72 73 74
emitter.o: build/include/zmq.h 
harvester.o: build/include/zmq.h
lumberjack.o:  build/include/zmq.h 
75 76 77 78
build/bin/lumberjack: | build/bin build/lib/libzmq.$(LIBEXT)
endif # zeromq

ifeq ($(filter jemalloc,$(VENDOR)),jemalloc)
79
harvester.o lumberjack.o ring.o str.o: build/include/jemalloc/jemalloc.h
80 81 82 83
build/bin/lumberjack: | build/lib/libjemalloc.$(LIBEXT)
endif # jemalloc

ifeq ($(filter openssl,$(VENDOR)),openssl)
84 85
proto.o: build/include/openssl/ssl.h
lumberjack.o:  build/include/openssl/ssl.h
86 87 88
build/bin/lumberjack: | build/lib/libssl.$(LIBEXT)
build/bin/lumberjack: | build/lib/libcrypto.$(LIBEXT)
endif # openssl
Jordan Sissel's avatar
Jordan Sissel committed
89

90
ifeq ($(filter zlib,$(VENDOR)),zlib)
91
proto.o: build/include/zlib.h
92 93
build/bin/lumberjack: | build/lib/libz.$(LIBEXT)
endif # zlib
Jordan Sissel's avatar
Jordan Sissel committed
94

Jordan Sissel's avatar
Jordan Sissel committed
95 96 97 98
.PHONY: test
test: | build/test/test_ring
	build/test/test_ring

Jordan Sissel's avatar
Jordan Sissel committed
99
# Tests
100
test_ring.o: ring.h build/include/jemalloc/jemalloc.h build/include/insist.h
Jordan Sissel's avatar
Jordan Sissel committed
101 102 103
build/test/test_ring: test_ring.o ring.o  | build/test
	$(CC) $(LDFLAGS) -o $@ $^ -ljemalloc

104 105 106
build/bin/lumberjack.sh: lumberjack.sh | build/bin
	install -m 755 $^ $@

107
build/bin/lumberjack: | build/bin
Jordan Sissel's avatar
Jordan Sissel committed
108
build/bin/lumberjack: lumberjack.o backoff.o harvester.o emitter.o str.o proto.o ring.o strlist.o flog.o
109
	$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
Jordan Sissel's avatar
Jordan Sissel committed
110
	@echo " => Build complete: $@"
111
	@echo " => Run '$(MAKE) rpm' to build an rpm (or deb or tarball)"
112

113
build/include/insist.h: | build/include
114
	PATH=$$PWD:$$PATH fetch.sh -o $@ https://raw.github.com/jordansissel/experiments/master/c/better-assert/insist.h
115

116
build/include/zmq.h build/lib/libzmq.$(LIBEXT): | build
Jordan Sissel's avatar
Jordan Sissel committed
117
	@echo " => Building zeromq"
Jordan Sissel's avatar
Jordan Sissel committed
118
	PATH=$$PWD:$$PATH $(MAKE) -C vendor/zeromq/ install PREFIX=$$PWD/build DEBUG=$(DEBUG)
119

Jordan Sissel's avatar
Jordan Sissel committed
120
build/include/msgpack.h build/lib/libmsgpack.$(LIBEXT): | build
Jordan Sissel's avatar
Jordan Sissel committed
121
	@echo " => Building msgpack"
Jordan Sissel's avatar
Jordan Sissel committed
122
	PATH=$$PWD:$$PATH $(MAKE) -C vendor/msgpack/ install PREFIX=$$PWD/build DEBUG=$(DEBUG)
123

Jordan Sissel's avatar
Jordan Sissel committed
124
build/include/jemalloc/jemalloc.h build/lib/libjemalloc.$(LIBEXT): | build
Jordan Sissel's avatar
Jordan Sissel committed
125
	@echo " => Building jemalloc"
Jordan Sissel's avatar
Jordan Sissel committed
126
	PATH=$$PWD:$$PATH $(MAKE) -C vendor/jemalloc/ install PREFIX=$$PWD/build DEBUG=$(DEBUG)
Jordan Sissel's avatar
Jordan Sissel committed
127

Jordan Sissel's avatar
Jordan Sissel committed
128 129 130 131
build/include/sodium/sodium.h build/lib/libsodium.$(LIBEXT): | build
	@echo " => Building libsodium"
	PATH=$$PWD:$$PATH $(MAKE) -C vendor/libsodium/ install PREFIX=$$PWD/build DEBUG=$(DEBUG)

Jordan Sissel's avatar
Jordan Sissel committed
132
build/include/lz4.h build/lib/liblz4.$(LIBEXT): | build
Jordan Sissel's avatar
Jordan Sissel committed
133
	@echo " => Building lz4"
Jordan Sissel's avatar
Jordan Sissel committed
134
	PATH=$$PWD:$$PATH $(MAKE) -C vendor/lz4/ install PREFIX=$$PWD/build DEBUG=$(DEBUG)
Jordan Sissel's avatar
Jordan Sissel committed
135 136

build/include/zlib.h build/lib/libz.$(LIBEXT): | build
Jordan Sissel's avatar
Jordan Sissel committed
137
	@echo " => Building zlib"
Jordan Sissel's avatar
Jordan Sissel committed
138
	PATH=$$PWD:$$PATH $(MAKE) -C vendor/zlib/ install PREFIX=$$PWD/build DEBUG=$(DEBUG)
Jordan Sissel's avatar
Jordan Sissel committed
139

Jordan Sissel's avatar
Jordan Sissel committed
140 141
build/include/openssl/ssl.h build/lib/libssl.$(LIBEXT) build/lib/libcrypto.$(LIBEXT): | build
	@echo " => Building openssl"
Jordan Sissel's avatar
Jordan Sissel committed
142
	PATH=$$PWD:$$PATH $(MAKE) -C vendor/openssl install PREFIX=$$PWD/build DEBUG=$(DEBUG)
Jordan Sissel's avatar
Jordan Sissel committed
143

Jordan Sissel's avatar
Jordan Sissel committed
144 145 146 147
build/include/apr-1/apr.h build/lib/libapr-1.$(LIBEXT): | build
	@echo " => Building apr"
	PATH=$$PWD:$$PATH $(MAKE) -C vendor/apr install PREFIX=$$PWD/build DEBUG=$(DEBUG)

148 149 150
build:
	mkdir $@

Jordan Sissel's avatar
Jordan Sissel committed
151
build/include build/bin build/test: | build
Jordan Sissel's avatar
Jordan Sissel committed
152
	mkdir $@