Makefile 4.14 KB
Newer Older
Gurvinder Singh's avatar
Gurvinder Singh committed
1
VERSION=0.3.1+uninett_0.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.
Jordan Sissel's avatar
Jordan Sissel committed
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
                logrouter_uninett.pem=/etc/ssl/certs/ \
                logstash-forwarder.conf=/etc/logstashforwarder/config.json.example \
58 59
                logstash-forwarder.default=/etc/default/logstash-forwarder \
                logstash-forwarder.logrotate=/etc/logrotate.d/logstash-forwarder \
Jordan Sissel's avatar
Jordan Sissel committed
60
		logstash-forwarder.init=/etc/init.d/logstash-forwarder
61

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

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

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

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

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

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

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

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

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

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

114 115 116
build:
	mkdir $@

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

test:
	rspec