@@ -66,6 +66,10 @@ OBJ := main.o \
6666
6767INCLUDES := -Itclap -Iinclude -Ispiffs/src -I.
6868
69+ FILES_TO_FORMAT := $(shell find . -not -path './spiffs/* ' \( -name '* .c' -o -name '* .cpp' \) )
70+
71+ DIFF_FILES := $(addsuffix .diff,$(FILES_TO_FORMAT ) )
72+
6973# clang doesn't seem to handle -D "ARG=\"foo bar\"" correctly, so replace spaces with \x20:
7074BUILD_CONFIG_STR := $(shell echo $(CPPFLAGS ) | sed 's- -\\\\x20-')
7175
@@ -86,8 +90,6 @@ DIST_NAME := mkspiffs-$(VERSION)$(BUILD_CONFIG_NAME)-$(TARGET_OS)
8690DIST_DIR := $(DIST_NAME )
8791DIST_ARCHIVE := $(DIST_NAME ) .$(ARCHIVE_EXTENSION )
8892
89- .PHONY : all clean dist
90-
9193all : $(TARGET )
9294
9395dist : $(DIST_ARCHIVE )
@@ -108,7 +110,7 @@ $(DIST_DIR):
108110 @mkdir -p $@
109111
110112clean :
111- @rm -f $(TARGET ) $(OBJ )
113+ @rm -f $(TARGET ) $(OBJ ) $( DIFF_FILES )
112114
113115SPIFFS_TEST_FS_CONFIG := -s 0x100000 -p 512 -b 0x2000
114116
@@ -132,3 +134,19 @@ test: $(TARGET)
132134 diff spiffs_t spiffs_u
133135 rm -f out.{list0,list1,list2,list_u,spiffs_t}
134136 rm -R spiffs_u spiffs_t
137+
138+ format-check : $(DIFF_FILES )
139+ @rm -f $(DIFF_FILES )
140+
141+ $(DIFF_FILES ) : % .diff: %
142+ @./format.sh < $< > $< .new
143+ @diff $< .new $< > $@ || ( \
144+ echo " File $^ not formatted correctly. Please use format.sh to re-format it." && \
145+ echo " Here's the diff that caused an error:" && \
146+ echo " " && \
147+ cat $@ && \
148+ rm $@ $< .new && \
149+ exit 1 )
150+ @rm -f $@ $< .new
151+
152+ .PHONY : all clean dist format-check
0 commit comments