Skip to content

Commit

Permalink
make the makefile a bit more dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
dropwhile committed Jul 17, 2023
1 parent 18de011 commit 235772d
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ SIGN_KEY ?= ${HOME}/.minisign/go-camo.key
# app specific info
APP_NAME := go-camo
APP_VER := $(shell git describe --always --tags|sed 's/^v//')
GOPATH := $(shell go env GOPATH)
VERSION_VAR := main.ServerVersion

# flags and build configuration
Expand All @@ -25,6 +26,8 @@ CC_OUTPUT_TPL := ${BUILDDIR}/bin/{{.Dir}}.{{.OS}}-{{.Arch}}
# some exported vars (pre-configure go build behavior)
export GO111MODULE=on
export CGO_ENABLED=0
## enable go 1.21 loopvar "experiment"
#export GOEXPERIMENT=loopvar

define HELP_OUTPUT
Available targets:
Expand All @@ -40,7 +43,7 @@ Available targets:
endef
export HELP_OUTPUT

.PHONY: help clean build test cover man man-copy all tar cross-tar
.PHONY: help clean build test cover man man-copy all tar cross-tar setup-check setup-gox

help:
@echo "$$HELP_OUTPUT"
Expand All @@ -50,13 +53,21 @@ clean:

setup:

setup-gox:
@if [ -z "$(shell which gox)" ]; then \
echo "* 'gox' command not found."; \
echo " install (or otherwise ensure presence in PATH)"; \
echo " go install github.com/mitchellh/gox"; \
exit 1;\
fi
setup-check: ${GOPATH}/bin/staticcheck ${GOPATH}/bin/gosec ${GOPATH}/bin/govulncheck

${GOPATH}/bin/staticcheck:
go install honnef.co/go/tools/cmd/staticcheck@latest

${GOPATH}/bin/gosec:
go install github.com/securego/gosec/v2/cmd/gosec@latest

${GOPATH}/bin/govulncheck:
go install golang.org/x/vuln/cmd/govulncheck@latest

setup-gox: $GOPATH/bin/gox

$GOPATH/bin/gox:
go install github.com/mitchellh/gox@latest

build: setup
@[ -d "${BUILDDIR}/bin" ] || mkdir -p "${BUILDDIR}/bin"
Expand All @@ -75,14 +86,16 @@ cover: setup
@echo "Running tests with coverage..."
@go test -vet=off -cover ${GOTEST_FLAGS} ./...

check: setup
check: setup setup-check
@echo "Running checks and validators..."
@echo "... staticcheck ..."
@$$(go env GOPATH)/bin/staticcheck ./...
@${GOPATH}/bin/staticcheck ./...
@echo "... go-vet ..."
@go vet ./...
@echo "... gosec ..."
@$$(go env GOPATH)/bin/gosec -quiet ./...
@${GOPATH}/bin/gosec -quiet ./...
@echo "... govulncheck ..."
@${GOPATH}/bin/govulncheck ./...

.PHONY: update-go-deps
update-go-deps:
Expand Down

0 comments on commit 235772d

Please sign in to comment.