|
| 1 | +SHELL = bash |
| 2 | +# Current git branch |
| 3 | +BRANCH := $(shell git rev-parse --abbrev-ref HEAD) |
| 4 | +# Current git commit hash |
| 5 | +GIT_COMMIT_HASH := $(shell git show --no-patch --no-notes --pretty='%h' HEAD) |
| 6 | +VERSION := $(BRANCH).$(GIT_COMMIT_HASH) |
| 7 | +ifeq ($(shell git status --porcelain),) |
| 8 | +DIRTY := |
| 9 | +else |
| 10 | +DIRTY := "dev" |
| 11 | +endif |
| 12 | +LDFLAGS=--ldflags "-s -X github.com/SwissDataScienceCenter/renku-dev-utils/pkg/version.Version=$(VERSION) -X github.com/SwissDataScienceCenter/renku-dev-utils/pkg/version.VersionSuffix=$(DIRTY)" |
| 13 | + |
| 14 | +.PHONY: all |
| 15 | +all: help |
| 16 | + |
| 17 | +.PHONY: vars |
| 18 | +vars: ## Show the Makefile vars |
| 19 | + @echo SHELL="'$(SHELL)'" |
| 20 | + @echo BRANCH="'$(BRANCH)'" |
| 21 | + @echo GIT_COMMIT_HASH="'$(GIT_COMMIT_HASH)'" |
| 22 | + @echo VERSION="'$(VERSION)'" |
| 23 | + @echo DIRTY="'$(DIRTY)'" |
| 24 | + |
| 25 | +.PHONY: rdu |
| 26 | +rdu: build/renku-dev-utils ## Build and install renku-dev-utils |
| 27 | + mkdir -p `go env GOPATH`/bin/ |
| 28 | + cp -av build/renku-dev-utils`go env GOEXE` `go env GOPATH`/bin/rdu`go env GOEXE`.new |
| 29 | + mv -v `go env GOPATH`/bin/rdu`go env GOEXE`.new `go env GOPATH`/bin/rdu`go env GOEXE` |
| 30 | + |
| 31 | +.PHONY: build/renku-dev-utils |
| 32 | +build/renku-dev-utils: |
| 33 | + go build -v -o build/ $(LDFLAGS) |
| 34 | + |
| 35 | +# From the operator sdk Makefile |
| 36 | +# The help target prints out all targets with their descriptions organized |
| 37 | +# beneath their categories. The categories are represented by '##@' and the |
| 38 | +# target descriptions by '##'. The awk command is responsible for reading the |
| 39 | +# entire set of makefiles included in this invocation, looking for lines of the |
| 40 | +# file as xyz: ## something, and then pretty-format the target and help. Then, |
| 41 | +# if there's a line with ##@ something, that gets pretty-printed as a category. |
| 42 | +# More info on the usage of ANSI control characters for terminal formatting: |
| 43 | +# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters |
| 44 | +# More info on the awk command: |
| 45 | +# http://linuxcommand.org/lc3_adv_awk.php |
| 46 | +.PHONY: help |
| 47 | +help: ## Display this help. |
| 48 | + @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-25s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) |
| 49 | + |
| 50 | +##@ Development |
| 51 | + |
| 52 | +.PHONY: format |
| 53 | +format: ## Format source files |
| 54 | + gofmt -l -w . |
0 commit comments