Skip to content

Instantly share code, notes, and snippets.

@mangar
Created August 17, 2017 02:39
Show Gist options
  • Save mangar/09a58ed2a2b9703e59e0a21c0f83636c to your computer and use it in GitHub Desktop.
Save mangar/09a58ed2a2b9703e59e0a21c0f83636c to your computer and use it in GitHub Desktop.
Makefile for Go - Template
package main
import "fmt"
var (
Version string
Build string
Hash string
)
func main() {
fmt.Println("Version :", Version)
fmt.Println("Build Time :", Build)
fmt.Println("Hash :", Hash)
// Probably the most awesome piece of code you’ve ever seen.
fmt.Println("foo bar")
}
#
# Reference:
# https://pt.slideshare.net/RaPz1/build-golang-projects-properly-with-makefiles
#
BINARY=s3upload
VERSION=1.0.0
BUILD=`date +%FT%T%z`
HASH=`git rev-parse HEAD`
# Setup the -ldflags option for go build here, interpolate the variable values
LDFLAGS=-ldflags "-X main.Version=${VERSION} -X main.Build=${BUILD} -X main.Hash=${HASH}"
default:
clear
go build ${LDFLAGS} -o ${BINARY}
install:
go install ${LDFLAGS}
clean:
if [ -f ${BINARY} ] ; then rm ${BINARY} ; fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment