diff --git a/Makefile b/Makefile index 819b1b3..613b445 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -.PHONY : default debug clean test +.PHONY : default debug clean test lint cppcheck make = make plt = $(shell uname) @@ -20,3 +20,9 @@ clean: test: default @./test/run.sh + +lint: + @$(make) -C src -f Makefile lint + +cppcheck: + @$(make) -C src -f Makefile cppcheck diff --git a/src/Makefile b/src/Makefile index 46b6787..dc0e397 100644 --- a/src/Makefile +++ b/src/Makefile @@ -94,7 +94,25 @@ objs = \ Proxy.o \ main.o -.PHONY : default debug clean +SRCS = $(objs:.o=.cpp) +LINT_SRCS ?= $(SRCS) + +CLANG_TIDY ?= clang-tidy +ifeq ($(shell command -v brew 2>/dev/null),) + CLANG_TIDY_BREW := +else + LLVM_PREFIX := $(shell brew --prefix llvm 2>/dev/null) + CLANG_TIDY_BREW := $(LLVM_PREFIX)/bin/clang-tidy +endif +ifeq ($(shell command -v $(CLANG_TIDY) 2>/dev/null),) + CLANG_TIDY_CMD := $(CLANG_TIDY_BREW) +else + CLANG_TIDY_CMD := $(CLANG_TIDY) +endif +CPPCHECK ?= cppcheck +CPPCHECK_FLAGS ?= --std=c++11 --enable=warning,performance,style --suppress=missingIncludeSystem + +.PHONY : default debug clean lint cppcheck default: $(target) @@ -109,6 +127,20 @@ clean: @rm -rf $(objs) $(target) @echo Done. +lint: + @command -v "$(CLANG_TIDY_CMD)" >/dev/null 2>&1 || { \ + echo "error: clang-tidy not found; set CLANG_TIDY or install llvm via Homebrew"; \ + exit 1; \ + } + $(CLANG_TIDY_CMD) $(LINT_SRCS) -- $(CFLAGS) $(INCFLAGS) + +cppcheck: + @command -v "$(CPPCHECK)" >/dev/null 2>&1 || { \ + echo "error: cppcheck not found; set CPPCHECK or install cppcheck via Homebrew"; \ + exit 1; \ + } + $(CPPCHECK) $(CPPCHECK_FLAGS) $(INCFLAGS) $(LINT_SRCS) + %.o : %.cpp $(CXX) $(CFLAGS) -c $^ $(INCFLAGS)