Skip to content

Commit c83464f

Browse files
committed
Makefile - introduce format and tidy target
1 parent f5639eb commit c83464f

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Makefile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@ ifeq ($(CMAKE),)
22
CMAKE := cmake
33
endif
44

5+
ifeq ($(CLANG_FORMAT),)
6+
CLANG_FORMAT := clang-format
7+
endif
8+
9+
ifeq ($(RUN_CLANG_TIDY),)
10+
RUN_CLANG_TIDY := run-clang-tidy
11+
endif
12+
13+
14+
SRC_DIR = "$(shell pwd)/src"
15+
INC_DIR = "$(shell pwd)/include"
16+
17+
SOURCE_DIR = "$(SRC_DIR)" "$(INC_DIR)"
18+
SOURCE_REGEX = '.*\.\(cpp\|hpp\|c\|h\)'
19+
20+
521
.PHONY: all
622
all: build/Makefile
723
@$(MAKE) --no-print-directory -C build
@@ -14,3 +30,19 @@ build/Makefile: | build
1430

1531
build:
1632
@mkdir -p $@
33+
34+
.PHONY: format
35+
format:
36+
@find $(SOURCE_DIR) -type f -regex $(SOURCE_REGEX) -print0 | xargs -0 $(CLANG_FORMAT) --dry-run
37+
38+
.PHONY: format-fix
39+
format-fix:
40+
@find $(SOURCE_DIR) -type f -regex $(SOURCE_REGEX) -print0 | xargs -0 $(CLANG_FORMAT) -i
41+
42+
.PHONY: tidy
43+
tidy: all
44+
$(RUN_CLANG_TIDY) -p build -quiet -j $(shell nproc) -header-filter=$(SOURCE_DIR) $(SOURCE_DIR)
45+
46+
.PHONY: tidy-fix
47+
tidy-fix: all
48+
$(RUN_CLANG_TIDY) -p build -quiet -fix -j $(shell nproc) -header-filter=$(SOURCE_DIR) $(SOURCE_DIR)

0 commit comments

Comments
 (0)