Created
June 8, 2018 10:24
-
-
Save cuiwm/f36d5043d8dd3037a2385fc38faaee95 to your computer and use it in GitHub Desktop.
golang build with version info
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SFILE:=$(wildcard *.go) | |
VERSION=`git describe --tags` | |
BUILD=`date +%F_%T%z` | |
TAGETFILE=uploadTool | |
LDFLAGS_DEBUG=-ldflags "-X main.Version=${VERSION} -X main.Build=${BUILD}" | |
LDFLAGS_REL=-ldflags "-w -s -X main.Version=${VERSION} -X main.Build=${BUILD}" | |
all: mac | |
@echo ${BUILD} ${VERSION} $(SFILE) | |
go build -o ${TAGETFILE} ${LDFLAGS_DEBUG} ${SFILE} | |
./${TAGETFILE} | |
linux: rhel | |
@echo ${BUILD} ${VERSION} $(SFILE) | |
GOOS="linux" GOARCH="amd64" go build -o ${TAGETFILE} ${LDFLAGS_DEBUG} ${SFILE} | |
file ${TAGETFILE} | |
mv ${TAGETFILE} ${TAGETFILE}Linux | |
clean: | |
if [ -f ${TAGETFILE} ] ; then rm ${TAGETFILE} ; fi | |
os:=$(shell uname -a) | |
.DEFAULT: | |
@echo "$(os)" | |
.PHONY: linux clean |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment