273 lines
8.0 KiB
Makefile
273 lines
8.0 KiB
Makefile
SHELL = /bin/bash
|
|
|
|
PROTOC = @PROTOC@
|
|
GO = @GO@
|
|
GOROOT = @GOROOT@
|
|
# or 386
|
|
arch = amd64
|
|
CGO_ENABLED = 1
|
|
|
|
ifneq ($(GOROOT),)
|
|
export GOROOT
|
|
endif
|
|
|
|
cflags =
|
|
ifeq ($(arch),386)
|
|
cflags = -m32
|
|
GOARCH = $(arch)
|
|
endif
|
|
|
|
export GOARCH
|
|
export CGO_ENABLED
|
|
|
|
.PHONY: all valgrind parser package replace_version_string build binary_package dependencies
|
|
|
|
all: | parser valgrind build test integration_test
|
|
|
|
parser:
|
|
$(MAKE) -C src/parser
|
|
|
|
GOPATH := $(shell pwd)
|
|
export GOPATH
|
|
uname_S = $(shell sh -c "uname -s 2>/dev/null || echo not")
|
|
|
|
valgrind:
|
|
ifeq ($(uname_S),Linux)
|
|
$(MAKE) -C src/parser valgrind
|
|
endif
|
|
|
|
# packages
|
|
packages = admin api/http common configuration \
|
|
checkers coordinator datastore engine parser \
|
|
protocol
|
|
|
|
# snappy variables
|
|
snappy_version = 1.1.0
|
|
snappy_dir = /tmp/snappy.influxdb.$(arch)
|
|
snappy_file = snappy-$(snappy_version).tar.gz
|
|
snappy_deps = $(snappy_dir)/.libs/libsnappy.a
|
|
|
|
# leveldb variables
|
|
leveldb_version = 1.12.0
|
|
leveldb_dir = /tmp/leveldb.influxdb.$(arch)
|
|
leveldb_file = leveldb-$(leveldb_version).tar.gz
|
|
leveldb_deps = $(leveldb_dir)/libleveldb.a
|
|
|
|
profile=off
|
|
ifneq ($(profile),off)
|
|
CGO_LDFLAGS += -ltcmalloc -lprofiler
|
|
GO_BUILD_OPTIONS = -tags profile
|
|
endif
|
|
|
|
# levigo flags
|
|
ifeq ($(uname_S),Linux)
|
|
CGO_CFLAGS += -I$(leveldb_dir)/include
|
|
CGO_LDFLAGS += $(leveldb_dir)/libleveldb.a $(snappy_dir)/.libs/libsnappy.a -lstdc++
|
|
export CGO_CFLAGS
|
|
export CGO_LDFLAGS
|
|
else
|
|
CGO_LDFLAGS += -lleveldb -lsnappy -lstdc++
|
|
export CGO_LDFLAGS
|
|
endif
|
|
|
|
ifneq ($(uname_S),Linux)
|
|
PYTHONPATH ?= /usr/local/lib/python2.7/site-packages/
|
|
export PYTHONPATH
|
|
endif
|
|
|
|
$(snappy_deps):
|
|
ifeq ($(uname_S),Linux)
|
|
rm -rf $(snappy_dir)
|
|
mkdir -p $(snappy_dir)
|
|
bash -c "cd $(snappy_dir); \
|
|
wget https://snappy.googlecode.com/files/$(snappy_file); \
|
|
tar --strip-components=1 -xvzf $(snappy_file); \
|
|
CFLAGS=$(cflags) CXXFLAGS=$(cflags) ./configure; \
|
|
$(MAKE)"
|
|
endif
|
|
|
|
$(leveldb_deps): $(snappy_deps)
|
|
ifeq ($(uname_S),Linux)
|
|
rm -rf $(leveldb_dir)
|
|
mkdir -p $(leveldb_dir)
|
|
bash -c "cd $(leveldb_dir); \
|
|
wget https://leveldb.googlecode.com/files/$(leveldb_file); \
|
|
tar --strip-components=1 -xvzf $(leveldb_file); \
|
|
CXXFLAGS='-I$(snappy_dir) $(cflags)' LDFLAGS='-L$(snappy_dir)/.libs' make"
|
|
endif
|
|
|
|
levigo_dependency = github.com/jmhodges/levigo
|
|
proto_dependency = code.google.com/p/goprotobuf/protoc-gen-go
|
|
|
|
dependencies = code.google.com/p/go.crypto/bcrypt \
|
|
code.google.com/p/goprotobuf/proto \
|
|
code.google.com/p/log4go \
|
|
github.com/bmizerany/pat \
|
|
github.com/fitstar/falcore \
|
|
github.com/fitstar/falcore/filter \
|
|
github.com/gorilla/mux \
|
|
github.com/goraft/raft \
|
|
github.com/influxdb/go-cache \
|
|
github.com/BurntSushi/toml \
|
|
github.com/influxdb/influxdb-go \
|
|
code.google.com/p/gogoprotobuf/proto \
|
|
$(proto_dependency)
|
|
|
|
dependencies_paths := $(addprefix src/,$(dependencies))
|
|
|
|
src/$(levigo_dependency):
|
|
$(GO) get -d $(levigo_dependency)
|
|
bash -c "pushd $@; find . -name \*.go | xargs sed -i 's/\/\/ #cgo LDFLAGS: -lleveldb\|#cgo LDFLAGS: -lleveldb//g'; popd"
|
|
|
|
|
|
$(dependencies_paths):
|
|
for i in $(dependencies); do $(GO) get -d $$i; done
|
|
|
|
dependencies: src/$(levigo_dependency) $(dependencies_paths) $(leveldb_deps) $(snappy_deps)
|
|
|
|
test_dependencies: dependencies
|
|
$(GO) get launchpad.net/gocheck
|
|
|
|
protobuf:
|
|
$(GO) get $(proto_dependency)
|
|
rm -f src/protocol/*.pb.go
|
|
PATH=$$PWD/bin:$$PATH $(PROTOC) --go_out=. src/protocol/*.proto
|
|
|
|
build: | dependencies protobuf parser build_version_string
|
|
# TODO: build all packages, otherwise we won't know
|
|
# if there's an error
|
|
$(GO) build $(GO_BUILD_OPTIONS) daemon
|
|
$(GO) build benchmark
|
|
|
|
clean:
|
|
rm -f daemon
|
|
rm -f benchmakr
|
|
rm -rf pkg/
|
|
rm -rf packages/
|
|
rm -rf src/$(levigo_dependency)
|
|
rm -rf /tmp/influxdb
|
|
rm -rf /tmp/admin.influxdb
|
|
$(MAKE) -C src/parser clean
|
|
|
|
only =
|
|
verbose = off
|
|
ifneq ($(only),)
|
|
GOTEST_OPTS = -gocheck.f '$(only)'
|
|
endif
|
|
ifneq ($(verbose),off)
|
|
GOTEST_OPTS += -v -gocheck.v -gocheck.vv
|
|
endif
|
|
|
|
version=
|
|
ifeq ($(version),)
|
|
version = "dev"
|
|
endif
|
|
|
|
timeout = 10m
|
|
GOTEST_OPTS += -test.timeout=$(timeout)
|
|
|
|
test: test_dependencies parser protobuf
|
|
$(GO) test $(packages) $(GOTEST_OPTS)
|
|
|
|
coverage: test_dependencies
|
|
for i in $(packages); do $(GO) test -coverprofile /tmp/influxdb.$${i/\//}.coverage $$i $(GOTEST_OPTS); \
|
|
$(GO) tool cover -html=/tmp/influxdb.$${i/\//}.coverage; done
|
|
|
|
|
|
integration_test: test_dependencies build
|
|
$(GO) test integration $(GOTEST_OPTS)
|
|
|
|
package_version=$(subst -,_,$(version))
|
|
admin_dir = /tmp/admin.influxdb
|
|
|
|
source_package = packages/influxdb-$(version).src.tar.gz
|
|
binary_package = packages/influxdb-$(version).$(arch).tar.gz
|
|
ifeq ($(arch),386)
|
|
rpm_package = packages/influxdb-$(package_version)-1.i686.rpm
|
|
debian_package = packages/influxdb_$(version)_i386.deb
|
|
rpm_args = setarch i386
|
|
deb_args = -a i386
|
|
else
|
|
rpm_package = packages/influxdb-$(package_version)-1.x86_64.rpm
|
|
debian_package = packages/influxdb_$(version)_amd64.deb
|
|
endif
|
|
|
|
files = $(binary_package) $(debian_package) $(rpm_package) $(source_package)
|
|
sha1 = $(shell sh -c "git rev-list --max-count=1 HEAD")
|
|
|
|
build_version_string:
|
|
@echo "package main" > src/daemon/version.go
|
|
@echo "const version = \"$(version)\"" >> src/daemon/version.go
|
|
@echo "const gitSha = \"$(sha1)\"" >> src/daemon/version.go
|
|
|
|
package_version_string: build_version_string
|
|
sed -i.bak -e "s/REPLACE_VERSION/$(version)/" scripts/post_install.sh
|
|
|
|
$(admin_dir)/build:
|
|
rm -rf $(admin_dir)
|
|
rvm 1.9.3 do rvm gemset create influxdb
|
|
git clone https://github.com/influxdb/influxdb-admin.git $(admin_dir)
|
|
rvm 1.9.3@influxdb do bash -c "pushd $(admin_dir); bundle install; middleman build; popd"
|
|
|
|
$(rpm_package): $(admin_dir)/build build
|
|
rm -rf out_rpm
|
|
mkdir -p out_rpm/opt/influxdb/versions/$(version)
|
|
cp -r build/* out_rpm/opt/influxdb/versions/$(version)
|
|
rvm 1.9.3@influxdb do bash -c "pushd out_rpm; $(rpm_args) fpm -s dir -t rpm --after-install ../scripts/post_install.sh -n influxdb -v $(version) .; popd"
|
|
mv out_rpm/$(shell basename $(rpm_package)) packages/
|
|
|
|
$(debian_package): $(admin_dir)/build build
|
|
rm -rf out_rpm
|
|
mkdir -p out_rpm/opt/influxdb/versions/$(version)
|
|
cp -r build/* out_rpm/opt/influxdb/versions/$(version)
|
|
rvm 1.9.3@influxdb do bash -c "pushd out_rpm; fpm -s dir -t deb $(deb_args) --after-install ../scripts/post_install.sh -n influxdb -v $(version) .; popd"
|
|
mv out_rpm/$(shell basename $(debian_package)) packages/
|
|
|
|
$(source_package): dependencies
|
|
rm -rf src/$(levigo_dependency)
|
|
$(GO) get -d $(levigo_dependency)
|
|
rm -f daemon
|
|
rm -f benchmark
|
|
git ls-files --others | egrep -v 'github|launchpad|code.google|version.go' > /tmp/influxdb.ignored
|
|
echo "pkg/*" >> /tmp/influxdb.ignored
|
|
echo "packages/*" >> /tmp/influxdb.ignored
|
|
echo "build/*" >> /tmp/influxdb.ignored
|
|
echo "out_rpm/*" >> /tmp/influxdb.ignored
|
|
rm -rf admin
|
|
cp -R $(admin_dir)/build admin
|
|
tar -czf $(source_package) --exclude-vcs -X /tmp/influxdb.ignored *
|
|
rm -rf /tmp/influxdb
|
|
mkdir /tmp/influxdb
|
|
tar -xzf $(source_package) -C /tmp/influxdb
|
|
rm $(source_package)
|
|
bash -c "pushd /tmp/; tar -czf `basename $(source_package)` influxdb; popd"
|
|
mv /tmp/$(shell basename $(source_package)) $(source_package)
|
|
rm -rf src/$(levigo_dependency)
|
|
rm -rf admin
|
|
|
|
$(binary_package): $(admin_dir)/build build packages
|
|
rm -rf build
|
|
mkdir build
|
|
mv daemon build/influxdb
|
|
mv benchmark build/influxdb-benchmark
|
|
cp src/benchmark/benchmark_config.sample.toml build/benchmark_config.toml
|
|
mkdir build/admin
|
|
cp -R $(admin_dir)/build/* build/admin/
|
|
cp -R scripts/ build/
|
|
cp config.toml.sample build/config.toml
|
|
sed -i 's/.\/admin/\/opt\/influxdb\/current\/admin/g' build/config.toml
|
|
sed -i 's/influxdb.log/\/opt\/influxdb\/shared\/log.txt/g' build/config.toml
|
|
sed -i 's/\/tmp\/influxdb\/development\/db/\/opt\/influxdb\/shared\/data\/db/g' build/config.toml
|
|
sed -i 's/\/tmp\/influxdb\/development\/raft/\/opt\/influxdb\/shared\/data\/raft/g' build/config.toml
|
|
sed -i 's/\/tmp\/influxdb\/development\/wal/\/opt\/influxdb\/shared\/data\/wal/g' build/config.toml
|
|
rm -f build/scripts/post_install.sh.bak
|
|
tar -czf $(binary_package) build/*
|
|
|
|
binary_package: $(binary_package)
|
|
|
|
packages:
|
|
mkdir $@
|
|
|
|
package: | packages build package_version_string $(files)
|
|
mv -f scripts/post_install.sh.bak scripts/post_install.sh
|