-file(WRITE ${PROJECT_DIRECTORY}/doc/logcategories.sh "\#! /bin/sh")
-file(APPEND ${PROJECT_DIRECTORY}/doc/logcategories.sh "\npwd=`pwd`")
-file(APPEND ${PROJECT_DIRECTORY}/doc/logcategories.sh "\nrm -f $pwd/logcategories.doc")
-file(APPEND ${PROJECT_DIRECTORY}/doc/logcategories.sh "\nset -e")
-file(APPEND ${PROJECT_DIRECTORY}/doc/logcategories.sh "\necho \"/* Generated file, do not edit */\" > $pwd/logcategories.doc")
-file(APPEND ${PROJECT_DIRECTORY}/doc/logcategories.sh "\necho \"/** \\addtogroup XBT_log_cats\" >> $pwd/logcategories.doc")
-file(APPEND ${PROJECT_DIRECTORY}/doc/logcategories.sh "\necho \" @{\" >> $pwd/logcategories.doc")
-file(APPEND ${PROJECT_DIRECTORY}/doc/logcategories.sh "\ncd ${PROJECT_DIRECTORY}/src")
-file(APPEND ${PROJECT_DIRECTORY}/doc/logcategories.sh "\n${PROJECT_DIRECTORY}/tools/doxygen/xbt_log_extract_hierarchy.pl >> $pwd/logcategories.doc")
-file(APPEND ${PROJECT_DIRECTORY}/doc/logcategories.sh "\necho \"@}*/\" >> $pwd/logcategories.doc")
-
-exec_program("chmod a=rwx ${PROJECT_DIRECTORY}/doc/logcategories.sh" "${PROJECT_DIRECTORY}/doc/")
-exec_program("${PROJECT_DIRECTORY}/doc/logcategories.sh" "${PROJECT_DIRECTORY}/doc/"
-ARGS ${DOCSSOURCES})
-
-
-file(WRITE ${PROJECT_DIRECTORY}/doc/realtoc.sh "\#! /bin/sh")
-file(APPEND ${PROJECT_DIRECTORY}/doc/realtoc.sh "\n\necho \"Check individual TOCs\"")
-file(APPEND ${PROJECT_DIRECTORY}/doc/realtoc.sh "\nfor n in gtut-tour-*.doc ; do")
-file(APPEND ${PROJECT_DIRECTORY}/doc/realtoc.sh "\n sed -n '/Table of Contents/,/hr/p' $n|grep ref > tmp.curtoc;")
-file(APPEND ${PROJECT_DIRECTORY}/doc/realtoc.sh "\n grep -E '\\\\s?u?b?section' $n | grep -v _toc | sed -e 's/\\\\section //' -e 's/\\\\subsection /subsection/' -e 's/ .*//' | sed -e 's/^/ - \\\\ref /' -e 's/- \\\\ref subsection/ - \\\\ref /' > tmp.realtoc;")
-file(APPEND ${PROJECT_DIRECTORY}/doc/realtoc.sh "\n if ! diff -q tmp.curtoc tmp.realtoc >/dev/null; then")
-file(APPEND ${PROJECT_DIRECTORY}/doc/realtoc.sh "\n echo \"Wrong toc for $n. Should be ;\"")
-file(APPEND ${PROJECT_DIRECTORY}/doc/realtoc.sh "\n cat tmp.realtoc;")
-file(APPEND ${PROJECT_DIRECTORY}/doc/realtoc.sh "\n fi ;")
-file(APPEND ${PROJECT_DIRECTORY}/doc/realtoc.sh "\ndone")
-file(APPEND ${PROJECT_DIRECTORY}/doc/realtoc.sh "\n\nrm tmp.realtoc tmp.curtoc")
-file(APPEND ${PROJECT_DIRECTORY}/doc/realtoc.sh "\necho \"Check main TOC\"")
-file(APPEND ${PROJECT_DIRECTORY}/doc/realtoc.sh "\nfor n in gtut-tour-*doc; do")
-file(APPEND ${PROJECT_DIRECTORY}/doc/realtoc.sh "\n grep @page $n | sed -e 's/@page //' -e 's/ .*//' -e 's/^/ - \\\\ref /' >>tmp.realtoc;")
-file(APPEND ${PROJECT_DIRECTORY}/doc/realtoc.sh "\n sed -n -e '/Table of Contents/,/hr/p' $n|sed -e 's/^/ /'| grep -v toc|grep -v '<hr>'|grep [^[:blank:]] >>tmp.realtoc;")
-file(APPEND ${PROJECT_DIRECTORY}/doc/realtoc.sh "\ndone")
-file(APPEND ${PROJECT_DIRECTORY}/doc/realtoc.sh "\ngrep ' *- \\\\ref' gtut-tour.doc > tmp.curtoc")
-file(APPEND ${PROJECT_DIRECTORY}/doc/realtoc.sh "\nif ! diff -b -u tmp.curtoc tmp.realtoc ; then")
-file(APPEND ${PROJECT_DIRECTORY}/doc/realtoc.sh "\n echo \"Wrong toc for gtut-tour.doc Right one is in tmp.realtoc\";")
-file(APPEND ${PROJECT_DIRECTORY}/doc/realtoc.sh "\nelse")
-file(APPEND ${PROJECT_DIRECTORY}/doc/realtoc.sh "\n rm tmp.realtoc;")
-file(APPEND ${PROJECT_DIRECTORY}/doc/realtoc.sh "\nfi ;")
-file(APPEND ${PROJECT_DIRECTORY}/doc/realtoc.sh "\nrm tmp.curtoc")
-
-exec_program("chmod a=rwx ${PROJECT_DIRECTORY}/doc/realtoc.sh" "${PROJECT_DIRECTORY}/doc/")
-exec_program("${PROJECT_DIRECTORY}/doc/realtoc.sh" "${PROJECT_DIRECTORY}/doc/")
+file(REMOVE ${PROJECT_DIRECTORY}/doc/logcategories.doc)
+file(APPEND ${PROJECT_DIRECTORY}/doc/logcategories.doc "/* Generated file, do not edit */\n")
+file(APPEND ${PROJECT_DIRECTORY}/doc/logcategories.doc "/** \\addtogroup XBT_log_cats\n")
+file(APPEND ${PROJECT_DIRECTORY}/doc/logcategories.doc " @{\n")
+exec_program("${PROJECT_DIRECTORY}/tools/doxygen/xbt_log_extract_hierarchy.pl" "${PROJECT_DIRECTORY}/src" OUTPUT_VARIABLE output_log_extract_hierarchy)
+file(APPEND ${PROJECT_DIRECTORY}/doc/logcategories.doc "${output_log_extract_hierarchy}\n")
+file(APPEND ${PROJECT_DIRECTORY}/doc/logcategories.doc "@}*/")
+
+file(WRITE ${PROJECT_DIRECTORY}/doc/realtoc.sh "\#! /bin/sh")
+
+message("Check individual TOCs")
+file(GLOB_RECURSE LISTE_GTUT
+"${PROJECT_DIRECTORY}/doc/gtut-tour-*.doc"
+)
+
+
+
+foreach(file_name ${LISTE_GTUT})
+ file(REMOVE ${PROJECT_DIRECTORY}/doc/tmp.curtoc)
+ file(REMOVE ${PROJECT_DIRECTORY}/doc/tmp.realtoc)
+
+ file(READ "${file_name}" file_content)
+ string(REGEX MATCH "Table of Contents.*<hr>" valeur_line "${file_content}")
+ string(REPLACE "\n" ";" valeur_line "${valeur_line}")
+ string(REPLACE "\n" ";" file_content "${file_content}")
+
+ foreach(line ${file_content})
+ string(REGEX MATCH "[\\]s?u?b?section.*" line2 "${line}")
+ string(REGEX MATCH ".*_toc.*" line3 "${line}")
+ if(line2 AND NOT line3)
+ string(REPLACE "\\section " "" line2 ${line2})
+ string(REPLACE "\\subsection " "subsection" line2 ${line2})
+ string(REGEX REPLACE " .*" "" line2 ${line2})
+ set(line2 " - \\ref ${line2}")
+ string(REPLACE " - \\ref subsection" " - \\ref " line2 ${line2})
+ file(APPEND ${PROJECT_DIRECTORY}/doc/tmp.realtoc "${line2}\n")
+ endif(line2 AND NOT line3)
+ endforeach(line ${file_content})
+
+ foreach(line ${valeur_line})
+ string(REGEX MATCH ".*ref.*" line_ok ${line})
+ if(line_ok)
+ file(APPEND ${PROJECT_DIRECTORY}/doc/tmp.curtoc "${line_ok}\n")
+ endif(line_ok)
+ endforeach(line ${valeur_line})
+
+ exec_program("${CMAKE_COMMAND} -E compare_files ${PROJECT_DIRECTORY}/doc/tmp.curtoc ${PROJECT_DIRECTORY}/doc/tmp.realtoc" OUTPUT_VARIABLE compare_files)
+ if(compare_files)
+ message("Wrong toc for ${file_name}. Should be;")
+ file(READ "${PROJECT_DIRECTORY}/doc/tmp.realtoc" file_content)
+ message("${file_content}")
+ endif(compare_files)
+endforeach(file_name ${LISTE_GTUT})
+
+file(REMOVE ${PROJECT_DIRECTORY}/doc/tmp.curtoc)
+file(REMOVE ${PROJECT_DIRECTORY}/doc/tmp.realtoc)
+
+message("Check main TOC")
+
+foreach(file_name ${LISTE_GTUT})
+ file(READ "${file_name}" file_content)
+ string(REGEX MATCH "Table of Contents.*<hr>" valeur_line "${file_content}")
+ string(REPLACE "\n" ";" valeur_line "${valeur_line}")
+ string(REPLACE "\n" ";" file_content "${file_content}")
+
+ foreach(line ${file_content})
+ string(REGEX MATCH ".*@page.*" line2 "${line}")
+ if(line2)
+ string(REPLACE "@page " "" line2 "${line2}")
+ string(REGEX REPLACE " .*" "" line2 "${line2}")
+ set(line2 " - \\ref ${line2}")
+ file(APPEND ${PROJECT_DIRECTORY}/doc/tmp.realtoc "${line2}\n")
+ endif(line2)
+ endforeach(line ${file_content})
+
+ foreach(line ${valeur_line})
+ string(REGEX MATCH ".*toc.*" line1 "${line}")
+ string(REGEX MATCH ".*<hr>.*" line2 "${line}")
+ string(REGEX MATCH "^[ ]*$" line3 "${line}")
+ string(REGEX MATCH "Table of Contents" line4 "${line}")
+ if(NOT line1 AND NOT line2 AND NOT line3 AND NOT line4)
+ file(APPEND ${PROJECT_DIRECTORY}/doc/tmp.realtoc " ${line}\n")
+ endif(NOT line1 AND NOT line2 AND NOT line3 AND NOT line4)
+ endforeach(line ${valeur_line})
+endforeach(file_name ${LISTE_GTUT})
+
+file(READ "${PROJECT_DIRECTORY}/doc/gtut-tour.doc" file_content)
+string(REPLACE "\n" ";" file_content "${file_content}")
+foreach(line ${file_content})
+ string(REGEX MATCH "^[ ]+.*\\ref" line1 "${line}")
+ if(line1)
+ file(APPEND ${PROJECT_DIRECTORY}/doc/tmp.curtoc "${line}\n")
+ endif(line1)
+endforeach(line ${file_content})
+
+exec_program("${CMAKE_COMMAND} -E compare_files ${PROJECT_DIRECTORY}/doc/tmp.curtoc ${PROJECT_DIRECTORY}/doc/tmp.realtoc" OUTPUT_VARIABLE compare_files)
+if(compare_files)
+ message("Wrong toc for gtut-tour.doc Right one is in tmp.realtoc")
+else(compare_files)
+ file(REMOVE ${PROJECT_DIRECTORY}/doc/tmp.realtoc)
+endif(compare_files)
+
+file(REMOVE ${PROJECT_DIRECTORY}/doc/tmp.curtoc)
+