summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorSjoerd Simons <sjoerd@luon.net>2009-03-17 19:41:23 +0000
committerSjoerd Simons <sjoerd@luon.net>2009-03-17 19:41:23 +0000
commit952f5bd31390e6d0e291e95e7035628e5e6f8ee9 (patch)
tree9543776a4c0715b9d9990ed2103a9c0165138604 /tools
parent467cc8de580acb2fd89a7e0f827c75408aadf526 (diff)
Add basic build infrastructure
Diffstat (limited to 'tools')
-rw-r--r--tools/Makefile.am5
-rw-r--r--tools/check-c-style.sh56
-rw-r--r--tools/check-coding-style.mk17
-rw-r--r--tools/check-misc.sh13
-rw-r--r--tools/check-whitespace.sh17
5 files changed, 108 insertions, 0 deletions
diff --git a/tools/Makefile.am b/tools/Makefile.am
new file mode 100644
index 0000000..7188449
--- /dev/null
+++ b/tools/Makefile.am
@@ -0,0 +1,5 @@
+EXTRA_DIST = \
+ check-coding-style.mk \
+ check-c-style.sh \
+ check-misc.sh \
+ check-whitespace.sh
diff --git a/tools/check-c-style.sh b/tools/check-c-style.sh
new file mode 100644
index 0000000..dd62fb7
--- /dev/null
+++ b/tools/check-c-style.sh
@@ -0,0 +1,56 @@
+#!/bin/sh
+fail=0
+
+( . "${tools_dir}"/check-misc.sh ) || fail=$?
+
+if grep -n '^ *GError *\*[[:alpha:]_][[:alnum:]_]* *;' "$@"
+then
+ echo "^^^ The above files contain uninitialized GError*s - they should be"
+ echo " initialized to NULL"
+ fail=1
+fi
+
+# The first regex finds function calls like foo() (as opposed to foo ()).
+# It attempts to ignore string constants (may cause false negatives).
+# The second and third ignore block comments (gtkdoc uses foo() as markup).
+# The fourth ignores cpp so you can
+# #define foo(bar) (_real_foo (__FUNC__, bar)) (cpp insists on foo() style).
+if grep -n '^[^"]*[[:lower:]](' "$@" \
+ | grep -v '^[-[:alnum:]_./]*:[[:digit:]]*: *\*' \
+ | grep -v '^[-[:alnum:]_./]*:[[:digit:]]*: */\*' \
+ | grep -v '^[-[:alnum:]_./]*:[[:digit:]]*: *#'
+then
+ echo "^^^ Our coding style is to use function calls like foo (), not foo()"
+ fail=1
+fi
+
+if grep -En '[(][[:alnum:]_]+ ?\*[)][(]?[[:alpha:]_]' "$@"; then
+ echo "^^^ Our coding style is to have a space between a cast and the "
+ echo " thing being cast"
+ fail=1
+fi
+
+# this only spots casts
+if grep -En '[(][[:alnum:]_]+\*+[)]' "$@"; then
+ echo "^^^ Our coding style is to have a space before the * of pointer types"
+ echo " (regex 1)"
+ fail=1
+fi
+# ... and this only spots variable declarations and function return types
+if grep -En '^ *(static |const |)* *[[:alnum:]_]+\*+([[:alnum:]_]|;|$)' \
+ "$@"; then
+ echo "^^^ Our coding style is to have a space before the * of pointer types"
+ echo " (regex 2)"
+ fail=1
+fi
+
+if test -n "$CHECK_FOR_LONG_LINES"
+then
+ if egrep -n '.{80,}' "$@"
+ then
+ echo "^^^ The above files contain long lines"
+ fail=1
+ fi
+fi
+
+exit $fail
diff --git a/tools/check-coding-style.mk b/tools/check-coding-style.mk
new file mode 100644
index 0000000..3fc92fc
--- /dev/null
+++ b/tools/check-coding-style.mk
@@ -0,0 +1,17 @@
+check-coding-style:
+ @fail=0; \
+ if test -n "$(check_misc_sources)"; then \
+ tools_dir=$(top_srcdir)/tools \
+ sh $(top_srcdir)/tools/check-misc.sh \
+ $(check_misc_sources) || fail=1; \
+ fi; \
+ if test -n "$(check_c_sources)"; then \
+ tools_dir=$(top_srcdir)/tools \
+ sh $(top_srcdir)/tools/check-c-style.sh \
+ $(check_c_sources) || fail=1; \
+ fi;\
+ if test yes = "$(ENABLE_CODING_STYLE_CHECKS)"; then \
+ exit "$$fail";\
+ else \
+ exit 0;\
+ fi
diff --git a/tools/check-misc.sh b/tools/check-misc.sh
new file mode 100644
index 0000000..89e8e87
--- /dev/null
+++ b/tools/check-misc.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+fail=0
+
+( . "${tools_dir}"/check-whitespace.sh ) || fail=$?
+
+if egrep '(Free\s*Software\s*Foundation.*02139|02111-1307)' "$@"
+then
+ echo "^^^ The above files contain the FSF's old address in GPL headers"
+ fail=1
+fi
+
+exit $fail
diff --git a/tools/check-whitespace.sh b/tools/check-whitespace.sh
new file mode 100644
index 0000000..5348331
--- /dev/null
+++ b/tools/check-whitespace.sh
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+fail=0
+
+if grep -n ' $' "$@"
+then
+ echo "^^^ The above files contain unwanted trailing spaces"
+ fail=1
+fi
+
+if grep -n ' ' "$@"
+then
+ echo "^^^ The above files contain tabs"
+ fail=1
+fi
+
+exit $fail