kdnotify/Makefile

107 lines
2.6 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 2>/dev/null)
Commit ?= $(shell git rev-parse HEAD 2>/dev/null)
Features ?= ""
Prefix ?= /bin
Systemd ?= /usr/lib/systemd
$(shell mkdir -p $(BUILD))
.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]
## @param Prefix=/bin Path install binaries in
## @param Systemd=/usr/lib/systemd Path to systemd installation, empty to skip
.PHONY: configure
configure:
@$(MAKE) --silent -B $(CONFIGURE)
## Install this project
.PHONY: install
install: $(BUILD)/$(PROJ)
@. $(CONFIGURE) && \
install -Dm 755 $< $$BIN_PATH/$(PROJ) && \
install -Dm 644 -t $$SYSTEMD_PATH/system/ \
./systemd/kdnotify.*
## 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:
@$(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): $(BUILDFLAGS)
@cat $@ >$@
@echo "BUILDFLAGS='$$(xargs <$(BUILDFLAGS))'" >>$@
@echo "BIN_PATH=$(Prefix)" >>$@
@echo "SYSTEMD_PATH=$(Systemd)" >>$@
$(BUILDFLAGS):
@cat $@ >$@
@echo '-X $(BUILDINFO).Version=$(Version)' >>$@
@echo '-X $(BUILDINFO).CommitHash=$(Commit)' >>$@
@echo '-X $(BUILDINFO).Features=$(Features)' >>$@
# vim: ts=4 sts=4