
.PHONY: build clean test help default

GO=go

GOBUILD_OPTIONS := -v -mod vendor
export GO111MODULE=on
export GOPROXY=https://goproxy.cn
PREFIX := /usr

BIN_UPDATE_TOOLS=deepin-system-update
BIN_FIXPKG_TOOLS=deepin-system-fixpkg

VERSION := $(shell grep "const Version " pkg/utils/version/version.go | sed -E 's/.*"(.+)"$$/\1/')
# GIT_COMMIT=$(shell -xc "head  -n 1 debian/changelog  | awk '{print $2}' | sed 's/[(]\(.*\)[)]/\1/' ")
GIT_COMMIT="1.0.0"
GIT_DIRTY=$(shell test -n "`git status --porcelain`" && echo "+Devel" || true)
BUILD_DATE=$(shell date '+%Y-%m-%d-%H:%M:%S')

default: build

all: bin
bin: build

help:
	@echo 'Management commands for deepin-system-update-tools:'
	@echo
	@echo 'Usage:'
	@echo '    make build           Compile the project.'
	@echo '    make get-deps        runs dep ensure, mostly used for ci.'
	
	@echo '    make clean           Clean the directory tree.'
	@echo

build:
	@echo "building ${BIN_UPDATE_TOOLS} ${VERSION} ${GIT_COMMIT}${GIT_DIRTY}"
	CGO_ENABLED=0 go build -gcflags "-N" -ldflags="-extldflags=-static" -o bin/${BIN_UPDATE_TOOLS} cmd/${BIN_UPDATE_TOOLS}/main.go

	@echo "building ${BIN_FIXPKG_TOOLS} ${VERSION} ${GIT_COMMIT}${GIT_DIRTY}"
	CGO_ENABLED=0 go build -ldflags="-extldflags=-static" -o bin/${BIN_FIXPKG_TOOLS} cmd/${BIN_FIXPKG_TOOLS}/main.go

	go build -o bin/sturn tools/sturn/main.go

get-deps:
	dep ensure

clean:
	@test ! -e bin/${BIN_UPDATE_TOOLS} || rm bin/${BIN_UPDATE_TOOLS}
	@test ! -e bin/${BIN_FIXPKG_TOOLS} || rm bin/${BIN_FIXPKG_TOOLS}
	@test ! -e bin/sturn || rm bin/sturn

test:
	go test ./...

