kdnotify/Makefile

99 lines
2.3 KiB
Makefile
Raw Normal View History

PROJ := kdnotify
PROJPATH := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
BUILD ?= $(PROJPATH)build
GO ?= $(shell command -v go)
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
SRC := $(shell find . -iname "*.go" -not -iname '*_test.go')
TEST_SRC := $(shell find . -iname '*_test.go')
CONFIGURE := $(BUILD)/.B.configure
LDFLAGS := $(BUILD)/.B.ldflags
BUILDINFO := git.st8l.com/luxolus/kdnotify/buildinfo
Version ?= $(shell git describe --tags --abbrev=0)
Commit ?= $(shell git rev-parse HEAD)
Features ?= ""
2022-12-09 16:44:11 +00:00
Prefix ?= /bin
.DEFAULT_GOAL := help
.PHONY: help
help:
@FILE=Makefile ./tool/make2doc.sh
## Build the project
##
## @param GOOS Compile for a different OS than the current
## @param GOARCH Compile for a different architecture than the current
## Also, see T:configure's docs for other compile time configuration
.PHONY: build
build: $(BUILD)/$(PROJ)
@echo "==> Built $(PROJ) -> $(BUILD)/$(PROJ)"
## Configure the build
##
## You can override the autodetected defaults with the following params
## @param Version=v<X.X.X> Version of this binary [Most recent Git tag]
## @param Commit=<SHA> Commit SHA of this binary [Git HEAD]
## @param Features=<,list> Comma separated list of features to enable [None]
.PHONY: configure
configure:
@$(MAKE) --silent -B $(CONFIGURE)
2022-12-09 16:44:11 +00:00
## Install this project
##
## @param Prefix=/bin Prefix path to install binary [/bin]
.PHONY: install
install: $(BUILD)/$(PROJ)
@install -Dm 755 $< $(Prefix)/$(PROJ)
## Clean build artifacts
.PHONY: clean
clean:
@rm -rvf $(BUILD)
## Format the project
.PHONY: fmt
fmt:
@$(GO) fmt ./...
## Check for code issues
.PHONY: vet
vet:
@$(GO) vet -c=8 ./...
## Run project fast checks
.PHONY: check
check: test.fmt vet test.unit
## Run unit tests
.PHONY: test.unit
test.unit: $(CONFIGURE)
@. $(CONFIGURE) && $(GO) test ./...
## Check code formatting
.PHONY: test.fmt
test.fmt:
@./tool/fmtck.sh $(SRC) $(TEST_SRC)
$(BUILD)/$(PROJ): $(CONFIGURE) $(SRC)
@. $(CONFIGURE) && $(GO) build -o $@ -ldflags "$$LDFLAGS"
$(CONFIGURE): $(BUILD) $(LDFLAGS)
@cat $@ >$@
@echo "LDFLAGS='$$(xargs <$(LDFLAGS))'" >>$@
$(LDFLAGS): $(BUILD)
@cat $@ >$@
@echo '-X $(BUILDINFO).Version=$(Version)' >>$@
@echo '-X $(BUILDINFO).CommitHash=$(Commit)' >>$@
@echo '-X $(BUILDINFO).Features=$(Features)' >>$@
@touch $(CONFIGURE)
$(BUILD):
@mkdir -p $@
# vim: ts=4 sts=4