123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 | BIN := blinker
AGENT := blinker-agent
POLICIES := $(wildcard policies/*.policy)
COMMAND_POLICIES := $(wildcard policies/commands/*.policy)
PREFIX ?= /usr/local
SRC := go.mod go.sum $(shell find . -name '*.go' -not -path './dist/*') $(POLICIES) $(COMMAND_POLICIES)
# Static, reproducible builds: no cgo, no local paths in the binary.
GOFLAGS := -trimpath
export CGO_ENABLED := 0
PLATFORMS := linux/amd64 linux/arm64 darwin/amd64 darwin/arm64
.PHONY: all build test check fmt fuzz install uninstall release clean
all: build
build: $(BIN) $(AGENT)
# File targets, so `make && sudo make install` only copies as root.
$(BIN): $(SRC)
go build $(GOFLAGS) -o $(BIN) ./cmd/$(BIN)
$(AGENT): $(SRC)
go build $(GOFLAGS) -o $(AGENT) ./cmd/$(AGENT)
test:
go test ./...
# What must pass before work is done (see AGENTS.md).
check:
@test -z "$$(gofmt -l .)" || { gofmt -l .; echo "run make fmt"; exit 1; }
go vet ./...
go test ./...
fmt:
gofmt -w .
# Every fuzz target in turn, for FUZZTIME each (a duration, or a count
# such as 10000x); FUZZ=FuzzName runs just that one. A failing input is
# saved under the package's testdata/fuzz, where go test then runs it.
FUZZTIME ?= 1m
FUZZ ?=
fuzz:
@targets=$$(grep -rHoE --include='*_test.go' '^func $(or $(FUZZ),Fuzz[A-Za-z0-9_]*)\(' internal | sed 's/:func /:/; s/($$//'); \
test -n "$$targets" || { echo "no fuzz target $(FUZZ)"; exit 1; }; \
status=0; \
for t in $$targets; do \
file=$${t%%:*}; name=$${t#*:}; \
echo "== ./$$(dirname $$file) $$name"; \
go test ./$$(dirname $$file) -run '^$$' -fuzz "^$$name\$$" -fuzztime $(FUZZTIME) || { status=1; break; }; \
done; \
rm -rf internal/sandbox/.fuzz-*; \
exit $$status
install: $(BIN) $(AGENT)
install -d $(DESTDIR)$(PREFIX)/bin
install -m755 $(BIN) $(DESTDIR)$(PREFIX)/bin/$(BIN)
install -m755 $(AGENT) $(DESTDIR)$(PREFIX)/bin/$(AGENT)
install -d $(DESTDIR)$(PREFIX)/share/blinker/policies
install -m644 $(POLICIES) $(DESTDIR)$(PREFIX)/share/blinker/policies/
install -d $(DESTDIR)$(PREFIX)/share/blinker/policies/commands
install -m644 $(COMMAND_POLICIES) $(DESTDIR)$(PREFIX)/share/blinker/policies/commands/
uninstall:
rm -f $(DESTDIR)$(PREFIX)/bin/$(BIN) $(DESTDIR)$(PREFIX)/bin/$(AGENT)
rm -f $(addprefix $(DESTDIR)$(PREFIX)/share/blinker/,$(POLICIES) $(COMMAND_POLICIES))
-rmdir $(DESTDIR)$(PREFIX)/share/blinker/policies/commands $(DESTDIR)$(PREFIX)/share/blinker/policies $(DESTDIR)$(PREFIX)/share/blinker 2>/dev/null
# Binaries for every supported platform in dist/, with SHA-256 sums.
release: $(SRC)
rm -rf dist && mkdir dist
for p in $(PLATFORMS); do \
GOOS=$${p%/*} GOARCH=$${p#*/} go build $(GOFLAGS) -o dist/$(BIN)-$${p%/*}-$${p#*/} ./cmd/$(BIN) || exit 1; \
GOOS=$${p%/*} GOARCH=$${p#*/} go build $(GOFLAGS) -o dist/$(AGENT)-$${p%/*}-$${p#*/} ./cmd/$(AGENT) || exit 1; \
done
cd dist && sha256sum $(BIN)-* > SHA256SUMS
clean:
rm -rf $(BIN) $(AGENT) dist
|