Skip to content

Commit

Permalink
Add makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
aswinkarthik committed Aug 12, 2019
1 parent 7c4aa62 commit e4a0210
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
-include .env

VERSION := $(shell git describe --tags)
BUILD := $(shell git rev-parse --short HEAD)
PROJECTNAME := $(shell basename "$(PWD)")

# Go related variables.
GOBASE := $(shell pwd)
GOPATH := $(GOBASE)/vendor:$(GOBASE)
GOBIN := $(GOBASE)/out
GOFILES := $(wildcard *.go)

# Use linker flags to provide version/build settings
LDFLAGS=-ldflags "-X=main.Version=$(VERSION) -X=main.Build=$(BUILD)"

# Make is verbose in Linux. Make it silent.
MAKEFLAGS += --silent

## install: Install missing dependencies. Runs `go get` internally. e.g; make install get=github.com/foo/bar
install: go-get

## test: Run all tests
test:
@-$(MAKE) -s go-test

## compile: Compile the binary.
compile:
@-$(MAKE) -s go-compile

## exec: Run given command, wrapped with custom GOPATH. e.g; make exec run="go test ./..."
exec:
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) $(run)

## clean: Clean build files. Runs `go clean` internally.
clean:
@-rm $(GOBIN)/$(PROJECTNAME) 2> /dev/null
@-$(MAKE) go-clean

go-compile: go-get go-build

go-build:
@echo " > Building binary..."
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go build $(LDFLAGS) -o $(GOBIN)/$(PROJECTNAME) $(GOFILES)

go-generate:
@echo " > Generating dependency files..."
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go generate $(generate)

go-get:
@echo " > Checking if there is any missing dependencies..."
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go get $(get)

go-install:
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go mod tidy

go-vendor:
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go mod vendor

go-test:
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go test -v ./...

richgo-test:
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) richgo test -v ./...

go-clean:
@echo " > Cleaning build cache"
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go clean

.PHONY: help
all: help
help: Makefile
@echo
@echo " Choose a command run in "$(PROJECTNAME)":"
@echo
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'
@echo

0 comments on commit e4a0210

Please sign in to comment.