chore: add root Makefile with namespaced targets

Namespaced go-* targets (build, run, test, test-verbose, check, cover,
fmt, vet, tidy, install, lint, clean) plus umbrella targets that delegate
to them. help is the default. py-* targets will slot in during the Python
port. Updates .gitignore with coverage artifacts.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-07-01 01:08:51 +02:00
parent a9534ec2c1
commit 0cf5b54070
6 changed files with 306 additions and 1 deletions

View File

@@ -0,0 +1,90 @@
# Plan: Root Makefile
## Context
The project has grown to a multi-step Go implementation with a test suite, and a
Python port is planned. Common workflows (build, test, vet, coverage) are
currently typed by hand with `cd go && go ...`. A root `Makefile` gives a single,
discoverable entry point for these tasks and a place to hang the future Python
targets.
Decisions confirmed with the user:
- Include **all** proposed targets: core set + `cover` + `tidy`/`install` + `lint`.
- **Namespaced** naming (`go-build`, `go-test`, …) with umbrella targets
(`build`, `test`, …) that delegate to the language-specific ones, so `py-*`
can slot in cleanly during the Python port.
Environment: GNU Make 3.81, Go 1.26.4, `golangci-lint` installed. Go commands use
`go -C go …` (Go 1.20+ directory flag) to avoid `cd`.
## File: `Makefile` (repo root)
Variables:
```make
GO_DIR := go
BINARY := latprobe
ARGS ?=
.DEFAULT_GOAL := help
```
### Umbrella targets (delegate now to Go; Python added later)
| Target | Delegates to | Notes |
|--------|--------------|-------|
| `help` | — | Default. Auto-generated from `##` comments. |
| `build` | `go-build` | `py-build` appended during Python port |
| `test` | `go-test` | `py-test` appended later |
| `check` | `go-check` | fmt + vet + test gate |
| `fmt` | `go-fmt` | |
| `vet` | `go-vet` | |
| `clean` | `go-clean` | |
| `all` | `check build` | |
A comment marks where `py-*` will be added (e.g. `test: go-test # + py-test later`).
### Go targets
| Target | Command |
|--------|---------|
| `go-build` | `go -C $(GO_DIR) build -o $(BINARY) .` |
| `go-run` | `go -C $(GO_DIR) run . $(ARGS)` |
| `go-test` | `go -C $(GO_DIR) test ./...` |
| `go-test-verbose` | `go -C $(GO_DIR) test -v ./...` |
| `go-fmt` | `gofmt -w $(GO_DIR)` |
| `go-vet` | `go -C $(GO_DIR) vet ./...` |
| `go-check` | depends on `go-fmt go-vet go-test` |
| `go-cover` | `go -C $(GO_DIR) test -coverprofile=coverage.out ./...` then `go -C $(GO_DIR) tool cover -html=coverage.out -o coverage.html` |
| `go-tidy` | `go -C $(GO_DIR) mod tidy` |
| `go-install` | `go -C $(GO_DIR) install .` |
| `go-lint` | guard for `golangci-lint` presence, then `cd $(GO_DIR) && golangci-lint run` |
| `go-clean` | `rm -f $(GO_DIR)/$(BINARY) $(GO_DIR)/coverage.out $(GO_DIR)/coverage.html` |
Details:
- `make run ARGS="https://example.com -n 3"` passes flags through.
- All targets listed in `.PHONY`.
- `help` recipe: `grep`/`awk` over `$(MAKEFILE_LIST)` printing `target ## description`
(works on GNU Make 3.81).
- `go-lint` guard:
```make
@command -v golangci-lint >/dev/null 2>&1 || { echo "golangci-lint not installed: https://golangci-lint.run"; exit 1; }
```
## Other changes
- `.gitignore`: add `go/coverage.out` and `go/coverage.html`.
- `docs/usage/makefile.md`: new user doc — target table + examples.
- `CHANGELOG.md`: timestamped entry.
- `README.md`: short "Development" note pointing at `make help`.
- `docs/plans/2026-07-01-01-05-makefile.md`: copy of this plan.
## Verification
```sh
make help # lists all targets with descriptions
make build # produces go/latprobe
make run ARGS="https://example.com"
make test # go test ./...
make go-test-verbose # per-test PASS/FAIL output
make check # fmt + vet + test
make go-cover # writes go/coverage.html
make go-lint # runs golangci-lint (installed)
make clean # removes binary + coverage artifacts
```
Confirm `make` with no args shows help, and that `clean` leaves the tree as
`git status` clean (no tracked files removed).

92
docs/usage/makefile.md Normal file
View File

@@ -0,0 +1,92 @@
# Makefile
The root `Makefile` provides a single entry point for all common development
tasks. Targets are namespaced by language (`go-*`, `py-*` when the Python port
lands) with short umbrella targets (`build`, `test`, …) that delegate to the
language-specific ones.
## Quick reference
```sh
make # same as: make help
make help # list all targets with descriptions
```
## Umbrella targets
| Target | Description |
|--------|-------------|
| `all` | Run `check` then `build` |
| `build` | Build the binary (→ `go-build`) |
| `test` | Run all tests (→ `go-test`) |
| `check` | Pre-commit gate: fmt + vet + test (→ `go-check`) |
| `fmt` | Format source (→ `go-fmt`) |
| `vet` | Static analysis (→ `go-vet`) |
| `clean` | Remove binary and coverage artifacts |
## Go targets
| Target | Description |
|--------|-------------|
| `go-build` | Compile `go/latprobe` |
| `go-run` | Build and run (pass flags via `ARGS=`) |
| `go-test` | `go test ./...` |
| `go-test-verbose` | `go test -v ./...` — per-case PASS/FAIL output |
| `go-check` | `go-fmt` + `go-vet` + `go-test` |
| `go-cover` | Coverage report → `go/coverage.html` |
| `go-fmt` | `gofmt -w go/` |
| `go-vet` | `go vet ./...` |
| `go-tidy` | `go mod tidy` |
| `go-install` | Install binary to `$GOBIN` |
| `go-lint` | `golangci-lint run` (must be installed) |
| `go-clean` | Remove `go/latprobe`, `go/coverage.out`, `go/coverage.html` |
## Examples
```sh
# Build and run a quick probe
make go-run ARGS="https://example.com"
make go-run ARGS="-n 5 --json https://example.com https://www.google.com"
# Run the full test suite
make test
# Verbose output showing each test case
make go-test-verbose
# Pre-commit gate (format, vet, test all in one)
make check
# Generate and open coverage report
make go-cover
open go/coverage.html # macOS
# Lint
make go-lint
# Clean up artifacts
make clean
```
## Passing arguments to `go-run`
```sh
make go-run ARGS="<url> [url ...] [flags]"
# Examples
make go-run ARGS="https://example.com"
make go-run ARGS="--timeout 2s --fail https://example.com"
make go-run ARGS="--json -n 3 https://example.com https://www.google.com"
```
## Adding Python targets (when the port lands)
The umbrella targets are designed to accept Python targets alongside the Go ones.
The pattern will be:
```make
test: go-test py-test # py-test added here during the port
```
`go-lint` requires `golangci-lint` to be installed. If it's missing the target
prints an install link and exits 1.