Makefile 4.26 KB
Newer Older
Gurvinder Singh's avatar
Gurvinder Singh committed
1
VERSION=0.3.1+uninett4
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
	fpm -s dir -t $@ -n logstash-forwarder -v $(VERSION) \
50 51 52
		--replaces logstash-forwarder \
                --after-install logstash-forwarder.postinst \
                --after-remove logstash-forwarder.remove \
53
		--exclude '*.a' --exclude 'lib/pkgconfig/zlib.pc' \
Jordan Sissel's avatar
Jordan Sissel committed
54
		--description "a log shipping tool" \
Jordan Sissel's avatar
Jordan Sissel committed
55 56 57
		--url "https://github.com/elasticsearch/logstash-forwarder" \
		build/bin/logstash-forwarder=$(PREFIX)/bin/ \
		build/bin/logstash-forwarder.sh=$(PREFIX)/bin/ \
58
                uninett-ca.pem=/etc/ssl/certs/ \
59
                logstash-forwarder.conf=/etc/logstashforwarder/config.json.example \
60 61
                logstash-forwarder.default=/etc/default/logstash-forwarder \
                logstash-forwarder.logrotate=/etc/logrotate.d/logstash-forwarder \
Jordan Sissel's avatar
Jordan Sissel committed
62
		logstash-forwarder.init=/etc/init.d/logstash-forwarder
63

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

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

Jordan Sissel's avatar
Jordan Sissel committed
79
build/bin/logstash-forwarder.sh: logstash-forwarder.sh | build/bin
80
	install -m 755 $^ $@
81

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

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

92 93 94 95 96 97 98 99
build/lib/pkgconfig/sodium.pc: src/sodium/sodium.pc | build/lib/pkgconfig
	cp $< $@

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

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

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

Jordan Sissel's avatar
Jordan Sissel committed
112 113 114 115
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)

116 117 118
build:
	mkdir $@

Jordan Sissel's avatar
Jordan Sissel committed
119
build/include build/bin build/test: | build
Jordan Sissel's avatar
Jordan Sissel committed
120
	mkdir $@
Jordan Sissel's avatar
Jordan Sissel committed
121 122 123

test:
	rspec