diff --git a/flymake.mk b/flymake.mk
new file mode 100644
index 0000000000000000000000000000000000000000..b4136e5324fc6b6687738afdb74332e04951e449
--- /dev/null
+++ b/flymake.mk
@@ -0,0 +1,13 @@
+# Taken from http://www.emacswiki.org/emacs/FlyMake#toc4
+
+get_cs_flags = $(foreach target,$(subst .,_,$(subst -,_,$($(2)))),$($(target)_$(1)FLAGS))
+get_cs_all_flags = $(foreach type,$(2),$(call get_cs_flags,$(1),$(type)))
+get_cs_compile = $(if $(subst C,,$(1)),$($(1)COMPILE),$(COMPILE))
+get_cs_cmdline = $(call get_cs_compile,$(1)) $(call get_cs_all_flags,$(1),check_PROGRAMS bin_PROGRAMS lib_LTLIBRARIES) -fsyntax-only
+
+.PHONY: check-syntax
+check-syntax:
+	s=$(suffix $(CHK_SOURCES));\
+	if   [ "$$s" = ".c"   ]; then LANG=C $(call get_cs_cmdline,C) $(CHK_SOURCES);\
+	elif [ "$$s" = ".cc" ]; then LANG=C $(call get_cs_cmdline,CXX) $(call get_cs_cmdline,CPP) $(CHK_SOURCES);\
+	else exit 1; fi
diff --git a/src/Makefile.am b/src/Makefile.am
index a57492b1cb9bf96fd43477ee5d52f78bb773a7b5..2cd56b5cdae128701557241ddfe393acfa1d4301 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -39,3 +39,4 @@ DISTCHECK_CONFIGURE_FLAGS = --with-dune-common=$(DUNE_COMMON_ROOT) --with-dune-f
 
 include $(top_srcdir)/am/global-rules
 
+include $(top_srcdir)/flymake.mk
diff --git a/src/bisection-simpler-example.cc b/src/bisection-simpler-example.cc
index f3ca72735d7fe8dee4a67b787db88eb7de2a5560..e38deb6bb457e820a5dcb50d23657cbe3d749282 100644
--- a/src/bisection-simpler-example.cc
+++ b/src/bisection-simpler-example.cc
@@ -1,3 +1,5 @@
+/* -*- mode:c++; mode: flymake -*- */
+
 #include <dune/fufem/interval.hh>
 
 #include <dune/tnnmg/nonlinearities/smallfunctional.hh>
diff --git a/src/bisection-simpler-example2-gradient.cc b/src/bisection-simpler-example2-gradient.cc
index 2637a48f22223cf97f9b32d60a3e67ba439ef97e..c4bc87d9572f0b1b8e2152f59a302a3859b5b5a0 100644
--- a/src/bisection-simpler-example2-gradient.cc
+++ b/src/bisection-simpler-example2-gradient.cc
@@ -1,3 +1,5 @@
+/* -*- mode:c++; mode: flymake -*- */
+
 // FIXME: is there a bette way to do this?
 //#define DUNE_MINIMAL_DEBUG_LEVEL 2
 #include <dune/common/stdstreams.hh>
diff --git a/src/bisection-simpler-example2.cc b/src/bisection-simpler-example2.cc
index dde6268c3e7e382d334cb71563ebac0a8f2ccc2e..840cd002faf1b2fcca565ff98be921c91eec42b2 100644
--- a/src/bisection-simpler-example2.cc
+++ b/src/bisection-simpler-example2.cc
@@ -1,3 +1,5 @@
+/* -*- mode:c++; mode: flymake -*- */
+
 #include <dune/fufem/interval.hh>
 
 #include <dune/tnnmg/nonlinearities/smallfunctional.hh>