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

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

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

57
ifeq ($(filter libsodium,$(VENDOR)),libsodium)
Jordan Sissel's avatar
Jordan Sissel committed
58 59 60 61
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)
62
endif # libsodium
63

64 65
build/bin/lumberjack.sh: lumberjack.sh | build/bin
	install -m 755 $^ $@
Jordan Sissel's avatar
Jordan Sissel committed
66

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

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

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

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

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

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

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

101 102 103
build:
	mkdir $@

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