Makefile 3.66 KB
Newer Older
1
VERSION=0.3.1
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.
Jordan Sissel's avatar
Jordan Sissel committed
5 6
#VENDOR?=zeromq libsodium
VENDOR=
7 8 9 10 11

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

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

16 17
default: build-all
build-all: build/bin/lumberjack build/bin/lumberjack.sh
18
#build-all: build/bin/keygen
19 20
include Makefile.ext

21 22 23 24 25 26
.PHONY: go-check
go-check:
	@go version > /dev/null || (echo "Go not found. You need to install go: http://golang.org/doc/install"; false)
	@go version | grep -q 'go version go1.1' || (echo "Go version 1.1.x required, you have a version of go that is too old See http://golang.org/doc/install for upgrading."; false)


Jordan Sissel's avatar
Jordan Sissel committed
27
clean:
Jordan Sissel's avatar
Jordan Sissel committed
28
	-@rm -fr build bin pkg
Jordan Sissel's avatar
Jordan Sissel committed
29

30 31 32 33
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
34 35

vendor-clean:
36 37 38 39 40 41 42 43 44 45
	$(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
46

47
rpm deb: PREFIX=/opt/lumberjack
48
rpm deb: | build-all
49 50
	fpm -s dir -t $@ -n lumberjack -v $(VERSION) \
		--exclude '*.a' --exclude 'lib/pkgconfig/zlib.pc' \
Jordan Sissel's avatar
Jordan Sissel committed
51 52
		--description "a log shipping tool" \
		--url "https://github.com/jordansissel/lumberjack" \
53 54
		build/bin/lumberjack=$(PREFIX)/bin/ build/bin/lumberjack.sh=$(PREFIX)/bin/ \
		lumberjack.init=/etc/init.d/lumberjack
55

Jordan Sissel's avatar
Jordan Sissel committed
56
# Vendor'd dependencies
57 58
# If VENDOR contains 'zeromq' download and build it.
ifeq ($(filter zeromq,$(VENDOR)),zeromq)
Jordan Sissel's avatar
Jordan Sissel committed
59
build/bin/lumberjack: | build/bin build/lib/libzmq.$(LIBEXT)
60 61
pkg/linux_amd64/github.com/alecthomas/gozmq.a: | build/lib/libzmq.$(LIBEXT)
src/github.com/alecthomas/gozmq/zmq.go: | build/lib/libzmq.$(LIBEXT)
62 63
endif # zeromq

64
ifeq ($(filter libsodium,$(VENDOR)),libsodium)
Jordan Sissel's avatar
Jordan Sissel committed
65 66 67 68
build/bin/lumberjack: | build/bin build/lib/libsodium.$(LIBEXT)
build/bin/lumberjack: | build/lib/pkgconfig/sodium.pc
build/bin/keygen: | build/lib/pkgconfig/sodium.pc
build/bin/keygen: | build/bin build/lib/libsodium.$(LIBEXT)
69
endif # libsodium
70

71 72
build/bin/lumberjack.sh: lumberjack.sh | build/bin
	install -m 755 $^ $@
Jordan Sissel's avatar
Jordan Sissel committed
73

74
build/bin/lumberjack: | build/bin go-check
75
	PKG_CONFIG_PATH=$$PWD/build/lib/pkgconfig \
76
		go build -ldflags '-r $$ORIGIN/../lib' -v -o $@
77
build/bin/keygen:  | build/bin go-check
78
	PKG_CONFIG_PATH=$$PWD/build/lib/pkgconfig \
79
		go install -ldflags '-r $$ORIGIN/../lib' -o $@
Jordan Sissel's avatar
Jordan Sissel committed
80

81
# Mark these phony; 'go install' takes care of knowing how and when to rebuild.
82
.PHONY: build/bin/keygen build/bin/lumberjack
83

84 85 86 87 88 89 90 91
build/lib/pkgconfig/sodium.pc: src/sodium/sodium.pc | build/lib/pkgconfig
	cp $< $@

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

92
# gozmq
93
src/github.com/alecthomas/gozmq/zmq.go: go-check
94
	go get -d github.com/alecthomas/gozmq
95
pkg/linux_amd64/github.com/alecthomas/gozmq.a: | build/lib/libzmq.$(LIBEXT)
96 97 98
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
99

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

Jordan Sissel's avatar
Jordan Sissel committed
104 105 106 107
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)

108 109 110
build:
	mkdir $@

Jordan Sissel's avatar
Jordan Sissel committed
111
build/include build/bin build/test: | build
Jordan Sissel's avatar
Jordan Sissel committed
112
	mkdir $@
Jordan Sissel's avatar
Jordan Sissel committed
113 114 115

test:
	rspec