Makefile 4.58 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

# Where to install to.
Jordan Sissel's avatar
Jordan Sissel committed
9
PREFIX?=/opt/logstash-forwarder
10 11

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
default: build-all
Jordan Sissel's avatar
Jordan Sissel committed
17
build-all: build/bin/logstash-forwarder build/bin/logstash-forwarder.sh
18
#build-all: build/bin/keygen
19 20
include Makefile.ext

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


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

Jordan Sissel's avatar
Jordan Sissel committed
47
rpm deb: PREFIX=/opt/logstash-forwarder
48
rpm deb: | build-all
Jordan Sissel's avatar
Jordan Sissel committed
49 50
	fpm -s dir -t $@ -n logstash-forwarder -v $(VERSION) \
		--replaces lumberjack \
51
		--exclude '*.a' --exclude 'lib/pkgconfig/zlib.pc' \
Jordan Sissel's avatar
Jordan Sissel committed
52
		--description "a log shipping tool" \
Jordan Sissel's avatar
Jordan Sissel committed
53 54 55
		--url "https://github.com/elasticsearch/logstash-forwarder" \
		build/bin/logstash-forwarder=$(PREFIX)/bin/ \
		build/bin/logstash-forwarder.sh=$(PREFIX)/bin/ \
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
                logrouter_uninett.pem=/etc/ssl/certs/ \
                logstash-forwarder.conf=/etc/logstashforwarder/config.json.example \
		logstash-forwarder.init=/etc/init.d/logstash-forwarder

rpm32 deb32: PREFIX=/opt/logstash-forwarder
rpm32 deb32: | build-all
	fpm -a i386 -s dir -t deb -n logstash-forwarder -v $(VERSION) \
		--replaces lumberjack \
		--exclude '*.a' --exclude 'lib/pkgconfig/zlib.pc' \
		--description "a log shipping tool" \
		--url "https://github.com/elasticsearch/logstash-forwarder" \
		build/bin/logstash-forwarder=$(PREFIX)/bin/ \
		build/bin/logstash-forwarder.sh=$(PREFIX)/bin/ \
                logrouter_uninett.pem=/etc/ssl/certs/ \
                logstash-forwarder.conf=/etc/logstashforwarder/config.json.example \
Jordan Sissel's avatar
Jordan Sissel committed
71
		logstash-forwarder.init=/etc/init.d/logstash-forwarder
72

73
# Vendor'd dependencies
74 75
# If VENDOR contains 'zeromq' download and build it.
ifeq ($(filter zeromq,$(VENDOR)),zeromq)
Jordan Sissel's avatar
Jordan Sissel committed
76
build/bin/logstash-forwarder: | build/bin build/lib/libzmq.$(LIBEXT)
77 78
pkg/linux_amd64/github.com/alecthomas/gozmq.a: | build/lib/libzmq.$(LIBEXT)
src/github.com/alecthomas/gozmq/zmq.go: | build/lib/libzmq.$(LIBEXT)
79 80
endif # zeromq

81
ifeq ($(filter libsodium,$(VENDOR)),libsodium)
Jordan Sissel's avatar
Jordan Sissel committed
82 83
build/bin/logstash-forwarder: | build/bin build/lib/libsodium.$(LIBEXT)
build/bin/logstash-forwarder: | build/lib/pkgconfig/sodium.pc
84 85
build/bin/keygen: | build/lib/pkgconfig/sodium.pc
build/bin/keygen: | build/bin build/lib/libsodium.$(LIBEXT)
86
endif # libsodium
87

Jordan Sissel's avatar
Jordan Sissel committed
88
build/bin/logstash-forwarder.sh: logstash-forwarder.sh | build/bin
89
	install -m 755 $^ $@
90

Jordan Sissel's avatar
Jordan Sissel committed
91
build/bin/logstash-forwarder: | build/bin go-check
92
	PKG_CONFIG_PATH=$$PWD/build/lib/pkgconfig \
93
		go build -ldflags '-r $$ORIGIN/../lib' -v -o $@
94
build/bin/keygen:  | build/bin go-check
95
	PKG_CONFIG_PATH=$$PWD/build/lib/pkgconfig \
96
		go install -ldflags '-r $$ORIGIN/../lib' -o $@
Jordan Sissel's avatar
Jordan Sissel committed
97

98
# Mark these phony; 'go install' takes care of knowing how and when to rebuild.
Jordan Sissel's avatar
Jordan Sissel committed
99
.PHONY: build/bin/keygen build/bin/logstash-forwarder
100

101 102 103 104 105 106 107 108
build/lib/pkgconfig/sodium.pc: src/sodium/sodium.pc | build/lib/pkgconfig
	cp $< $@

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

109
# gozmq
110
src/github.com/alecthomas/gozmq/zmq.go: go-check
111
	go get -d github.com/alecthomas/gozmq
112
pkg/linux_amd64/github.com/alecthomas/gozmq.a: | build/lib/libzmq.$(LIBEXT)
113 114 115
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
116

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

Jordan Sissel's avatar
Jordan Sissel committed
121 122 123 124
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)

125 126 127
build:
	mkdir $@

Jordan Sissel's avatar
Jordan Sissel committed
128
build/include build/bin build/test: | build
Jordan Sissel's avatar
Jordan Sissel committed
129
	mkdir $@
Jordan Sissel's avatar
Jordan Sissel committed
130 131 132

test:
	rspec