Makefile 3.35 KB
Newer Older
1
VERSION=0.1.0
Jordan Sissel's avatar
Jordan Sissel committed
2

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

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

FETCH=sh fetch.sh
11
MAKE?=make
12 13
CFLAGS+=-Ibuild/include 
LDFLAGS+=-Lbuild/lib -Wl,-rpath,'$$ORIGIN/../lib'
Jordan Sissel's avatar
Jordan Sissel committed
14

15 16
default: build-all
build-all: build/bin/lumberjack build/bin/lumberjack.sh
Jordan Sissel's avatar
Jordan Sissel committed
17
build-all: build/bin/keygen
18 19
include Makefile.ext

Jordan Sissel's avatar
Jordan Sissel committed
20
clean:
Jordan Sissel's avatar
Jordan Sissel committed
21
	-@rm -fr lumberjack unixsock *.o build
Jordan Sissel's avatar
Jordan Sissel committed
22

23 24 25 26
deps-clean:
	rm -fr src/code.google.com/
	rm -fr src/github.com/ugorji/go-msgpack
	rm -fr src/github.com/alecthomas/gozmq
Jordan Sissel's avatar
Jordan Sissel committed
27 28

vendor-clean:
29 30 31 32 33 34 35 36 37 38
	$(MAKE) -C vendor/apr/ clean
	$(MAKE) -C vendor/jansson/ clean
	$(MAKE) -C vendor/jemalloc/ clean
	$(MAKE) -C vendor/libsodium/ clean
	$(MAKE) -C vendor/libuuid/ clean
	$(MAKE) -C vendor/lz4/ clean
	$(MAKE) -C vendor/msgpack/ clean
	$(MAKE) -C vendor/openssl/ clean
	$(MAKE) -C vendor/zeromq/ clean
	$(MAKE) -C vendor/zlib/ clean
Jordan Sissel's avatar
Jordan Sissel committed
39

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

Jordan Sissel's avatar
Jordan Sissel committed
47
# Vendor'd dependencies
48 49
# If VENDOR contains 'zeromq' download and build it.
ifeq ($(filter zeromq,$(VENDOR)),zeromq)
50 51 52
bin/lumberjack: | build/bin build/lib/libzmq.$(LIBEXT)
pkg/linux_amd64/github.com/alecthomas/gozmq.a: | build/lib/libzmq.$(LIBEXT)
src/github.com/alecthomas/gozmq/zmq.go: | build/lib/libzmq.$(LIBEXT)
53 54
endif # zeromq

55
ifeq ($(filter libsodium,$(VENDOR)),libsodium)
Jordan Sissel's avatar
Jordan Sissel committed
56
bin/lumberjack: | build/bin build/lib/libsodium.$(LIBEXT)
57 58
bin/keygen: | build/bin build/lib/libsodium.$(LIBEXT)
endif # libsodium
59

60 61
build/bin/lumberjack.sh: lumberjack.sh | build/bin
	install -m 755 $^ $@
Jordan Sissel's avatar
Jordan Sissel committed
62

Jordan Sissel's avatar
Jordan Sissel committed
63
build/bin/lumberjack: bin/lumberjack | build/bin
64
	cp bin/lumberjack build/bin/lumberjack
Jordan Sissel's avatar
Jordan Sissel committed
65 66
build/bin/keygen: bin/keygen | build/bin
	cp bin/keygen build/bin/keygen
Jordan Sissel's avatar
Jordan Sissel committed
67

68
bin/lumberjack: pkg/linux_amd64/github.com/alecthomas/gozmq.a
69 70 71 72 73 74
bin/lumberjack: | build/lib/pkgconfig/sodium.pc
	PKG_CONFIG_PATH=$$PWD/build/lib/pkgconfig \
		go install -ldflags '-r $$ORIGIN/../lib' lumberjack
bin/keygen: | build/lib/pkgconfig/sodium.pc
	PKG_CONFIG_PATH=$$PWD/build/lib/pkgconfig \
		go install -ldflags '-r $$ORIGIN/../lib' keygen
Jordan Sissel's avatar
Jordan Sissel committed
75

76 77 78
# Mark these phony; 'go install' takes care of knowing how and when to rebuild.
.PHONY: bin/keygen bin/lumberjack

79 80 81 82 83 84 85 86 87 88
build/lib/pkgconfig/sodium.pc: src/sodium/sodium.pc | build/lib/pkgconfig
	cp $< $@

build/lib/pkgconfig: | build/lib
	mkdir $@
build/lib: | build
	mkdir $@



89 90 91
# gozmq
src/github.com/alecthomas/gozmq/zmq.go:
	go get -d github.com/alecthomas/gozmq
92
pkg/linux_amd64/github.com/alecthomas/gozmq.a: | build/lib/libzmq.$(LIBEXT)
93 94 95
pkg/linux_amd64/github.com/alecthomas/gozmq.a: src/github.com/alecthomas/gozmq/zmq.go
	PKG_CONFIG_PATH=$$PWD/build/lib/pkgconfig \
	  go install -tags zmq_3_x github.com/alecthomas/gozmq
96

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

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

105 106 107
build:
	mkdir $@

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