diff --git a/Makefile b/Makefile index ca96777..8d780a2 100644 --- a/Makefile +++ b/Makefile @@ -62,12 +62,22 @@ examples: $(EXAMPLE_DIRS) clean: $(EXAMPLE_DIRS:=.clean) $(Q)$(MAKE) -C libopencm3 clean +stylecheck: $(EXAMPLE_DIRS:=.stylecheck) +styleclean: $(EXAMPLE_DIRS:=.styleclean) + + %.clean: $(Q)if [ -d $* ]; then \ printf " CLEAN $*\n"; \ $(MAKE) -C $* clean OPENCM3_DIR=$(OPENCM3_DIR) || exit $?; \ fi; +%.styleclean: + $(Q)$(MAKE) -C $* styleclean OPENCM3_DIR=$(OPENCM3_DIR) -.PHONY: build lib examples $(EXAMPLE_DIRS) install clean +%.stylecheck: + $(Q)$(MAKE) -C $* stylecheck OPENCM3_DIR=$(OPENCM3_DIR) + + +.PHONY: build lib examples $(EXAMPLE_DIRS) install clean stylecheck styleclean diff --git a/examples/Makefile.rules b/examples/Makefile.rules index 381dedb..27ff601 100644 --- a/examples/Makefile.rules +++ b/examples/Makefile.rules @@ -39,6 +39,10 @@ OBJCOPY := $(PREFIX)-objcopy OBJDUMP := $(PREFIX)-objdump GDB := $(PREFIX)-gdb STFLASH = $(shell which st-flash) +STYLECHECK := /checkpatch.pl +STYLECHECKFLAGS := --no-tree -f --terse --mailback +STYLECHECKFILES := $(shell find . -name '*.[ch]') + ############################################################################### # Source files @@ -163,6 +167,22 @@ clean: @#printf " CLEAN\n" $(Q)$(RM) *.o *.d *.elf *.bin *.hex *.srec *.list *.map +stylecheck: $(STYLECHECKFILES:=.stylecheck) +styleclean: $(STYLECHECKFILES:=.styleclean) + +# the cat is due to multithreaded nature - we like to have consistent chunks of text on the output +%.stylecheck: % + $(Q)$(SCRIPT_DIR)$(STYLECHECK) $(STYLECHECKFLAGS) $* > $*.stylecheck; \ + if [ -s $*.stylecheck ]; then \ + cat $*.stylecheck; \ + else \ + rm -f $*.stylecheck; \ + fi; + +%.styleclean: + $(Q)rm -f $*.stylecheck; + + %.stlink-flash: %.bin @printf " FLASH $<\n" $(Q)$(STFLASH) write $(*).bin 0x8000000 @@ -208,6 +228,6 @@ else $(*).elf endif -.PHONY: images clean +.PHONY: images clean stylecheck styleclean -include $(OBJS:.o=.d) \ No newline at end of file