Skip to content

Commit d0cbdcc

Browse files
udrechslernopeslide
authored andcommitted
makefile: added uncrustify target for code format
1 parent e4289ce commit d0cbdcc

File tree

4 files changed

+3080
-0
lines changed

4 files changed

+3080
-0
lines changed

.Makefile.mk

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ VARIABLE+=ESPPORT
88
HELP_ESPPORT=which device to flash/monitor
99
export ESPPORT
1010

11+
VARIABLE+=FORMAT
12+
HELP_FORMAT=patterns of files to format
13+
ifndef FORMAT
14+
FORMAT += **/*.h
15+
FORMAT += **/*.c
16+
endif
17+
1118
### internal variables ###
1219

1320
# assume /etc/passwd holds right shell of user
@@ -31,6 +38,8 @@ TEMPLATEPATH=../.Makefile.template
3138
### default target ###
3239
DEFAULT += help
3340

41+
UNCRUSTIFY_CFG = ./.uncrustify.cfg
42+
3443
### menuconfig targets ###
3544

3645
.PHONY: menuconfig
@@ -107,6 +116,28 @@ CHECK += check-monitor
107116
HELP_check-monitor = check env if monitor is possible
108117
check-monitor: | check-docker check-dev
109118

119+
### uncrustidy code format
120+
121+
.PHONY: uncrustify
122+
TARGET += uncrustify
123+
HELP_uncrustify = formats code with uncrustify
124+
uncrustify: | check-docker
125+
@make --no-print-directory -C $(DOCKERDIR) uncrustify \
126+
EXEC="git ls-files -ico $(foreach PATTERN,$(FORMAT),-x $(PATTERN)) \
127+
| xargs -I % uncrustify -c $(UNCRUSTIFY_CFG) --replace --no-backup %"
128+
129+
.PHONY: check-uncrustify
130+
TARGET += check-uncrustify
131+
HELP_check-uncrustify = check if formatting code with uncrustify is necessary
132+
check-uncrustify: | check-docker
133+
@make --no-print-directory -C $(DOCKERDIR) uncrustify \
134+
EXEC="git ls-files -ico $(foreach PATTERN,$(FORMAT),-x $(PATTERN)) \
135+
| xargs -I % sh -c \"uncrustify -c $(UNCRUSTIFY_CFG) -f % \
136+
| git diff --exit-code \
137+
--no-index \
138+
--color \
139+
% - \""
140+
110141
### vscode ###
111142

112143
.PHONY: vscode

0 commit comments

Comments
 (0)