Makefile 4.2 KB
Newer Older
Jordan Sissel's avatar
Jordan Sissel committed
1
VERSION=0.0.4
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
CFLAGS+=-Ibuild/include 
LDFLAGS+=-Lbuild/lib -Wl,-rpath,'$$ORIGIN/../lib'
Jordan Sissel's avatar
Jordan Sissel committed
20

Jordan Sissel's avatar
Jordan Sissel committed
21
default: build/bin/lumberjack
22 23
include Makefile.ext

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

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

vendor-clean:
	-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
Jordan Sissel's avatar
Jordan Sissel committed
38

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

Jordan Sissel's avatar
Jordan Sissel committed
46 47 48 49
#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
50
backoff.c: backoff.h
Jordan Sissel's avatar
Jordan Sissel committed
51
harvester.c: harvester.h proto.h str.h
52
emitter.c: emitter.h ring.h
53
lumberjack.c: backoff.h harvester.h emitter.h
Jordan Sissel's avatar
Jordan Sissel committed
54
str.c: str.h
Jordan Sissel's avatar
Jordan Sissel committed
55
proto.c: proto.h str.h 
Jordan Sissel's avatar
Jordan Sissel committed
56
ring.c: ring.h
57 58
harvester.c: build/include/insist.h 
lumberjack.c: build/include/insist.h 
Jordan Sissel's avatar
Jordan Sissel committed
59

Jordan Sissel's avatar
Jordan Sissel committed
60
# Vendor'd dependencies
61 62 63 64 65 66 67 68 69
# If VENDOR contains 'zeromq' download and build it.
ifeq ($(filter zeromq,$(VENDOR)),zeromq)
emitter.c: build/include/zmq.h 
harvester.c: build/include/zmq.h
lumberjack.c:  build/include/zmq.h 
build/bin/lumberjack: | build/bin build/lib/libzmq.$(LIBEXT)
endif # zeromq

ifeq ($(filter jemalloc,$(VENDOR)),jemalloc)
Jordan Sissel's avatar
Jordan Sissel committed
70
harvester.c lumberjack.c ring.c str.c: build/include/jemalloc/jemalloc.h
71 72 73 74
build/bin/lumberjack: | build/lib/libjemalloc.$(LIBEXT)
endif # jemalloc

ifeq ($(filter openssl,$(VENDOR)),openssl)
Jordan Sissel's avatar
Jordan Sissel committed
75
proto.c: build/include/openssl/ssl.h
76
lumberjack.c:  build/include/openssl/ssl.h
77 78 79
build/bin/lumberjack: | build/lib/libssl.$(LIBEXT)
build/bin/lumberjack: | build/lib/libcrypto.$(LIBEXT)
endif # openssl
Jordan Sissel's avatar
Jordan Sissel committed
80

81 82 83 84
ifeq ($(filter zlib,$(VENDOR)),zlib)
proto.c: build/include/zlib.h
build/bin/lumberjack: | build/lib/libz.$(LIBEXT)
endif # zlib
Jordan Sissel's avatar
Jordan Sissel committed
85

Jordan Sissel's avatar
Jordan Sissel committed
86 87 88 89
.PHONY: test
test: | build/test/test_ring
	build/test/test_ring

Jordan Sissel's avatar
Jordan Sissel committed
90 91 92 93 94
# Tests
test_ring.c: ring.h build/include/jemalloc/jemalloc.h build/include/insist.h
build/test/test_ring: test_ring.o ring.o  | build/test
	$(CC) $(LDFLAGS) -o $@ $^ -ljemalloc

95 96 97
proto.o: proto.c
	$(CC) $(CFLAGS) -c -o $@ $^

98
build/bin/lumberjack: | build/bin
Jordan Sissel's avatar
Jordan Sissel committed
99
build/bin/lumberjack: lumberjack.o backoff.o harvester.o emitter.o str.o proto.o ring.o
100
	$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
Jordan Sissel's avatar
Jordan Sissel committed
101 102
	@echo " => Build complete: $@"
	@echo " => Run 'make rpm' to build an rpm (or deb or tarball)"
103

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

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

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

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

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

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

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

131 132 133
build:
	mkdir $@

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