Makefile 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # OpenPuck developer convenience targets.
  2. # Pin to clang-format 18 to match CI; output differs between versions, so a
  3. # mismatch would make CI reject locally-formatted code. Resolve the binary in
  4. # order of preference: the apt-style versioned name (CI / Linux), the Homebrew
  5. # llvm@18 keg (macOS), then a bare clang-format as a last resort. Override with
  6. # `make format CLANG_FORMAT=/path/to/clang-format` if yours lives elsewhere.
  7. CLANG_FORMAT ?= $(shell command -v clang-format-18 \
  8. || ([ -x /opt/homebrew/opt/llvm@18/bin/clang-format ] && echo /opt/homebrew/opt/llvm@18/bin/clang-format) \
  9. || ([ -x /usr/local/opt/llvm@18/bin/clang-format ] && echo /usr/local/opt/llvm@18/bin/clang-format) \
  10. || command -v clang-format)
  11. # All hand-written C/C++ sources. Generated headers (git_version.h) are
  12. # gitignored and excluded here so formatting never touches them.
  13. FORMAT_FILES := $(shell find OpenPuck ReversePuckFirmware puck_sniffer pairtui \
  14. \( -name '*.c' -o -name '*.cpp' -o -name '*.h' -o -name '*.hpp' -o -name '*.ino' \) \
  15. -not -name 'git_version.h')
  16. .PHONY: format format-check lint check
  17. ## Reformat all C/C++ sources in place using the Linux kernel style.
  18. format:
  19. $(CLANG_FORMAT) -i $(FORMAT_FILES)
  20. ## Verify all C/C++ sources are formatted; exit non-zero if any differ.
  21. ## Used by CI to reject unformatted code.
  22. format-check:
  23. $(CLANG_FORMAT) --dry-run --Werror $(FORMAT_FILES)
  24. ## Style rules clang-format can't enforce. Currently: a long trailing //
  25. ## comment must be moved onto its own line above the statement (clang-format
  26. ## won't relocate it, so it would otherwise split the code or run past 80).
  27. lint:
  28. python3 tools/check-trailing-comments.py $(FORMAT_FILES)
  29. ## Everything CI gates on.
  30. check: format-check lint