Created
August 17, 2017 02:39
-
-
Save mangar/09a58ed2a2b9703e59e0a21c0f83636c to your computer and use it in GitHub Desktop.
Makefile for Go - Template
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
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") | |
} |
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
# | |
# 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