From 2ca63f51b8d301c79b0d74b0aa88190dee99cff1 Mon Sep 17 00:00:00 2001
From: Giovanni Bussi <giovanni.bussi@gmail.com>
Date: Wed, 30 Mar 2016 19:13:03 +0200
Subject: [PATCH] Possibility to choose if manual is needed at configure time

[makedoc]
---
 Makefile.conf.in       |  2 ++
 configure              | 77 ++++++++++++++++++++++++++++++++++++++++--
 configure.ac           | 31 ++++++++++++++++-
 developer-doc/Makefile |  4 +++
 user-doc/Intro.txt     |  7 ++--
 user-doc/Makefile      |  7 ++--
 user-doc/extract       | 12 +++++++
 user-doc/go-doxygen    |  4 +++
 8 files changed, 133 insertions(+), 11 deletions(-)

diff --git a/Makefile.conf.in b/Makefile.conf.in
index adc18cda0..b525a10a4 100644
--- a/Makefile.conf.in
+++ b/Makefile.conf.in
@@ -18,6 +18,8 @@ program_name=@program_name@
 program_transform_name=@program_transform_name@
 program_can_run_mpi=@program_can_run_mpi@
 program_can_run=@program_can_run@
+make_pdfdoc=@make_pdfdoc@
+make_doc=@make_doc@
 PACKAGE_TARNAME=@program_name@
 LD_RO=@LD_RO@
 exec_prefix=@exec_prefix@
diff --git a/configure b/configure
index 2586638be..87bd64d43 100755
--- a/configure
+++ b/configure
@@ -626,8 +626,10 @@ LD_RO
 program_can_run_mpi
 program_can_run
 xxd
+make_pdfdoc
 dot
 doxygen
+make_doc
 LD
 OPENMP_CXXFLAGS
 EGREP
@@ -691,6 +693,8 @@ ac_subst_files=''
 ac_user_opts='
 enable_option_checking
 enable_modules
+enable_doc
+enable_pdfdoc
 enable_debug
 enable_basic_warnings
 enable_fussy
@@ -1349,6 +1353,8 @@ Optional Features:
   --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
   --enable-modules        all/none/reset or : separated list such as
                           +crystallization:-bias default: reset
+  --enable-doc            enable documentation, default: yes
+  --enable-pdfdoc         enable pdf version of the manual, default: yes
   --enable-debug          enable debugging, default: no
   --enable-basic-warnings enable basic warnings, default: yes
   --enable-fussy          enable fussy warnings, default: no
@@ -2392,6 +2398,42 @@ fi
 
 # set enable flags for ./configure
 
+doc=
+# Check whether --enable-doc was given.
+if test "${enable_doc+set}" = set; then :
+  enableval=$enable_doc; case "${enableval}" in
+             (yes) doc=true ;;
+             (no)  doc=false ;;
+             (*)   as_fn_error $? "wrong argument to --enable-doc" "$LINENO" 5 ;;
+  esac
+else
+  case "yes" in
+             (yes) doc=true ;;
+             (no)  doc=false ;;
+  esac
+
+fi
+
+
+
+pdfdoc=
+# Check whether --enable-pdfdoc was given.
+if test "${enable_pdfdoc+set}" = set; then :
+  enableval=$enable_pdfdoc; case "${enableval}" in
+             (yes) pdfdoc=true ;;
+             (no)  pdfdoc=false ;;
+             (*)   as_fn_error $? "wrong argument to --enable-pdfdoc" "$LINENO" 5 ;;
+  esac
+else
+  case "yes" in
+             (yes) pdfdoc=true ;;
+             (no)  pdfdoc=false ;;
+  esac
+
+fi
+
+
+
 debug=
 # Check whether --enable-debug was given.
 if test "${enable_debug+set}" = set; then :
@@ -6532,6 +6574,13 @@ $as_echo "$as_me: WARNING: dynamic library will be disabled" >&2;}
 fi
 #### Options for dynamic library to work properly ####
 
+
+make_doc=no
+if test "$doc" == true
+then
+
+make_doc=yes
+
 ### Look for doxygen
 # Extract the first word of "doxygen", so it can be a program name with args.
 set dummy doxygen; ac_word=$2
