From aae097cc2020371b3b1a008817354027c9bc8f2c Mon Sep 17 00:00:00 2001
From: Giovanni Bussi <giovanni.bussi@gmail.com>
Date: Fri, 14 Oct 2016 08:54:46 +0200
Subject: [PATCH] Added astyle script

I added a script located in src that applies astyle to
all source files and add them to git. This script can
be invoked as `make astyle`.

File .astyle.options contains the astyle command line options

See #215
---
 .astyle.options   |  1 +
 Makefile          |  7 +++++--
 astyle/.gitignore |  1 +
 astyle/Makefile   |  9 +++++++++
 src/.gitignore    |  5 +++--
 src/Makefile      |  6 +++++-
 src/astyle.sh     | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 70 insertions(+), 5 deletions(-)
 create mode 100644 .astyle.options
 create mode 100644 astyle/.gitignore
 create mode 100644 astyle/Makefile
 create mode 100755 src/astyle.sh

diff --git a/.astyle.options b/.astyle.options
new file mode 100644
index 000000000..0a17526e3
--- /dev/null
+++ b/.astyle.options
@@ -0,0 +1 @@
+-n --indent=spaces=2 --keep-one-line-statements --keep-one-line-blocks
diff --git a/Makefile b/Makefile
index 47ea922b1..c7302fac5 100644
--- a/Makefile
+++ b/Makefile
@@ -4,12 +4,12 @@ endif
 
 
 SRCDIRS := src test
-SUBDIRS := $(SRCDIRS) user-doc developer-doc regtest macports vim
+SUBDIRS := $(SRCDIRS) user-doc developer-doc regtest macports vim astyle
 
 SUBDIRSCLEAN:=$(addsuffix .clean,$(SUBDIRS))
 
      
-.PHONY: all lib clean $(SRCDIRS) doc docclean check cppcheck distclean all_plus_docs macports codecheck plumedcheck
+.PHONY: all lib clean $(SRCDIRS) doc docclean check cppcheck distclean all_plus_docs macports codecheck plumedcheck astyle
 
 # if machine dependent configuration has been found:
 ifdef GCCDEP
@@ -111,5 +111,8 @@ stamp-h: sourceme.sh.in Makefile.conf.in config.status
 config.status: configure
 	./config.status --recheck
 
+astyle:
+	$(MAKE) -C astyle
+	$(MAKE) -C src astyle
 
 
diff --git a/astyle/.gitignore b/astyle/.gitignore
new file mode 100644
index 000000000..dbd60edda
--- /dev/null
+++ b/astyle/.gitignore
@@ -0,0 +1 @@
+astyle
diff --git a/astyle/Makefile b/astyle/Makefile
new file mode 100644
index 000000000..cb01f9b33
--- /dev/null
+++ b/astyle/Makefile
@@ -0,0 +1,9 @@
+.PHONY: astyle
+
+astyle:
+	$(MAKE) -C build/gcc
+	ln -fs build/gcc/bin/astyle .
+
+clean:
+	$(MAKE) -C build/gcc clean
+	rm -f astyle
diff --git a/src/.gitignore b/src/.gitignore
index 668919a38..399e65c9e 100644
--- a/src/.gitignore
+++ b/src/.gitignore
@@ -15,8 +15,6 @@
 !/function
 !/generic
 !/gridtools
-!/header.sh
-!/release.sh
 !/imd
 !/lapack
 !/lib
@@ -33,6 +31,9 @@
 !/vatom
 !/vesselbase
 !/wrapper
+!/header.sh
+!/release.sh
+!/astyle.sh
 
 # And just ignore these files
 *.xxd
diff --git a/src/Makefile b/src/Makefile
index 3a7e14bf2..66b315927 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,5 +1,5 @@
 
-.PHONY: all clean lib install uninstall install-html
+.PHONY: all clean lib install uninstall install-html astyle
 
 # by default we compile the lib directory, which in turn requests all the needeed modules
 all: lib
@@ -49,4 +49,8 @@ help:
 	@echo "  cppcheck: check source (requires cppcheck and gawk installed)"
 	@echo "  plumedcheck: check source (requires gawk installed)"
 
+astyle:
+	$(MAKE) -C ../astyle
+	./astyle.sh
+
 
diff --git a/src/astyle.sh b/src/astyle.sh
new file mode 100755
index 000000000..308b30ae6
--- /dev/null
+++ b/src/astyle.sh
@@ -0,0 +1,46 @@
+#! /bin/bash
+
+DIRS=$1
+
+# remove trailing "/"
+DIRS=${DIRS%%/*}
+
+test -z "$DIRS" && DIRS=*
+
+for dir in $DIRS
+do
+test -d "$dir" || continue
+
+test "$dir" = lapack && continue
+test "$dir" = blas && continue
+test "$dir" = molfile && continue
+
+cd $dir
+
+
+for file in *.c *.cpp *.h *.inc.in
+do
+
+test -f "$file" || continue
+
+echo -n "astyle $file"
+
+../../astyle/astyle --options=../../.astyle.options < $file > $file.tmp && {
+if cmp -s $file $file.tmp ; then
+  echo 
+else
+  cp $file.tmp $file
+  echo " +++ PATCHED"
+  git add $file
+fi
+}
+
+rm $file.tmp
+
+done
+
+cd -
+
+done
+
+
-- 
GitLab