kdnotify/Makefile

103 lines
2.4 KiB
Makefile

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
BUILDFLAGS := $(BUILD)/.B.buildflags
BUILDINFO := git.st8l.com/luxolus/kdnotify/buildinfo
Version ?= $(shell git describe --tags --abbrev=0)
Commit ?= $(shell git rev-parse HEAD)
Features ?= ""
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)
## 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 $@ \
-buildmode=pie \
-ldflags "-linkmode=external -extldflags=$$LDFLAGS $$BUILDFLAGS"
$(CONFIGURE): $(BUILD) $(BUILDFLAGS)
@cat $@ >$@
@echo "BUILDFLAGS='$$(xargs <$(BUILDFLAGS))'" >>$@
$(BUILDFLAGS): $(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