@@ -6578,8 +6627,9 @@ then
     { $as_echo "$as_me:${as_lineno-$LINENO}: Doxygen version is fine" >&5
 $as_echo "$as_me: Doxygen version is fine" >&6;}
   else
-    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Doxygen version is <1.8. You might have problems in generating manuals" >&5
-$as_echo "$as_me: WARNING: Doxygen version is <1.8. You might have problems in generating manuals" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Doxygen version is <1.8" >&5
+$as_echo "$as_me: WARNING: Doxygen version is <1.8" >&2;}
+    make_doc=no
   fi
   # Extract the first word of "dot", so it can be a program name with args.
 set dummy dot; ac_word=$2
@@ -6624,6 +6674,29 @@ fi
 $as_echo "$as_me: WARNING: You will not be able to see diagrams in the manual" >&2;}
   fi
 fi
+fi
+
+if test "$make_doc" = yes
+then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: Manuals will be generated" >&5
+$as_echo "$as_me: Manuals will be generated" >&6;}
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: Manuals will not be generated" >&5
+$as_echo "$as_me: Manuals will not be generated" >&6;}
+fi
+
+
+make_pdfdoc=""
+if test "$pdfdoc" == true && test "$make_doc" == yes
+then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: A PDF version of the manual will be generated" >&5
+$as_echo "$as_me: A PDF version of the manual will be generated" >&6;}
+  make_pdfdoc=yes
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: A PDF version of the manual will not be generated" >&5
+$as_echo "$as_me: A PDF version of the manual will not be generated" >&6;}
+  make_pdfdoc=no
+fi
 
 ### Look for xxd
 # Extract the first word of "xxd", so it can be a program name with args.
