checkmake is a linter for Makefiles. It scans Makefiles for potential issues based on configurable rules.
% checkmake Makefile
% checkmake Makefile foo.mk bar.mk baz.mkcheckmake analyzes one or more Makefiles and reports potential issues according to configurable rules.
Usage:
checkmake [flags] [makefile...]
checkmake [command]
Available Commands:
completion Generate the autocompletion script for the specified shell
help Help about any command
list-rules List registered rules
Flags:
--config string Configuration file to read (default "checkmake.ini")
--debug Enable debug mode
--format string Custom Go template for text output (ignored in JSON mode)
-h, --help help for checkmake
-o, --output string Output format: 'text' (default) or 'json' (mutually exclusive with --format) (default "text")
-v, --version version for checkmake
Use "checkmake [command] --help" for more information about a command.% checkmake fixtures/missing_phony.make
RULE DESCRIPTION FILE NAME LINE NUMBER
minphony Missing required phony target fixtures/missing_phony.make 21
"all"
minphony Missing required phony target fixtures/missing_phony.make 21
"test"
phonydeclared Target "all" should be fixtures/missing_phony.make 16
declared PHONY.Build the image, or pull it:
docker build --build-arg BUILDER_NAME='Your Name' --build-arg [email protected] . -t checkerThen run it with your Makefile attached, below is an example of it assuming the Makefile is in your current working directory:
docker run -v "$PWD"/Makefile:/Makefile checkerThis repo includes a pre-commit hook, which you may choose to use in your own
repos. Simply add a .pre-commit-config.yaml to your repo's top-level directory
repos:
- repo: https://github.com/checkmake/checkmake.git
# Or another commit hash or version
rev: 0.2.2
hooks:
# Use this hook to let pre-commit build checkmake in its sandbox
- id: checkmake
# OR Use this hook to use a pre-installed checkmake executable
# - id: checkmake-systemThere are two hooks available:
-
checkmake(Recommended)pre-commit will set up a Go environment from scratch to compile and run checkmake. See the pre-commit
golangplugin docs for more information. -
checkmake-systempre-commit will look for
checkmakeon yourPATH. This hook requires you to installcheckmakeseparately, e.g. with your package manager or a prebuilt binary release. Only recommended if it's permissible to require all repository users installcheckmakemanually.
Then, run pre-commit as usual as a part of git commit or explicitly, for example:
pre-commit run --all-filesYou may also choose to run this as a GitHub Actions workflow. To do this, add a
.github/workflows/pre-commit.yml workflow to your repo:
name: pre-commit
on:
pull_request:
branches:
- master
- main
paths:
- '.pre-commit-config.yaml'
- '.pre-commit-hooks.yaml'
- 'Makefile'
- 'makefile'
- 'GNUmakefile'
- '**.mk'
- '**.make'
push:
paths:
- '.pre-commit-config.yaml'
- '.pre-commit-hooks.yaml'
- 'Makefile'
- 'makefile'
- 'GNUmakefile'
- '**.mk'
- '**.make'
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- name: Set up Go 1.17
uses: actions/setup-go@v2
with:
go-version: 1.17
id: go
- uses: pre-commit/[email protected]With go 1.16 or higher:
go install github.com/checkmake/checkmake/cmd/checkmake@latest
checkmake MakefileOr alternatively, run it directly:
go run github.com/checkmake/checkmake/cmd/checkmake@latest Makefilecheckmake is available in many Linux distributions and package managers. See Repology for full list:
Packages are also available on packagecloud.io.
You'll need Go installed.
git clone https://github.com/checkmake/checkmake
cd checkmake
make checkmakeTo build the man page (optional), install pandoc and run:
make checkmake.1checkmake is natively embedded within MegaLinter
To install it, run npx mega-linter-runner --install (requires Node.js)
This is totally inspired by an idea by Dan Buch.