Makefile 3.32 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.
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

Jordan Sissel's avatar
Jordan Sissel committed
21
clean:
Jordan Sissel's avatar
Jordan Sissel committed
22
	-@rm -fr build bin pkg
Jordan Sissel's avatar
Jordan Sissel committed
23

24 25 26 27
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
28 29

vendor-clean:
30 31 32 33 34 35 36 37 38 39
	$(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
40

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

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

58
ifeq ($(filter libsodium,$(VENDOR)),libsodium)
59 60 61 62
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)
63
endif # libsodium
64

65 66
build/bin/lumberjack.sh: lumberjack.sh | build/bin
	install -m 755 $^ $@
67

68
build/bin/lumberjack: | build/bin
69
	PKG_CONFIG_PATH=$$PWD/build/lib/pkgconfig \
70
		go build -ldflags '-r $$ORIGIN/../lib' -v -o $@
71
build/bin/keygen:  | build/bin
72
	PKG_CONFIG_PATH=$$PWD/build/lib/pkgconfig \
73
		go install -ldflags '-r $$ORIGIN/../lib' -o $@
Jordan Sissel's avatar
Jordan Sissel committed
74

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

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

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

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

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

Jordan Sissel's avatar
Jordan Sissel committed
98 99 100 101
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)

102 103 104
build:
	mkdir $@

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

test:
	rspec