Makefile 4.32 KB
Newer Older
Jørn Åne de Jong's avatar
Jørn Åne de Jong committed
1
VERSION=0.3.1+uninett5
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.
9
PREFIX?=/usr/local/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

47
rpm: OS=lsb
Jørn Åne de Jong's avatar
Jørn Åne de Jong committed
48 49
deb: OS=debian

50
rpm deb: PREFIX=/usr/local/logstash-forwarder
51
rpm deb: | build-all
Jordan Sissel's avatar
Jordan Sissel committed
52
	fpm -s dir -t $@ -n logstash-forwarder -v $(VERSION) \
53
		--replaces logstash-forwarder \
Jørn Åne de Jong's avatar
Jørn Åne de Jong committed
54 55
                --after-install logstash-forwarder.$(OS).postinst \
                --after-remove logstash-forwarder.$(OS).remove \
56
		--exclude '*.a' --exclude 'lib/pkgconfig/zlib.pc' \
Jordan Sissel's avatar
Jordan Sissel committed
57
		--description "a log shipping tool" \
Jordan Sissel's avatar
Jordan Sissel committed
58 59 60
		--url "https://github.com/elasticsearch/logstash-forwarder" \
		build/bin/logstash-forwarder=$(PREFIX)/bin/ \
		build/bin/logstash-forwarder.sh=$(PREFIX)/bin/ \
61
                uninett-ca.pem=/etc/ssl/certs/ \
62
                logstash-forwarder.conf=/etc/logstashforwarder/config.json.example \
63 64
                logstash-forwarder.default=/etc/default/logstash-forwarder \
                logstash-forwarder.logrotate=/etc/logrotate.d/logstash-forwarder \
Jørn Åne de Jong's avatar
Jørn Åne de Jong committed
65
		logstash-forwarder.$(OS).init=/etc/init.d/logstash-forwarder
66

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

75
ifeq ($(filter libsodium,$(VENDOR)),libsodium)
Jordan Sissel's avatar
Jordan Sissel committed
76 77
build/bin/logstash-forwarder: | build/bin build/lib/libsodium.$(LIBEXT)
build/bin/logstash-forwarder: | build/lib/pkgconfig/sodium.pc
78 79
build/bin/keygen: | build/lib/pkgconfig/sodium.pc
build/bin/keygen: | build/bin build/lib/libsodium.$(LIBEXT)
80
endif # libsodium
81

Jordan Sissel's avatar
Jordan Sissel committed
82
build/bin/logstash-forwarder.sh: logstash-forwarder.sh | build/bin
83
	install -m 755 $^ $@
84

Jordan Sissel's avatar
Jordan Sissel committed
85
build/bin/logstash-forwarder: | build/bin go-check
86
	PKG_CONFIG_PATH=$$PWD/build/lib/pkgconfig \
87
		go build -ldflags '-r $$ORIGIN/../lib' -v -o $@
88
build/bin/keygen:  | build/bin go-check
89
	PKG_CONFIG_PATH=$$PWD/build/lib/pkgconfig \
90
		go install -ldflags '-r $$ORIGIN/../lib' -o $@
Jordan Sissel's avatar
Jordan Sissel committed
91

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

95 96 97 98 99 100 101 102
build/lib/pkgconfig/sodium.pc: src/sodium/sodium.pc | build/lib/pkgconfig
	cp $< $@

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

103
# gozmq
104
src/github.com/alecthomas/gozmq/zmq.go: go-check
105
	go get -d github.com/alecthomas/gozmq
106
pkg/linux_amd64/github.com/alecthomas/gozmq.a: | build/lib/libzmq.$(LIBEXT)
107 108 109
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
110

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

Jordan Sissel's avatar
Jordan Sissel committed
115 116 117 118
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)

119 120 121
build:
	mkdir $@

Jordan Sissel's avatar
Jordan Sissel committed
122
build/include build/bin build/test: | build
Jordan Sissel's avatar
Jordan Sissel committed
123
	mkdir $@
Jordan Sissel's avatar
Jordan Sissel committed
124 125 126

test:
	rspec