.DEFAULT_GOAL := out
export DATE := $(shell date '+%Y-%m-%d %H:%M:%S')
export LATEST_COMMIT := $(shell git log --pretty=format:'%h' -n 1)
export BRANCH := $(shell git branch |grep -v "no branch"| grep \*|cut -d ' ' -f2)
export BUILT_ON_IP := $(shell [ $$(uname) = Linux ] && hostname -i || hostname )
export RUNTIME_VER := $(shell go version)
export BUILT_ON_OS=$(shell uname -a)
ifeq ($(BRANCH),)
BRANCH := master
endif

export COMMIT_CNT := $(shell git rev-list HEAD | wc -l | sed 's/ //g' )
export BUILD_NUMBER := ${BRANCH}-${COMMIT_CNT}

export COMPILE_LDFLAGS='-s -w \
                          -X "main.BuildDate=${DATE}" \
                          -X "main.LatestCommit=${LATEST_COMMIT}" \
                          -X "main.BuildNumber=${BUILD_NUMBER}" \
                          -X "main.BuiltOnIP=${BUILT_ON_IP}" \
                          -X "main.BuiltOnOs=${BUILT_ON_OS}" \
                          -X "main.Branch=${BRANCH}" \
                          -X "main.CommitCnt=${COMMIT_CNT}" \
                          -X "main.RuntimeVer=${RUNTIME_VER}" '

out:
	GOOS=darwin GOARCH=arm64 go build -o bin/sjy01-imgproc-darwin-arm64 -ldflags=${COMPILE_LDFLAGS} cmd/*.go 

clean:
	rm -rf ./bin/*

linux:
	GOOS=linux GOARCH=amd64 go build -o bin/sjy01-imgproc -ldflags=${COMPILE_LDFLAGS} cmd/*.go

release:
	docker run --rm -v .:/src -v /Users/lan/workspace/sjy01/build/go:/build/go nuknal/gdal38-cv49-builder sh -c "cd /src && make linux"
