.PHONY: arm build clean tool lint help

check=$(shell if [ ! -d "./build/" ]; then mkdir build; else echo "exist"; fi;)
version=$(shell ./version.sh) 
tarfile = $(shell echo "chain33-pai_$(version).tar.gz" | sed s/[[:space:]]//g)
all: build

arm:
	@GOOS=linux GOARCH=arm GOARM=7 go build -v -o pai .
	@echo $(check)
	@rm -rf chain33-pai
	@mkdir chain33-pai
	@mv pai chain33-pai/chain33-pai
	@cp *.sh chain33-pai
	@cp -r conf chain33-pai
	@cp -r scripts chain33-pai
	@chmod +x chain33-pai/*.sh
	@chmod +x chain33-pai/scripts/*.sh
	@tar cvfpz $(tarfile) chain33-pai
	@mv $(tarfile) build
	@rm -rf chain33-pai
	@echo "ok"

build:
	@go build -v -o pai .
	@echo $(check)
	@rm -rf chain33-pai
	@mkdir chain33-pai
	@mv pai chain33-pai/chain33-pai
	@cp *.sh chain33-pai
	@cp -r conf chain33-pai
	@cp -r scripts chain33-pai
	@chmod +x chain33-pai/*.sh
	@chmod +x chain33-pai/scripts/*.sh
	@tar cvfpz $(tarfile) chain33-pai	
	@mv $(tarfile) build
	@rm -rf chain33-pai
	@echo "ok"

tool:
	go vet ./...; true
	gofmt -w .

lint:
	golint ./...

clean:
	rm -rf chain33-pai
	go clean -i .

help:
	@echo "make: compile packages and dependencies"
	@echo "make tool: run specified go tool"
	@echo "make lint: golint ./..."
	@echo "make clean: remove object files and cached files"