diff --git a/configure.ac b/configure.ac
index c003c4136..48926f216 100644
--- a/configure.ac
+++ b/configure.ac
@@ -156,6 +156,8 @@ AC_ARG_ENABLE([modules],
 
 
 # set enable flags for ./configure
+PLUMED_CONFIG_ENABLE([doc],[doc],[documentation],[yes])
+PLUMED_CONFIG_ENABLE([pdfdoc],[pdfdoc],[pdf version of the manual],[yes])
 PLUMED_CONFIG_ENABLE([debug],[debug],[debugging],[no])
 PLUMED_CONFIG_ENABLE([basic_warnings],[basic-warnings],[basic warnings],[yes])
 PLUMED_CONFIG_ENABLE([fussy],[fussy],[fussy warnings],[no])
@@ -534,6 +536,13 @@ then
 fi
 #### Options for dynamic library to work properly ####
 
+AC_SUBST(make_doc)
+make_doc=no
+if test "$doc" == true
+then
+
+make_doc=yes
+
 ### Look for doxygen
 AC_CHECK_PROG([doxygen],[doxygen],[found])
 if test "$doxygen" == found
@@ -543,7 +552,8 @@ then
   then
     AC_MSG_NOTICE([Doxygen version is fine])
   else
-    AC_MSG_WARN([Doxygen version is <1.8. You might have problems in generating manuals])
+    AC_MSG_WARN([Doxygen version is <1.8])
+    make_doc=no
   fi
   AC_CHECK_PROG([dot],[dot],[found])
   if test "$dot" != found
@@ -551,6 +561,25 @@ then
     AC_MSG_WARN([You will not be able to see diagrams in the manual])
   fi
 fi
+fi
+
+if test "$make_doc" = yes
+then
+  AC_MSG_NOTICE([Manuals will be generated])
+else
+  AC_MSG_NOTICE([Manuals will not be generated])
+fi
+
+AC_SUBST(make_pdfdoc)
+make_pdfdoc=""
+if test "$pdfdoc" == true && test "$make_doc" == yes
+then
+  AC_MSG_NOTICE([A PDF version of the manual will be generated])
+  make_pdfdoc=yes
+else
+  AC_MSG_NOTICE([A PDF version of the manual will not be generated])
+  make_pdfdoc=no
+fi
 
 ### Look for xxd
 AC_CHECK_PROG([xxd],[xxd],[found])
diff --git a/developer-doc/Makefile b/developer-doc/Makefile
index f62e49feb..da31eaa8b 100644
--- a/developer-doc/Makefile
+++ b/developer-doc/Makefile
@@ -1,10 +1,14 @@
+# include the machine dependent configuration
+-include ../Makefile.conf
 
 .PHONY: all clean
 
 all:
+ifeq ($(make_doc),yes)
 	./extract
 	./go-doxygen
 	cp *png html/
+endif
 
 clean:
 	rm -fr automatic html latex *~ links-to-user-manual.txt
diff --git a/user-doc/Intro.txt b/user-doc/Intro.txt
index a1d6d7b1e..eab2c19e0 100644
--- a/user-doc/Intro.txt
+++ b/user-doc/Intro.txt
@@ -10,10 +10,7 @@ new methods, more straightforward to add it to MD codes and hopefully simpler to
 This is the user manual -  if you want to modify PLUMED or to understand how it works internally, have a look at the 
 <a href="../../developer-doc/html/index.html"> developer manual </a>.
 
-\htmlonly
-An experimental PDF copy of this manual can be found
-<a href="../manual.pdf"> here </a>.
-\endhtmlonly
+@PDFMANUAL@
 
 To understand the difference between PLUMED 1 and PLUMED 2, and to
 follow the development of PLUMED 2, you can look at the detailed \ref Changelog.
@@ -27,7 +24,7 @@ To install PLUMED 2, see this page: \ref Installation
 
 @VERSION@
 
-Since version 2.1 we provide an experimental PDF manual.
+Since version 2.1 we optionally provide an experimental PDF manual.
 The PDF version is still not complete and has some known issue (e.g. some
 links are not working properly and images are not correctly included),
 and the html documentation should be considered as the official one.
diff --git a/user-doc/Makefile b/user-doc/Makefile
index 934a42675..604feb262 100644
--- a/user-doc/Makefile
+++ b/user-doc/Makefile
@@ -13,11 +13,12 @@ all:
 else
 
 all:
-	./extract
-	./go-doxygen
+ifeq ($(make_doc),yes)
+	make_pdfdoc=$(make_pdfdoc) ./extract
+	make_pdfdoc=$(make_pdfdoc) ./go-doxygen
 	cp *png html/
 	./report_errors
-
+endif
 endif
 
 clean:
diff --git a/user-doc/extract b/user-doc/extract
index 368ed57f5..2c48711d5 100755
--- a/user-doc/extract
+++ b/user-doc/extract
@@ -46,6 +46,17 @@ for file in ../CHANGES/* ; do
 echo "- Changes for \\subpage $(cat $file | grep "@page" | awk '{print $2}')"
 done > automatic/changes.tmp
 
+if test "$make_pdfdoc" = yes ; then
+cat > automatic/pdfmanual.tmp << \EOF
+\htmlonly
+An experimental PDF copy of this manual can be found
+<a href="../manual.pdf"> here </a>.
+\endhtmlonly
+EOF
+else
+touch automatic/pdfmanual.tmp
+fi
+
 # Check for files that register actions with no documentation
 for file in ../src/*/*.cpp
 do
@@ -284,5 +295,6 @@ cat $file.txt |
     /^ *@CODESL@ *$/r     automatic/codesl.list
     /^ *@VERSION@ *$/r    automatic/version.tmp
     /^ *@CHANGES@ *$/r    automatic/changes.tmp
+    /^ *@PDFMANUAL@ *$/r  automatic/pdfmanual.tmp
 " | grep -Ev '^ *@[A-Z]*@ *$' > ${file}PP.txt
 done
diff --git a/user-doc/go-doxygen b/user-doc/go-doxygen
index c58e5c1f6..edf3465a2 100755
--- a/user-doc/go-doxygen
+++ b/user-doc/go-doxygen
@@ -54,6 +54,10 @@ done
 cat html/doxygen.css plumed.css > html/doxygen.css.tmp
 mv html/doxygen.css.tmp html/doxygen.css
 
+if [ "$make_pdfdoc" != yes ] ; then
+  exit
+fi
+
 cd latex
 
 # this is a workaround for a problem on the linux workstation
-- 
GitLab