diff --git a/Makefile b/Makefile index bec83d0..1856b97 100644 --- a/Makefile +++ b/Makefile @@ -7,29 +7,65 @@ GOCOMMAND := go GOBUILD := $(GOCOMMAND) build GOCLEAN := $(GOCOMMAND) clean GOTEST := $(GOCOMMAND) test +GOLINT := $(shell command -v golangci-lint 2>/dev/null) + +EXECUTABLE := ikscc +INSTALL_PATH := /usr/local/bin +INSTALL := $(INSTALL_PATH)/$(EXECUTABLE) + +PROJECT_CHANGESET := $(shell git rev-parse --verify HEAD 2>/dev/null) + + +define assert-command + @$(if $(shell command -v $1 2>/dev/null),,$(error $(1) command not found)) +endef -BINARY := ./bin/ikscc .PHONY: help help: - @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \n\nTargets:\n"} /^[a-z0-9//_-]+:.*?##/ { printf " %-15s %s\n", $$1, $$2 }' $(MAKEFILE_LIST) + @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \n\nTargets:\n"} /^[a-z0-9\/_-]+:.*?##/ { printf " %-15s %s\n", $$1, $$2 }' $(MAKEFILE_LIST) + + +.PHONY: lint +lint: ## Lint + $(call assert-command,$(GOLINT)) + @$(GOLINT) --verbose run ./... + + +./bin/$(EXECUTABLE): +ifdef PROJECT_VERSION + @$(GOBUILD) -v -ldflags="-X github.com/jjuarez/iks-ctx-cleaner/cmd.Version='v$(PROJECT_VERSION)'" -o ./bin/$(EXECUTABLE) main.go +else + @$(GOBUILD) -v -ldflags="-X github.com/jjuarez/iks-ctx-cleaner/cmd.Version='nightly:$(PROJECT_CHANGESET)'" -o ./bin/$(EXECUTABLE) main.go +endif + .PHONY: build -build: ## Builds the binary - @$(GOBUILD) -o $(BINARY) -v main.go +build: ./bin/$(EXECUTABLE) ## Builds the binary -.PHONY: run -run: build ## Runs the latest binary - @$(BINARY) .PHONY: test test: ## Testing all the things @$(GOTEST) -v ./... + .PHONY: clean clean: ## Clean the generated products @$(GOCLEAN) - @rm -fr $(BINARY) ./dist/* + @rm -fr ./bin/$(EXECUTABLE) ./dist/* + + +$(INSTALL): + @install -m 0755 ./bin/$(EXECUTABLE) $(INSTALL_PATH) + +.PHONY: build install +install: $(INSTALL) ## Installs the program in the system + + +.PHONY: uninstall +uninstall: ## Uninstalls the program from the system + @rm -f $(INSTALL) + .PHONY: all -all: clean build test +all: lint build test install