From f205f9db8760518ec38bc6e4a972207e67f18f80 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Tue, 12 Mar 2019 00:11:27 +0100 Subject: [PATCH] make style: take care of EOF LF --- HACKING.txt | 8 +++----- Makefile | 8 +++++++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/HACKING.txt b/HACKING.txt index 69eb96201..9d7bdaedc 100644 --- a/HACKING.txt +++ b/HACKING.txt @@ -258,9 +258,7 @@ you shouldn't use it (same for _FOOBAR_H). === WHITESPACE === -Avoid trailing whitespace (no line should end in tab or space). People forget -this all the time if their editor doesn't handle it, but don't be surprised if -you see someone fixing it from time to time. -"make style" will take care of that. - +Avoid trailing whitespace (no line should end in tab or space). Keep a newline (blank line) at the end of each file. + +"make style" will take care of both. diff --git a/Makefile b/Makefile index 14bf98074..6e7c9abd5 100644 --- a/Makefile +++ b/Makefile @@ -106,8 +106,14 @@ endif print-%: ; @echo $* = $($*) style: + # Make sure astyle is installed @which astyle >/dev/null || ( echo "Please install 'astyle' package first" ; exit 1 ) - find . \( -name "*.[ch]" -or -name "*.cpp" -or -name "*.lua" -or -name "Makefile" \) -exec perl -pi -e 's/[ \t\r]+$$//' {} \; + # Remove spaces & tabs at EOL, add LF at EOF if needed on *.c, *.h, *.cpp. *.lua, *.py, *.pl, Makefile + find . \( -name "*.[ch]" -or -name "*.cpp" -or -name "*.lua" -or -name "*.py" -or -name "*.pl" -or -name "Makefile" \) \ + -exec perl -pi -e 's/[ \t\r]+$$//' {} \; \ + -exec sh -c "tail -c1 {} | xxd -p | tail -1 | grep -q -v 0a$$" \; \ + -exec sh -c "echo >> {}" \; + # Apply astyle on *.c, *.h, *.cpp find . \( -name "*.[ch]" -or -name "*.cpp" \) -exec astyle --formatted --mode=c --suffix=none \ --indent=spaces=4 --indent-switches --indent-preprocessor \ --keep-one-line-blocks --max-instatement-indent=60 \