diff --git a/cmake/modules/DumuxDoxygen.cmake b/cmake/modules/DumuxDoxygen.cmake
index 109786e671d7feda9708ea0fa7dda3ea8d4fea9f..f9d6be18138e09e471046e1308974aeb2eca897a 100644
--- a/cmake/modules/DumuxDoxygen.cmake
+++ b/cmake/modules/DumuxDoxygen.cmake
@@ -4,8 +4,11 @@
 MACRO (add_dumux_doxygen_target)
   if(DOXYGEN_FOUND)
     add_doxygen_target()
+    add_custom_target(doxygen_${ProjectName}_prebuild
+                      COMMAND rm -rf ${CMAKE_BINARY_DIR}/doc/doxygen/html)
+    add_dependencies(doxygen_${ProjectName} doxygen_${ProjectName}_prebuild)
     add_custom_command(TARGET doxygen_${ProjectName}
                        POST_BUILD
                        COMMAND ${CMAKE_SOURCE_DIR}/doc/doxygen/sanitizelinks.sh)
   endif()
-ENDMACRO (add_dumux_doxygen_target)
+ENDMACRO ()
diff --git a/doc/doxygen/sanitizelinks.sh b/doc/doxygen/sanitizelinks.sh
index afdd216f66c9310921d7ee747ea7213826857972..f23c1417bd50ac515cbdf71db756eda02913c623 100755
--- a/doc/doxygen/sanitizelinks.sh
+++ b/doc/doxygen/sanitizelinks.sh
@@ -1,6 +1,6 @@
 # sanitizes the links to the given lists, because doxygen somehow links
 # to a page with a wrong index
-function sanitizelinks {
+sanitizelinks () {
   NEW_FILE=`grep -l "\"title\">$1" html/*html | egrep -o [0-9]+`
   OLD_FILE=`awk -v a=$NEW_FILE 'BEGIN {printf("%05d", a-1)}'`
   sed -i "s/$OLD_FILE/$NEW_FILE/g" html/*html