Makefile 3.22 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
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 build bin pkg
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

63 64
build/bin/lumberjack: pkg/linux_amd64/github.com/alecthomas/gozmq.a
build/bin/lumberjack: | build/lib/pkgconfig/sodium.pc
65
	PKG_CONFIG_PATH=$$PWD/build/lib/pkgconfig \
66 67
		go build -ldflags '-r $$ORIGIN/../lib' -v -o $@
build/bin/keygen: | build/lib/pkgconfig/sodium.pc
68
	PKG_CONFIG_PATH=$$PWD/build/lib/pkgconfig \
69
		go install -ldflags '-r $$ORIGIN/../lib' -o $@
Jordan Sissel's avatar
Jordan Sissel committed
70

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

74 75 76 77 78 79 80 81
build/lib/pkgconfig/sodium.pc: src/sodium/sodium.pc | build/lib/pkgconfig
	cp $< $@

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

82 83 84
# gozmq
src/github.com/alecthomas/gozmq/zmq.go:
	go get -d github.com/alecthomas/gozmq
85
pkg/linux_amd64/github.com/alecthomas/gozmq.a: | build/lib/libzmq.$(LIBEXT)
86 87 88
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
89

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

Jordan Sissel's avatar
Jordan Sissel committed
94 95 96 97
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)

98 99 100
build:
	mkdir $@

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