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 package_init build binary_package all: | parser valgrind build test integration_test parser: $(MAKE) -C src/parser valgrind: $(MAKE) -C src/parser valgrind GOPATH := $(shell pwd) export GOPATH uname_S = $(shell sh -c "uname -s 2>/dev/null || echo not") # packages packages = admin api/http common configuration \ checkers coordinator datastore engine parser \ protocol server # 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 # 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/stvp/go-toml-config \ $(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 # TODO: build all packages, otherwise we won't know # if there's an error $(GO) build daemon clean: rm -f daemon 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 endif test: test_dependencies parser $(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) 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-$(version)-1.i686.rpm debian_package = packages/influxdb_$(version)_i386.deb rpm_args = setarch i386 deb_args = -a i386 else rpm_package = packages/influxdb-$(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") package_init: ifeq ($(version),) $(error Please specify the version to be packaged using 'make version=major.minor.patch') endif sed -i.bak -e "s/version = \"dev\"/version = \"$(version)\"/" -e "s/gitSha\s*=\s*\"HEAD\"/gitSha = \"$(sha1)\"/" src/daemon/influxd.go 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 rvm 1.9.3@influxdb do bundle install git clone https://github.com/influxdb/influxdb-admin.git $(admin_dir) rvm 1.9.3@influxdb do bash -c "pushd $(admin_dir); 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 git ls-files --others | egrep -v 'github|launchpad|code.google' > /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 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 rm -f build/scripts/post_install.sh.bak tar -czf $(binary_package) build/* binary_package: $(binary_package) packages: mkdir $@ package: | packages package_init $(files) mv -f src/daemon/influxd.go.bak src/daemon/influxd.go mv -f scripts/post_install.sh.bak scripts/post_install.sh