2022-12-09 16:28:42 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2022-12-09 19:22:19 +00:00
|
|
|
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
|
2022-12-09 16:28:42 +00:00
|
|
|
|
2022-12-10 21:08:42 +00:00
|
|
|
Version ?= $(shell git describe --tags --abbrev=0 2>/dev/null)
|
|
|
|
Commit ?= $(shell git rev-parse HEAD 2>/dev/null)
|
2022-12-09 16:28:42 +00:00
|
|
|
Features ?= ""
|
2022-12-09 16:44:11 +00:00
|
|
|
Prefix ?= /bin
|
2022-12-10 19:06:36 +00:00
|
|
|
Systemd ?= /usr/lib/systemd
|
2022-12-09 16:28:42 +00:00
|
|
|
|
2022-12-10 21:08:42 +00:00
|
|
|
$(shell mkdir -p $(BUILD))
|
|
|
|
|
2022-12-09 16:28:42 +00:00
|
|
|
.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]
|
2022-12-10 19:06:36 +00:00
|
|
|
## @param Prefix=/bin Path install binaries in
|
|
|
|
## @param Systemd=/usr/lib/systemd Path to systemd installation, empty to skip
|
2022-12-09 16:28:42 +00:00
|
|
|
.PHONY: configure
|
|
|
|
configure:
|
|
|
|
@$(MAKE) --silent -B $(CONFIGURE)
|
|
|
|
|
2022-12-09 16:44:11 +00:00
|
|
|
## Install this project
|
|
|
|
.PHONY: install
|
|
|
|
install: $(BUILD)/$(PROJ)
|
2022-12-10 19:06:36 +00:00
|
|
|
@. $(CONFIGURE) && \
|
|
|
|
install -Dm 755 $< $$BIN_PATH/$(PROJ) && \
|
|
|
|
install -Dm 644 -t $$SYSTEMD_PATH/system/ \
|
|
|
|
./systemd/kdnotify.*
|
2022-12-09 16:44:11 +00:00
|
|
|
|
2022-12-09 16:28:42 +00:00
|
|
|
## 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
|
2022-12-10 20:04:30 +00:00
|
|
|
test.unit:
|
|
|
|
@$(GO) test ./...
|
2022-12-09 16:28:42 +00:00
|
|
|
|
|
|
|
## Check code formatting
|
|
|
|
.PHONY: test.fmt
|
|
|
|
test.fmt:
|
|
|
|
@./tool/fmtck.sh $(SRC) $(TEST_SRC)
|
|
|
|
|
|
|
|
$(BUILD)/$(PROJ): $(CONFIGURE) $(SRC)
|
2022-12-09 19:08:24 +00:00
|
|
|
@. $(CONFIGURE) && $(GO) \
|
|
|
|
build \
|
|
|
|
-o $@ \
|
|
|
|
-buildmode=pie \
|
|
|
|
-ldflags "-linkmode=external -extldflags=$$LDFLAGS $$BUILDFLAGS"
|
2022-12-09 16:28:42 +00:00
|
|
|
|
2022-12-10 21:08:42 +00:00
|
|
|
$(CONFIGURE): $(BUILDFLAGS)
|
2022-12-09 16:28:42 +00:00
|
|
|
@cat $@ >$@
|
2022-12-09 19:22:19 +00:00
|
|
|
@echo "BUILDFLAGS='$$(xargs <$(BUILDFLAGS))'" >>$@
|
2022-12-10 19:06:36 +00:00
|
|
|
@echo "BIN_PATH=$(Prefix)" >>$@
|
|
|
|
@echo "SYSTEMD_PATH=$(Systemd)" >>$@
|
2022-12-09 16:28:42 +00:00
|
|
|
|
2022-12-10 21:08:42 +00:00
|
|
|
$(BUILDFLAGS):
|
2022-12-09 16:28:42 +00:00
|
|
|
@cat $@ >$@
|
|
|
|
@echo '-X $(BUILDINFO).Version=$(Version)' >>$@
|
|
|
|
@echo '-X $(BUILDINFO).CommitHash=$(Commit)' >>$@
|
|
|
|
@echo '-X $(BUILDINFO).Features=$(Features)' >>$@
|
|
|
|
|
|
|
|
# vim: ts=4 sts=4
|