public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/marxin/heads/sphinx-v2)] Build system integration.
@ 2021-06-24 14:06 Martin Liska
  0 siblings, 0 replies; 6+ messages in thread
From: Martin Liska @ 2021-06-24 14:06 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:0a4977f648292ce7565c153bd6016ca8630bda6f

commit 0a4977f648292ce7565c153bd6016ca8630bda6f
Author: Martin Liska <mliska@suse.cz>
Date:   Thu Jun 17 22:08:57 2021 +0200

    Build system integration.

Diff:
---
 config/acx.m4            |   2 +-
 configure                |   1 -
 configure.ac             |   1 -
 doc/baseconf.py          |   5 +-
 gcc/Makefile.in          | 216 ++++++++++++++++++++-----------------------
 gcc/configure            |  28 +++++-
 gcc/configure.ac         |  15 +++
 gcc/cp/Make-lang.in      |   2 +-
 gcc/doc/gcc/conf.py      |   9 +-
 gcc/fortran/Make-lang.in |  42 ++++-----
 gcc/genhooks.c           | 232 ++++++++++-------------------------------------
 11 files changed, 214 insertions(+), 339 deletions(-)

diff --git a/config/acx.m4 b/config/acx.m4
index 87c1b5e2932..65a7f4bc446 100644
--- a/config/acx.m4
+++ b/config/acx.m4
@@ -615,7 +615,7 @@ AC_DEFUN([ACX_BUGURL],[
     REPORT_BUGS_TEXI=
     ;;
   *)
-    REPORT_BUGS_TO="<$BUGURL>"
+    REPORT_BUGS_TO="$BUGURL"
     REPORT_BUGS_TEXI=@uref{`echo "$BUGURL" | sed 's/@/@@/g'`}
     ;;
   esac;
diff --git a/configure b/configure
index 1224fc4039e..e58cbb65158 100755
--- a/configure
+++ b/configure
@@ -10458,7 +10458,6 @@ case " $configdirs " in
     ;;
 esac
 
-
 # Host tools.
 ncn_tool_prefix=
 test -n "$host_alias" && ncn_tool_prefix=$host_alias-
diff --git a/configure.ac b/configure.ac
index 66d637d70dc..68c209852e9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3454,7 +3454,6 @@ case " $configdirs " in
     ;;
 esac
 
-
 # Host tools.
 NCN_STRICT_CHECK_TOOLS(AR, ar)
 NCN_STRICT_CHECK_TOOLS(AS, as)
diff --git a/doc/baseconf.py b/doc/baseconf.py
index 07bf2c551c8..206328d43e5 100644
--- a/doc/baseconf.py
+++ b/doc/baseconf.py
@@ -34,8 +34,9 @@ gcc_DEVPHASE = __read_file('DEV-PHASE')
 gcc_DATESTAMP = __read_file('DATESTAMP')
 gcc_REVISION = __read_file('REVISION')
 
-VERSION_PACKAGE = os.getenv('VERSION_PACKAGE', '(GCC)')
-BUGURL = os.getenv('BUGURL', 'https://gcc.gnu.org/bugs/')
+VERSION_PACKAGE = os.getenv('VERSION_PACKAGE')
+BUGURL = os.getenv('BUGURL')
+assert VERSION_PACKAGE and BUGURL
 
 # The short X.Y version.
 version = gcc_BASEVER
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index d32de22e4f2..12c38ed25ca 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -771,11 +771,8 @@ LIBCONVERT =
 # Control whether header files are installed.
 INSTALL_HEADERS=install-headers install-mkheaders
 
-# Control whether Info documentation is built and installed.
-BUILD_INFO = @BUILD_INFO@
-
-# Control whether manpages generated by texi2pod.pl can be rebuilt.
-GENERATED_MANPAGES = @GENERATED_MANPAGES@
+# Control whether manpages generated by sphinx-build can be rebuilt.
+SPHINX_BUILD = @SPHINX_BUILD@
 
 # Additional directories of header files to run fixincludes on.
 # These should be directories searched automatically by default
@@ -2580,38 +2577,20 @@ s-d-target-hooks-def-h: build/genhooks$(build_exeext)
 					     d/d-target-hooks-def.h
 	$(STAMP) s-d-target-hooks-def-h
 
-# check if someone mistakenly only changed tm.texi.
-# We use a different pathname here to avoid a circular dependency.
-s-tm-texi: $(srcdir)/doc/../doc/tm.texi
-
 # The tm.texi we want to compare against / check into svn should have
 # unix-style line endings.  To make this work on MinGW, remove \r.
 # \r is not portable to Solaris tr, therefore we have a special
 # case for ASCII.  We use \r for other encodings like EBCDIC.
-s-tm-texi: build/genhooks$(build_exeext) $(srcdir)/doc/tm.texi.in
-	$(RUN_GEN) build/genhooks$(build_exeext) -d \
-			$(srcdir)/doc/tm.texi.in > tmp-tm.texi
-	case `echo X|tr X '\101'` in \
-	  A) tr -d '\015' < tmp-tm.texi > tmp2-tm.texi ;; \
-	  *) tr -d '\r' < tmp-tm.texi > tmp2-tm.texi ;; \
-	esac
-	mv tmp2-tm.texi tmp-tm.texi
-	$(SHELL) $(srcdir)/../move-if-change tmp-tm.texi tm.texi
-	@if cmp -s $(srcdir)/doc/tm.texi tm.texi; then \
+s-tm-rst-in: build/genhooks$(build_exeext)
+	$(RUN_GEN) build/genhooks$(build_exeext) > tmp-tm.rst.in
+	$(SHELL) $(srcdir)/../move-if-change tmp-tm.rst.in tm.rst.in
+
+	@if cmp -s $(srcdir)/doc/gccint/target-macros/tm.rst.in tm.rst.in; then \
 	  $(STAMP) $@; \
-	elif test $(srcdir)/doc/tm.texi -nt $(srcdir)/doc/tm.texi.in \
-	  && ( test $(srcdir)/doc/tm.texi -nt $(srcdir)/target.def \
-	    || test $(srcdir)/doc/tm.texi -nt $(srcdir)/c-family/c-target.def \
-	    || test $(srcdir)/doc/tm.texi -nt $(srcdir)/common/common-target.def \
-	    || test $(srcdir)/doc/tm.texi -nt $(srcdir)/d/d-target.def \
-	  ); then \
-	  echo >&2 ; \
-	  echo You should edit $(srcdir)/doc/tm.texi.in rather than $(srcdir)/doc/tm.texi . >&2 ; \
-	  false; \
 	else \
 	  echo >&2 ; \
 	  echo Verify that you have permission to grant a GFDL license for all >&2 ; \
-	  echo new text in $(objdir)/tm.texi, then copy it to $(srcdir)/doc/tm.texi. >&2 ; \
+	  echo new text in $(objdir)/tm.rst.in, then copy it to $(srcdir)/doc/gccint/target-macros/tm.rst.in. >&2 ; \
 	  false; \
 	fi
 
@@ -3282,15 +3261,7 @@ install-no-fixedincludes:
 
 # Remake the info files.
 
-doc: $(BUILD_INFO) $(GENERATED_MANPAGES)
-
-INFOFILES = doc/cpp.info doc/gcc.info doc/gccint.info \
-            doc/gccinstall.info doc/cppinternals.info
-
-info: $(INFOFILES) lang.info @GENINSRC@ srcinfo lang.srcinfo
-
-srcinfo: $(INFOFILES)
-	-cp -p $^ $(srcdir)/doc
+doc: $(SPHINX_BUILD)
 
 TEXI_CPP_FILES = cpp.texi fdl.texi cppenv.texi cppopts.texi		\
 	 gcc-common.texi gcc-vers.texi
@@ -3337,28 +3308,6 @@ gcc-vers.texi: $(BASEVER) $(DEVPHASE)
 	mv -f $@T $@
 
 
-# The *.1, *.7, *.info, *.dvi, and *.pdf files are being generated from implicit
-# patterns.  To use them, put each of the specific targets with its
-# specific dependencies but no build commands.
-
-doc/cpp.info: $(TEXI_CPP_FILES)
-doc/gcc.info: $(TEXI_GCC_FILES)
-doc/gccint.info: $(TEXI_GCCINT_FILES)
-doc/cppinternals.info: $(TEXI_CPPINT_FILES)
-
-doc/%.info: %.texi
-	if [ x$(BUILD_INFO) = xinfo ]; then \
-		$(MAKEINFO) $(MAKEINFOFLAGS) -I . -I $(gcc_docdir) \
-			-I $(gcc_docdir)/include -o $@ $<; \
-	fi
-
-# Duplicate entry to handle renaming of gccinstall.info
-doc/gccinstall.info: $(TEXI_GCCINSTALL_FILES)
-	if [ x$(BUILD_INFO) = xinfo ]; then \
-		$(MAKEINFO) $(MAKEINFOFLAGS) -I $(gcc_docdir) \
-			-I $(gcc_docdir)/include -o $@ $<; \
-	fi
-
 doc/cpp.dvi: $(TEXI_CPP_FILES)
 doc/gcc.dvi: $(TEXI_GCC_FILES)
 doc/gccint.dvi: $(TEXI_GCCINT_FILES)
@@ -3423,51 +3372,43 @@ $(build_htmldir)/gccinstall/index.html: $(TEXI_GCCINSTALL_FILES)
 	DESTDIR=$(@D) \
 	$(SHELL) $(srcdir)/doc/install.texi2html
 
-MANFILES = doc/gcov.1 doc/cpp.1 doc/gcc.1 doc/gfdl.7 doc/gpl.7 \
-           doc/fsf-funding.7 doc/gcov-tool.1 doc/gcov-dump.1 \
 	   $(if $(filter yes,@enable_lto@),doc/lto-dump.1)
 
-generated-manpages: man
+export VERSION_PACKAGE="$(PKGVERSION)"
+export ENABLE_LTO=$(enable_lto)
+export BUGURL="$(BUGURL_s)"
 
-man: $(MANFILES) lang.man @GENINSRC@ srcman lang.srcman
+man: man-gcc man-cpp lang.man @GENINSRC@
 
-srcman: $(MANFILES)
-	-cp -p $^ $(srcdir)/doc
+info: info-gcc info-gccint info-cpp info-cppinternals info-install lang.info @GENINSRC@
 
-doc/%.1: %.pod
-	$(STAMP) $@
-	-($(POD2MAN) --section=1 $< > $(@).T$$$$ && \
-		mv -f $(@).T$$$$ $@) || \
-		(rm -f $(@).T$$$$ && exit 1)
+sphinx-build: man info
 
-doc/%.7: %.pod
-	$(STAMP) $@
-	-($(POD2MAN) --section=7 $< > $(@).T$$$$ && \
-		mv -f $(@).T$$$$ $@) || \
-		(rm -f $(@).T$$$$ && exit 1)
+man-gcc: doc/gcc/man/man/gcc.1
 
-%.pod: %.texi
-	$(STAMP) $@
-	-$(TEXI2POD) -DBUGURL="$(BUGURL_TEXI)" $< > $@
+doc/gcc/man/man/gcc.1:
+	+ make -C $(srcdir)/../doc man SOURCEDIR=$(srcdir)/doc/gcc BUILDDIR=$(objdir)/doc/gcc/man
 
-.INTERMEDIATE: cpp.pod gcc.pod gfdl.pod fsf-funding.pod gpl.pod
-cpp.pod: cpp.texi cppenv.texi cppopts.texi
+man-cpp:
+	+ make -C $(srcdir)/../doc man SOURCEDIR=$(srcdir)/doc/cpp BUILDDIR=$(objdir)/doc/cpp/man
 
-# These next rules exist because the output name is not the same as
-# the input name, so our implicit %.pod rule will not work.
+info-gcc:
+	+ make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/doc/gcc BUILDDIR=$(objdir)/doc/gcc/info
 
-gcc.pod: invoke.texi cppenv.texi cppopts.texi gcc-vers.texi
-	$(STAMP) $@
-	-$(TEXI2POD) $< > $@
-gfdl.pod: fdl.texi
-	$(STAMP) $@
-	-$(TEXI2POD) $< > $@
-fsf-funding.pod: funding.texi
-	$(STAMP) $@
-	-$(TEXI2POD) $< > $@
-gpl.pod: gpl_v3.texi
-	$(STAMP) $@
-	-$(TEXI2POD) $< > $@
+info-gccint: s-tm-rst-in
+	+ make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/doc/gccint BUILDDIR=$(objdir)/doc/gccint/info
+
+info-cpp:
+	+ make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/doc/cpp BUILDDIR=$(objdir)/doc/cpp/info
+
+info-cppinternals:
+	+ make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/doc/cppinternals BUILDDIR=$(objdir)/doc/cppinternals/info
+
+info-install:
+	+ make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/doc/install BUILDDIR=$(objdir)/doc/install/info
+
+html-gccint: s-tm-rst-in
+	+ make -C $(srcdir)/../doc html SOURCEDIR=$(srcdir)/doc/gccint BUILDDIR=$(objdir)/doc/gccint/html
 
 #\f
 # Deletion of files made during compilation.
@@ -3527,8 +3468,7 @@ clean: mostlyclean lang.clean
 	-rm -f config.h tconfig.h bconfig.h tm_p.h tm.h
 	-rm -f options.c options.h optionlist
 	-rm -f cs-*
-	-rm -f doc/*.dvi
-	-rm -f doc/*.pdf
+	-rm -rf doc
 # Delete the include directories.
 	-rm -rf include include-fixed
 # Delete files used by the "multilib" facility (including libgcc subdirs).
@@ -3569,7 +3509,7 @@ maintainer-clean:
 	$(MAKE) lang.maintainer-clean distclean
 	-rm -f cpp.??s cpp.*aux
 	-rm -f gcc.??s gcc.*aux
-	-rm -f $(gcc_docdir)/*.info $(gcc_docdir)/*.1 $(gcc_docdir)/*.7 $(gcc_docdir)/*.dvi $(gcc_docdir)/*.pdf
+	-rm -rf doc
 #\f
 # Entry points `install', `install-strip', and `uninstall'.
 # Also use `install-collect2' to install collect2 when the config files don't.
@@ -3766,24 +3706,46 @@ install-info:: doc installdirs \
 	$(DESTDIR)$(infodir)/cpp.info \
 	$(DESTDIR)$(infodir)/gcc.info \
 	$(DESTDIR)$(infodir)/cppinternals.info \
-	$(DESTDIR)$(infodir)/gccinstall.info \
+	$(DESTDIR)$(infodir)/install.info \
 	$(DESTDIR)$(infodir)/gccint.info \
 	lang.install-info
 
-$(DESTDIR)$(infodir)/%.info: doc/%.info installdirs
-	rm -f $@
-	if [ -f $< ]; then \
-	  for f in $(<)*; do \
-	    realfile=`echo $$f | sed -e 's|.*/\([^/]*\)$$|\1|'`; \
-	    $(INSTALL_DATA) $$f $(DESTDIR)$(infodir)/$$realfile; \
-	    chmod a-x $(DESTDIR)$(infodir)/$$realfile; \
-	  done; \
-	else true; fi
-	-if $(SHELL) -c 'install-info --version' >/dev/null 2>&1; then \
-	  if [ -f $@ ]; then \
-	    install-info --dir-file=$(DESTDIR)$(infodir)/dir $@; \
-	  else true; fi; \
-	else true; fi;
+$(DESTDIR)$(infodir)/gcc.info: doc/gcc/info/texinfo/gcc.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/gccint.info: doc/gccint/info/texinfo/gccint.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/install.info: doc/install/info/texinfo/install.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/cpp.info: doc/cpp/info/texinfo/cpp.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/cppinternals.info: doc/cppinternals/info/texinfo/cppinternals.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/gcov.info: doc/gcc/info/texinfo/gcov.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/gcov-tool.info: doc/gcc/info/texinfo/gcov-tool.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/gcov-dump.info: doc/gcc/info/texinfo/gcov-dump.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/lto-dump.info: doc/gcc/info/texinfo/lto-dump.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
 
 pdf__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
 
@@ -3833,36 +3795,52 @@ $(DESTDIR)$(man7dir)/%$(man7ext): doc/%.7 installdirs
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
-$(DESTDIR)$(man1dir)/$(GCC_INSTALL_NAME)$(man1ext): doc/gcc.1 installdirs
+$(DESTDIR)$(man1dir)/$(GCC_INSTALL_NAME)$(man1ext): doc/gcc/man/man/gcc.1 installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
-$(DESTDIR)$(man1dir)/$(CPP_INSTALL_NAME)$(man1ext): doc/cpp.1 installdirs
+$(DESTDIR)$(man1dir)/$(CPP_INSTALL_NAME)$(man1ext): doc/cpp/man/man/cpp.1 installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
-$(DESTDIR)$(man1dir)/$(GCOV_INSTALL_NAME)$(man1ext): doc/gcov.1 installdirs
+$(DESTDIR)$(man1dir)/$(GCOV_INSTALL_NAME)$(man1ext): doc/gcc/man/man/gcov.1 installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
-$(DESTDIR)$(man1dir)/$(GCOV_TOOL_INSTALL_NAME)$(man1ext): doc/gcov-tool.1 installdirs
+$(DESTDIR)$(man1dir)/$(GCOV_TOOL_INSTALL_NAME)$(man1ext): doc/gcc/man/man/gcov-tool.1 installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
-$(DESTDIR)$(man1dir)/$(GCOV_DUMP_INSTALL_NAME)$(man1ext): doc/gcov-dump.1 installdirs
+$(DESTDIR)$(man1dir)/$(GCOV_DUMP_INSTALL_NAME)$(man1ext): doc/gcc/man/man/gcov-dump.1 installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
-$(DESTDIR)$(man1dir)/$(LTO_DUMP_INSTALL_NAME)$(man1ext): doc/lto-dump.1 installdirs
+$(DESTDIR)$(man1dir)/$(LTO_DUMP_INSTALL_NAME)$(man1ext): doc/gcc/man/man/lto-dump.1 installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
+$(DESTDIR)$(man7dir)/fsf-funding$(man7ext): doc/gcc/man/man/fsf-funding.7 installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+	-chmod a-x $@
+
+$(DESTDIR)$(man7dir)/gfdl$(man7ext): doc/gcc/man/man/gfdl.7 installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+	-chmod a-x $@
+
+$(DESTDIR)$(man7dir)/gpl$(man7ext): doc/gcc/man/man/gpl.7 installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+	-chmod a-x $@
+
+
 # Install all the header files built in the include subdirectory.
 install-headers: $(INSTALL_HEADERS_DIR)
 # Fix symlinks to absolute paths in the installed include directory to
diff --git a/gcc/configure b/gcc/configure
index f0b2ebde3cf..ba82207748b 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -806,6 +806,7 @@ AR
 NM
 BISON
 FLEX
+SPHINX_BUILD
 GENERATED_MANPAGES
 BUILD_INFO
 MAKEINFO
@@ -7905,7 +7906,7 @@ fi
     REPORT_BUGS_TEXI=
     ;;
   *)
-    REPORT_BUGS_TO="<$BUGURL>"
+    REPORT_BUGS_TO="$BUGURL"
     REPORT_BUGS_TEXI=@uref{`echo "$BUGURL" | sed 's/@/@@/g'`}
     ;;
   esac;
@@ -8557,6 +8558,27 @@ $as_echo "no" >&6; }
 fi
 
 
+# See if sphinx-build has been installed and is modern enough
+# that we can use it.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for sphinx-build" >&5
+$as_echo_n "checking for sphinx-build... " >&6; }
+if sphinx-build -j auto -h &>/dev/null ; then
+  SPHINX_BUILD=sphinx-build
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING:
+  *** sphinx-build is missing or too old.
+  *** Info and man pages documentation will not be built." >&5
+$as_echo "$as_me: WARNING:
+  *** sphinx-build is missing or too old.
+  *** Info and man pages documentation will not be built." >&2;}
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+  SPHINX_BUILD=
+fi
+
+
 MISSING="${CONFIG_SHELL-/bin/sh} $ac_aux_dir/missing"
 
 # How about lex?
@@ -19435,7 +19457,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 19438 "configure"
+#line 19460 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -19541,7 +19563,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 19544 "configure"
+#line 19566 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 70089394429..ce12cbf18e9 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -1208,6 +1208,21 @@ else
 fi
 AC_SUBST(GENERATED_MANPAGES)
 
+# See if sphinx-build has been installed and is modern enough
+# that we can use it.
+AC_MSG_CHECKING([for sphinx-build])
+if sphinx-build -j auto -h &>/dev/null ; then
+  SPHINX_BUILD=sphinx-build
+  AC_MSG_RESULT(yes)
+else
+  AC_MSG_WARN([
+  *** sphinx-build is missing or too old.
+  *** Info and man pages documentation will not be built.])
+  AC_MSG_RESULT(no)
+  SPHINX_BUILD=
+fi
+AC_SUBST(SPHINX_BUILD)
+
 MISSING="${CONFIG_SHELL-/bin/sh} $ac_aux_dir/missing"
 
 # How about lex?
diff --git a/gcc/cp/Make-lang.in b/gcc/cp/Make-lang.in
index 155be74efdb..6e49e3117db 100644
--- a/gcc/cp/Make-lang.in
+++ b/gcc/cp/Make-lang.in
@@ -260,7 +260,7 @@ c++.install-common: installdirs
 
 # We can't use links because not everyone supports them.  So just copy the
 # manpage.
-doc/g++.1: doc/gcc.1
+doc/g++.1: doc/gcc/man/man/gcc.1
 	cp $< doc/g++.1
 
 c++.install-man: $(DESTDIR)$(man1dir)/$(GXX_INSTALL_NAME)$(man1ext)
diff --git a/gcc/doc/gcc/conf.py b/gcc/doc/gcc/conf.py
index d6d69de24f8..ac1bc73ca78 100644
--- a/gcc/doc/gcc/conf.py
+++ b/gcc/doc/gcc/conf.py
@@ -1,5 +1,6 @@
 # Configuration file for the Sphinx documentation builder.
 
+import os
 import sys
 sys.path.append('../../..//doc')
 
@@ -29,8 +30,14 @@ man_pages = [
     ('funding', 'fsf-funding', 'Funding Free Software', [], 7)
 ]
 
+ENABLE_LTO = os.getenv('ENABLE_LTO')
+assert ENABLE_LTO
+
+if ENABLE_LTO  == 'yes':
+    man_pages += [('lto-dump', 'lto-dump', 'Tool for dumping LTO object files', [authors], 1)]
+
 texinfo_documents = [
   ('index', 'gcc', project, authors, None, None, None, True)
 ]
 
-tags.add('gcc')
\ No newline at end of file
+tags.add('gcc')
diff --git a/gcc/fortran/Make-lang.in b/gcc/fortran/Make-lang.in
index 63195a9c7ed..686788ee868 100644
--- a/gcc/fortran/Make-lang.in
+++ b/gcc/fortran/Make-lang.in
@@ -109,16 +109,18 @@ fortran.all.cross: gfortran-cross$(exeext)
 fortran.start.encap: gfortran$(exeext)
 fortran.rest.encap:
 
-fortran.srcinfo: doc/gfortran.info
-	-cp -p $^ $(srcdir)/fortran
-
 fortran.tags: force
 	cd $(srcdir)/fortran; etags -o TAGS.sub *.c *.h; \
 	etags --include TAGS.sub --include ../TAGS.sub
 
-fortran.info: doc/gfortran.info doc/gfc-internals.info
+fortran.info: info-gfortran info-gfc-internals
 fortran.dvi: doc/gfortran.dvi doc/gfc-internals.dvi
 
+info-gfortran:
+	+ if [ x$(SPHINX_BUILD) = xsphinx-build ]; then \
+	  make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/fortran/doc/gfortran BUILDDIR=$(objdir)/doc/fortran/info; \
+	else true; fi
+
 F95_HTMLFILES = $(build_htmldir)/gfortran
 
 fortran.html: $(F95_HTMLFILES)/index.html
@@ -154,9 +156,10 @@ fortran.install-pdf: $(F95_PDFFILES)
 	  $(INSTALL_DATA) "$$d$$p" "$(DESTDIR)$(pdfdir)/gcc/$$f"; \
 	done
 
-F95_MANFILES = doc/gfortran.1
+man-fortran:
+	+ make -C $(srcdir)/../doc man SOURCEDIR=$(srcdir)/fortran/doc/gfortran BUILDDIR=$(objdir)/doc/fortran/man
 
-fortran.man: $(F95_MANFILES)
+fortran.man: man-fortran
 
 fortran.srcman: $(F95_MANFILES)
 	-cp -p $^ $(srcdir)/doc
@@ -186,13 +189,6 @@ GFORTRAN_TEXI = \
   $(srcdir)/doc/include/gcc-common.texi \
   gcc-vers.texi
 
-doc/gfortran.info: $(GFORTRAN_TEXI)
-	if [ x$(BUILD_INFO) = xinfo ]; then \
-	  rm -f doc/gfortran.info-*; \
-	  $(MAKEINFO) -I $(srcdir)/doc/include -I $(srcdir)/fortran \
-	    -o $@ $<; \
-	else true; fi
-
 doc/gfortran.dvi: $(GFORTRAN_TEXI)
 	$(TEXI2DVI) -I $(srcdir)/fortran -I $(abs_docdir)/include -o $@ $<
 
@@ -217,11 +213,9 @@ GFC_INTERNALS_TEXI = \
   $(srcdir)/doc/include/gcc-common.texi \
   gcc-vers.texi
 
-doc/gfc-internals.info: $(GFC_INTERNALS_TEXI)
-	if [ x$(BUILD_INFO) = xinfo ]; then \
-	  rm -f doc/gfc-internals.info-*; \
-	  $(MAKEINFO) -I $(srcdir)/doc/include -I $(srcdir)/fortran \
-	    -o $@ $<; \
+info-gfc-internals:
+	+ if [ x$(SPHINX_BUILD) = xsphinx-build ]; then \
+	  make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/fortran/doc/gfc-internals BUILDDIR=$(objdir)/doc/gfc-internals/info; \
 	else true; fi
 
 doc/gfc-internals.dvi: $(GFC_INTERNALS_TEXI)
@@ -256,9 +250,13 @@ fortran.install-plugin:
 
 fortran.install-info: $(DESTDIR)$(infodir)/gfortran.info
 
+$(DESTDIR)$(infodir)/gfortran.info: doc/fortran/info/texinfo/gfortran.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
 fortran.install-man: $(DESTDIR)$(man1dir)/$(GFORTRAN_INSTALL_NAME)$(man1ext)
 
-$(DESTDIR)$(man1dir)/$(GFORTRAN_INSTALL_NAME)$(man1ext): doc/gfortran.1 \
+$(DESTDIR)$(man1dir)/$(GFORTRAN_INSTALL_NAME)$(man1ext): doc/fortran/man/man/gfortran.1 \
 		installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
@@ -286,12 +284,6 @@ fortran.mostlyclean:
 fortran.clean:
 fortran.distclean:
 	-rm -f fortran/config.status fortran/Makefile
-
-fortran.extraclean:
-fortran.maintainer-clean:
-	-rm -f doc/gfortran.info* fortran/gfortran.*aux
-	-rm -f $(docobjdir)/gfortran.1
-
 #\f
 # Stage hooks:
 # The toplevel makefile has already created stage?/fortran at this point.
diff --git a/gcc/genhooks.c b/gcc/genhooks.c
index ebe0d0954e6..6ba6254381b 100644
--- a/gcc/genhooks.c
+++ b/gcc/genhooks.c
@@ -48,212 +48,74 @@ upstrdup (const char *in)
   return ret;
 }
 
-/* Struct for 'start hooks' which start a sequence of consecutive hooks
-   that are defined in target.def and to be documented in tm.texi.  */
-struct s_hook
-{
-  char *name;
-  int pos;
-};
-
-static hashval_t
-s_hook_hash (const void *p)
-{
-  const struct s_hook *s_hook = (const struct s_hook *)p;
-  return htab_hash_string (s_hook->name);
-}
+/* Emit shared .rst.in file that is used by the corresponding
+   .. include:: tm.rst.in
+     :start-after: [HOOK_NAME]
+     :end-before: [HOOK_NAME]
 
-static int
-s_hook_eq_p (const void *p1, const void *p2)
-{
-  return (strcmp (((const struct s_hook *) p1)->name, 
-		  ((const struct s_hook *) p2)->name) == 0);
-}
-
-/* Read the documentation file with name IN_FNAME, perform substitutions
-   to incorporate information from hook_array, and emit the result on stdout.
-   Hooks defined with DEFHOOK / DEFHOOKPOD are emitted at the place of a
-   matching @hook in the input file; if there is no matching @hook, the
-   hook is emitted after the hook that precedes it in target.def .
-   Usually, the emitted hook documentation starts with the hook
-   signature, followed by the string from the doc field.
-   The documentation is bracketed in @deftypefn / @deftypevr and a matching
-   @end.
-   While emitting the doc field, an @findex entry is added
-   to the affected paragraph.
    If the doc field starts with '*', the leading '*' is stripped, and the doc
    field is otherwise emitted unaltered; no function signature/
    @deftypefn/deftypevr/@end is emitted.
    In particular, a doc field of "*" means not to emit any ocumentation for
    this target.def / hook_array entry at all (there might be documentation
    for this hook in the file named IN_FNAME, though).
-   A doc field of 0 is used to append the hook signature after the previous
-   hook's signture, so that one description can be used for a group of hooks.
-   When the doc field is "", @deftypefn/@deftypevr and the hook signature
-   is emitted, but not the matching @end.  This allows all the free-form
+
+   This allows all the free-form
    documentation to be placed in IN_FNAME, to work around GPL/GFDL
    licensing incompatibility issues.  */
+
 static void
-emit_documentation (const char *in_fname)
+emit_documentation (void)
 {
-  int i, j;
-  char buf[1000];
-  htab_t start_hooks = htab_create (99, s_hook_hash, s_hook_eq_p, (htab_del) 0);
-  FILE *f;
-
-  /* Enter all the start hooks in start_hooks.  */
-  f = fopen (in_fname, "r");
-  if (!f)
-    {
-      perror ("");
-      fatal ("Couldn't open input file");
-    }
-  while (fscanf (f, "%*[^@]"), buf[0] = '\0',
-	 fscanf (f, "@%5[^ \n]", buf) != EOF)
-    {
-      void **p;
-      struct s_hook *shp;
-
-      if (strcmp (buf, "hook") != 0)
-	continue;
-      buf[0] = '\0';
-      fscanf (f, "%999s", buf);
-      shp = XNEW (struct s_hook);
-      shp->name = upstrdup (buf);
-      shp->pos = -1;
-      p = htab_find_slot (start_hooks, shp, INSERT);
-      if (*p != HTAB_EMPTY_ENTRY)
-	fatal ("Duplicate placement for hook %s\n", shp->name);
-      *(struct s_hook **) p = shp;
-    }
-  fclose (f);
   /* For each hook in hook_array, if it is a start hook, store its position.  */
-  for (i = 0; i < (int) (sizeof hook_array / sizeof hook_array[0]); i++)
+  for (int i = 0; i < (int) (sizeof hook_array / sizeof hook_array[0]); i++)
     {
-      struct s_hook sh, *shp;
-      void *p;
-
       if (!hook_array[i].doc || strcmp (hook_array[i].doc, "*") == 0)
 	continue;
-      sh.name = upstrdup (hook_array[i].name);
-      p = htab_find (start_hooks, &sh);
-      if (p)
-	{
-	  shp = (struct s_hook *) p;
-	  if (shp->pos >= 0)
-	    fatal ("Duplicate hook %s\n", sh.name);
-	  shp->pos = i;
-	}
+      const char *hook_name = upstrdup (hook_array[i].name);
+      printf ("[%s]\n", hook_name);
+      /* Print header.  Function-valued hooks have a parameter list,
+	 unlike POD-valued ones.  */
+      const char *deftype = hook_array[i].param ? "c:function" : "c:var";
+      printf (".. %s:: ", deftype);
+      if (strchr (hook_array[i].type, ' '))
+	printf ("%s", hook_array[i].type);
       else
-	fatal ("No place specified to document hook %s\n", sh.name);
-      free (sh.name);
-    }
-  /* Copy input file to stdout, substituting @hook directives with the
-     corresponding hook documentation sequences.  */
-  f = fopen (in_fname, "r");
-  if (!f)
-    {
-      perror ("");
-      fatal ("Couldn't open input file");
-    }
-  for (;;)
-    {
-      struct s_hook sh, *shp;
-      int c = getc (f);
-      char *name;
-
-      if (c == EOF)
-	break;
-      if (c != '@')
-	{
-	  putchar (c);
-	  continue;
-	}
-      buf[0] = '\0';
-      fscanf (f, "%5[^ \n]", buf);
-      if (strcmp (buf, "hook") != 0)
+	printf ("%s", hook_array[i].type);
+      printf (" %s", hook_name);
+      if (hook_array[i].param)
 	{
-	  printf ("@%s", buf);
-	  continue;
+	  const char *q, *e;
+	  /* Print the parameter list, with the parameter names
+	     enclosed in @var{}.  */
+	  printf (" ");
+	  for (q = hook_array[i].param; (e = strpbrk (q, " *,)"));
+	       q = e + 1)
+	    /* Type names like 'int' are followed by a space, sometimes
+	       also by '*'.  'void' should appear only in "(void)".  */
+	    if (*e == ' ' || *e == '*' || *q == '(')
+	      printf ("%.*s", (int) (e - q + 1), q);
+	    else
+	      printf ("%.*s%c", (int) (e - q), q, *e);
 	}
-      fscanf (f, "%999s", buf);
-      sh.name = name = upstrdup (buf);
-      shp = (struct s_hook *) htab_find (start_hooks, &sh);
-      if (!shp || shp->pos < 0)
-	fatal ("No documentation for hook %s\n", sh.name);
-      i = shp->pos;
-      do
+
+      printf ("\n");
+      if (hook_array[i].doc[0])
 	{
-	  const char *q, *e;
-	  const char *deftype;
 	  const char *doc, *p_end;
-
-	  /* A leading '*' means to output the documentation string without
-	     further processing.  */
-	  if (*hook_array[i].doc == '*')
-	    printf ("%s", hook_array[i].doc + 1);
-	  else
+	  printf ("\n");
+	  /* Print each documentation paragraph in turn.  */
+	  for (doc = hook_array[i].doc; *doc; doc = p_end)
 	    {
-	      if (i != shp->pos)
-		printf ("\n\n");
-
-	      /* Print header.  Function-valued hooks have a parameter list, 
-		 unlike POD-valued ones.  */
-	      deftype = hook_array[i].param ? "deftypefn" : "deftypevr";
-	      printf ("@%s {%s} ", deftype, hook_array[i].docname);
-	      if (strchr (hook_array[i].type, ' '))
-		printf ("{%s}", hook_array[i].type);
-	      else
-		printf ("%s", hook_array[i].type);
-	      printf (" %s", name);
-	      if (hook_array[i].param)
-		{
-		  /* Print the parameter list, with the parameter names
-		     enclosed in @var{}.  */
-		  printf (" ");
-		  for (q = hook_array[i].param; (e = strpbrk (q, " *,)"));
-		       q = e + 1)
-		    /* Type names like 'int' are followed by a space, sometimes
-		       also by '*'.  'void' should appear only in "(void)".  */
-		    if (*e == ' ' || *e == '*' || *q == '(')
-		      printf ("%.*s", (int) (e - q + 1), q);
-		    else
-		      printf ("@var{%.*s}%c", (int) (e - q), q, *e);
-		}
-	      /* POD-valued hooks sometimes come in groups with common
-		 documentation.*/
-	      for (j = i + 1;
-		   j < (int) (sizeof hook_array / sizeof hook_array[0])
-		   && hook_array[j].doc == 0 && hook_array[j].type; j++)
-		{
-		  char *namex = upstrdup (hook_array[j].name);
-
-		  printf ("\n@%sx {%s} {%s} %s",
-			  deftype, hook_array[j].docname,
-			  hook_array[j].type, namex);
-		}
-	      if (hook_array[i].doc[0])
-		{
-		  printf ("\n");
-		  /* Print each documentation paragraph in turn.  */
-		  for (doc = hook_array[i].doc; *doc; doc = p_end)
-		    {
-		      /* Find paragraph end.  */
-		      p_end = strstr (doc, "\n\n");
-		      p_end = (p_end ? p_end + 2 : doc + strlen (doc));
-		      printf ("%.*s", (int) (p_end - doc), doc);
-		    }
-		  printf ("\n@end %s", deftype);
-		}
+	      /* Find paragraph end.  */
+	      p_end = strstr (doc, "\n");
+	      p_end = (p_end ? p_end + 1 : doc + strlen (doc));
+	      printf ("  %.*s", (int) (p_end - doc), doc);
 	    }
-	  if (++i >= (int) (sizeof hook_array / sizeof hook_array[0])
-	      || !hook_array[i].doc)
-	    break;
-	  free (name);
-	  sh.name = name = upstrdup (hook_array[i].name);
+	  printf ("\n");
 	}
-      while (!htab_find (start_hooks, &sh));
-      free (name);
+
+      printf ("\n[%s]\n\n", hook_name);
     }
 }
 
@@ -314,8 +176,8 @@ main (int argc, char **argv)
 {
   progname = "genhooks";
 
-  if (argc >= 3)
-    emit_documentation (argv[2]);
+  if (argc == 1)
+    emit_documentation ();
   else
     emit_init_macros (argv[1]);
   return 0;


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [gcc(refs/users/marxin/heads/sphinx-v2)] Build system integration.
@ 2021-06-23 11:51 Martin Liska
  0 siblings, 0 replies; 6+ messages in thread
From: Martin Liska @ 2021-06-23 11:51 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:059e908a2bbe34dfbf4c10bd73d796600433c873

commit 059e908a2bbe34dfbf4c10bd73d796600433c873
Author: Martin Liska <mliska@suse.cz>
Date:   Thu Jun 17 22:08:57 2021 +0200

    Build system integration.

Diff:
---
 config/acx.m4            |   2 +-
 configure                |   1 -
 configure.ac             |   1 -
 doc/baseconf.py          |   5 +-
 gcc/Makefile.in          | 216 ++++++++++++++++++++-----------------------
 gcc/configure            |  28 +++++-
 gcc/configure.ac         |  15 +++
 gcc/cp/Make-lang.in      |   2 +-
 gcc/doc/gcc/conf.py      |   9 +-
 gcc/fortran/Make-lang.in |  42 ++++-----
 gcc/genhooks.c           | 232 ++++++++++-------------------------------------
 11 files changed, 214 insertions(+), 339 deletions(-)

diff --git a/config/acx.m4 b/config/acx.m4
index 87c1b5e2932..65a7f4bc446 100644
--- a/config/acx.m4
+++ b/config/acx.m4
@@ -615,7 +615,7 @@ AC_DEFUN([ACX_BUGURL],[
     REPORT_BUGS_TEXI=
     ;;
   *)
-    REPORT_BUGS_TO="<$BUGURL>"
+    REPORT_BUGS_TO="$BUGURL"
     REPORT_BUGS_TEXI=@uref{`echo "$BUGURL" | sed 's/@/@@/g'`}
     ;;
   esac;
diff --git a/configure b/configure
index 1224fc4039e..e58cbb65158 100755
--- a/configure
+++ b/configure
@@ -10458,7 +10458,6 @@ case " $configdirs " in
     ;;
 esac
 
-
 # Host tools.
 ncn_tool_prefix=
 test -n "$host_alias" && ncn_tool_prefix=$host_alias-
diff --git a/configure.ac b/configure.ac
index 66d637d70dc..68c209852e9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3454,7 +3454,6 @@ case " $configdirs " in
     ;;
 esac
 
-
 # Host tools.
 NCN_STRICT_CHECK_TOOLS(AR, ar)
 NCN_STRICT_CHECK_TOOLS(AS, as)
diff --git a/doc/baseconf.py b/doc/baseconf.py
index 07bf2c551c8..206328d43e5 100644
--- a/doc/baseconf.py
+++ b/doc/baseconf.py
@@ -34,8 +34,9 @@ gcc_DEVPHASE = __read_file('DEV-PHASE')
 gcc_DATESTAMP = __read_file('DATESTAMP')
 gcc_REVISION = __read_file('REVISION')
 
-VERSION_PACKAGE = os.getenv('VERSION_PACKAGE', '(GCC)')
-BUGURL = os.getenv('BUGURL', 'https://gcc.gnu.org/bugs/')
+VERSION_PACKAGE = os.getenv('VERSION_PACKAGE')
+BUGURL = os.getenv('BUGURL')
+assert VERSION_PACKAGE and BUGURL
 
 # The short X.Y version.
 version = gcc_BASEVER
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index ebf26442992..66d99c1e9f9 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -771,11 +771,8 @@ LIBCONVERT =
 # Control whether header files are installed.
 INSTALL_HEADERS=install-headers install-mkheaders
 
-# Control whether Info documentation is built and installed.
-BUILD_INFO = @BUILD_INFO@
-
-# Control whether manpages generated by texi2pod.pl can be rebuilt.
-GENERATED_MANPAGES = @GENERATED_MANPAGES@
+# Control whether manpages generated by sphinx-build can be rebuilt.
+SPHINX_BUILD = @SPHINX_BUILD@
 
 # Additional directories of header files to run fixincludes on.
 # These should be directories searched automatically by default
@@ -2579,38 +2576,20 @@ s-d-target-hooks-def-h: build/genhooks$(build_exeext)
 					     d/d-target-hooks-def.h
 	$(STAMP) s-d-target-hooks-def-h
 
-# check if someone mistakenly only changed tm.texi.
-# We use a different pathname here to avoid a circular dependency.
-s-tm-texi: $(srcdir)/doc/../doc/tm.texi
-
 # The tm.texi we want to compare against / check into svn should have
 # unix-style line endings.  To make this work on MinGW, remove \r.
 # \r is not portable to Solaris tr, therefore we have a special
 # case for ASCII.  We use \r for other encodings like EBCDIC.
-s-tm-texi: build/genhooks$(build_exeext) $(srcdir)/doc/tm.texi.in
-	$(RUN_GEN) build/genhooks$(build_exeext) -d \
-			$(srcdir)/doc/tm.texi.in > tmp-tm.texi
-	case `echo X|tr X '\101'` in \
-	  A) tr -d '\015' < tmp-tm.texi > tmp2-tm.texi ;; \
-	  *) tr -d '\r' < tmp-tm.texi > tmp2-tm.texi ;; \
-	esac
-	mv tmp2-tm.texi tmp-tm.texi
-	$(SHELL) $(srcdir)/../move-if-change tmp-tm.texi tm.texi
-	@if cmp -s $(srcdir)/doc/tm.texi tm.texi; then \
+s-tm-rst-in: build/genhooks$(build_exeext)
+	$(RUN_GEN) build/genhooks$(build_exeext) > tmp-tm.rst.in
+	$(SHELL) $(srcdir)/../move-if-change tmp-tm.rst.in tm.rst.in
+
+	@if cmp -s $(srcdir)/doc/gccint/target-macros/tm.rst.in tm.rst.in; then \
 	  $(STAMP) $@; \
-	elif test $(srcdir)/doc/tm.texi -nt $(srcdir)/doc/tm.texi.in \
-	  && ( test $(srcdir)/doc/tm.texi -nt $(srcdir)/target.def \
-	    || test $(srcdir)/doc/tm.texi -nt $(srcdir)/c-family/c-target.def \
-	    || test $(srcdir)/doc/tm.texi -nt $(srcdir)/common/common-target.def \
-	    || test $(srcdir)/doc/tm.texi -nt $(srcdir)/d/d-target.def \
-	  ); then \
-	  echo >&2 ; \
-	  echo You should edit $(srcdir)/doc/tm.texi.in rather than $(srcdir)/doc/tm.texi . >&2 ; \
-	  false; \
 	else \
 	  echo >&2 ; \
 	  echo Verify that you have permission to grant a GFDL license for all >&2 ; \
-	  echo new text in $(objdir)/tm.texi, then copy it to $(srcdir)/doc/tm.texi. >&2 ; \
+	  echo new text in $(objdir)/tm.rst.in, then copy it to $(srcdir)/doc/gccint/target-macros/tm.rst.in. >&2 ; \
 	  false; \
 	fi
 
@@ -3281,15 +3260,7 @@ install-no-fixedincludes:
 
 # Remake the info files.
 
-doc: $(BUILD_INFO) $(GENERATED_MANPAGES)
-
-INFOFILES = doc/cpp.info doc/gcc.info doc/gccint.info \
-            doc/gccinstall.info doc/cppinternals.info
-
-info: $(INFOFILES) lang.info @GENINSRC@ srcinfo lang.srcinfo
-
-srcinfo: $(INFOFILES)
-	-cp -p $^ $(srcdir)/doc
+doc: $(SPHINX_BUILD)
 
 TEXI_CPP_FILES = cpp.texi fdl.texi cppenv.texi cppopts.texi		\
 	 gcc-common.texi gcc-vers.texi
@@ -3336,28 +3307,6 @@ gcc-vers.texi: $(BASEVER) $(DEVPHASE)
 	mv -f $@T $@
 
 
-# The *.1, *.7, *.info, *.dvi, and *.pdf files are being generated from implicit
-# patterns.  To use them, put each of the specific targets with its
-# specific dependencies but no build commands.
-
-doc/cpp.info: $(TEXI_CPP_FILES)
-doc/gcc.info: $(TEXI_GCC_FILES)
-doc/gccint.info: $(TEXI_GCCINT_FILES)
-doc/cppinternals.info: $(TEXI_CPPINT_FILES)
-
-doc/%.info: %.texi
-	if [ x$(BUILD_INFO) = xinfo ]; then \
-		$(MAKEINFO) $(MAKEINFOFLAGS) -I . -I $(gcc_docdir) \
-			-I $(gcc_docdir)/include -o $@ $<; \
-	fi
-
-# Duplicate entry to handle renaming of gccinstall.info
-doc/gccinstall.info: $(TEXI_GCCINSTALL_FILES)
-	if [ x$(BUILD_INFO) = xinfo ]; then \
-		$(MAKEINFO) $(MAKEINFOFLAGS) -I $(gcc_docdir) \
-			-I $(gcc_docdir)/include -o $@ $<; \
-	fi
-
 doc/cpp.dvi: $(TEXI_CPP_FILES)
 doc/gcc.dvi: $(TEXI_GCC_FILES)
 doc/gccint.dvi: $(TEXI_GCCINT_FILES)
@@ -3422,51 +3371,43 @@ $(build_htmldir)/gccinstall/index.html: $(TEXI_GCCINSTALL_FILES)
 	DESTDIR=$(@D) \
 	$(SHELL) $(srcdir)/doc/install.texi2html
 
-MANFILES = doc/gcov.1 doc/cpp.1 doc/gcc.1 doc/gfdl.7 doc/gpl.7 \
-           doc/fsf-funding.7 doc/gcov-tool.1 doc/gcov-dump.1 \
 	   $(if $(filter yes,@enable_lto@),doc/lto-dump.1)
 
-generated-manpages: man
+export VERSION_PACKAGE="$(PKGVERSION)"
+export ENABLE_LTO=$(enable_lto)
+export BUGURL="$(BUGURL_s)"
 
-man: $(MANFILES) lang.man @GENINSRC@ srcman lang.srcman
+man: man-gcc man-cpp lang.man @GENINSRC@
 
-srcman: $(MANFILES)
-	-cp -p $^ $(srcdir)/doc
+info: info-gcc info-gccint info-cpp info-cppinternals info-install lang.info @GENINSRC@
 
-doc/%.1: %.pod
-	$(STAMP) $@
-	-($(POD2MAN) --section=1 $< > $(@).T$$$$ && \
-		mv -f $(@).T$$$$ $@) || \
-		(rm -f $(@).T$$$$ && exit 1)
+sphinx-build: man info
 
-doc/%.7: %.pod
-	$(STAMP) $@
-	-($(POD2MAN) --section=7 $< > $(@).T$$$$ && \
-		mv -f $(@).T$$$$ $@) || \
-		(rm -f $(@).T$$$$ && exit 1)
+man-gcc: doc/gcc/man/man/gcc.1
 
-%.pod: %.texi
-	$(STAMP) $@
-	-$(TEXI2POD) -DBUGURL="$(BUGURL_TEXI)" $< > $@
+doc/gcc/man/man/gcc.1:
+	+ make -C $(srcdir)/../doc man SOURCEDIR=$(srcdir)/doc/gcc BUILDDIR=$(objdir)/doc/gcc/man
 
-.INTERMEDIATE: cpp.pod gcc.pod gfdl.pod fsf-funding.pod gpl.pod
-cpp.pod: cpp.texi cppenv.texi cppopts.texi
+man-cpp:
+	+ make -C $(srcdir)/../doc man SOURCEDIR=$(srcdir)/doc/cpp BUILDDIR=$(objdir)/doc/cpp/man
 
-# These next rules exist because the output name is not the same as
-# the input name, so our implicit %.pod rule will not work.
+info-gcc:
+	+ make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/doc/gcc BUILDDIR=$(objdir)/doc/gcc/info
 
-gcc.pod: invoke.texi cppenv.texi cppopts.texi gcc-vers.texi
-	$(STAMP) $@
-	-$(TEXI2POD) $< > $@
-gfdl.pod: fdl.texi
-	$(STAMP) $@
-	-$(TEXI2POD) $< > $@
-fsf-funding.pod: funding.texi
-	$(STAMP) $@
-	-$(TEXI2POD) $< > $@
-gpl.pod: gpl_v3.texi
-	$(STAMP) $@
-	-$(TEXI2POD) $< > $@
+info-gccint: s-tm-rst-in
+	+ make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/doc/gccint BUILDDIR=$(objdir)/doc/gccint/info
+
+info-cpp:
+	+ make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/doc/cpp BUILDDIR=$(objdir)/doc/cpp/info
+
+info-cppinternals:
+	+ make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/doc/cppinternals BUILDDIR=$(objdir)/doc/cppinternals/info
+
+info-install:
+	+ make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/doc/install BUILDDIR=$(objdir)/doc/install/info
+
+html-gccint: s-tm-rst-in
+	+ make -C $(srcdir)/../doc html SOURCEDIR=$(srcdir)/doc/gccint BUILDDIR=$(objdir)/doc/gccint/html
 
 #\f
 # Deletion of files made during compilation.
@@ -3526,8 +3467,7 @@ clean: mostlyclean lang.clean
 	-rm -f config.h tconfig.h bconfig.h tm_p.h tm.h
 	-rm -f options.c options.h optionlist
 	-rm -f cs-*
-	-rm -f doc/*.dvi
-	-rm -f doc/*.pdf
+	-rm -rf doc
 # Delete the include directories.
 	-rm -rf include include-fixed
 # Delete files used by the "multilib" facility (including libgcc subdirs).
@@ -3568,7 +3508,7 @@ maintainer-clean:
 	$(MAKE) lang.maintainer-clean distclean
 	-rm -f cpp.??s cpp.*aux
 	-rm -f gcc.??s gcc.*aux
-	-rm -f $(gcc_docdir)/*.info $(gcc_docdir)/*.1 $(gcc_docdir)/*.7 $(gcc_docdir)/*.dvi $(gcc_docdir)/*.pdf
+	-rm -rf doc
 #\f
 # Entry points `install', `install-strip', and `uninstall'.
 # Also use `install-collect2' to install collect2 when the config files don't.
@@ -3765,24 +3705,46 @@ install-info:: doc installdirs \
 	$(DESTDIR)$(infodir)/cpp.info \
 	$(DESTDIR)$(infodir)/gcc.info \
 	$(DESTDIR)$(infodir)/cppinternals.info \
-	$(DESTDIR)$(infodir)/gccinstall.info \
+	$(DESTDIR)$(infodir)/install.info \
 	$(DESTDIR)$(infodir)/gccint.info \
 	lang.install-info
 
-$(DESTDIR)$(infodir)/%.info: doc/%.info installdirs
-	rm -f $@
-	if [ -f $< ]; then \
-	  for f in $(<)*; do \
-	    realfile=`echo $$f | sed -e 's|.*/\([^/]*\)$$|\1|'`; \
-	    $(INSTALL_DATA) $$f $(DESTDIR)$(infodir)/$$realfile; \
-	    chmod a-x $(DESTDIR)$(infodir)/$$realfile; \
-	  done; \
-	else true; fi
-	-if $(SHELL) -c 'install-info --version' >/dev/null 2>&1; then \
-	  if [ -f $@ ]; then \
-	    install-info --dir-file=$(DESTDIR)$(infodir)/dir $@; \
-	  else true; fi; \
-	else true; fi;
+$(DESTDIR)$(infodir)/gcc.info: doc/gcc/info/texinfo/gcc.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/gccint.info: doc/gccint/info/texinfo/gccint.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/install.info: doc/install/info/texinfo/install.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/cpp.info: doc/cpp/info/texinfo/cpp.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/cppinternals.info: doc/cppinternals/info/texinfo/cppinternals.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/gcov.info: doc/gcc/info/texinfo/gcov.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/gcov-tool.info: doc/gcc/info/texinfo/gcov-tool.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/gcov-dump.info: doc/gcc/info/texinfo/gcov-dump.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/lto-dump.info: doc/gcc/info/texinfo/lto-dump.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
 
 pdf__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
 
@@ -3832,36 +3794,52 @@ $(DESTDIR)$(man7dir)/%$(man7ext): doc/%.7 installdirs
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
-$(DESTDIR)$(man1dir)/$(GCC_INSTALL_NAME)$(man1ext): doc/gcc.1 installdirs
+$(DESTDIR)$(man1dir)/$(GCC_INSTALL_NAME)$(man1ext): doc/gcc/man/man/gcc.1 installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
-$(DESTDIR)$(man1dir)/$(CPP_INSTALL_NAME)$(man1ext): doc/cpp.1 installdirs
+$(DESTDIR)$(man1dir)/$(CPP_INSTALL_NAME)$(man1ext): doc/cpp/man/man/cpp.1 installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
-$(DESTDIR)$(man1dir)/$(GCOV_INSTALL_NAME)$(man1ext): doc/gcov.1 installdirs
+$(DESTDIR)$(man1dir)/$(GCOV_INSTALL_NAME)$(man1ext): doc/gcc/man/man/gcov.1 installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
-$(DESTDIR)$(man1dir)/$(GCOV_TOOL_INSTALL_NAME)$(man1ext): doc/gcov-tool.1 installdirs
+$(DESTDIR)$(man1dir)/$(GCOV_TOOL_INSTALL_NAME)$(man1ext): doc/gcc/man/man/gcov-tool.1 installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
-$(DESTDIR)$(man1dir)/$(GCOV_DUMP_INSTALL_NAME)$(man1ext): doc/gcov-dump.1 installdirs
+$(DESTDIR)$(man1dir)/$(GCOV_DUMP_INSTALL_NAME)$(man1ext): doc/gcc/man/man/gcov-dump.1 installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
-$(DESTDIR)$(man1dir)/$(LTO_DUMP_INSTALL_NAME)$(man1ext): doc/lto-dump.1 installdirs
+$(DESTDIR)$(man1dir)/$(LTO_DUMP_INSTALL_NAME)$(man1ext): doc/gcc/man/man/lto-dump.1 installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
+$(DESTDIR)$(man7dir)/fsf-funding$(man7ext): doc/gcc/man/man/fsf-funding.7 installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+	-chmod a-x $@
+
+$(DESTDIR)$(man7dir)/gfdl$(man7ext): doc/gcc/man/man/gfdl.7 installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+	-chmod a-x $@
+
+$(DESTDIR)$(man7dir)/gpl$(man7ext): doc/gcc/man/man/gpl.7 installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+	-chmod a-x $@
+
+
 # Install all the header files built in the include subdirectory.
 install-headers: $(INSTALL_HEADERS_DIR)
 # Fix symlinks to absolute paths in the installed include directory to
diff --git a/gcc/configure b/gcc/configure
index dd0194a57f4..b7274875b84 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -806,6 +806,7 @@ AR
 NM
 BISON
 FLEX
+SPHINX_BUILD
 GENERATED_MANPAGES
 BUILD_INFO
 MAKEINFO
@@ -7905,7 +7906,7 @@ fi
     REPORT_BUGS_TEXI=
     ;;
   *)
-    REPORT_BUGS_TO="<$BUGURL>"
+    REPORT_BUGS_TO="$BUGURL"
     REPORT_BUGS_TEXI=@uref{`echo "$BUGURL" | sed 's/@/@@/g'`}
     ;;
   esac;
@@ -8557,6 +8558,27 @@ $as_echo "no" >&6; }
 fi
 
 
+# See if sphinx-build has been installed and is modern enough
+# that we can use it.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for sphinx-build" >&5
+$as_echo_n "checking for sphinx-build... " >&6; }
+if sphinx-build -j auto -h &>/dev/null ; then
+  SPHINX_BUILD=sphinx-build
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING:
+  *** sphinx-build is missing or too old.
+  *** Info and man pages documentation will not be built." >&5
+$as_echo "$as_me: WARNING:
+  *** sphinx-build is missing or too old.
+  *** Info and man pages documentation will not be built." >&2;}
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+  SPHINX_BUILD=
+fi
+
+
 MISSING="${CONFIG_SHELL-/bin/sh} $ac_aux_dir/missing"
 
 # How about lex?
@@ -19435,7 +19457,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 19438 "configure"
+#line 19460 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -19541,7 +19563,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 19544 "configure"
+#line 19566 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 5f30f80833e..cecdd339862 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -1208,6 +1208,21 @@ else
 fi
 AC_SUBST(GENERATED_MANPAGES)
 
+# See if sphinx-build has been installed and is modern enough
+# that we can use it.
+AC_MSG_CHECKING([for sphinx-build])
+if sphinx-build -j auto -h &>/dev/null ; then
+  SPHINX_BUILD=sphinx-build
+  AC_MSG_RESULT(yes)
+else
+  AC_MSG_WARN([
+  *** sphinx-build is missing or too old.
+  *** Info and man pages documentation will not be built.])
+  AC_MSG_RESULT(no)
+  SPHINX_BUILD=
+fi
+AC_SUBST(SPHINX_BUILD)
+
 MISSING="${CONFIG_SHELL-/bin/sh} $ac_aux_dir/missing"
 
 # How about lex?
diff --git a/gcc/cp/Make-lang.in b/gcc/cp/Make-lang.in
index 155be74efdb..6e49e3117db 100644
--- a/gcc/cp/Make-lang.in
+++ b/gcc/cp/Make-lang.in
@@ -260,7 +260,7 @@ c++.install-common: installdirs
 
 # We can't use links because not everyone supports them.  So just copy the
 # manpage.
-doc/g++.1: doc/gcc.1
+doc/g++.1: doc/gcc/man/man/gcc.1
 	cp $< doc/g++.1
 
 c++.install-man: $(DESTDIR)$(man1dir)/$(GXX_INSTALL_NAME)$(man1ext)
diff --git a/gcc/doc/gcc/conf.py b/gcc/doc/gcc/conf.py
index d6d69de24f8..ac1bc73ca78 100644
--- a/gcc/doc/gcc/conf.py
+++ b/gcc/doc/gcc/conf.py
@@ -1,5 +1,6 @@
 # Configuration file for the Sphinx documentation builder.
 
+import os
 import sys
 sys.path.append('../../..//doc')
 
@@ -29,8 +30,14 @@ man_pages = [
     ('funding', 'fsf-funding', 'Funding Free Software', [], 7)
 ]
 
+ENABLE_LTO = os.getenv('ENABLE_LTO')
+assert ENABLE_LTO
+
+if ENABLE_LTO  == 'yes':
+    man_pages += [('lto-dump', 'lto-dump', 'Tool for dumping LTO object files', [authors], 1)]
+
 texinfo_documents = [
   ('index', 'gcc', project, authors, None, None, None, True)
 ]
 
-tags.add('gcc')
\ No newline at end of file
+tags.add('gcc')
diff --git a/gcc/fortran/Make-lang.in b/gcc/fortran/Make-lang.in
index 63195a9c7ed..686788ee868 100644
--- a/gcc/fortran/Make-lang.in
+++ b/gcc/fortran/Make-lang.in
@@ -109,16 +109,18 @@ fortran.all.cross: gfortran-cross$(exeext)
 fortran.start.encap: gfortran$(exeext)
 fortran.rest.encap:
 
-fortran.srcinfo: doc/gfortran.info
-	-cp -p $^ $(srcdir)/fortran
-
 fortran.tags: force
 	cd $(srcdir)/fortran; etags -o TAGS.sub *.c *.h; \
 	etags --include TAGS.sub --include ../TAGS.sub
 
-fortran.info: doc/gfortran.info doc/gfc-internals.info
+fortran.info: info-gfortran info-gfc-internals
 fortran.dvi: doc/gfortran.dvi doc/gfc-internals.dvi
 
+info-gfortran:
+	+ if [ x$(SPHINX_BUILD) = xsphinx-build ]; then \
+	  make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/fortran/doc/gfortran BUILDDIR=$(objdir)/doc/fortran/info; \
+	else true; fi
+
 F95_HTMLFILES = $(build_htmldir)/gfortran
 
 fortran.html: $(F95_HTMLFILES)/index.html
@@ -154,9 +156,10 @@ fortran.install-pdf: $(F95_PDFFILES)
 	  $(INSTALL_DATA) "$$d$$p" "$(DESTDIR)$(pdfdir)/gcc/$$f"; \
 	done
 
-F95_MANFILES = doc/gfortran.1
+man-fortran:
+	+ make -C $(srcdir)/../doc man SOURCEDIR=$(srcdir)/fortran/doc/gfortran BUILDDIR=$(objdir)/doc/fortran/man
 
-fortran.man: $(F95_MANFILES)
+fortran.man: man-fortran
 
 fortran.srcman: $(F95_MANFILES)
 	-cp -p $^ $(srcdir)/doc
@@ -186,13 +189,6 @@ GFORTRAN_TEXI = \
   $(srcdir)/doc/include/gcc-common.texi \
   gcc-vers.texi
 
-doc/gfortran.info: $(GFORTRAN_TEXI)
-	if [ x$(BUILD_INFO) = xinfo ]; then \
-	  rm -f doc/gfortran.info-*; \
-	  $(MAKEINFO) -I $(srcdir)/doc/include -I $(srcdir)/fortran \
-	    -o $@ $<; \
-	else true; fi
-
 doc/gfortran.dvi: $(GFORTRAN_TEXI)
 	$(TEXI2DVI) -I $(srcdir)/fortran -I $(abs_docdir)/include -o $@ $<
 
@@ -217,11 +213,9 @@ GFC_INTERNALS_TEXI = \
   $(srcdir)/doc/include/gcc-common.texi \
   gcc-vers.texi
 
-doc/gfc-internals.info: $(GFC_INTERNALS_TEXI)
-	if [ x$(BUILD_INFO) = xinfo ]; then \
-	  rm -f doc/gfc-internals.info-*; \
-	  $(MAKEINFO) -I $(srcdir)/doc/include -I $(srcdir)/fortran \
-	    -o $@ $<; \
+info-gfc-internals:
+	+ if [ x$(SPHINX_BUILD) = xsphinx-build ]; then \
+	  make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/fortran/doc/gfc-internals BUILDDIR=$(objdir)/doc/gfc-internals/info; \
 	else true; fi
 
 doc/gfc-internals.dvi: $(GFC_INTERNALS_TEXI)
@@ -256,9 +250,13 @@ fortran.install-plugin:
 
 fortran.install-info: $(DESTDIR)$(infodir)/gfortran.info
 
+$(DESTDIR)$(infodir)/gfortran.info: doc/fortran/info/texinfo/gfortran.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
 fortran.install-man: $(DESTDIR)$(man1dir)/$(GFORTRAN_INSTALL_NAME)$(man1ext)
 
-$(DESTDIR)$(man1dir)/$(GFORTRAN_INSTALL_NAME)$(man1ext): doc/gfortran.1 \
+$(DESTDIR)$(man1dir)/$(GFORTRAN_INSTALL_NAME)$(man1ext): doc/fortran/man/man/gfortran.1 \
 		installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
@@ -286,12 +284,6 @@ fortran.mostlyclean:
 fortran.clean:
 fortran.distclean:
 	-rm -f fortran/config.status fortran/Makefile
-
-fortran.extraclean:
-fortran.maintainer-clean:
-	-rm -f doc/gfortran.info* fortran/gfortran.*aux
-	-rm -f $(docobjdir)/gfortran.1
-
 #\f
 # Stage hooks:
 # The toplevel makefile has already created stage?/fortran at this point.
diff --git a/gcc/genhooks.c b/gcc/genhooks.c
index ebe0d0954e6..6ba6254381b 100644
--- a/gcc/genhooks.c
+++ b/gcc/genhooks.c
@@ -48,212 +48,74 @@ upstrdup (const char *in)
   return ret;
 }
 
-/* Struct for 'start hooks' which start a sequence of consecutive hooks
-   that are defined in target.def and to be documented in tm.texi.  */
-struct s_hook
-{
-  char *name;
-  int pos;
-};
-
-static hashval_t
-s_hook_hash (const void *p)
-{
-  const struct s_hook *s_hook = (const struct s_hook *)p;
-  return htab_hash_string (s_hook->name);
-}
+/* Emit shared .rst.in file that is used by the corresponding
+   .. include:: tm.rst.in
+     :start-after: [HOOK_NAME]
+     :end-before: [HOOK_NAME]
 
-static int
-s_hook_eq_p (const void *p1, const void *p2)
-{
-  return (strcmp (((const struct s_hook *) p1)->name, 
-		  ((const struct s_hook *) p2)->name) == 0);
-}
-
-/* Read the documentation file with name IN_FNAME, perform substitutions
-   to incorporate information from hook_array, and emit the result on stdout.
-   Hooks defined with DEFHOOK / DEFHOOKPOD are emitted at the place of a
-   matching @hook in the input file; if there is no matching @hook, the
-   hook is emitted after the hook that precedes it in target.def .
-   Usually, the emitted hook documentation starts with the hook
-   signature, followed by the string from the doc field.
-   The documentation is bracketed in @deftypefn / @deftypevr and a matching
-   @end.
-   While emitting the doc field, an @findex entry is added
-   to the affected paragraph.
    If the doc field starts with '*', the leading '*' is stripped, and the doc
    field is otherwise emitted unaltered; no function signature/
    @deftypefn/deftypevr/@end is emitted.
    In particular, a doc field of "*" means not to emit any ocumentation for
    this target.def / hook_array entry at all (there might be documentation
    for this hook in the file named IN_FNAME, though).
-   A doc field of 0 is used to append the hook signature after the previous
-   hook's signture, so that one description can be used for a group of hooks.
-   When the doc field is "", @deftypefn/@deftypevr and the hook signature
-   is emitted, but not the matching @end.  This allows all the free-form
+
+   This allows all the free-form
    documentation to be placed in IN_FNAME, to work around GPL/GFDL
    licensing incompatibility issues.  */
+
 static void
-emit_documentation (const char *in_fname)
+emit_documentation (void)
 {
-  int i, j;
-  char buf[1000];
-  htab_t start_hooks = htab_create (99, s_hook_hash, s_hook_eq_p, (htab_del) 0);
-  FILE *f;
-
-  /* Enter all the start hooks in start_hooks.  */
-  f = fopen (in_fname, "r");
-  if (!f)
-    {
-      perror ("");
-      fatal ("Couldn't open input file");
-    }
-  while (fscanf (f, "%*[^@]"), buf[0] = '\0',
-	 fscanf (f, "@%5[^ \n]", buf) != EOF)
-    {
-      void **p;
-      struct s_hook *shp;
-
-      if (strcmp (buf, "hook") != 0)
-	continue;
-      buf[0] = '\0';
-      fscanf (f, "%999s", buf);
-      shp = XNEW (struct s_hook);
-      shp->name = upstrdup (buf);
-      shp->pos = -1;
-      p = htab_find_slot (start_hooks, shp, INSERT);
-      if (*p != HTAB_EMPTY_ENTRY)
-	fatal ("Duplicate placement for hook %s\n", shp->name);
-      *(struct s_hook **) p = shp;
-    }
-  fclose (f);
   /* For each hook in hook_array, if it is a start hook, store its position.  */
-  for (i = 0; i < (int) (sizeof hook_array / sizeof hook_array[0]); i++)
+  for (int i = 0; i < (int) (sizeof hook_array / sizeof hook_array[0]); i++)
     {
-      struct s_hook sh, *shp;
-      void *p;
-
       if (!hook_array[i].doc || strcmp (hook_array[i].doc, "*") == 0)
 	continue;
-      sh.name = upstrdup (hook_array[i].name);
-      p = htab_find (start_hooks, &sh);
-      if (p)
-	{
-	  shp = (struct s_hook *) p;
-	  if (shp->pos >= 0)
-	    fatal ("Duplicate hook %s\n", sh.name);
-	  shp->pos = i;
-	}
+      const char *hook_name = upstrdup (hook_array[i].name);
+      printf ("[%s]\n", hook_name);
+      /* Print header.  Function-valued hooks have a parameter list,
+	 unlike POD-valued ones.  */
+      const char *deftype = hook_array[i].param ? "c:function" : "c:var";
+      printf (".. %s:: ", deftype);
+      if (strchr (hook_array[i].type, ' '))
+	printf ("%s", hook_array[i].type);
       else
-	fatal ("No place specified to document hook %s\n", sh.name);
-      free (sh.name);
-    }
-  /* Copy input file to stdout, substituting @hook directives with the
-     corresponding hook documentation sequences.  */
-  f = fopen (in_fname, "r");
-  if (!f)
-    {
-      perror ("");
-      fatal ("Couldn't open input file");
-    }
-  for (;;)
-    {
-      struct s_hook sh, *shp;
-      int c = getc (f);
-      char *name;
-
-      if (c == EOF)
-	break;
-      if (c != '@')
-	{
-	  putchar (c);
-	  continue;
-	}
-      buf[0] = '\0';
-      fscanf (f, "%5[^ \n]", buf);
-      if (strcmp (buf, "hook") != 0)
+	printf ("%s", hook_array[i].type);
+      printf (" %s", hook_name);
+      if (hook_array[i].param)
 	{
-	  printf ("@%s", buf);
-	  continue;
+	  const char *q, *e;
+	  /* Print the parameter list, with the parameter names
+	     enclosed in @var{}.  */
+	  printf (" ");
+	  for (q = hook_array[i].param; (e = strpbrk (q, " *,)"));
+	       q = e + 1)
+	    /* Type names like 'int' are followed by a space, sometimes
+	       also by '*'.  'void' should appear only in "(void)".  */
+	    if (*e == ' ' || *e == '*' || *q == '(')
+	      printf ("%.*s", (int) (e - q + 1), q);
+	    else
+	      printf ("%.*s%c", (int) (e - q), q, *e);
 	}
-      fscanf (f, "%999s", buf);
-      sh.name = name = upstrdup (buf);
-      shp = (struct s_hook *) htab_find (start_hooks, &sh);
-      if (!shp || shp->pos < 0)
-	fatal ("No documentation for hook %s\n", sh.name);
-      i = shp->pos;
-      do
+
+      printf ("\n");
+      if (hook_array[i].doc[0])
 	{
-	  const char *q, *e;
-	  const char *deftype;
 	  const char *doc, *p_end;
-
-	  /* A leading '*' means to output the documentation string without
-	     further processing.  */
-	  if (*hook_array[i].doc == '*')
-	    printf ("%s", hook_array[i].doc + 1);
-	  else
+	  printf ("\n");
+	  /* Print each documentation paragraph in turn.  */
+	  for (doc = hook_array[i].doc; *doc; doc = p_end)
 	    {
-	      if (i != shp->pos)
-		printf ("\n\n");
-
-	      /* Print header.  Function-valued hooks have a parameter list, 
-		 unlike POD-valued ones.  */
-	      deftype = hook_array[i].param ? "deftypefn" : "deftypevr";
-	      printf ("@%s {%s} ", deftype, hook_array[i].docname);
-	      if (strchr (hook_array[i].type, ' '))
-		printf ("{%s}", hook_array[i].type);
-	      else
-		printf ("%s", hook_array[i].type);
-	      printf (" %s", name);
-	      if (hook_array[i].param)
-		{
-		  /* Print the parameter list, with the parameter names
-		     enclosed in @var{}.  */
-		  printf (" ");
-		  for (q = hook_array[i].param; (e = strpbrk (q, " *,)"));
-		       q = e + 1)
-		    /* Type names like 'int' are followed by a space, sometimes
-		       also by '*'.  'void' should appear only in "(void)".  */
-		    if (*e == ' ' || *e == '*' || *q == '(')
-		      printf ("%.*s", (int) (e - q + 1), q);
-		    else
-		      printf ("@var{%.*s}%c", (int) (e - q), q, *e);
-		}
-	      /* POD-valued hooks sometimes come in groups with common
-		 documentation.*/
-	      for (j = i + 1;
-		   j < (int) (sizeof hook_array / sizeof hook_array[0])
-		   && hook_array[j].doc == 0 && hook_array[j].type; j++)
-		{
-		  char *namex = upstrdup (hook_array[j].name);
-
-		  printf ("\n@%sx {%s} {%s} %s",
-			  deftype, hook_array[j].docname,
-			  hook_array[j].type, namex);
-		}
-	      if (hook_array[i].doc[0])
-		{
-		  printf ("\n");
-		  /* Print each documentation paragraph in turn.  */
-		  for (doc = hook_array[i].doc; *doc; doc = p_end)
-		    {
-		      /* Find paragraph end.  */
-		      p_end = strstr (doc, "\n\n");
-		      p_end = (p_end ? p_end + 2 : doc + strlen (doc));
-		      printf ("%.*s", (int) (p_end - doc), doc);
-		    }
-		  printf ("\n@end %s", deftype);
-		}
+	      /* Find paragraph end.  */
+	      p_end = strstr (doc, "\n");
+	      p_end = (p_end ? p_end + 1 : doc + strlen (doc));
+	      printf ("  %.*s", (int) (p_end - doc), doc);
 	    }
-	  if (++i >= (int) (sizeof hook_array / sizeof hook_array[0])
-	      || !hook_array[i].doc)
-	    break;
-	  free (name);
-	  sh.name = name = upstrdup (hook_array[i].name);
+	  printf ("\n");
 	}
-      while (!htab_find (start_hooks, &sh));
-      free (name);
+
+      printf ("\n[%s]\n\n", hook_name);
     }
 }
 
@@ -314,8 +176,8 @@ main (int argc, char **argv)
 {
   progname = "genhooks";
 
-  if (argc >= 3)
-    emit_documentation (argv[2]);
+  if (argc == 1)
+    emit_documentation ();
   else
     emit_init_macros (argv[1]);
   return 0;


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [gcc(refs/users/marxin/heads/sphinx-v2)] Build system integration.
@ 2021-06-23 11:27 Martin Liska
  0 siblings, 0 replies; 6+ messages in thread
From: Martin Liska @ 2021-06-23 11:27 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:b0075758dc4d323d0b1fa31994417f676768555c

commit b0075758dc4d323d0b1fa31994417f676768555c
Author: Martin Liska <mliska@suse.cz>
Date:   Thu Jun 17 22:08:57 2021 +0200

    Build system integration.

Diff:
---
 config/acx.m4            |   2 +-
 configure                |   1 -
 configure.ac             |   1 -
 doc/Makefile             |   3 +-
 doc/baseconf.py          |   5 +-
 gcc/Makefile.in          | 216 ++++++++++++++++++++-----------------------
 gcc/configure            |  28 +++++-
 gcc/configure.ac         |  15 +++
 gcc/cp/Make-lang.in      |   2 +-
 gcc/doc/gcc/conf.py      |   9 +-
 gcc/fortran/Make-lang.in |  42 ++++-----
 gcc/genhooks.c           | 232 ++++++++++-------------------------------------
 12 files changed, 216 insertions(+), 340 deletions(-)

diff --git a/config/acx.m4 b/config/acx.m4
index 87c1b5e2932..65a7f4bc446 100644
--- a/config/acx.m4
+++ b/config/acx.m4
@@ -615,7 +615,7 @@ AC_DEFUN([ACX_BUGURL],[
     REPORT_BUGS_TEXI=
     ;;
   *)
-    REPORT_BUGS_TO="<$BUGURL>"
+    REPORT_BUGS_TO="$BUGURL"
     REPORT_BUGS_TEXI=@uref{`echo "$BUGURL" | sed 's/@/@@/g'`}
     ;;
   esac;
diff --git a/configure b/configure
index 1224fc4039e..e58cbb65158 100755
--- a/configure
+++ b/configure
@@ -10458,7 +10458,6 @@ case " $configdirs " in
     ;;
 esac
 
-
 # Host tools.
 ncn_tool_prefix=
 test -n "$host_alias" && ncn_tool_prefix=$host_alias-
diff --git a/configure.ac b/configure.ac
index 66d637d70dc..68c209852e9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3454,7 +3454,6 @@ case " $configdirs " in
     ;;
 esac
 
-
 # Host tools.
 NCN_STRICT_CHECK_TOOLS(AR, ar)
 NCN_STRICT_CHECK_TOOLS(AS, as)
diff --git a/doc/Makefile b/doc/Makefile
index 9e305a8e7da..7f3690e7e50 100644
--- a/doc/Makefile
+++ b/doc/Makefile
@@ -3,7 +3,8 @@
 
 # You can set these variables from the command line.
 SPHINXOPTS   ?= -j auto -q
-SPHINXBUILD  ?= sphinx-build
+# FIXME
+SPHINXBUILD  ?= /tmp/venv/bin/sphinx-build
 PAPER        ?=
 SOURCEDIR     = .
 BUILDDIR      = _build
diff --git a/doc/baseconf.py b/doc/baseconf.py
index 07bf2c551c8..206328d43e5 100644
--- a/doc/baseconf.py
+++ b/doc/baseconf.py
@@ -34,8 +34,9 @@ gcc_DEVPHASE = __read_file('DEV-PHASE')
 gcc_DATESTAMP = __read_file('DATESTAMP')
 gcc_REVISION = __read_file('REVISION')
 
-VERSION_PACKAGE = os.getenv('VERSION_PACKAGE', '(GCC)')
-BUGURL = os.getenv('BUGURL', 'https://gcc.gnu.org/bugs/')
+VERSION_PACKAGE = os.getenv('VERSION_PACKAGE')
+BUGURL = os.getenv('BUGURL')
+assert VERSION_PACKAGE and BUGURL
 
 # The short X.Y version.
 version = gcc_BASEVER
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index ebf26442992..66d99c1e9f9 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -771,11 +771,8 @@ LIBCONVERT =
 # Control whether header files are installed.
 INSTALL_HEADERS=install-headers install-mkheaders
 
-# Control whether Info documentation is built and installed.
-BUILD_INFO = @BUILD_INFO@
-
-# Control whether manpages generated by texi2pod.pl can be rebuilt.
-GENERATED_MANPAGES = @GENERATED_MANPAGES@
+# Control whether manpages generated by sphinx-build can be rebuilt.
+SPHINX_BUILD = @SPHINX_BUILD@
 
 # Additional directories of header files to run fixincludes on.
 # These should be directories searched automatically by default
@@ -2579,38 +2576,20 @@ s-d-target-hooks-def-h: build/genhooks$(build_exeext)
 					     d/d-target-hooks-def.h
 	$(STAMP) s-d-target-hooks-def-h
 
-# check if someone mistakenly only changed tm.texi.
-# We use a different pathname here to avoid a circular dependency.
-s-tm-texi: $(srcdir)/doc/../doc/tm.texi
-
 # The tm.texi we want to compare against / check into svn should have
 # unix-style line endings.  To make this work on MinGW, remove \r.
 # \r is not portable to Solaris tr, therefore we have a special
 # case for ASCII.  We use \r for other encodings like EBCDIC.
-s-tm-texi: build/genhooks$(build_exeext) $(srcdir)/doc/tm.texi.in
-	$(RUN_GEN) build/genhooks$(build_exeext) -d \
-			$(srcdir)/doc/tm.texi.in > tmp-tm.texi
-	case `echo X|tr X '\101'` in \
-	  A) tr -d '\015' < tmp-tm.texi > tmp2-tm.texi ;; \
-	  *) tr -d '\r' < tmp-tm.texi > tmp2-tm.texi ;; \
-	esac
-	mv tmp2-tm.texi tmp-tm.texi
-	$(SHELL) $(srcdir)/../move-if-change tmp-tm.texi tm.texi
-	@if cmp -s $(srcdir)/doc/tm.texi tm.texi; then \
+s-tm-rst-in: build/genhooks$(build_exeext)
+	$(RUN_GEN) build/genhooks$(build_exeext) > tmp-tm.rst.in
+	$(SHELL) $(srcdir)/../move-if-change tmp-tm.rst.in tm.rst.in
+
+	@if cmp -s $(srcdir)/doc/gccint/target-macros/tm.rst.in tm.rst.in; then \
 	  $(STAMP) $@; \
-	elif test $(srcdir)/doc/tm.texi -nt $(srcdir)/doc/tm.texi.in \
-	  && ( test $(srcdir)/doc/tm.texi -nt $(srcdir)/target.def \
-	    || test $(srcdir)/doc/tm.texi -nt $(srcdir)/c-family/c-target.def \
-	    || test $(srcdir)/doc/tm.texi -nt $(srcdir)/common/common-target.def \
-	    || test $(srcdir)/doc/tm.texi -nt $(srcdir)/d/d-target.def \
-	  ); then \
-	  echo >&2 ; \
-	  echo You should edit $(srcdir)/doc/tm.texi.in rather than $(srcdir)/doc/tm.texi . >&2 ; \
-	  false; \
 	else \
 	  echo >&2 ; \
 	  echo Verify that you have permission to grant a GFDL license for all >&2 ; \
-	  echo new text in $(objdir)/tm.texi, then copy it to $(srcdir)/doc/tm.texi. >&2 ; \
+	  echo new text in $(objdir)/tm.rst.in, then copy it to $(srcdir)/doc/gccint/target-macros/tm.rst.in. >&2 ; \
 	  false; \
 	fi
 
@@ -3281,15 +3260,7 @@ install-no-fixedincludes:
 
 # Remake the info files.
 
-doc: $(BUILD_INFO) $(GENERATED_MANPAGES)
-
-INFOFILES = doc/cpp.info doc/gcc.info doc/gccint.info \
-            doc/gccinstall.info doc/cppinternals.info
-
-info: $(INFOFILES) lang.info @GENINSRC@ srcinfo lang.srcinfo
-
-srcinfo: $(INFOFILES)
-	-cp -p $^ $(srcdir)/doc
+doc: $(SPHINX_BUILD)
 
 TEXI_CPP_FILES = cpp.texi fdl.texi cppenv.texi cppopts.texi		\
 	 gcc-common.texi gcc-vers.texi
@@ -3336,28 +3307,6 @@ gcc-vers.texi: $(BASEVER) $(DEVPHASE)
 	mv -f $@T $@
 
 
-# The *.1, *.7, *.info, *.dvi, and *.pdf files are being generated from implicit
-# patterns.  To use them, put each of the specific targets with its
-# specific dependencies but no build commands.
-
-doc/cpp.info: $(TEXI_CPP_FILES)
-doc/gcc.info: $(TEXI_GCC_FILES)
-doc/gccint.info: $(TEXI_GCCINT_FILES)
-doc/cppinternals.info: $(TEXI_CPPINT_FILES)
-
-doc/%.info: %.texi
-	if [ x$(BUILD_INFO) = xinfo ]; then \
-		$(MAKEINFO) $(MAKEINFOFLAGS) -I . -I $(gcc_docdir) \
-			-I $(gcc_docdir)/include -o $@ $<; \
-	fi
-
-# Duplicate entry to handle renaming of gccinstall.info
-doc/gccinstall.info: $(TEXI_GCCINSTALL_FILES)
-	if [ x$(BUILD_INFO) = xinfo ]; then \
-		$(MAKEINFO) $(MAKEINFOFLAGS) -I $(gcc_docdir) \
-			-I $(gcc_docdir)/include -o $@ $<; \
-	fi
-
 doc/cpp.dvi: $(TEXI_CPP_FILES)
 doc/gcc.dvi: $(TEXI_GCC_FILES)
 doc/gccint.dvi: $(TEXI_GCCINT_FILES)
@@ -3422,51 +3371,43 @@ $(build_htmldir)/gccinstall/index.html: $(TEXI_GCCINSTALL_FILES)
 	DESTDIR=$(@D) \
 	$(SHELL) $(srcdir)/doc/install.texi2html
 
-MANFILES = doc/gcov.1 doc/cpp.1 doc/gcc.1 doc/gfdl.7 doc/gpl.7 \
-           doc/fsf-funding.7 doc/gcov-tool.1 doc/gcov-dump.1 \
 	   $(if $(filter yes,@enable_lto@),doc/lto-dump.1)
 
-generated-manpages: man
+export VERSION_PACKAGE="$(PKGVERSION)"
+export ENABLE_LTO=$(enable_lto)
+export BUGURL="$(BUGURL_s)"
 
-man: $(MANFILES) lang.man @GENINSRC@ srcman lang.srcman
+man: man-gcc man-cpp lang.man @GENINSRC@
 
-srcman: $(MANFILES)
-	-cp -p $^ $(srcdir)/doc
+info: info-gcc info-gccint info-cpp info-cppinternals info-install lang.info @GENINSRC@
 
-doc/%.1: %.pod
-	$(STAMP) $@
-	-($(POD2MAN) --section=1 $< > $(@).T$$$$ && \
-		mv -f $(@).T$$$$ $@) || \
-		(rm -f $(@).T$$$$ && exit 1)
+sphinx-build: man info
 
-doc/%.7: %.pod
-	$(STAMP) $@
-	-($(POD2MAN) --section=7 $< > $(@).T$$$$ && \
-		mv -f $(@).T$$$$ $@) || \
-		(rm -f $(@).T$$$$ && exit 1)
+man-gcc: doc/gcc/man/man/gcc.1
 
-%.pod: %.texi
-	$(STAMP) $@
-	-$(TEXI2POD) -DBUGURL="$(BUGURL_TEXI)" $< > $@
+doc/gcc/man/man/gcc.1:
+	+ make -C $(srcdir)/../doc man SOURCEDIR=$(srcdir)/doc/gcc BUILDDIR=$(objdir)/doc/gcc/man
 
-.INTERMEDIATE: cpp.pod gcc.pod gfdl.pod fsf-funding.pod gpl.pod
-cpp.pod: cpp.texi cppenv.texi cppopts.texi
+man-cpp:
+	+ make -C $(srcdir)/../doc man SOURCEDIR=$(srcdir)/doc/cpp BUILDDIR=$(objdir)/doc/cpp/man
 
-# These next rules exist because the output name is not the same as
-# the input name, so our implicit %.pod rule will not work.
+info-gcc:
+	+ make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/doc/gcc BUILDDIR=$(objdir)/doc/gcc/info
 
-gcc.pod: invoke.texi cppenv.texi cppopts.texi gcc-vers.texi
-	$(STAMP) $@
-	-$(TEXI2POD) $< > $@
-gfdl.pod: fdl.texi
-	$(STAMP) $@
-	-$(TEXI2POD) $< > $@
-fsf-funding.pod: funding.texi
-	$(STAMP) $@
-	-$(TEXI2POD) $< > $@
-gpl.pod: gpl_v3.texi
-	$(STAMP) $@
-	-$(TEXI2POD) $< > $@
+info-gccint: s-tm-rst-in
+	+ make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/doc/gccint BUILDDIR=$(objdir)/doc/gccint/info
+
+info-cpp:
+	+ make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/doc/cpp BUILDDIR=$(objdir)/doc/cpp/info
+
+info-cppinternals:
+	+ make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/doc/cppinternals BUILDDIR=$(objdir)/doc/cppinternals/info
+
+info-install:
+	+ make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/doc/install BUILDDIR=$(objdir)/doc/install/info
+
+html-gccint: s-tm-rst-in
+	+ make -C $(srcdir)/../doc html SOURCEDIR=$(srcdir)/doc/gccint BUILDDIR=$(objdir)/doc/gccint/html
 
 #\f
 # Deletion of files made during compilation.
@@ -3526,8 +3467,7 @@ clean: mostlyclean lang.clean
 	-rm -f config.h tconfig.h bconfig.h tm_p.h tm.h
 	-rm -f options.c options.h optionlist
 	-rm -f cs-*
-	-rm -f doc/*.dvi
-	-rm -f doc/*.pdf
+	-rm -rf doc
 # Delete the include directories.
 	-rm -rf include include-fixed
 # Delete files used by the "multilib" facility (including libgcc subdirs).
@@ -3568,7 +3508,7 @@ maintainer-clean:
 	$(MAKE) lang.maintainer-clean distclean
 	-rm -f cpp.??s cpp.*aux
 	-rm -f gcc.??s gcc.*aux
-	-rm -f $(gcc_docdir)/*.info $(gcc_docdir)/*.1 $(gcc_docdir)/*.7 $(gcc_docdir)/*.dvi $(gcc_docdir)/*.pdf
+	-rm -rf doc
 #\f
 # Entry points `install', `install-strip', and `uninstall'.
 # Also use `install-collect2' to install collect2 when the config files don't.
@@ -3765,24 +3705,46 @@ install-info:: doc installdirs \
 	$(DESTDIR)$(infodir)/cpp.info \
 	$(DESTDIR)$(infodir)/gcc.info \
 	$(DESTDIR)$(infodir)/cppinternals.info \
-	$(DESTDIR)$(infodir)/gccinstall.info \
+	$(DESTDIR)$(infodir)/install.info \
 	$(DESTDIR)$(infodir)/gccint.info \
 	lang.install-info
 
-$(DESTDIR)$(infodir)/%.info: doc/%.info installdirs
-	rm -f $@
-	if [ -f $< ]; then \
-	  for f in $(<)*; do \
-	    realfile=`echo $$f | sed -e 's|.*/\([^/]*\)$$|\1|'`; \
-	    $(INSTALL_DATA) $$f $(DESTDIR)$(infodir)/$$realfile; \
-	    chmod a-x $(DESTDIR)$(infodir)/$$realfile; \
-	  done; \
-	else true; fi
-	-if $(SHELL) -c 'install-info --version' >/dev/null 2>&1; then \
-	  if [ -f $@ ]; then \
-	    install-info --dir-file=$(DESTDIR)$(infodir)/dir $@; \
-	  else true; fi; \
-	else true; fi;
+$(DESTDIR)$(infodir)/gcc.info: doc/gcc/info/texinfo/gcc.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/gccint.info: doc/gccint/info/texinfo/gccint.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/install.info: doc/install/info/texinfo/install.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/cpp.info: doc/cpp/info/texinfo/cpp.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/cppinternals.info: doc/cppinternals/info/texinfo/cppinternals.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/gcov.info: doc/gcc/info/texinfo/gcov.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/gcov-tool.info: doc/gcc/info/texinfo/gcov-tool.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/gcov-dump.info: doc/gcc/info/texinfo/gcov-dump.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/lto-dump.info: doc/gcc/info/texinfo/lto-dump.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
 
 pdf__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
 
@@ -3832,36 +3794,52 @@ $(DESTDIR)$(man7dir)/%$(man7ext): doc/%.7 installdirs
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
-$(DESTDIR)$(man1dir)/$(GCC_INSTALL_NAME)$(man1ext): doc/gcc.1 installdirs
+$(DESTDIR)$(man1dir)/$(GCC_INSTALL_NAME)$(man1ext): doc/gcc/man/man/gcc.1 installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
-$(DESTDIR)$(man1dir)/$(CPP_INSTALL_NAME)$(man1ext): doc/cpp.1 installdirs
+$(DESTDIR)$(man1dir)/$(CPP_INSTALL_NAME)$(man1ext): doc/cpp/man/man/cpp.1 installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
-$(DESTDIR)$(man1dir)/$(GCOV_INSTALL_NAME)$(man1ext): doc/gcov.1 installdirs
+$(DESTDIR)$(man1dir)/$(GCOV_INSTALL_NAME)$(man1ext): doc/gcc/man/man/gcov.1 installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
-$(DESTDIR)$(man1dir)/$(GCOV_TOOL_INSTALL_NAME)$(man1ext): doc/gcov-tool.1 installdirs
+$(DESTDIR)$(man1dir)/$(GCOV_TOOL_INSTALL_NAME)$(man1ext): doc/gcc/man/man/gcov-tool.1 installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
-$(DESTDIR)$(man1dir)/$(GCOV_DUMP_INSTALL_NAME)$(man1ext): doc/gcov-dump.1 installdirs
+$(DESTDIR)$(man1dir)/$(GCOV_DUMP_INSTALL_NAME)$(man1ext): doc/gcc/man/man/gcov-dump.1 installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
-$(DESTDIR)$(man1dir)/$(LTO_DUMP_INSTALL_NAME)$(man1ext): doc/lto-dump.1 installdirs
+$(DESTDIR)$(man1dir)/$(LTO_DUMP_INSTALL_NAME)$(man1ext): doc/gcc/man/man/lto-dump.1 installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
+$(DESTDIR)$(man7dir)/fsf-funding$(man7ext): doc/gcc/man/man/fsf-funding.7 installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+	-chmod a-x $@
+
+$(DESTDIR)$(man7dir)/gfdl$(man7ext): doc/gcc/man/man/gfdl.7 installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+	-chmod a-x $@
+
+$(DESTDIR)$(man7dir)/gpl$(man7ext): doc/gcc/man/man/gpl.7 installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+	-chmod a-x $@
+
+
 # Install all the header files built in the include subdirectory.
 install-headers: $(INSTALL_HEADERS_DIR)
 # Fix symlinks to absolute paths in the installed include directory to
diff --git a/gcc/configure b/gcc/configure
index dd0194a57f4..b7274875b84 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -806,6 +806,7 @@ AR
 NM
 BISON
 FLEX
+SPHINX_BUILD
 GENERATED_MANPAGES
 BUILD_INFO
 MAKEINFO
@@ -7905,7 +7906,7 @@ fi
     REPORT_BUGS_TEXI=
     ;;
   *)
-    REPORT_BUGS_TO="<$BUGURL>"
+    REPORT_BUGS_TO="$BUGURL"
     REPORT_BUGS_TEXI=@uref{`echo "$BUGURL" | sed 's/@/@@/g'`}
     ;;
   esac;
@@ -8557,6 +8558,27 @@ $as_echo "no" >&6; }
 fi
 
 
+# See if sphinx-build has been installed and is modern enough
+# that we can use it.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for sphinx-build" >&5
+$as_echo_n "checking for sphinx-build... " >&6; }
+if sphinx-build -j auto -h &>/dev/null ; then
+  SPHINX_BUILD=sphinx-build
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING:
+  *** sphinx-build is missing or too old.
+  *** Info and man pages documentation will not be built." >&5
+$as_echo "$as_me: WARNING:
+  *** sphinx-build is missing or too old.
+  *** Info and man pages documentation will not be built." >&2;}
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+  SPHINX_BUILD=
+fi
+
+
 MISSING="${CONFIG_SHELL-/bin/sh} $ac_aux_dir/missing"
 
 # How about lex?
@@ -19435,7 +19457,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 19438 "configure"
+#line 19460 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -19541,7 +19563,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 19544 "configure"
+#line 19566 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 5f30f80833e..cecdd339862 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -1208,6 +1208,21 @@ else
 fi
 AC_SUBST(GENERATED_MANPAGES)
 
+# See if sphinx-build has been installed and is modern enough
+# that we can use it.
+AC_MSG_CHECKING([for sphinx-build])
+if sphinx-build -j auto -h &>/dev/null ; then
+  SPHINX_BUILD=sphinx-build
+  AC_MSG_RESULT(yes)
+else
+  AC_MSG_WARN([
+  *** sphinx-build is missing or too old.
+  *** Info and man pages documentation will not be built.])
+  AC_MSG_RESULT(no)
+  SPHINX_BUILD=
+fi
+AC_SUBST(SPHINX_BUILD)
+
 MISSING="${CONFIG_SHELL-/bin/sh} $ac_aux_dir/missing"
 
 # How about lex?
diff --git a/gcc/cp/Make-lang.in b/gcc/cp/Make-lang.in
index 155be74efdb..6e49e3117db 100644
--- a/gcc/cp/Make-lang.in
+++ b/gcc/cp/Make-lang.in
@@ -260,7 +260,7 @@ c++.install-common: installdirs
 
 # We can't use links because not everyone supports them.  So just copy the
 # manpage.
-doc/g++.1: doc/gcc.1
+doc/g++.1: doc/gcc/man/man/gcc.1
 	cp $< doc/g++.1
 
 c++.install-man: $(DESTDIR)$(man1dir)/$(GXX_INSTALL_NAME)$(man1ext)
diff --git a/gcc/doc/gcc/conf.py b/gcc/doc/gcc/conf.py
index d6d69de24f8..ac1bc73ca78 100644
--- a/gcc/doc/gcc/conf.py
+++ b/gcc/doc/gcc/conf.py
@@ -1,5 +1,6 @@
 # Configuration file for the Sphinx documentation builder.
 
+import os
 import sys
 sys.path.append('../../..//doc')
 
@@ -29,8 +30,14 @@ man_pages = [
     ('funding', 'fsf-funding', 'Funding Free Software', [], 7)
 ]
 
+ENABLE_LTO = os.getenv('ENABLE_LTO')
+assert ENABLE_LTO
+
+if ENABLE_LTO  == 'yes':
+    man_pages += [('lto-dump', 'lto-dump', 'Tool for dumping LTO object files', [authors], 1)]
+
 texinfo_documents = [
   ('index', 'gcc', project, authors, None, None, None, True)
 ]
 
-tags.add('gcc')
\ No newline at end of file
+tags.add('gcc')
diff --git a/gcc/fortran/Make-lang.in b/gcc/fortran/Make-lang.in
index 63195a9c7ed..686788ee868 100644
--- a/gcc/fortran/Make-lang.in
+++ b/gcc/fortran/Make-lang.in
@@ -109,16 +109,18 @@ fortran.all.cross: gfortran-cross$(exeext)
 fortran.start.encap: gfortran$(exeext)
 fortran.rest.encap:
 
-fortran.srcinfo: doc/gfortran.info
-	-cp -p $^ $(srcdir)/fortran
-
 fortran.tags: force
 	cd $(srcdir)/fortran; etags -o TAGS.sub *.c *.h; \
 	etags --include TAGS.sub --include ../TAGS.sub
 
-fortran.info: doc/gfortran.info doc/gfc-internals.info
+fortran.info: info-gfortran info-gfc-internals
 fortran.dvi: doc/gfortran.dvi doc/gfc-internals.dvi
 
+info-gfortran:
+	+ if [ x$(SPHINX_BUILD) = xsphinx-build ]; then \
+	  make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/fortran/doc/gfortran BUILDDIR=$(objdir)/doc/fortran/info; \
+	else true; fi
+
 F95_HTMLFILES = $(build_htmldir)/gfortran
 
 fortran.html: $(F95_HTMLFILES)/index.html
@@ -154,9 +156,10 @@ fortran.install-pdf: $(F95_PDFFILES)
 	  $(INSTALL_DATA) "$$d$$p" "$(DESTDIR)$(pdfdir)/gcc/$$f"; \
 	done
 
-F95_MANFILES = doc/gfortran.1
+man-fortran:
+	+ make -C $(srcdir)/../doc man SOURCEDIR=$(srcdir)/fortran/doc/gfortran BUILDDIR=$(objdir)/doc/fortran/man
 
-fortran.man: $(F95_MANFILES)
+fortran.man: man-fortran
 
 fortran.srcman: $(F95_MANFILES)
 	-cp -p $^ $(srcdir)/doc
@@ -186,13 +189,6 @@ GFORTRAN_TEXI = \
   $(srcdir)/doc/include/gcc-common.texi \
   gcc-vers.texi
 
-doc/gfortran.info: $(GFORTRAN_TEXI)
-	if [ x$(BUILD_INFO) = xinfo ]; then \
-	  rm -f doc/gfortran.info-*; \
-	  $(MAKEINFO) -I $(srcdir)/doc/include -I $(srcdir)/fortran \
-	    -o $@ $<; \
-	else true; fi
-
 doc/gfortran.dvi: $(GFORTRAN_TEXI)
 	$(TEXI2DVI) -I $(srcdir)/fortran -I $(abs_docdir)/include -o $@ $<
 
@@ -217,11 +213,9 @@ GFC_INTERNALS_TEXI = \
   $(srcdir)/doc/include/gcc-common.texi \
   gcc-vers.texi
 
-doc/gfc-internals.info: $(GFC_INTERNALS_TEXI)
-	if [ x$(BUILD_INFO) = xinfo ]; then \
-	  rm -f doc/gfc-internals.info-*; \
-	  $(MAKEINFO) -I $(srcdir)/doc/include -I $(srcdir)/fortran \
-	    -o $@ $<; \
+info-gfc-internals:
+	+ if [ x$(SPHINX_BUILD) = xsphinx-build ]; then \
+	  make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/fortran/doc/gfc-internals BUILDDIR=$(objdir)/doc/gfc-internals/info; \
 	else true; fi
 
 doc/gfc-internals.dvi: $(GFC_INTERNALS_TEXI)
@@ -256,9 +250,13 @@ fortran.install-plugin:
 
 fortran.install-info: $(DESTDIR)$(infodir)/gfortran.info
 
+$(DESTDIR)$(infodir)/gfortran.info: doc/fortran/info/texinfo/gfortran.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
 fortran.install-man: $(DESTDIR)$(man1dir)/$(GFORTRAN_INSTALL_NAME)$(man1ext)
 
-$(DESTDIR)$(man1dir)/$(GFORTRAN_INSTALL_NAME)$(man1ext): doc/gfortran.1 \
+$(DESTDIR)$(man1dir)/$(GFORTRAN_INSTALL_NAME)$(man1ext): doc/fortran/man/man/gfortran.1 \
 		installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
@@ -286,12 +284,6 @@ fortran.mostlyclean:
 fortran.clean:
 fortran.distclean:
 	-rm -f fortran/config.status fortran/Makefile
-
-fortran.extraclean:
-fortran.maintainer-clean:
-	-rm -f doc/gfortran.info* fortran/gfortran.*aux
-	-rm -f $(docobjdir)/gfortran.1
-
 #\f
 # Stage hooks:
 # The toplevel makefile has already created stage?/fortran at this point.
diff --git a/gcc/genhooks.c b/gcc/genhooks.c
index ebe0d0954e6..6ba6254381b 100644
--- a/gcc/genhooks.c
+++ b/gcc/genhooks.c
@@ -48,212 +48,74 @@ upstrdup (const char *in)
   return ret;
 }
 
-/* Struct for 'start hooks' which start a sequence of consecutive hooks
-   that are defined in target.def and to be documented in tm.texi.  */
-struct s_hook
-{
-  char *name;
-  int pos;
-};
-
-static hashval_t
-s_hook_hash (const void *p)
-{
-  const struct s_hook *s_hook = (const struct s_hook *)p;
-  return htab_hash_string (s_hook->name);
-}
+/* Emit shared .rst.in file that is used by the corresponding
+   .. include:: tm.rst.in
+     :start-after: [HOOK_NAME]
+     :end-before: [HOOK_NAME]
 
-static int
-s_hook_eq_p (const void *p1, const void *p2)
-{
-  return (strcmp (((const struct s_hook *) p1)->name, 
-		  ((const struct s_hook *) p2)->name) == 0);
-}
-
-/* Read the documentation file with name IN_FNAME, perform substitutions
-   to incorporate information from hook_array, and emit the result on stdout.
-   Hooks defined with DEFHOOK / DEFHOOKPOD are emitted at the place of a
-   matching @hook in the input file; if there is no matching @hook, the
-   hook is emitted after the hook that precedes it in target.def .
-   Usually, the emitted hook documentation starts with the hook
-   signature, followed by the string from the doc field.
-   The documentation is bracketed in @deftypefn / @deftypevr and a matching
-   @end.
-   While emitting the doc field, an @findex entry is added
-   to the affected paragraph.
    If the doc field starts with '*', the leading '*' is stripped, and the doc
    field is otherwise emitted unaltered; no function signature/
    @deftypefn/deftypevr/@end is emitted.
    In particular, a doc field of "*" means not to emit any ocumentation for
    this target.def / hook_array entry at all (there might be documentation
    for this hook in the file named IN_FNAME, though).
-   A doc field of 0 is used to append the hook signature after the previous
-   hook's signture, so that one description can be used for a group of hooks.
-   When the doc field is "", @deftypefn/@deftypevr and the hook signature
-   is emitted, but not the matching @end.  This allows all the free-form
+
+   This allows all the free-form
    documentation to be placed in IN_FNAME, to work around GPL/GFDL
    licensing incompatibility issues.  */
+
 static void
-emit_documentation (const char *in_fname)
+emit_documentation (void)
 {
-  int i, j;
-  char buf[1000];
-  htab_t start_hooks = htab_create (99, s_hook_hash, s_hook_eq_p, (htab_del) 0);
-  FILE *f;
-
-  /* Enter all the start hooks in start_hooks.  */
-  f = fopen (in_fname, "r");
-  if (!f)
-    {
-      perror ("");
-      fatal ("Couldn't open input file");
-    }
-  while (fscanf (f, "%*[^@]"), buf[0] = '\0',
-	 fscanf (f, "@%5[^ \n]", buf) != EOF)
-    {
-      void **p;
-      struct s_hook *shp;
-
-      if (strcmp (buf, "hook") != 0)
-	continue;
-      buf[0] = '\0';
-      fscanf (f, "%999s", buf);
-      shp = XNEW (struct s_hook);
-      shp->name = upstrdup (buf);
-      shp->pos = -1;
-      p = htab_find_slot (start_hooks, shp, INSERT);
-      if (*p != HTAB_EMPTY_ENTRY)
-	fatal ("Duplicate placement for hook %s\n", shp->name);
-      *(struct s_hook **) p = shp;
-    }
-  fclose (f);
   /* For each hook in hook_array, if it is a start hook, store its position.  */
-  for (i = 0; i < (int) (sizeof hook_array / sizeof hook_array[0]); i++)
+  for (int i = 0; i < (int) (sizeof hook_array / sizeof hook_array[0]); i++)
     {
-      struct s_hook sh, *shp;
-      void *p;
-
       if (!hook_array[i].doc || strcmp (hook_array[i].doc, "*") == 0)
 	continue;
-      sh.name = upstrdup (hook_array[i].name);
-      p = htab_find (start_hooks, &sh);
-      if (p)
-	{
-	  shp = (struct s_hook *) p;
-	  if (shp->pos >= 0)
-	    fatal ("Duplicate hook %s\n", sh.name);
-	  shp->pos = i;
-	}
+      const char *hook_name = upstrdup (hook_array[i].name);
+      printf ("[%s]\n", hook_name);
+      /* Print header.  Function-valued hooks have a parameter list,
+	 unlike POD-valued ones.  */
+      const char *deftype = hook_array[i].param ? "c:function" : "c:var";
+      printf (".. %s:: ", deftype);
+      if (strchr (hook_array[i].type, ' '))
+	printf ("%s", hook_array[i].type);
       else
-	fatal ("No place specified to document hook %s\n", sh.name);
-      free (sh.name);
-    }
-  /* Copy input file to stdout, substituting @hook directives with the
-     corresponding hook documentation sequences.  */
-  f = fopen (in_fname, "r");
-  if (!f)
-    {
-      perror ("");
-      fatal ("Couldn't open input file");
-    }
-  for (;;)
-    {
-      struct s_hook sh, *shp;
-      int c = getc (f);
-      char *name;
-
-      if (c == EOF)
-	break;
-      if (c != '@')
-	{
-	  putchar (c);
-	  continue;
-	}
-      buf[0] = '\0';
-      fscanf (f, "%5[^ \n]", buf);
-      if (strcmp (buf, "hook") != 0)
+	printf ("%s", hook_array[i].type);
+      printf (" %s", hook_name);
+      if (hook_array[i].param)
 	{
-	  printf ("@%s", buf);
-	  continue;
+	  const char *q, *e;
+	  /* Print the parameter list, with the parameter names
+	     enclosed in @var{}.  */
+	  printf (" ");
+	  for (q = hook_array[i].param; (e = strpbrk (q, " *,)"));
+	       q = e + 1)
+	    /* Type names like 'int' are followed by a space, sometimes
+	       also by '*'.  'void' should appear only in "(void)".  */
+	    if (*e == ' ' || *e == '*' || *q == '(')
+	      printf ("%.*s", (int) (e - q + 1), q);
+	    else
+	      printf ("%.*s%c", (int) (e - q), q, *e);
 	}
-      fscanf (f, "%999s", buf);
-      sh.name = name = upstrdup (buf);
-      shp = (struct s_hook *) htab_find (start_hooks, &sh);
-      if (!shp || shp->pos < 0)
-	fatal ("No documentation for hook %s\n", sh.name);
-      i = shp->pos;
-      do
+
+      printf ("\n");
+      if (hook_array[i].doc[0])
 	{
-	  const char *q, *e;
-	  const char *deftype;
 	  const char *doc, *p_end;
-
-	  /* A leading '*' means to output the documentation string without
-	     further processing.  */
-	  if (*hook_array[i].doc == '*')
-	    printf ("%s", hook_array[i].doc + 1);
-	  else
+	  printf ("\n");
+	  /* Print each documentation paragraph in turn.  */
+	  for (doc = hook_array[i].doc; *doc; doc = p_end)
 	    {
-	      if (i != shp->pos)
-		printf ("\n\n");
-
-	      /* Print header.  Function-valued hooks have a parameter list, 
-		 unlike POD-valued ones.  */
-	      deftype = hook_array[i].param ? "deftypefn" : "deftypevr";
-	      printf ("@%s {%s} ", deftype, hook_array[i].docname);
-	      if (strchr (hook_array[i].type, ' '))
-		printf ("{%s}", hook_array[i].type);
-	      else
-		printf ("%s", hook_array[i].type);
-	      printf (" %s", name);
-	      if (hook_array[i].param)
-		{
-		  /* Print the parameter list, with the parameter names
-		     enclosed in @var{}.  */
-		  printf (" ");
-		  for (q = hook_array[i].param; (e = strpbrk (q, " *,)"));
-		       q = e + 1)
-		    /* Type names like 'int' are followed by a space, sometimes
-		       also by '*'.  'void' should appear only in "(void)".  */
-		    if (*e == ' ' || *e == '*' || *q == '(')
-		      printf ("%.*s", (int) (e - q + 1), q);
-		    else
-		      printf ("@var{%.*s}%c", (int) (e - q), q, *e);
-		}
-	      /* POD-valued hooks sometimes come in groups with common
-		 documentation.*/
-	      for (j = i + 1;
-		   j < (int) (sizeof hook_array / sizeof hook_array[0])
-		   && hook_array[j].doc == 0 && hook_array[j].type; j++)
-		{
-		  char *namex = upstrdup (hook_array[j].name);
-
-		  printf ("\n@%sx {%s} {%s} %s",
-			  deftype, hook_array[j].docname,
-			  hook_array[j].type, namex);
-		}
-	      if (hook_array[i].doc[0])
-		{
-		  printf ("\n");
-		  /* Print each documentation paragraph in turn.  */
-		  for (doc = hook_array[i].doc; *doc; doc = p_end)
-		    {
-		      /* Find paragraph end.  */
-		      p_end = strstr (doc, "\n\n");
-		      p_end = (p_end ? p_end + 2 : doc + strlen (doc));
-		      printf ("%.*s", (int) (p_end - doc), doc);
-		    }
-		  printf ("\n@end %s", deftype);
-		}
+	      /* Find paragraph end.  */
+	      p_end = strstr (doc, "\n");
+	      p_end = (p_end ? p_end + 1 : doc + strlen (doc));
+	      printf ("  %.*s", (int) (p_end - doc), doc);
 	    }
-	  if (++i >= (int) (sizeof hook_array / sizeof hook_array[0])
-	      || !hook_array[i].doc)
-	    break;
-	  free (name);
-	  sh.name = name = upstrdup (hook_array[i].name);
+	  printf ("\n");
 	}
-      while (!htab_find (start_hooks, &sh));
-      free (name);
+
+      printf ("\n[%s]\n\n", hook_name);
     }
 }
 
@@ -314,8 +176,8 @@ main (int argc, char **argv)
 {
   progname = "genhooks";
 
-  if (argc >= 3)
-    emit_documentation (argv[2]);
+  if (argc == 1)
+    emit_documentation ();
   else
     emit_init_macros (argv[1]);
   return 0;


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [gcc(refs/users/marxin/heads/sphinx-v2)] Build system integration.
@ 2021-06-23 11:24 Martin Liska
  0 siblings, 0 replies; 6+ messages in thread
From: Martin Liska @ 2021-06-23 11:24 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:593c778961b00f64345eebecdca46b45a0b7466a

commit 593c778961b00f64345eebecdca46b45a0b7466a
Author: Martin Liska <mliska@suse.cz>
Date:   Thu Jun 17 22:08:57 2021 +0200

    Build system integration.

Diff:
---
 config/acx.m4            |   2 +-
 configure                |   1 -
 configure.ac             |   1 -
 doc/Makefile             |   3 +-
 doc/baseconf.py          |   5 +-
 gcc/Makefile.in          | 216 ++++++++++++++++++++-----------------------
 gcc/configure            |  28 +++++-
 gcc/configure.ac         |  15 +++
 gcc/cp/Make-lang.in      |   2 +-
 gcc/doc/gcc/conf.py      |   9 +-
 gcc/fortran/Make-lang.in |  42 ++++-----
 gcc/genhooks.c           | 232 ++++++++++-------------------------------------
 12 files changed, 216 insertions(+), 340 deletions(-)

diff --git a/config/acx.m4 b/config/acx.m4
index 87c1b5e2932..65a7f4bc446 100644
--- a/config/acx.m4
+++ b/config/acx.m4
@@ -615,7 +615,7 @@ AC_DEFUN([ACX_BUGURL],[
     REPORT_BUGS_TEXI=
     ;;
   *)
-    REPORT_BUGS_TO="<$BUGURL>"
+    REPORT_BUGS_TO="$BUGURL"
     REPORT_BUGS_TEXI=@uref{`echo "$BUGURL" | sed 's/@/@@/g'`}
     ;;
   esac;
diff --git a/configure b/configure
index 1224fc4039e..e58cbb65158 100755
--- a/configure
+++ b/configure
@@ -10458,7 +10458,6 @@ case " $configdirs " in
     ;;
 esac
 
-
 # Host tools.
 ncn_tool_prefix=
 test -n "$host_alias" && ncn_tool_prefix=$host_alias-
diff --git a/configure.ac b/configure.ac
index 66d637d70dc..68c209852e9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3454,7 +3454,6 @@ case " $configdirs " in
     ;;
 esac
 
-
 # Host tools.
 NCN_STRICT_CHECK_TOOLS(AR, ar)
 NCN_STRICT_CHECK_TOOLS(AS, as)
diff --git a/doc/Makefile b/doc/Makefile
index 9e305a8e7da..7f3690e7e50 100644
--- a/doc/Makefile
+++ b/doc/Makefile
@@ -3,7 +3,8 @@
 
 # You can set these variables from the command line.
 SPHINXOPTS   ?= -j auto -q
-SPHINXBUILD  ?= sphinx-build
+# FIXME
+SPHINXBUILD  ?= /tmp/venv/bin/sphinx-build
 PAPER        ?=
 SOURCEDIR     = .
 BUILDDIR      = _build
diff --git a/doc/baseconf.py b/doc/baseconf.py
index 07bf2c551c8..206328d43e5 100644
--- a/doc/baseconf.py
+++ b/doc/baseconf.py
@@ -34,8 +34,9 @@ gcc_DEVPHASE = __read_file('DEV-PHASE')
 gcc_DATESTAMP = __read_file('DATESTAMP')
 gcc_REVISION = __read_file('REVISION')
 
-VERSION_PACKAGE = os.getenv('VERSION_PACKAGE', '(GCC)')
-BUGURL = os.getenv('BUGURL', 'https://gcc.gnu.org/bugs/')
+VERSION_PACKAGE = os.getenv('VERSION_PACKAGE')
+BUGURL = os.getenv('BUGURL')
+assert VERSION_PACKAGE and BUGURL
 
 # The short X.Y version.
 version = gcc_BASEVER
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index ebf26442992..66d99c1e9f9 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -771,11 +771,8 @@ LIBCONVERT =
 # Control whether header files are installed.
 INSTALL_HEADERS=install-headers install-mkheaders
 
-# Control whether Info documentation is built and installed.
-BUILD_INFO = @BUILD_INFO@
-
-# Control whether manpages generated by texi2pod.pl can be rebuilt.
-GENERATED_MANPAGES = @GENERATED_MANPAGES@
+# Control whether manpages generated by sphinx-build can be rebuilt.
+SPHINX_BUILD = @SPHINX_BUILD@
 
 # Additional directories of header files to run fixincludes on.
 # These should be directories searched automatically by default
@@ -2579,38 +2576,20 @@ s-d-target-hooks-def-h: build/genhooks$(build_exeext)
 					     d/d-target-hooks-def.h
 	$(STAMP) s-d-target-hooks-def-h
 
-# check if someone mistakenly only changed tm.texi.
-# We use a different pathname here to avoid a circular dependency.
-s-tm-texi: $(srcdir)/doc/../doc/tm.texi
-
 # The tm.texi we want to compare against / check into svn should have
 # unix-style line endings.  To make this work on MinGW, remove \r.
 # \r is not portable to Solaris tr, therefore we have a special
 # case for ASCII.  We use \r for other encodings like EBCDIC.
-s-tm-texi: build/genhooks$(build_exeext) $(srcdir)/doc/tm.texi.in
-	$(RUN_GEN) build/genhooks$(build_exeext) -d \
-			$(srcdir)/doc/tm.texi.in > tmp-tm.texi
-	case `echo X|tr X '\101'` in \
-	  A) tr -d '\015' < tmp-tm.texi > tmp2-tm.texi ;; \
-	  *) tr -d '\r' < tmp-tm.texi > tmp2-tm.texi ;; \
-	esac
-	mv tmp2-tm.texi tmp-tm.texi
-	$(SHELL) $(srcdir)/../move-if-change tmp-tm.texi tm.texi
-	@if cmp -s $(srcdir)/doc/tm.texi tm.texi; then \
+s-tm-rst-in: build/genhooks$(build_exeext)
+	$(RUN_GEN) build/genhooks$(build_exeext) > tmp-tm.rst.in
+	$(SHELL) $(srcdir)/../move-if-change tmp-tm.rst.in tm.rst.in
+
+	@if cmp -s $(srcdir)/doc/gccint/target-macros/tm.rst.in tm.rst.in; then \
 	  $(STAMP) $@; \
-	elif test $(srcdir)/doc/tm.texi -nt $(srcdir)/doc/tm.texi.in \
-	  && ( test $(srcdir)/doc/tm.texi -nt $(srcdir)/target.def \
-	    || test $(srcdir)/doc/tm.texi -nt $(srcdir)/c-family/c-target.def \
-	    || test $(srcdir)/doc/tm.texi -nt $(srcdir)/common/common-target.def \
-	    || test $(srcdir)/doc/tm.texi -nt $(srcdir)/d/d-target.def \
-	  ); then \
-	  echo >&2 ; \
-	  echo You should edit $(srcdir)/doc/tm.texi.in rather than $(srcdir)/doc/tm.texi . >&2 ; \
-	  false; \
 	else \
 	  echo >&2 ; \
 	  echo Verify that you have permission to grant a GFDL license for all >&2 ; \
-	  echo new text in $(objdir)/tm.texi, then copy it to $(srcdir)/doc/tm.texi. >&2 ; \
+	  echo new text in $(objdir)/tm.rst.in, then copy it to $(srcdir)/doc/gccint/target-macros/tm.rst.in. >&2 ; \
 	  false; \
 	fi
 
@@ -3281,15 +3260,7 @@ install-no-fixedincludes:
 
 # Remake the info files.
 
-doc: $(BUILD_INFO) $(GENERATED_MANPAGES)
-
-INFOFILES = doc/cpp.info doc/gcc.info doc/gccint.info \
-            doc/gccinstall.info doc/cppinternals.info
-
-info: $(INFOFILES) lang.info @GENINSRC@ srcinfo lang.srcinfo
-
-srcinfo: $(INFOFILES)
-	-cp -p $^ $(srcdir)/doc
+doc: $(SPHINX_BUILD)
 
 TEXI_CPP_FILES = cpp.texi fdl.texi cppenv.texi cppopts.texi		\
 	 gcc-common.texi gcc-vers.texi
@@ -3336,28 +3307,6 @@ gcc-vers.texi: $(BASEVER) $(DEVPHASE)
 	mv -f $@T $@
 
 
-# The *.1, *.7, *.info, *.dvi, and *.pdf files are being generated from implicit
-# patterns.  To use them, put each of the specific targets with its
-# specific dependencies but no build commands.
-
-doc/cpp.info: $(TEXI_CPP_FILES)
-doc/gcc.info: $(TEXI_GCC_FILES)
-doc/gccint.info: $(TEXI_GCCINT_FILES)
-doc/cppinternals.info: $(TEXI_CPPINT_FILES)
-
-doc/%.info: %.texi
-	if [ x$(BUILD_INFO) = xinfo ]; then \
-		$(MAKEINFO) $(MAKEINFOFLAGS) -I . -I $(gcc_docdir) \
-			-I $(gcc_docdir)/include -o $@ $<; \
-	fi
-
-# Duplicate entry to handle renaming of gccinstall.info
-doc/gccinstall.info: $(TEXI_GCCINSTALL_FILES)
-	if [ x$(BUILD_INFO) = xinfo ]; then \
-		$(MAKEINFO) $(MAKEINFOFLAGS) -I $(gcc_docdir) \
-			-I $(gcc_docdir)/include -o $@ $<; \
-	fi
-
 doc/cpp.dvi: $(TEXI_CPP_FILES)
 doc/gcc.dvi: $(TEXI_GCC_FILES)
 doc/gccint.dvi: $(TEXI_GCCINT_FILES)
@@ -3422,51 +3371,43 @@ $(build_htmldir)/gccinstall/index.html: $(TEXI_GCCINSTALL_FILES)
 	DESTDIR=$(@D) \
 	$(SHELL) $(srcdir)/doc/install.texi2html
 
-MANFILES = doc/gcov.1 doc/cpp.1 doc/gcc.1 doc/gfdl.7 doc/gpl.7 \
-           doc/fsf-funding.7 doc/gcov-tool.1 doc/gcov-dump.1 \
 	   $(if $(filter yes,@enable_lto@),doc/lto-dump.1)
 
-generated-manpages: man
+export VERSION_PACKAGE="$(PKGVERSION)"
+export ENABLE_LTO=$(enable_lto)
+export BUGURL="$(BUGURL_s)"
 
-man: $(MANFILES) lang.man @GENINSRC@ srcman lang.srcman
+man: man-gcc man-cpp lang.man @GENINSRC@
 
-srcman: $(MANFILES)
-	-cp -p $^ $(srcdir)/doc
+info: info-gcc info-gccint info-cpp info-cppinternals info-install lang.info @GENINSRC@
 
-doc/%.1: %.pod
-	$(STAMP) $@
-	-($(POD2MAN) --section=1 $< > $(@).T$$$$ && \
-		mv -f $(@).T$$$$ $@) || \
-		(rm -f $(@).T$$$$ && exit 1)
+sphinx-build: man info
 
-doc/%.7: %.pod
-	$(STAMP) $@
-	-($(POD2MAN) --section=7 $< > $(@).T$$$$ && \
-		mv -f $(@).T$$$$ $@) || \
-		(rm -f $(@).T$$$$ && exit 1)
+man-gcc: doc/gcc/man/man/gcc.1
 
-%.pod: %.texi
-	$(STAMP) $@
-	-$(TEXI2POD) -DBUGURL="$(BUGURL_TEXI)" $< > $@
+doc/gcc/man/man/gcc.1:
+	+ make -C $(srcdir)/../doc man SOURCEDIR=$(srcdir)/doc/gcc BUILDDIR=$(objdir)/doc/gcc/man
 
-.INTERMEDIATE: cpp.pod gcc.pod gfdl.pod fsf-funding.pod gpl.pod
-cpp.pod: cpp.texi cppenv.texi cppopts.texi
+man-cpp:
+	+ make -C $(srcdir)/../doc man SOURCEDIR=$(srcdir)/doc/cpp BUILDDIR=$(objdir)/doc/cpp/man
 
-# These next rules exist because the output name is not the same as
-# the input name, so our implicit %.pod rule will not work.
+info-gcc:
+	+ make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/doc/gcc BUILDDIR=$(objdir)/doc/gcc/info
 
-gcc.pod: invoke.texi cppenv.texi cppopts.texi gcc-vers.texi
-	$(STAMP) $@
-	-$(TEXI2POD) $< > $@
-gfdl.pod: fdl.texi
-	$(STAMP) $@
-	-$(TEXI2POD) $< > $@
-fsf-funding.pod: funding.texi
-	$(STAMP) $@
-	-$(TEXI2POD) $< > $@
-gpl.pod: gpl_v3.texi
-	$(STAMP) $@
-	-$(TEXI2POD) $< > $@
+info-gccint: s-tm-rst-in
+	+ make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/doc/gccint BUILDDIR=$(objdir)/doc/gccint/info
+
+info-cpp:
+	+ make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/doc/cpp BUILDDIR=$(objdir)/doc/cpp/info
+
+info-cppinternals:
+	+ make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/doc/cppinternals BUILDDIR=$(objdir)/doc/cppinternals/info
+
+info-install:
+	+ make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/doc/install BUILDDIR=$(objdir)/doc/install/info
+
+html-gccint: s-tm-rst-in
+	+ make -C $(srcdir)/../doc html SOURCEDIR=$(srcdir)/doc/gccint BUILDDIR=$(objdir)/doc/gccint/html
 
 #\f
 # Deletion of files made during compilation.
@@ -3526,8 +3467,7 @@ clean: mostlyclean lang.clean
 	-rm -f config.h tconfig.h bconfig.h tm_p.h tm.h
 	-rm -f options.c options.h optionlist
 	-rm -f cs-*
-	-rm -f doc/*.dvi
-	-rm -f doc/*.pdf
+	-rm -rf doc
 # Delete the include directories.
 	-rm -rf include include-fixed
 # Delete files used by the "multilib" facility (including libgcc subdirs).
@@ -3568,7 +3508,7 @@ maintainer-clean:
 	$(MAKE) lang.maintainer-clean distclean
 	-rm -f cpp.??s cpp.*aux
 	-rm -f gcc.??s gcc.*aux
-	-rm -f $(gcc_docdir)/*.info $(gcc_docdir)/*.1 $(gcc_docdir)/*.7 $(gcc_docdir)/*.dvi $(gcc_docdir)/*.pdf
+	-rm -rf doc
 #\f
 # Entry points `install', `install-strip', and `uninstall'.
 # Also use `install-collect2' to install collect2 when the config files don't.
@@ -3765,24 +3705,46 @@ install-info:: doc installdirs \
 	$(DESTDIR)$(infodir)/cpp.info \
 	$(DESTDIR)$(infodir)/gcc.info \
 	$(DESTDIR)$(infodir)/cppinternals.info \
-	$(DESTDIR)$(infodir)/gccinstall.info \
+	$(DESTDIR)$(infodir)/install.info \
 	$(DESTDIR)$(infodir)/gccint.info \
 	lang.install-info
 
-$(DESTDIR)$(infodir)/%.info: doc/%.info installdirs
-	rm -f $@
-	if [ -f $< ]; then \
-	  for f in $(<)*; do \
-	    realfile=`echo $$f | sed -e 's|.*/\([^/]*\)$$|\1|'`; \
-	    $(INSTALL_DATA) $$f $(DESTDIR)$(infodir)/$$realfile; \
-	    chmod a-x $(DESTDIR)$(infodir)/$$realfile; \
-	  done; \
-	else true; fi
-	-if $(SHELL) -c 'install-info --version' >/dev/null 2>&1; then \
-	  if [ -f $@ ]; then \
-	    install-info --dir-file=$(DESTDIR)$(infodir)/dir $@; \
-	  else true; fi; \
-	else true; fi;
+$(DESTDIR)$(infodir)/gcc.info: doc/gcc/info/texinfo/gcc.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/gccint.info: doc/gccint/info/texinfo/gccint.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/install.info: doc/install/info/texinfo/install.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/cpp.info: doc/cpp/info/texinfo/cpp.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/cppinternals.info: doc/cppinternals/info/texinfo/cppinternals.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/gcov.info: doc/gcc/info/texinfo/gcov.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/gcov-tool.info: doc/gcc/info/texinfo/gcov-tool.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/gcov-dump.info: doc/gcc/info/texinfo/gcov-dump.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/lto-dump.info: doc/gcc/info/texinfo/lto-dump.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
 
 pdf__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
 
@@ -3832,36 +3794,52 @@ $(DESTDIR)$(man7dir)/%$(man7ext): doc/%.7 installdirs
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
-$(DESTDIR)$(man1dir)/$(GCC_INSTALL_NAME)$(man1ext): doc/gcc.1 installdirs
+$(DESTDIR)$(man1dir)/$(GCC_INSTALL_NAME)$(man1ext): doc/gcc/man/man/gcc.1 installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
-$(DESTDIR)$(man1dir)/$(CPP_INSTALL_NAME)$(man1ext): doc/cpp.1 installdirs
+$(DESTDIR)$(man1dir)/$(CPP_INSTALL_NAME)$(man1ext): doc/cpp/man/man/cpp.1 installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
-$(DESTDIR)$(man1dir)/$(GCOV_INSTALL_NAME)$(man1ext): doc/gcov.1 installdirs
+$(DESTDIR)$(man1dir)/$(GCOV_INSTALL_NAME)$(man1ext): doc/gcc/man/man/gcov.1 installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
-$(DESTDIR)$(man1dir)/$(GCOV_TOOL_INSTALL_NAME)$(man1ext): doc/gcov-tool.1 installdirs
+$(DESTDIR)$(man1dir)/$(GCOV_TOOL_INSTALL_NAME)$(man1ext): doc/gcc/man/man/gcov-tool.1 installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
-$(DESTDIR)$(man1dir)/$(GCOV_DUMP_INSTALL_NAME)$(man1ext): doc/gcov-dump.1 installdirs
+$(DESTDIR)$(man1dir)/$(GCOV_DUMP_INSTALL_NAME)$(man1ext): doc/gcc/man/man/gcov-dump.1 installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
-$(DESTDIR)$(man1dir)/$(LTO_DUMP_INSTALL_NAME)$(man1ext): doc/lto-dump.1 installdirs
+$(DESTDIR)$(man1dir)/$(LTO_DUMP_INSTALL_NAME)$(man1ext): doc/gcc/man/man/lto-dump.1 installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
+$(DESTDIR)$(man7dir)/fsf-funding$(man7ext): doc/gcc/man/man/fsf-funding.7 installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+	-chmod a-x $@
+
+$(DESTDIR)$(man7dir)/gfdl$(man7ext): doc/gcc/man/man/gfdl.7 installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+	-chmod a-x $@
+
+$(DESTDIR)$(man7dir)/gpl$(man7ext): doc/gcc/man/man/gpl.7 installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+	-chmod a-x $@
+
+
 # Install all the header files built in the include subdirectory.
 install-headers: $(INSTALL_HEADERS_DIR)
 # Fix symlinks to absolute paths in the installed include directory to
diff --git a/gcc/configure b/gcc/configure
index dd0194a57f4..b7274875b84 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -806,6 +806,7 @@ AR
 NM
 BISON
 FLEX
+SPHINX_BUILD
 GENERATED_MANPAGES
 BUILD_INFO
 MAKEINFO
@@ -7905,7 +7906,7 @@ fi
     REPORT_BUGS_TEXI=
     ;;
   *)
-    REPORT_BUGS_TO="<$BUGURL>"
+    REPORT_BUGS_TO="$BUGURL"
     REPORT_BUGS_TEXI=@uref{`echo "$BUGURL" | sed 's/@/@@/g'`}
     ;;
   esac;
@@ -8557,6 +8558,27 @@ $as_echo "no" >&6; }
 fi
 
 
+# See if sphinx-build has been installed and is modern enough
+# that we can use it.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for sphinx-build" >&5
+$as_echo_n "checking for sphinx-build... " >&6; }
+if sphinx-build -j auto -h &>/dev/null ; then
+  SPHINX_BUILD=sphinx-build
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING:
+  *** sphinx-build is missing or too old.
+  *** Info and man pages documentation will not be built." >&5
+$as_echo "$as_me: WARNING:
+  *** sphinx-build is missing or too old.
+  *** Info and man pages documentation will not be built." >&2;}
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+  SPHINX_BUILD=
+fi
+
+
 MISSING="${CONFIG_SHELL-/bin/sh} $ac_aux_dir/missing"
 
 # How about lex?
@@ -19435,7 +19457,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 19438 "configure"
+#line 19460 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -19541,7 +19563,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 19544 "configure"
+#line 19566 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 5f30f80833e..cecdd339862 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -1208,6 +1208,21 @@ else
 fi
 AC_SUBST(GENERATED_MANPAGES)
 
+# See if sphinx-build has been installed and is modern enough
+# that we can use it.
+AC_MSG_CHECKING([for sphinx-build])
+if sphinx-build -j auto -h &>/dev/null ; then
+  SPHINX_BUILD=sphinx-build
+  AC_MSG_RESULT(yes)
+else
+  AC_MSG_WARN([
+  *** sphinx-build is missing or too old.
+  *** Info and man pages documentation will not be built.])
+  AC_MSG_RESULT(no)
+  SPHINX_BUILD=
+fi
+AC_SUBST(SPHINX_BUILD)
+
 MISSING="${CONFIG_SHELL-/bin/sh} $ac_aux_dir/missing"
 
 # How about lex?
diff --git a/gcc/cp/Make-lang.in b/gcc/cp/Make-lang.in
index 155be74efdb..6e49e3117db 100644
--- a/gcc/cp/Make-lang.in
+++ b/gcc/cp/Make-lang.in
@@ -260,7 +260,7 @@ c++.install-common: installdirs
 
 # We can't use links because not everyone supports them.  So just copy the
 # manpage.
-doc/g++.1: doc/gcc.1
+doc/g++.1: doc/gcc/man/man/gcc.1
 	cp $< doc/g++.1
 
 c++.install-man: $(DESTDIR)$(man1dir)/$(GXX_INSTALL_NAME)$(man1ext)
diff --git a/gcc/doc/gcc/conf.py b/gcc/doc/gcc/conf.py
index d6d69de24f8..ac1bc73ca78 100644
--- a/gcc/doc/gcc/conf.py
+++ b/gcc/doc/gcc/conf.py
@@ -1,5 +1,6 @@
 # Configuration file for the Sphinx documentation builder.
 
+import os
 import sys
 sys.path.append('../../..//doc')
 
@@ -29,8 +30,14 @@ man_pages = [
     ('funding', 'fsf-funding', 'Funding Free Software', [], 7)
 ]
 
+ENABLE_LTO = os.getenv('ENABLE_LTO')
+assert ENABLE_LTO
+
+if ENABLE_LTO  == 'yes':
+    man_pages += [('lto-dump', 'lto-dump', 'Tool for dumping LTO object files', [authors], 1)]
+
 texinfo_documents = [
   ('index', 'gcc', project, authors, None, None, None, True)
 ]
 
-tags.add('gcc')
\ No newline at end of file
+tags.add('gcc')
diff --git a/gcc/fortran/Make-lang.in b/gcc/fortran/Make-lang.in
index 63195a9c7ed..686788ee868 100644
--- a/gcc/fortran/Make-lang.in
+++ b/gcc/fortran/Make-lang.in
@@ -109,16 +109,18 @@ fortran.all.cross: gfortran-cross$(exeext)
 fortran.start.encap: gfortran$(exeext)
 fortran.rest.encap:
 
-fortran.srcinfo: doc/gfortran.info
-	-cp -p $^ $(srcdir)/fortran
-
 fortran.tags: force
 	cd $(srcdir)/fortran; etags -o TAGS.sub *.c *.h; \
 	etags --include TAGS.sub --include ../TAGS.sub
 
-fortran.info: doc/gfortran.info doc/gfc-internals.info
+fortran.info: info-gfortran info-gfc-internals
 fortran.dvi: doc/gfortran.dvi doc/gfc-internals.dvi
 
+info-gfortran:
+	+ if [ x$(SPHINX_BUILD) = xsphinx-build ]; then \
+	  make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/fortran/doc/gfortran BUILDDIR=$(objdir)/doc/fortran/info; \
+	else true; fi
+
 F95_HTMLFILES = $(build_htmldir)/gfortran
 
 fortran.html: $(F95_HTMLFILES)/index.html
@@ -154,9 +156,10 @@ fortran.install-pdf: $(F95_PDFFILES)
 	  $(INSTALL_DATA) "$$d$$p" "$(DESTDIR)$(pdfdir)/gcc/$$f"; \
 	done
 
-F95_MANFILES = doc/gfortran.1
+man-fortran:
+	+ make -C $(srcdir)/../doc man SOURCEDIR=$(srcdir)/fortran/doc/gfortran BUILDDIR=$(objdir)/doc/fortran/man
 
-fortran.man: $(F95_MANFILES)
+fortran.man: man-fortran
 
 fortran.srcman: $(F95_MANFILES)
 	-cp -p $^ $(srcdir)/doc
@@ -186,13 +189,6 @@ GFORTRAN_TEXI = \
   $(srcdir)/doc/include/gcc-common.texi \
   gcc-vers.texi
 
-doc/gfortran.info: $(GFORTRAN_TEXI)
-	if [ x$(BUILD_INFO) = xinfo ]; then \
-	  rm -f doc/gfortran.info-*; \
-	  $(MAKEINFO) -I $(srcdir)/doc/include -I $(srcdir)/fortran \
-	    -o $@ $<; \
-	else true; fi
-
 doc/gfortran.dvi: $(GFORTRAN_TEXI)
 	$(TEXI2DVI) -I $(srcdir)/fortran -I $(abs_docdir)/include -o $@ $<
 
@@ -217,11 +213,9 @@ GFC_INTERNALS_TEXI = \
   $(srcdir)/doc/include/gcc-common.texi \
   gcc-vers.texi
 
-doc/gfc-internals.info: $(GFC_INTERNALS_TEXI)
-	if [ x$(BUILD_INFO) = xinfo ]; then \
-	  rm -f doc/gfc-internals.info-*; \
-	  $(MAKEINFO) -I $(srcdir)/doc/include -I $(srcdir)/fortran \
-	    -o $@ $<; \
+info-gfc-internals:
+	+ if [ x$(SPHINX_BUILD) = xsphinx-build ]; then \
+	  make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/fortran/doc/gfc-internals BUILDDIR=$(objdir)/doc/gfc-internals/info; \
 	else true; fi
 
 doc/gfc-internals.dvi: $(GFC_INTERNALS_TEXI)
@@ -256,9 +250,13 @@ fortran.install-plugin:
 
 fortran.install-info: $(DESTDIR)$(infodir)/gfortran.info
 
+$(DESTDIR)$(infodir)/gfortran.info: doc/fortran/info/texinfo/gfortran.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
 fortran.install-man: $(DESTDIR)$(man1dir)/$(GFORTRAN_INSTALL_NAME)$(man1ext)
 
-$(DESTDIR)$(man1dir)/$(GFORTRAN_INSTALL_NAME)$(man1ext): doc/gfortran.1 \
+$(DESTDIR)$(man1dir)/$(GFORTRAN_INSTALL_NAME)$(man1ext): doc/fortran/man/man/gfortran.1 \
 		installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
@@ -286,12 +284,6 @@ fortran.mostlyclean:
 fortran.clean:
 fortran.distclean:
 	-rm -f fortran/config.status fortran/Makefile
-
-fortran.extraclean:
-fortran.maintainer-clean:
-	-rm -f doc/gfortran.info* fortran/gfortran.*aux
-	-rm -f $(docobjdir)/gfortran.1
-
 #\f
 # Stage hooks:
 # The toplevel makefile has already created stage?/fortran at this point.
diff --git a/gcc/genhooks.c b/gcc/genhooks.c
index ebe0d0954e6..84635bd5c08 100644
--- a/gcc/genhooks.c
+++ b/gcc/genhooks.c
@@ -48,212 +48,74 @@ upstrdup (const char *in)
   return ret;
 }
 
-/* Struct for 'start hooks' which start a sequence of consecutive hooks
-   that are defined in target.def and to be documented in tm.texi.  */
-struct s_hook
-{
-  char *name;
-  int pos;
-};
-
-static hashval_t
-s_hook_hash (const void *p)
-{
-  const struct s_hook *s_hook = (const struct s_hook *)p;
-  return htab_hash_string (s_hook->name);
-}
+/* Emit shared .rst.in file that is used by the corresponding
+   .. include:: tm.rst.in
+     :start-after: [HOOK_NAME]
+     :end-before: [HOOK_NAME]
 
-static int
-s_hook_eq_p (const void *p1, const void *p2)
-{
-  return (strcmp (((const struct s_hook *) p1)->name, 
-		  ((const struct s_hook *) p2)->name) == 0);
-}
-
-/* Read the documentation file with name IN_FNAME, perform substitutions
-   to incorporate information from hook_array, and emit the result on stdout.
-   Hooks defined with DEFHOOK / DEFHOOKPOD are emitted at the place of a
-   matching @hook in the input file; if there is no matching @hook, the
-   hook is emitted after the hook that precedes it in target.def .
-   Usually, the emitted hook documentation starts with the hook
-   signature, followed by the string from the doc field.
-   The documentation is bracketed in @deftypefn / @deftypevr and a matching
-   @end.
-   While emitting the doc field, an @findex entry is added
-   to the affected paragraph.
    If the doc field starts with '*', the leading '*' is stripped, and the doc
    field is otherwise emitted unaltered; no function signature/
    @deftypefn/deftypevr/@end is emitted.
    In particular, a doc field of "*" means not to emit any ocumentation for
    this target.def / hook_array entry at all (there might be documentation
    for this hook in the file named IN_FNAME, though).
-   A doc field of 0 is used to append the hook signature after the previous
-   hook's signture, so that one description can be used for a group of hooks.
-   When the doc field is "", @deftypefn/@deftypevr and the hook signature
-   is emitted, but not the matching @end.  This allows all the free-form
+
+   This allows all the free-form
    documentation to be placed in IN_FNAME, to work around GPL/GFDL
    licensing incompatibility issues.  */
+
 static void
-emit_documentation (const char *in_fname)
+emit_documentation (void)
 {
-  int i, j;
-  char buf[1000];
-  htab_t start_hooks = htab_create (99, s_hook_hash, s_hook_eq_p, (htab_del) 0);
-  FILE *f;
-
-  /* Enter all the start hooks in start_hooks.  */
-  f = fopen (in_fname, "r");
-  if (!f)
-    {
-      perror ("");
-      fatal ("Couldn't open input file");
-    }
-  while (fscanf (f, "%*[^@]"), buf[0] = '\0',
-	 fscanf (f, "@%5[^ \n]", buf) != EOF)
-    {
-      void **p;
-      struct s_hook *shp;
-
-      if (strcmp (buf, "hook") != 0)
-	continue;
-      buf[0] = '\0';
-      fscanf (f, "%999s", buf);
-      shp = XNEW (struct s_hook);
-      shp->name = upstrdup (buf);
-      shp->pos = -1;
-      p = htab_find_slot (start_hooks, shp, INSERT);
-      if (*p != HTAB_EMPTY_ENTRY)
-	fatal ("Duplicate placement for hook %s\n", shp->name);
-      *(struct s_hook **) p = shp;
-    }
-  fclose (f);
   /* For each hook in hook_array, if it is a start hook, store its position.  */
-  for (i = 0; i < (int) (sizeof hook_array / sizeof hook_array[0]); i++)
+  for (int i = 0; i < (int) (sizeof hook_array / sizeof hook_array[0]); i++)
     {
-      struct s_hook sh, *shp;
-      void *p;
-
       if (!hook_array[i].doc || strcmp (hook_array[i].doc, "*") == 0)
 	continue;
-      sh.name = upstrdup (hook_array[i].name);
-      p = htab_find (start_hooks, &sh);
-      if (p)
-	{
-	  shp = (struct s_hook *) p;
-	  if (shp->pos >= 0)
-	    fatal ("Duplicate hook %s\n", sh.name);
-	  shp->pos = i;
-	}
+      const char *hook_name = upstrdup (hook_array[i].name);
+      printf ("[%s]\n", hook_name);
+      /* Print header.  Function-valued hooks have a parameter list,
+	 unlike POD-valued ones.  */
+      const char *deftype = hook_array[i].param ? "function" : "c:var";
+      printf (".. %s:: ", deftype);
+      if (strchr (hook_array[i].type, ' '))
+	printf ("%s", hook_array[i].type);
       else
-	fatal ("No place specified to document hook %s\n", sh.name);
-      free (sh.name);
-    }
-  /* Copy input file to stdout, substituting @hook directives with the
-     corresponding hook documentation sequences.  */
-  f = fopen (in_fname, "r");
-  if (!f)
-    {
-      perror ("");
-      fatal ("Couldn't open input file");
-    }
-  for (;;)
-    {
-      struct s_hook sh, *shp;
-      int c = getc (f);
-      char *name;
-
-      if (c == EOF)
-	break;
-      if (c != '@')
-	{
-	  putchar (c);
-	  continue;
-	}
-      buf[0] = '\0';
-      fscanf (f, "%5[^ \n]", buf);
-      if (strcmp (buf, "hook") != 0)
+	printf ("%s", hook_array[i].type);
+      printf (" %s", hook_name);
+      if (hook_array[i].param)
 	{
-	  printf ("@%s", buf);
-	  continue;
+	  const char *q, *e;
+	  /* Print the parameter list, with the parameter names
+	     enclosed in @var{}.  */
+	  printf (" ");
+	  for (q = hook_array[i].param; (e = strpbrk (q, " *,)"));
+	       q = e + 1)
+	    /* Type names like 'int' are followed by a space, sometimes
+	       also by '*'.  'void' should appear only in "(void)".  */
+	    if (*e == ' ' || *e == '*' || *q == '(')
+	      printf ("%.*s", (int) (e - q + 1), q);
+	    else
+	      printf ("%.*s%c", (int) (e - q), q, *e);
 	}
-      fscanf (f, "%999s", buf);
-      sh.name = name = upstrdup (buf);
-      shp = (struct s_hook *) htab_find (start_hooks, &sh);
-      if (!shp || shp->pos < 0)
-	fatal ("No documentation for hook %s\n", sh.name);
-      i = shp->pos;
-      do
+
+      printf ("\n");
+      if (hook_array[i].doc[0])
 	{
-	  const char *q, *e;
-	  const char *deftype;
 	  const char *doc, *p_end;
-
-	  /* A leading '*' means to output the documentation string without
-	     further processing.  */
-	  if (*hook_array[i].doc == '*')
-	    printf ("%s", hook_array[i].doc + 1);
-	  else
+	  printf ("\n");
+	  /* Print each documentation paragraph in turn.  */
+	  for (doc = hook_array[i].doc; *doc; doc = p_end)
 	    {
-	      if (i != shp->pos)
-		printf ("\n\n");
-
-	      /* Print header.  Function-valued hooks have a parameter list, 
-		 unlike POD-valued ones.  */
-	      deftype = hook_array[i].param ? "deftypefn" : "deftypevr";
-	      printf ("@%s {%s} ", deftype, hook_array[i].docname);
-	      if (strchr (hook_array[i].type, ' '))
-		printf ("{%s}", hook_array[i].type);
-	      else
-		printf ("%s", hook_array[i].type);
-	      printf (" %s", name);
-	      if (hook_array[i].param)
-		{
-		  /* Print the parameter list, with the parameter names
-		     enclosed in @var{}.  */
-		  printf (" ");
-		  for (q = hook_array[i].param; (e = strpbrk (q, " *,)"));
-		       q = e + 1)
-		    /* Type names like 'int' are followed by a space, sometimes
-		       also by '*'.  'void' should appear only in "(void)".  */
-		    if (*e == ' ' || *e == '*' || *q == '(')
-		      printf ("%.*s", (int) (e - q + 1), q);
-		    else
-		      printf ("@var{%.*s}%c", (int) (e - q), q, *e);
-		}
-	      /* POD-valued hooks sometimes come in groups with common
-		 documentation.*/
-	      for (j = i + 1;
-		   j < (int) (sizeof hook_array / sizeof hook_array[0])
-		   && hook_array[j].doc == 0 && hook_array[j].type; j++)
-		{
-		  char *namex = upstrdup (hook_array[j].name);
-
-		  printf ("\n@%sx {%s} {%s} %s",
-			  deftype, hook_array[j].docname,
-			  hook_array[j].type, namex);
-		}
-	      if (hook_array[i].doc[0])
-		{
-		  printf ("\n");
-		  /* Print each documentation paragraph in turn.  */
-		  for (doc = hook_array[i].doc; *doc; doc = p_end)
-		    {
-		      /* Find paragraph end.  */
-		      p_end = strstr (doc, "\n\n");
-		      p_end = (p_end ? p_end + 2 : doc + strlen (doc));
-		      printf ("%.*s", (int) (p_end - doc), doc);
-		    }
-		  printf ("\n@end %s", deftype);
-		}
+	      /* Find paragraph end.  */
+	      p_end = strstr (doc, "\n");
+	      p_end = (p_end ? p_end + 1 : doc + strlen (doc));
+	      printf ("  %.*s", (int) (p_end - doc), doc);
 	    }
-	  if (++i >= (int) (sizeof hook_array / sizeof hook_array[0])
-	      || !hook_array[i].doc)
-	    break;
-	  free (name);
-	  sh.name = name = upstrdup (hook_array[i].name);
+	  printf ("\n");
 	}
-      while (!htab_find (start_hooks, &sh));
-      free (name);
+
+      printf ("\n[%s]\n\n", hook_name);
     }
 }
 
@@ -314,8 +176,8 @@ main (int argc, char **argv)
 {
   progname = "genhooks";
 
-  if (argc >= 3)
-    emit_documentation (argv[2]);
+  if (argc == 1)
+    emit_documentation ();
   else
     emit_init_macros (argv[1]);
   return 0;


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [gcc(refs/users/marxin/heads/sphinx-v2)] Build system integration.
@ 2021-06-23 10:24 Martin Liska
  0 siblings, 0 replies; 6+ messages in thread
From: Martin Liska @ 2021-06-23 10:24 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:dd785a530be8771e6154b4142181146259ab5c04

commit dd785a530be8771e6154b4142181146259ab5c04
Author: Martin Liska <mliska@suse.cz>
Date:   Thu Jun 17 22:08:57 2021 +0200

    Build system integration.

Diff:
---
 config/acx.m4            |   2 +-
 configure                |   1 -
 configure.ac             |   1 -
 doc/Makefile             |   3 +-
 doc/baseconf.py          |   5 +-
 gcc/Makefile.in          | 216 ++++++++++++++++++++-----------------------
 gcc/configure            |  28 +++++-
 gcc/configure.ac         |  15 +++
 gcc/cp/Make-lang.in      |   2 +-
 gcc/doc/gcc/conf.py      |   9 +-
 gcc/fortran/Make-lang.in |  42 ++++-----
 gcc/genhooks.c           | 232 ++++++++++-------------------------------------
 12 files changed, 216 insertions(+), 340 deletions(-)

diff --git a/config/acx.m4 b/config/acx.m4
index 87c1b5e2932..65a7f4bc446 100644
--- a/config/acx.m4
+++ b/config/acx.m4
@@ -615,7 +615,7 @@ AC_DEFUN([ACX_BUGURL],[
     REPORT_BUGS_TEXI=
     ;;
   *)
-    REPORT_BUGS_TO="<$BUGURL>"
+    REPORT_BUGS_TO="$BUGURL"
     REPORT_BUGS_TEXI=@uref{`echo "$BUGURL" | sed 's/@/@@/g'`}
     ;;
   esac;
diff --git a/configure b/configure
index 1224fc4039e..e58cbb65158 100755
--- a/configure
+++ b/configure
@@ -10458,7 +10458,6 @@ case " $configdirs " in
     ;;
 esac
 
-
 # Host tools.
 ncn_tool_prefix=
 test -n "$host_alias" && ncn_tool_prefix=$host_alias-
diff --git a/configure.ac b/configure.ac
index 66d637d70dc..68c209852e9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3454,7 +3454,6 @@ case " $configdirs " in
     ;;
 esac
 
-
 # Host tools.
 NCN_STRICT_CHECK_TOOLS(AR, ar)
 NCN_STRICT_CHECK_TOOLS(AS, as)
diff --git a/doc/Makefile b/doc/Makefile
index 9e305a8e7da..7f3690e7e50 100644
--- a/doc/Makefile
+++ b/doc/Makefile
@@ -3,7 +3,8 @@
 
 # You can set these variables from the command line.
 SPHINXOPTS   ?= -j auto -q
-SPHINXBUILD  ?= sphinx-build
+# FIXME
+SPHINXBUILD  ?= /tmp/venv/bin/sphinx-build
 PAPER        ?=
 SOURCEDIR     = .
 BUILDDIR      = _build
diff --git a/doc/baseconf.py b/doc/baseconf.py
index 07bf2c551c8..206328d43e5 100644
--- a/doc/baseconf.py
+++ b/doc/baseconf.py
@@ -34,8 +34,9 @@ gcc_DEVPHASE = __read_file('DEV-PHASE')
 gcc_DATESTAMP = __read_file('DATESTAMP')
 gcc_REVISION = __read_file('REVISION')
 
-VERSION_PACKAGE = os.getenv('VERSION_PACKAGE', '(GCC)')
-BUGURL = os.getenv('BUGURL', 'https://gcc.gnu.org/bugs/')
+VERSION_PACKAGE = os.getenv('VERSION_PACKAGE')
+BUGURL = os.getenv('BUGURL')
+assert VERSION_PACKAGE and BUGURL
 
 # The short X.Y version.
 version = gcc_BASEVER
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index ebf26442992..66d99c1e9f9 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -771,11 +771,8 @@ LIBCONVERT =
 # Control whether header files are installed.
 INSTALL_HEADERS=install-headers install-mkheaders
 
-# Control whether Info documentation is built and installed.
-BUILD_INFO = @BUILD_INFO@
-
-# Control whether manpages generated by texi2pod.pl can be rebuilt.
-GENERATED_MANPAGES = @GENERATED_MANPAGES@
+# Control whether manpages generated by sphinx-build can be rebuilt.
+SPHINX_BUILD = @SPHINX_BUILD@
 
 # Additional directories of header files to run fixincludes on.
 # These should be directories searched automatically by default
@@ -2579,38 +2576,20 @@ s-d-target-hooks-def-h: build/genhooks$(build_exeext)
 					     d/d-target-hooks-def.h
 	$(STAMP) s-d-target-hooks-def-h
 
-# check if someone mistakenly only changed tm.texi.
-# We use a different pathname here to avoid a circular dependency.
-s-tm-texi: $(srcdir)/doc/../doc/tm.texi
-
 # The tm.texi we want to compare against / check into svn should have
 # unix-style line endings.  To make this work on MinGW, remove \r.
 # \r is not portable to Solaris tr, therefore we have a special
 # case for ASCII.  We use \r for other encodings like EBCDIC.
-s-tm-texi: build/genhooks$(build_exeext) $(srcdir)/doc/tm.texi.in
-	$(RUN_GEN) build/genhooks$(build_exeext) -d \
-			$(srcdir)/doc/tm.texi.in > tmp-tm.texi
-	case `echo X|tr X '\101'` in \
-	  A) tr -d '\015' < tmp-tm.texi > tmp2-tm.texi ;; \
-	  *) tr -d '\r' < tmp-tm.texi > tmp2-tm.texi ;; \
-	esac
-	mv tmp2-tm.texi tmp-tm.texi
-	$(SHELL) $(srcdir)/../move-if-change tmp-tm.texi tm.texi
-	@if cmp -s $(srcdir)/doc/tm.texi tm.texi; then \
+s-tm-rst-in: build/genhooks$(build_exeext)
+	$(RUN_GEN) build/genhooks$(build_exeext) > tmp-tm.rst.in
+	$(SHELL) $(srcdir)/../move-if-change tmp-tm.rst.in tm.rst.in
+
+	@if cmp -s $(srcdir)/doc/gccint/target-macros/tm.rst.in tm.rst.in; then \
 	  $(STAMP) $@; \
-	elif test $(srcdir)/doc/tm.texi -nt $(srcdir)/doc/tm.texi.in \
-	  && ( test $(srcdir)/doc/tm.texi -nt $(srcdir)/target.def \
-	    || test $(srcdir)/doc/tm.texi -nt $(srcdir)/c-family/c-target.def \
-	    || test $(srcdir)/doc/tm.texi -nt $(srcdir)/common/common-target.def \
-	    || test $(srcdir)/doc/tm.texi -nt $(srcdir)/d/d-target.def \
-	  ); then \
-	  echo >&2 ; \
-	  echo You should edit $(srcdir)/doc/tm.texi.in rather than $(srcdir)/doc/tm.texi . >&2 ; \
-	  false; \
 	else \
 	  echo >&2 ; \
 	  echo Verify that you have permission to grant a GFDL license for all >&2 ; \
-	  echo new text in $(objdir)/tm.texi, then copy it to $(srcdir)/doc/tm.texi. >&2 ; \
+	  echo new text in $(objdir)/tm.rst.in, then copy it to $(srcdir)/doc/gccint/target-macros/tm.rst.in. >&2 ; \
 	  false; \
 	fi
 
@@ -3281,15 +3260,7 @@ install-no-fixedincludes:
 
 # Remake the info files.
 
-doc: $(BUILD_INFO) $(GENERATED_MANPAGES)
-
-INFOFILES = doc/cpp.info doc/gcc.info doc/gccint.info \
-            doc/gccinstall.info doc/cppinternals.info
-
-info: $(INFOFILES) lang.info @GENINSRC@ srcinfo lang.srcinfo
-
-srcinfo: $(INFOFILES)
-	-cp -p $^ $(srcdir)/doc
+doc: $(SPHINX_BUILD)
 
 TEXI_CPP_FILES = cpp.texi fdl.texi cppenv.texi cppopts.texi		\
 	 gcc-common.texi gcc-vers.texi
@@ -3336,28 +3307,6 @@ gcc-vers.texi: $(BASEVER) $(DEVPHASE)
 	mv -f $@T $@
 
 
-# The *.1, *.7, *.info, *.dvi, and *.pdf files are being generated from implicit
-# patterns.  To use them, put each of the specific targets with its
-# specific dependencies but no build commands.
-
-doc/cpp.info: $(TEXI_CPP_FILES)
-doc/gcc.info: $(TEXI_GCC_FILES)
-doc/gccint.info: $(TEXI_GCCINT_FILES)
-doc/cppinternals.info: $(TEXI_CPPINT_FILES)
-
-doc/%.info: %.texi
-	if [ x$(BUILD_INFO) = xinfo ]; then \
-		$(MAKEINFO) $(MAKEINFOFLAGS) -I . -I $(gcc_docdir) \
-			-I $(gcc_docdir)/include -o $@ $<; \
-	fi
-
-# Duplicate entry to handle renaming of gccinstall.info
-doc/gccinstall.info: $(TEXI_GCCINSTALL_FILES)
-	if [ x$(BUILD_INFO) = xinfo ]; then \
-		$(MAKEINFO) $(MAKEINFOFLAGS) -I $(gcc_docdir) \
-			-I $(gcc_docdir)/include -o $@ $<; \
-	fi
-
 doc/cpp.dvi: $(TEXI_CPP_FILES)
 doc/gcc.dvi: $(TEXI_GCC_FILES)
 doc/gccint.dvi: $(TEXI_GCCINT_FILES)
@@ -3422,51 +3371,43 @@ $(build_htmldir)/gccinstall/index.html: $(TEXI_GCCINSTALL_FILES)
 	DESTDIR=$(@D) \
 	$(SHELL) $(srcdir)/doc/install.texi2html
 
-MANFILES = doc/gcov.1 doc/cpp.1 doc/gcc.1 doc/gfdl.7 doc/gpl.7 \
-           doc/fsf-funding.7 doc/gcov-tool.1 doc/gcov-dump.1 \
 	   $(if $(filter yes,@enable_lto@),doc/lto-dump.1)
 
-generated-manpages: man
+export VERSION_PACKAGE="$(PKGVERSION)"
+export ENABLE_LTO=$(enable_lto)
+export BUGURL="$(BUGURL_s)"
 
-man: $(MANFILES) lang.man @GENINSRC@ srcman lang.srcman
+man: man-gcc man-cpp lang.man @GENINSRC@
 
-srcman: $(MANFILES)
-	-cp -p $^ $(srcdir)/doc
+info: info-gcc info-gccint info-cpp info-cppinternals info-install lang.info @GENINSRC@
 
-doc/%.1: %.pod
-	$(STAMP) $@
-	-($(POD2MAN) --section=1 $< > $(@).T$$$$ && \
-		mv -f $(@).T$$$$ $@) || \
-		(rm -f $(@).T$$$$ && exit 1)
+sphinx-build: man info
 
-doc/%.7: %.pod
-	$(STAMP) $@
-	-($(POD2MAN) --section=7 $< > $(@).T$$$$ && \
-		mv -f $(@).T$$$$ $@) || \
-		(rm -f $(@).T$$$$ && exit 1)
+man-gcc: doc/gcc/man/man/gcc.1
 
-%.pod: %.texi
-	$(STAMP) $@
-	-$(TEXI2POD) -DBUGURL="$(BUGURL_TEXI)" $< > $@
+doc/gcc/man/man/gcc.1:
+	+ make -C $(srcdir)/../doc man SOURCEDIR=$(srcdir)/doc/gcc BUILDDIR=$(objdir)/doc/gcc/man
 
-.INTERMEDIATE: cpp.pod gcc.pod gfdl.pod fsf-funding.pod gpl.pod
-cpp.pod: cpp.texi cppenv.texi cppopts.texi
+man-cpp:
+	+ make -C $(srcdir)/../doc man SOURCEDIR=$(srcdir)/doc/cpp BUILDDIR=$(objdir)/doc/cpp/man
 
-# These next rules exist because the output name is not the same as
-# the input name, so our implicit %.pod rule will not work.
+info-gcc:
+	+ make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/doc/gcc BUILDDIR=$(objdir)/doc/gcc/info
 
-gcc.pod: invoke.texi cppenv.texi cppopts.texi gcc-vers.texi
-	$(STAMP) $@
-	-$(TEXI2POD) $< > $@
-gfdl.pod: fdl.texi
-	$(STAMP) $@
-	-$(TEXI2POD) $< > $@
-fsf-funding.pod: funding.texi
-	$(STAMP) $@
-	-$(TEXI2POD) $< > $@
-gpl.pod: gpl_v3.texi
-	$(STAMP) $@
-	-$(TEXI2POD) $< > $@
+info-gccint: s-tm-rst-in
+	+ make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/doc/gccint BUILDDIR=$(objdir)/doc/gccint/info
+
+info-cpp:
+	+ make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/doc/cpp BUILDDIR=$(objdir)/doc/cpp/info
+
+info-cppinternals:
+	+ make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/doc/cppinternals BUILDDIR=$(objdir)/doc/cppinternals/info
+
+info-install:
+	+ make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/doc/install BUILDDIR=$(objdir)/doc/install/info
+
+html-gccint: s-tm-rst-in
+	+ make -C $(srcdir)/../doc html SOURCEDIR=$(srcdir)/doc/gccint BUILDDIR=$(objdir)/doc/gccint/html
 
 #\f
 # Deletion of files made during compilation.
@@ -3526,8 +3467,7 @@ clean: mostlyclean lang.clean
 	-rm -f config.h tconfig.h bconfig.h tm_p.h tm.h
 	-rm -f options.c options.h optionlist
 	-rm -f cs-*
-	-rm -f doc/*.dvi
-	-rm -f doc/*.pdf
+	-rm -rf doc
 # Delete the include directories.
 	-rm -rf include include-fixed
 # Delete files used by the "multilib" facility (including libgcc subdirs).
@@ -3568,7 +3508,7 @@ maintainer-clean:
 	$(MAKE) lang.maintainer-clean distclean
 	-rm -f cpp.??s cpp.*aux
 	-rm -f gcc.??s gcc.*aux
-	-rm -f $(gcc_docdir)/*.info $(gcc_docdir)/*.1 $(gcc_docdir)/*.7 $(gcc_docdir)/*.dvi $(gcc_docdir)/*.pdf
+	-rm -rf doc
 #\f
 # Entry points `install', `install-strip', and `uninstall'.
 # Also use `install-collect2' to install collect2 when the config files don't.
@@ -3765,24 +3705,46 @@ install-info:: doc installdirs \
 	$(DESTDIR)$(infodir)/cpp.info \
 	$(DESTDIR)$(infodir)/gcc.info \
 	$(DESTDIR)$(infodir)/cppinternals.info \
-	$(DESTDIR)$(infodir)/gccinstall.info \
+	$(DESTDIR)$(infodir)/install.info \
 	$(DESTDIR)$(infodir)/gccint.info \
 	lang.install-info
 
-$(DESTDIR)$(infodir)/%.info: doc/%.info installdirs
-	rm -f $@
-	if [ -f $< ]; then \
-	  for f in $(<)*; do \
-	    realfile=`echo $$f | sed -e 's|.*/\([^/]*\)$$|\1|'`; \
-	    $(INSTALL_DATA) $$f $(DESTDIR)$(infodir)/$$realfile; \
-	    chmod a-x $(DESTDIR)$(infodir)/$$realfile; \
-	  done; \
-	else true; fi
-	-if $(SHELL) -c 'install-info --version' >/dev/null 2>&1; then \
-	  if [ -f $@ ]; then \
-	    install-info --dir-file=$(DESTDIR)$(infodir)/dir $@; \
-	  else true; fi; \
-	else true; fi;
+$(DESTDIR)$(infodir)/gcc.info: doc/gcc/info/texinfo/gcc.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/gccint.info: doc/gccint/info/texinfo/gccint.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/install.info: doc/install/info/texinfo/install.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/cpp.info: doc/cpp/info/texinfo/cpp.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/cppinternals.info: doc/cppinternals/info/texinfo/cppinternals.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/gcov.info: doc/gcc/info/texinfo/gcov.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/gcov-tool.info: doc/gcc/info/texinfo/gcov-tool.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/gcov-dump.info: doc/gcc/info/texinfo/gcov-dump.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/lto-dump.info: doc/gcc/info/texinfo/lto-dump.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
 
 pdf__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
 
@@ -3832,36 +3794,52 @@ $(DESTDIR)$(man7dir)/%$(man7ext): doc/%.7 installdirs
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
-$(DESTDIR)$(man1dir)/$(GCC_INSTALL_NAME)$(man1ext): doc/gcc.1 installdirs
+$(DESTDIR)$(man1dir)/$(GCC_INSTALL_NAME)$(man1ext): doc/gcc/man/man/gcc.1 installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
-$(DESTDIR)$(man1dir)/$(CPP_INSTALL_NAME)$(man1ext): doc/cpp.1 installdirs
+$(DESTDIR)$(man1dir)/$(CPP_INSTALL_NAME)$(man1ext): doc/cpp/man/man/cpp.1 installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
-$(DESTDIR)$(man1dir)/$(GCOV_INSTALL_NAME)$(man1ext): doc/gcov.1 installdirs
+$(DESTDIR)$(man1dir)/$(GCOV_INSTALL_NAME)$(man1ext): doc/gcc/man/man/gcov.1 installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
-$(DESTDIR)$(man1dir)/$(GCOV_TOOL_INSTALL_NAME)$(man1ext): doc/gcov-tool.1 installdirs
+$(DESTDIR)$(man1dir)/$(GCOV_TOOL_INSTALL_NAME)$(man1ext): doc/gcc/man/man/gcov-tool.1 installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
-$(DESTDIR)$(man1dir)/$(GCOV_DUMP_INSTALL_NAME)$(man1ext): doc/gcov-dump.1 installdirs
+$(DESTDIR)$(man1dir)/$(GCOV_DUMP_INSTALL_NAME)$(man1ext): doc/gcc/man/man/gcov-dump.1 installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
-$(DESTDIR)$(man1dir)/$(LTO_DUMP_INSTALL_NAME)$(man1ext): doc/lto-dump.1 installdirs
+$(DESTDIR)$(man1dir)/$(LTO_DUMP_INSTALL_NAME)$(man1ext): doc/gcc/man/man/lto-dump.1 installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
+$(DESTDIR)$(man7dir)/fsf-funding$(man7ext): doc/gcc/man/man/fsf-funding.7 installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+	-chmod a-x $@
+
+$(DESTDIR)$(man7dir)/gfdl$(man7ext): doc/gcc/man/man/gfdl.7 installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+	-chmod a-x $@
+
+$(DESTDIR)$(man7dir)/gpl$(man7ext): doc/gcc/man/man/gpl.7 installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+	-chmod a-x $@
+
+
 # Install all the header files built in the include subdirectory.
 install-headers: $(INSTALL_HEADERS_DIR)
 # Fix symlinks to absolute paths in the installed include directory to
diff --git a/gcc/configure b/gcc/configure
index dd0194a57f4..b7274875b84 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -806,6 +806,7 @@ AR
 NM
 BISON
 FLEX
+SPHINX_BUILD
 GENERATED_MANPAGES
 BUILD_INFO
 MAKEINFO
@@ -7905,7 +7906,7 @@ fi
     REPORT_BUGS_TEXI=
     ;;
   *)
-    REPORT_BUGS_TO="<$BUGURL>"
+    REPORT_BUGS_TO="$BUGURL"
     REPORT_BUGS_TEXI=@uref{`echo "$BUGURL" | sed 's/@/@@/g'`}
     ;;
   esac;
@@ -8557,6 +8558,27 @@ $as_echo "no" >&6; }
 fi
 
 
+# See if sphinx-build has been installed and is modern enough
+# that we can use it.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for sphinx-build" >&5
+$as_echo_n "checking for sphinx-build... " >&6; }
+if sphinx-build -j auto -h &>/dev/null ; then
+  SPHINX_BUILD=sphinx-build
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING:
+  *** sphinx-build is missing or too old.
+  *** Info and man pages documentation will not be built." >&5
+$as_echo "$as_me: WARNING:
+  *** sphinx-build is missing or too old.
+  *** Info and man pages documentation will not be built." >&2;}
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+  SPHINX_BUILD=
+fi
+
+
 MISSING="${CONFIG_SHELL-/bin/sh} $ac_aux_dir/missing"
 
 # How about lex?
@@ -19435,7 +19457,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 19438 "configure"
+#line 19460 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -19541,7 +19563,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 19544 "configure"
+#line 19566 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 5f30f80833e..cecdd339862 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -1208,6 +1208,21 @@ else
 fi
 AC_SUBST(GENERATED_MANPAGES)
 
+# See if sphinx-build has been installed and is modern enough
+# that we can use it.
+AC_MSG_CHECKING([for sphinx-build])
+if sphinx-build -j auto -h &>/dev/null ; then
+  SPHINX_BUILD=sphinx-build
+  AC_MSG_RESULT(yes)
+else
+  AC_MSG_WARN([
+  *** sphinx-build is missing or too old.
+  *** Info and man pages documentation will not be built.])
+  AC_MSG_RESULT(no)
+  SPHINX_BUILD=
+fi
+AC_SUBST(SPHINX_BUILD)
+
 MISSING="${CONFIG_SHELL-/bin/sh} $ac_aux_dir/missing"
 
 # How about lex?
diff --git a/gcc/cp/Make-lang.in b/gcc/cp/Make-lang.in
index 155be74efdb..6e49e3117db 100644
--- a/gcc/cp/Make-lang.in
+++ b/gcc/cp/Make-lang.in
@@ -260,7 +260,7 @@ c++.install-common: installdirs
 
 # We can't use links because not everyone supports them.  So just copy the
 # manpage.
-doc/g++.1: doc/gcc.1
+doc/g++.1: doc/gcc/man/man/gcc.1
 	cp $< doc/g++.1
 
 c++.install-man: $(DESTDIR)$(man1dir)/$(GXX_INSTALL_NAME)$(man1ext)
diff --git a/gcc/doc/gcc/conf.py b/gcc/doc/gcc/conf.py
index d6d69de24f8..ac1bc73ca78 100644
--- a/gcc/doc/gcc/conf.py
+++ b/gcc/doc/gcc/conf.py
@@ -1,5 +1,6 @@
 # Configuration file for the Sphinx documentation builder.
 
+import os
 import sys
 sys.path.append('../../..//doc')
 
@@ -29,8 +30,14 @@ man_pages = [
     ('funding', 'fsf-funding', 'Funding Free Software', [], 7)
 ]
 
+ENABLE_LTO = os.getenv('ENABLE_LTO')
+assert ENABLE_LTO
+
+if ENABLE_LTO  == 'yes':
+    man_pages += [('lto-dump', 'lto-dump', 'Tool for dumping LTO object files', [authors], 1)]
+
 texinfo_documents = [
   ('index', 'gcc', project, authors, None, None, None, True)
 ]
 
-tags.add('gcc')
\ No newline at end of file
+tags.add('gcc')
diff --git a/gcc/fortran/Make-lang.in b/gcc/fortran/Make-lang.in
index 63195a9c7ed..686788ee868 100644
--- a/gcc/fortran/Make-lang.in
+++ b/gcc/fortran/Make-lang.in
@@ -109,16 +109,18 @@ fortran.all.cross: gfortran-cross$(exeext)
 fortran.start.encap: gfortran$(exeext)
 fortran.rest.encap:
 
-fortran.srcinfo: doc/gfortran.info
-	-cp -p $^ $(srcdir)/fortran
-
 fortran.tags: force
 	cd $(srcdir)/fortran; etags -o TAGS.sub *.c *.h; \
 	etags --include TAGS.sub --include ../TAGS.sub
 
-fortran.info: doc/gfortran.info doc/gfc-internals.info
+fortran.info: info-gfortran info-gfc-internals
 fortran.dvi: doc/gfortran.dvi doc/gfc-internals.dvi
 
+info-gfortran:
+	+ if [ x$(SPHINX_BUILD) = xsphinx-build ]; then \
+	  make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/fortran/doc/gfortran BUILDDIR=$(objdir)/doc/fortran/info; \
+	else true; fi
+
 F95_HTMLFILES = $(build_htmldir)/gfortran
 
 fortran.html: $(F95_HTMLFILES)/index.html
@@ -154,9 +156,10 @@ fortran.install-pdf: $(F95_PDFFILES)
 	  $(INSTALL_DATA) "$$d$$p" "$(DESTDIR)$(pdfdir)/gcc/$$f"; \
 	done
 
-F95_MANFILES = doc/gfortran.1
+man-fortran:
+	+ make -C $(srcdir)/../doc man SOURCEDIR=$(srcdir)/fortran/doc/gfortran BUILDDIR=$(objdir)/doc/fortran/man
 
-fortran.man: $(F95_MANFILES)
+fortran.man: man-fortran
 
 fortran.srcman: $(F95_MANFILES)
 	-cp -p $^ $(srcdir)/doc
@@ -186,13 +189,6 @@ GFORTRAN_TEXI = \
   $(srcdir)/doc/include/gcc-common.texi \
   gcc-vers.texi
 
-doc/gfortran.info: $(GFORTRAN_TEXI)
-	if [ x$(BUILD_INFO) = xinfo ]; then \
-	  rm -f doc/gfortran.info-*; \
-	  $(MAKEINFO) -I $(srcdir)/doc/include -I $(srcdir)/fortran \
-	    -o $@ $<; \
-	else true; fi
-
 doc/gfortran.dvi: $(GFORTRAN_TEXI)
 	$(TEXI2DVI) -I $(srcdir)/fortran -I $(abs_docdir)/include -o $@ $<
 
@@ -217,11 +213,9 @@ GFC_INTERNALS_TEXI = \
   $(srcdir)/doc/include/gcc-common.texi \
   gcc-vers.texi
 
-doc/gfc-internals.info: $(GFC_INTERNALS_TEXI)
-	if [ x$(BUILD_INFO) = xinfo ]; then \
-	  rm -f doc/gfc-internals.info-*; \
-	  $(MAKEINFO) -I $(srcdir)/doc/include -I $(srcdir)/fortran \
-	    -o $@ $<; \
+info-gfc-internals:
+	+ if [ x$(SPHINX_BUILD) = xsphinx-build ]; then \
+	  make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/fortran/doc/gfc-internals BUILDDIR=$(objdir)/doc/gfc-internals/info; \
 	else true; fi
 
 doc/gfc-internals.dvi: $(GFC_INTERNALS_TEXI)
@@ -256,9 +250,13 @@ fortran.install-plugin:
 
 fortran.install-info: $(DESTDIR)$(infodir)/gfortran.info
 
+$(DESTDIR)$(infodir)/gfortran.info: doc/fortran/info/texinfo/gfortran.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
 fortran.install-man: $(DESTDIR)$(man1dir)/$(GFORTRAN_INSTALL_NAME)$(man1ext)
 
-$(DESTDIR)$(man1dir)/$(GFORTRAN_INSTALL_NAME)$(man1ext): doc/gfortran.1 \
+$(DESTDIR)$(man1dir)/$(GFORTRAN_INSTALL_NAME)$(man1ext): doc/fortran/man/man/gfortran.1 \
 		installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
@@ -286,12 +284,6 @@ fortran.mostlyclean:
 fortran.clean:
 fortran.distclean:
 	-rm -f fortran/config.status fortran/Makefile
-
-fortran.extraclean:
-fortran.maintainer-clean:
-	-rm -f doc/gfortran.info* fortran/gfortran.*aux
-	-rm -f $(docobjdir)/gfortran.1
-
 #\f
 # Stage hooks:
 # The toplevel makefile has already created stage?/fortran at this point.
diff --git a/gcc/genhooks.c b/gcc/genhooks.c
index ebe0d0954e6..84635bd5c08 100644
--- a/gcc/genhooks.c
+++ b/gcc/genhooks.c
@@ -48,212 +48,74 @@ upstrdup (const char *in)
   return ret;
 }
 
-/* Struct for 'start hooks' which start a sequence of consecutive hooks
-   that are defined in target.def and to be documented in tm.texi.  */
-struct s_hook
-{
-  char *name;
-  int pos;
-};
-
-static hashval_t
-s_hook_hash (const void *p)
-{
-  const struct s_hook *s_hook = (const struct s_hook *)p;
-  return htab_hash_string (s_hook->name);
-}
+/* Emit shared .rst.in file that is used by the corresponding
+   .. include:: tm.rst.in
+     :start-after: [HOOK_NAME]
+     :end-before: [HOOK_NAME]
 
-static int
-s_hook_eq_p (const void *p1, const void *p2)
-{
-  return (strcmp (((const struct s_hook *) p1)->name, 
-		  ((const struct s_hook *) p2)->name) == 0);
-}
-
-/* Read the documentation file with name IN_FNAME, perform substitutions
-   to incorporate information from hook_array, and emit the result on stdout.
-   Hooks defined with DEFHOOK / DEFHOOKPOD are emitted at the place of a
-   matching @hook in the input file; if there is no matching @hook, the
-   hook is emitted after the hook that precedes it in target.def .
-   Usually, the emitted hook documentation starts with the hook
-   signature, followed by the string from the doc field.
-   The documentation is bracketed in @deftypefn / @deftypevr and a matching
-   @end.
-   While emitting the doc field, an @findex entry is added
-   to the affected paragraph.
    If the doc field starts with '*', the leading '*' is stripped, and the doc
    field is otherwise emitted unaltered; no function signature/
    @deftypefn/deftypevr/@end is emitted.
    In particular, a doc field of "*" means not to emit any ocumentation for
    this target.def / hook_array entry at all (there might be documentation
    for this hook in the file named IN_FNAME, though).
-   A doc field of 0 is used to append the hook signature after the previous
-   hook's signture, so that one description can be used for a group of hooks.
-   When the doc field is "", @deftypefn/@deftypevr and the hook signature
-   is emitted, but not the matching @end.  This allows all the free-form
+
+   This allows all the free-form
    documentation to be placed in IN_FNAME, to work around GPL/GFDL
    licensing incompatibility issues.  */
+
 static void
-emit_documentation (const char *in_fname)
+emit_documentation (void)
 {
-  int i, j;
-  char buf[1000];
-  htab_t start_hooks = htab_create (99, s_hook_hash, s_hook_eq_p, (htab_del) 0);
-  FILE *f;
-
-  /* Enter all the start hooks in start_hooks.  */
-  f = fopen (in_fname, "r");
-  if (!f)
-    {
-      perror ("");
-      fatal ("Couldn't open input file");
-    }
-  while (fscanf (f, "%*[^@]"), buf[0] = '\0',
-	 fscanf (f, "@%5[^ \n]", buf) != EOF)
-    {
-      void **p;
-      struct s_hook *shp;
-
-      if (strcmp (buf, "hook") != 0)
-	continue;
-      buf[0] = '\0';
-      fscanf (f, "%999s", buf);
-      shp = XNEW (struct s_hook);
-      shp->name = upstrdup (buf);
-      shp->pos = -1;
-      p = htab_find_slot (start_hooks, shp, INSERT);
-      if (*p != HTAB_EMPTY_ENTRY)
-	fatal ("Duplicate placement for hook %s\n", shp->name);
-      *(struct s_hook **) p = shp;
-    }
-  fclose (f);
   /* For each hook in hook_array, if it is a start hook, store its position.  */
-  for (i = 0; i < (int) (sizeof hook_array / sizeof hook_array[0]); i++)
+  for (int i = 0; i < (int) (sizeof hook_array / sizeof hook_array[0]); i++)
     {
-      struct s_hook sh, *shp;
-      void *p;
-
       if (!hook_array[i].doc || strcmp (hook_array[i].doc, "*") == 0)
 	continue;
-      sh.name = upstrdup (hook_array[i].name);
-      p = htab_find (start_hooks, &sh);
-      if (p)
-	{
-	  shp = (struct s_hook *) p;
-	  if (shp->pos >= 0)
-	    fatal ("Duplicate hook %s\n", sh.name);
-	  shp->pos = i;
-	}
+      const char *hook_name = upstrdup (hook_array[i].name);
+      printf ("[%s]\n", hook_name);
+      /* Print header.  Function-valued hooks have a parameter list,
+	 unlike POD-valued ones.  */
+      const char *deftype = hook_array[i].param ? "function" : "c:var";
+      printf (".. %s:: ", deftype);
+      if (strchr (hook_array[i].type, ' '))
+	printf ("%s", hook_array[i].type);
       else
-	fatal ("No place specified to document hook %s\n", sh.name);
-      free (sh.name);
-    }
-  /* Copy input file to stdout, substituting @hook directives with the
-     corresponding hook documentation sequences.  */
-  f = fopen (in_fname, "r");
-  if (!f)
-    {
-      perror ("");
-      fatal ("Couldn't open input file");
-    }
-  for (;;)
-    {
-      struct s_hook sh, *shp;
-      int c = getc (f);
-      char *name;
-
-      if (c == EOF)
-	break;
-      if (c != '@')
-	{
-	  putchar (c);
-	  continue;
-	}
-      buf[0] = '\0';
-      fscanf (f, "%5[^ \n]", buf);
-      if (strcmp (buf, "hook") != 0)
+	printf ("%s", hook_array[i].type);
+      printf (" %s", hook_name);
+      if (hook_array[i].param)
 	{
-	  printf ("@%s", buf);
-	  continue;
+	  const char *q, *e;
+	  /* Print the parameter list, with the parameter names
+	     enclosed in @var{}.  */
+	  printf (" ");
+	  for (q = hook_array[i].param; (e = strpbrk (q, " *,)"));
+	       q = e + 1)
+	    /* Type names like 'int' are followed by a space, sometimes
+	       also by '*'.  'void' should appear only in "(void)".  */
+	    if (*e == ' ' || *e == '*' || *q == '(')
+	      printf ("%.*s", (int) (e - q + 1), q);
+	    else
+	      printf ("%.*s%c", (int) (e - q), q, *e);
 	}
-      fscanf (f, "%999s", buf);
-      sh.name = name = upstrdup (buf);
-      shp = (struct s_hook *) htab_find (start_hooks, &sh);
-      if (!shp || shp->pos < 0)
-	fatal ("No documentation for hook %s\n", sh.name);
-      i = shp->pos;
-      do
+
+      printf ("\n");
+      if (hook_array[i].doc[0])
 	{
-	  const char *q, *e;
-	  const char *deftype;
 	  const char *doc, *p_end;
-
-	  /* A leading '*' means to output the documentation string without
-	     further processing.  */
-	  if (*hook_array[i].doc == '*')
-	    printf ("%s", hook_array[i].doc + 1);
-	  else
+	  printf ("\n");
+	  /* Print each documentation paragraph in turn.  */
+	  for (doc = hook_array[i].doc; *doc; doc = p_end)
 	    {
-	      if (i != shp->pos)
-		printf ("\n\n");
-
-	      /* Print header.  Function-valued hooks have a parameter list, 
-		 unlike POD-valued ones.  */
-	      deftype = hook_array[i].param ? "deftypefn" : "deftypevr";
-	      printf ("@%s {%s} ", deftype, hook_array[i].docname);
-	      if (strchr (hook_array[i].type, ' '))
-		printf ("{%s}", hook_array[i].type);
-	      else
-		printf ("%s", hook_array[i].type);
-	      printf (" %s", name);
-	      if (hook_array[i].param)
-		{
-		  /* Print the parameter list, with the parameter names
-		     enclosed in @var{}.  */
-		  printf (" ");
-		  for (q = hook_array[i].param; (e = strpbrk (q, " *,)"));
-		       q = e + 1)
-		    /* Type names like 'int' are followed by a space, sometimes
-		       also by '*'.  'void' should appear only in "(void)".  */
-		    if (*e == ' ' || *e == '*' || *q == '(')
-		      printf ("%.*s", (int) (e - q + 1), q);
-		    else
-		      printf ("@var{%.*s}%c", (int) (e - q), q, *e);
-		}
-	      /* POD-valued hooks sometimes come in groups with common
-		 documentation.*/
-	      for (j = i + 1;
-		   j < (int) (sizeof hook_array / sizeof hook_array[0])
-		   && hook_array[j].doc == 0 && hook_array[j].type; j++)
-		{
-		  char *namex = upstrdup (hook_array[j].name);
-
-		  printf ("\n@%sx {%s} {%s} %s",
-			  deftype, hook_array[j].docname,
-			  hook_array[j].type, namex);
-		}
-	      if (hook_array[i].doc[0])
-		{
-		  printf ("\n");
-		  /* Print each documentation paragraph in turn.  */
-		  for (doc = hook_array[i].doc; *doc; doc = p_end)
-		    {
-		      /* Find paragraph end.  */
-		      p_end = strstr (doc, "\n\n");
-		      p_end = (p_end ? p_end + 2 : doc + strlen (doc));
-		      printf ("%.*s", (int) (p_end - doc), doc);
-		    }
-		  printf ("\n@end %s", deftype);
-		}
+	      /* Find paragraph end.  */
+	      p_end = strstr (doc, "\n");
+	      p_end = (p_end ? p_end + 1 : doc + strlen (doc));
+	      printf ("  %.*s", (int) (p_end - doc), doc);
 	    }
-	  if (++i >= (int) (sizeof hook_array / sizeof hook_array[0])
-	      || !hook_array[i].doc)
-	    break;
-	  free (name);
-	  sh.name = name = upstrdup (hook_array[i].name);
+	  printf ("\n");
 	}
-      while (!htab_find (start_hooks, &sh));
-      free (name);
+
+      printf ("\n[%s]\n\n", hook_name);
     }
 }
 
@@ -314,8 +176,8 @@ main (int argc, char **argv)
 {
   progname = "genhooks";
 
-  if (argc >= 3)
-    emit_documentation (argv[2]);
+  if (argc == 1)
+    emit_documentation ();
   else
     emit_init_macros (argv[1]);
   return 0;


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [gcc(refs/users/marxin/heads/sphinx-v2)] Build system integration.
@ 2021-06-23 10:22 Martin Liska
  0 siblings, 0 replies; 6+ messages in thread
From: Martin Liska @ 2021-06-23 10:22 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:45e22f4503dd25a1f6cf8ebc892e94d3a0d1184a

commit 45e22f4503dd25a1f6cf8ebc892e94d3a0d1184a
Author: Martin Liska <mliska@suse.cz>
Date:   Thu Jun 17 22:08:57 2021 +0200

    Build system integration.

Diff:
---
 config/acx.m4            |   2 +-
 configure                |   1 -
 configure.ac             |   1 -
 doc/Makefile             |   3 +-
 doc/baseconf.py          |   5 +-
 gcc/Makefile.in          | 216 ++++++++++++++++++++-----------------------
 gcc/configure            |  28 +++++-
 gcc/configure.ac         |  15 +++
 gcc/cp/Make-lang.in      |   2 +-
 gcc/doc/gcc/conf.py      |   9 +-
 gcc/fortran/Make-lang.in |  42 ++++-----
 gcc/genhooks.c           | 232 ++++++++++-------------------------------------
 12 files changed, 216 insertions(+), 340 deletions(-)

diff --git a/config/acx.m4 b/config/acx.m4
index 87c1b5e2932..65a7f4bc446 100644
--- a/config/acx.m4
+++ b/config/acx.m4
@@ -615,7 +615,7 @@ AC_DEFUN([ACX_BUGURL],[
     REPORT_BUGS_TEXI=
     ;;
   *)
-    REPORT_BUGS_TO="<$BUGURL>"
+    REPORT_BUGS_TO="$BUGURL"
     REPORT_BUGS_TEXI=@uref{`echo "$BUGURL" | sed 's/@/@@/g'`}
     ;;
   esac;
diff --git a/configure b/configure
index 1224fc4039e..e58cbb65158 100755
--- a/configure
+++ b/configure
@@ -10458,7 +10458,6 @@ case " $configdirs " in
     ;;
 esac
 
-
 # Host tools.
 ncn_tool_prefix=
 test -n "$host_alias" && ncn_tool_prefix=$host_alias-
diff --git a/configure.ac b/configure.ac
index 66d637d70dc..68c209852e9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3454,7 +3454,6 @@ case " $configdirs " in
     ;;
 esac
 
-
 # Host tools.
 NCN_STRICT_CHECK_TOOLS(AR, ar)
 NCN_STRICT_CHECK_TOOLS(AS, as)
diff --git a/doc/Makefile b/doc/Makefile
index 9e305a8e7da..7f3690e7e50 100644
--- a/doc/Makefile
+++ b/doc/Makefile
@@ -3,7 +3,8 @@
 
 # You can set these variables from the command line.
 SPHINXOPTS   ?= -j auto -q
-SPHINXBUILD  ?= sphinx-build
+# FIXME
+SPHINXBUILD  ?= /tmp/venv/bin/sphinx-build
 PAPER        ?=
 SOURCEDIR     = .
 BUILDDIR      = _build
diff --git a/doc/baseconf.py b/doc/baseconf.py
index 07bf2c551c8..206328d43e5 100644
--- a/doc/baseconf.py
+++ b/doc/baseconf.py
@@ -34,8 +34,9 @@ gcc_DEVPHASE = __read_file('DEV-PHASE')
 gcc_DATESTAMP = __read_file('DATESTAMP')
 gcc_REVISION = __read_file('REVISION')
 
-VERSION_PACKAGE = os.getenv('VERSION_PACKAGE', '(GCC)')
-BUGURL = os.getenv('BUGURL', 'https://gcc.gnu.org/bugs/')
+VERSION_PACKAGE = os.getenv('VERSION_PACKAGE')
+BUGURL = os.getenv('BUGURL')
+assert VERSION_PACKAGE and BUGURL
 
 # The short X.Y version.
 version = gcc_BASEVER
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index ebf26442992..66d99c1e9f9 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -771,11 +771,8 @@ LIBCONVERT =
 # Control whether header files are installed.
 INSTALL_HEADERS=install-headers install-mkheaders
 
-# Control whether Info documentation is built and installed.
-BUILD_INFO = @BUILD_INFO@
-
-# Control whether manpages generated by texi2pod.pl can be rebuilt.
-GENERATED_MANPAGES = @GENERATED_MANPAGES@
+# Control whether manpages generated by sphinx-build can be rebuilt.
+SPHINX_BUILD = @SPHINX_BUILD@
 
 # Additional directories of header files to run fixincludes on.
 # These should be directories searched automatically by default
@@ -2579,38 +2576,20 @@ s-d-target-hooks-def-h: build/genhooks$(build_exeext)
 					     d/d-target-hooks-def.h
 	$(STAMP) s-d-target-hooks-def-h
 
-# check if someone mistakenly only changed tm.texi.
-# We use a different pathname here to avoid a circular dependency.
-s-tm-texi: $(srcdir)/doc/../doc/tm.texi
-
 # The tm.texi we want to compare against / check into svn should have
 # unix-style line endings.  To make this work on MinGW, remove \r.
 # \r is not portable to Solaris tr, therefore we have a special
 # case for ASCII.  We use \r for other encodings like EBCDIC.
-s-tm-texi: build/genhooks$(build_exeext) $(srcdir)/doc/tm.texi.in
-	$(RUN_GEN) build/genhooks$(build_exeext) -d \
-			$(srcdir)/doc/tm.texi.in > tmp-tm.texi
-	case `echo X|tr X '\101'` in \
-	  A) tr -d '\015' < tmp-tm.texi > tmp2-tm.texi ;; \
-	  *) tr -d '\r' < tmp-tm.texi > tmp2-tm.texi ;; \
-	esac
-	mv tmp2-tm.texi tmp-tm.texi
-	$(SHELL) $(srcdir)/../move-if-change tmp-tm.texi tm.texi
-	@if cmp -s $(srcdir)/doc/tm.texi tm.texi; then \
+s-tm-rst-in: build/genhooks$(build_exeext)
+	$(RUN_GEN) build/genhooks$(build_exeext) > tmp-tm.rst.in
+	$(SHELL) $(srcdir)/../move-if-change tmp-tm.rst.in tm.rst.in
+
+	@if cmp -s $(srcdir)/doc/gccint/target-macros/tm.rst.in tm.rst.in; then \
 	  $(STAMP) $@; \
-	elif test $(srcdir)/doc/tm.texi -nt $(srcdir)/doc/tm.texi.in \
-	  && ( test $(srcdir)/doc/tm.texi -nt $(srcdir)/target.def \
-	    || test $(srcdir)/doc/tm.texi -nt $(srcdir)/c-family/c-target.def \
-	    || test $(srcdir)/doc/tm.texi -nt $(srcdir)/common/common-target.def \
-	    || test $(srcdir)/doc/tm.texi -nt $(srcdir)/d/d-target.def \
-	  ); then \
-	  echo >&2 ; \
-	  echo You should edit $(srcdir)/doc/tm.texi.in rather than $(srcdir)/doc/tm.texi . >&2 ; \
-	  false; \
 	else \
 	  echo >&2 ; \
 	  echo Verify that you have permission to grant a GFDL license for all >&2 ; \
-	  echo new text in $(objdir)/tm.texi, then copy it to $(srcdir)/doc/tm.texi. >&2 ; \
+	  echo new text in $(objdir)/tm.rst.in, then copy it to $(srcdir)/doc/gccint/target-macros/tm.rst.in. >&2 ; \
 	  false; \
 	fi
 
@@ -3281,15 +3260,7 @@ install-no-fixedincludes:
 
 # Remake the info files.
 
-doc: $(BUILD_INFO) $(GENERATED_MANPAGES)
-
-INFOFILES = doc/cpp.info doc/gcc.info doc/gccint.info \
-            doc/gccinstall.info doc/cppinternals.info
-
-info: $(INFOFILES) lang.info @GENINSRC@ srcinfo lang.srcinfo
-
-srcinfo: $(INFOFILES)
-	-cp -p $^ $(srcdir)/doc
+doc: $(SPHINX_BUILD)
 
 TEXI_CPP_FILES = cpp.texi fdl.texi cppenv.texi cppopts.texi		\
 	 gcc-common.texi gcc-vers.texi
@@ -3336,28 +3307,6 @@ gcc-vers.texi: $(BASEVER) $(DEVPHASE)
 	mv -f $@T $@
 
 
-# The *.1, *.7, *.info, *.dvi, and *.pdf files are being generated from implicit
-# patterns.  To use them, put each of the specific targets with its
-# specific dependencies but no build commands.
-
-doc/cpp.info: $(TEXI_CPP_FILES)
-doc/gcc.info: $(TEXI_GCC_FILES)
-doc/gccint.info: $(TEXI_GCCINT_FILES)
-doc/cppinternals.info: $(TEXI_CPPINT_FILES)
-
-doc/%.info: %.texi
-	if [ x$(BUILD_INFO) = xinfo ]; then \
-		$(MAKEINFO) $(MAKEINFOFLAGS) -I . -I $(gcc_docdir) \
-			-I $(gcc_docdir)/include -o $@ $<; \
-	fi
-
-# Duplicate entry to handle renaming of gccinstall.info
-doc/gccinstall.info: $(TEXI_GCCINSTALL_FILES)
-	if [ x$(BUILD_INFO) = xinfo ]; then \
-		$(MAKEINFO) $(MAKEINFOFLAGS) -I $(gcc_docdir) \
-			-I $(gcc_docdir)/include -o $@ $<; \
-	fi
-
 doc/cpp.dvi: $(TEXI_CPP_FILES)
 doc/gcc.dvi: $(TEXI_GCC_FILES)
 doc/gccint.dvi: $(TEXI_GCCINT_FILES)
@@ -3422,51 +3371,43 @@ $(build_htmldir)/gccinstall/index.html: $(TEXI_GCCINSTALL_FILES)
 	DESTDIR=$(@D) \
 	$(SHELL) $(srcdir)/doc/install.texi2html
 
-MANFILES = doc/gcov.1 doc/cpp.1 doc/gcc.1 doc/gfdl.7 doc/gpl.7 \
-           doc/fsf-funding.7 doc/gcov-tool.1 doc/gcov-dump.1 \
 	   $(if $(filter yes,@enable_lto@),doc/lto-dump.1)
 
-generated-manpages: man
+export VERSION_PACKAGE="$(PKGVERSION)"
+export ENABLE_LTO=$(enable_lto)
+export BUGURL="$(BUGURL_s)"
 
-man: $(MANFILES) lang.man @GENINSRC@ srcman lang.srcman
+man: man-gcc man-cpp lang.man @GENINSRC@
 
-srcman: $(MANFILES)
-	-cp -p $^ $(srcdir)/doc
+info: info-gcc info-gccint info-cpp info-cppinternals info-install lang.info @GENINSRC@
 
-doc/%.1: %.pod
-	$(STAMP) $@
-	-($(POD2MAN) --section=1 $< > $(@).T$$$$ && \
-		mv -f $(@).T$$$$ $@) || \
-		(rm -f $(@).T$$$$ && exit 1)
+sphinx-build: man info
 
-doc/%.7: %.pod
-	$(STAMP) $@
-	-($(POD2MAN) --section=7 $< > $(@).T$$$$ && \
-		mv -f $(@).T$$$$ $@) || \
-		(rm -f $(@).T$$$$ && exit 1)
+man-gcc: doc/gcc/man/man/gcc.1
 
-%.pod: %.texi
-	$(STAMP) $@
-	-$(TEXI2POD) -DBUGURL="$(BUGURL_TEXI)" $< > $@
+doc/gcc/man/man/gcc.1:
+	+ make -C $(srcdir)/../doc man SOURCEDIR=$(srcdir)/doc/gcc BUILDDIR=$(objdir)/doc/gcc/man
 
-.INTERMEDIATE: cpp.pod gcc.pod gfdl.pod fsf-funding.pod gpl.pod
-cpp.pod: cpp.texi cppenv.texi cppopts.texi
+man-cpp:
+	+ make -C $(srcdir)/../doc man SOURCEDIR=$(srcdir)/doc/cpp BUILDDIR=$(objdir)/doc/cpp/man
 
-# These next rules exist because the output name is not the same as
-# the input name, so our implicit %.pod rule will not work.
+info-gcc:
+	+ make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/doc/gcc BUILDDIR=$(objdir)/doc/gcc/info
 
-gcc.pod: invoke.texi cppenv.texi cppopts.texi gcc-vers.texi
-	$(STAMP) $@
-	-$(TEXI2POD) $< > $@
-gfdl.pod: fdl.texi
-	$(STAMP) $@
-	-$(TEXI2POD) $< > $@
-fsf-funding.pod: funding.texi
-	$(STAMP) $@
-	-$(TEXI2POD) $< > $@
-gpl.pod: gpl_v3.texi
-	$(STAMP) $@
-	-$(TEXI2POD) $< > $@
+info-gccint: s-tm-rst-in
+	+ make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/doc/gccint BUILDDIR=$(objdir)/doc/gccint/info
+
+info-cpp:
+	+ make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/doc/cpp BUILDDIR=$(objdir)/doc/cpp/info
+
+info-cppinternals:
+	+ make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/doc/cppinternals BUILDDIR=$(objdir)/doc/cppinternals/info
+
+info-install:
+	+ make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/doc/install BUILDDIR=$(objdir)/doc/install/info
+
+html-gccint: s-tm-rst-in
+	+ make -C $(srcdir)/../doc html SOURCEDIR=$(srcdir)/doc/gccint BUILDDIR=$(objdir)/doc/gccint/html
 
 #\f
 # Deletion of files made during compilation.
@@ -3526,8 +3467,7 @@ clean: mostlyclean lang.clean
 	-rm -f config.h tconfig.h bconfig.h tm_p.h tm.h
 	-rm -f options.c options.h optionlist
 	-rm -f cs-*
-	-rm -f doc/*.dvi
-	-rm -f doc/*.pdf
+	-rm -rf doc
 # Delete the include directories.
 	-rm -rf include include-fixed
 # Delete files used by the "multilib" facility (including libgcc subdirs).
@@ -3568,7 +3508,7 @@ maintainer-clean:
 	$(MAKE) lang.maintainer-clean distclean
 	-rm -f cpp.??s cpp.*aux
 	-rm -f gcc.??s gcc.*aux
-	-rm -f $(gcc_docdir)/*.info $(gcc_docdir)/*.1 $(gcc_docdir)/*.7 $(gcc_docdir)/*.dvi $(gcc_docdir)/*.pdf
+	-rm -rf doc
 #\f
 # Entry points `install', `install-strip', and `uninstall'.
 # Also use `install-collect2' to install collect2 when the config files don't.
@@ -3765,24 +3705,46 @@ install-info:: doc installdirs \
 	$(DESTDIR)$(infodir)/cpp.info \
 	$(DESTDIR)$(infodir)/gcc.info \
 	$(DESTDIR)$(infodir)/cppinternals.info \
-	$(DESTDIR)$(infodir)/gccinstall.info \
+	$(DESTDIR)$(infodir)/install.info \
 	$(DESTDIR)$(infodir)/gccint.info \
 	lang.install-info
 
-$(DESTDIR)$(infodir)/%.info: doc/%.info installdirs
-	rm -f $@
-	if [ -f $< ]; then \
-	  for f in $(<)*; do \
-	    realfile=`echo $$f | sed -e 's|.*/\([^/]*\)$$|\1|'`; \
-	    $(INSTALL_DATA) $$f $(DESTDIR)$(infodir)/$$realfile; \
-	    chmod a-x $(DESTDIR)$(infodir)/$$realfile; \
-	  done; \
-	else true; fi
-	-if $(SHELL) -c 'install-info --version' >/dev/null 2>&1; then \
-	  if [ -f $@ ]; then \
-	    install-info --dir-file=$(DESTDIR)$(infodir)/dir $@; \
-	  else true; fi; \
-	else true; fi;
+$(DESTDIR)$(infodir)/gcc.info: doc/gcc/info/texinfo/gcc.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/gccint.info: doc/gccint/info/texinfo/gccint.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/install.info: doc/install/info/texinfo/install.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/cpp.info: doc/cpp/info/texinfo/cpp.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/cppinternals.info: doc/cppinternals/info/texinfo/cppinternals.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/gcov.info: doc/gcc/info/texinfo/gcov.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/gcov-tool.info: doc/gcc/info/texinfo/gcov-tool.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/gcov-dump.info: doc/gcc/info/texinfo/gcov-dump.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
+$(DESTDIR)$(infodir)/lto-dump.info: doc/gcc/info/texinfo/lto-dump.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
 
 pdf__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
 
@@ -3832,36 +3794,52 @@ $(DESTDIR)$(man7dir)/%$(man7ext): doc/%.7 installdirs
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
-$(DESTDIR)$(man1dir)/$(GCC_INSTALL_NAME)$(man1ext): doc/gcc.1 installdirs
+$(DESTDIR)$(man1dir)/$(GCC_INSTALL_NAME)$(man1ext): doc/gcc/man/man/gcc.1 installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
-$(DESTDIR)$(man1dir)/$(CPP_INSTALL_NAME)$(man1ext): doc/cpp.1 installdirs
+$(DESTDIR)$(man1dir)/$(CPP_INSTALL_NAME)$(man1ext): doc/cpp/man/man/cpp.1 installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
-$(DESTDIR)$(man1dir)/$(GCOV_INSTALL_NAME)$(man1ext): doc/gcov.1 installdirs
+$(DESTDIR)$(man1dir)/$(GCOV_INSTALL_NAME)$(man1ext): doc/gcc/man/man/gcov.1 installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
-$(DESTDIR)$(man1dir)/$(GCOV_TOOL_INSTALL_NAME)$(man1ext): doc/gcov-tool.1 installdirs
+$(DESTDIR)$(man1dir)/$(GCOV_TOOL_INSTALL_NAME)$(man1ext): doc/gcc/man/man/gcov-tool.1 installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
-$(DESTDIR)$(man1dir)/$(GCOV_DUMP_INSTALL_NAME)$(man1ext): doc/gcov-dump.1 installdirs
+$(DESTDIR)$(man1dir)/$(GCOV_DUMP_INSTALL_NAME)$(man1ext): doc/gcc/man/man/gcov-dump.1 installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
-$(DESTDIR)$(man1dir)/$(LTO_DUMP_INSTALL_NAME)$(man1ext): doc/lto-dump.1 installdirs
+$(DESTDIR)$(man1dir)/$(LTO_DUMP_INSTALL_NAME)$(man1ext): doc/gcc/man/man/lto-dump.1 installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
+$(DESTDIR)$(man7dir)/fsf-funding$(man7ext): doc/gcc/man/man/fsf-funding.7 installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+	-chmod a-x $@
+
+$(DESTDIR)$(man7dir)/gfdl$(man7ext): doc/gcc/man/man/gfdl.7 installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+	-chmod a-x $@
+
+$(DESTDIR)$(man7dir)/gpl$(man7ext): doc/gcc/man/man/gpl.7 installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+	-chmod a-x $@
+
+
 # Install all the header files built in the include subdirectory.
 install-headers: $(INSTALL_HEADERS_DIR)
 # Fix symlinks to absolute paths in the installed include directory to
diff --git a/gcc/configure b/gcc/configure
index dd0194a57f4..b7274875b84 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -806,6 +806,7 @@ AR
 NM
 BISON
 FLEX
+SPHINX_BUILD
 GENERATED_MANPAGES
 BUILD_INFO
 MAKEINFO
@@ -7905,7 +7906,7 @@ fi
     REPORT_BUGS_TEXI=
     ;;
   *)
-    REPORT_BUGS_TO="<$BUGURL>"
+    REPORT_BUGS_TO="$BUGURL"
     REPORT_BUGS_TEXI=@uref{`echo "$BUGURL" | sed 's/@/@@/g'`}
     ;;
   esac;
@@ -8557,6 +8558,27 @@ $as_echo "no" >&6; }
 fi
 
 
+# See if sphinx-build has been installed and is modern enough
+# that we can use it.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for sphinx-build" >&5
+$as_echo_n "checking for sphinx-build... " >&6; }
+if sphinx-build -j auto -h &>/dev/null ; then
+  SPHINX_BUILD=sphinx-build
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING:
+  *** sphinx-build is missing or too old.
+  *** Info and man pages documentation will not be built." >&5
+$as_echo "$as_me: WARNING:
+  *** sphinx-build is missing or too old.
+  *** Info and man pages documentation will not be built." >&2;}
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+  SPHINX_BUILD=
+fi
+
+
 MISSING="${CONFIG_SHELL-/bin/sh} $ac_aux_dir/missing"
 
 # How about lex?
@@ -19435,7 +19457,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 19438 "configure"
+#line 19460 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -19541,7 +19563,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 19544 "configure"
+#line 19566 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 5f30f80833e..cecdd339862 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -1208,6 +1208,21 @@ else
 fi
 AC_SUBST(GENERATED_MANPAGES)
 
+# See if sphinx-build has been installed and is modern enough
+# that we can use it.
+AC_MSG_CHECKING([for sphinx-build])
+if sphinx-build -j auto -h &>/dev/null ; then
+  SPHINX_BUILD=sphinx-build
+  AC_MSG_RESULT(yes)
+else
+  AC_MSG_WARN([
+  *** sphinx-build is missing or too old.
+  *** Info and man pages documentation will not be built.])
+  AC_MSG_RESULT(no)
+  SPHINX_BUILD=
+fi
+AC_SUBST(SPHINX_BUILD)
+
 MISSING="${CONFIG_SHELL-/bin/sh} $ac_aux_dir/missing"
 
 # How about lex?
diff --git a/gcc/cp/Make-lang.in b/gcc/cp/Make-lang.in
index 155be74efdb..6e49e3117db 100644
--- a/gcc/cp/Make-lang.in
+++ b/gcc/cp/Make-lang.in
@@ -260,7 +260,7 @@ c++.install-common: installdirs
 
 # We can't use links because not everyone supports them.  So just copy the
 # manpage.
-doc/g++.1: doc/gcc.1
+doc/g++.1: doc/gcc/man/man/gcc.1
 	cp $< doc/g++.1
 
 c++.install-man: $(DESTDIR)$(man1dir)/$(GXX_INSTALL_NAME)$(man1ext)
diff --git a/gcc/doc/gcc/conf.py b/gcc/doc/gcc/conf.py
index d6d69de24f8..ac1bc73ca78 100644
--- a/gcc/doc/gcc/conf.py
+++ b/gcc/doc/gcc/conf.py
@@ -1,5 +1,6 @@
 # Configuration file for the Sphinx documentation builder.
 
+import os
 import sys
 sys.path.append('../../..//doc')
 
@@ -29,8 +30,14 @@ man_pages = [
     ('funding', 'fsf-funding', 'Funding Free Software', [], 7)
 ]
 
+ENABLE_LTO = os.getenv('ENABLE_LTO')
+assert ENABLE_LTO
+
+if ENABLE_LTO  == 'yes':
+    man_pages += [('lto-dump', 'lto-dump', 'Tool for dumping LTO object files', [authors], 1)]
+
 texinfo_documents = [
   ('index', 'gcc', project, authors, None, None, None, True)
 ]
 
-tags.add('gcc')
\ No newline at end of file
+tags.add('gcc')
diff --git a/gcc/fortran/Make-lang.in b/gcc/fortran/Make-lang.in
index 63195a9c7ed..686788ee868 100644
--- a/gcc/fortran/Make-lang.in
+++ b/gcc/fortran/Make-lang.in
@@ -109,16 +109,18 @@ fortran.all.cross: gfortran-cross$(exeext)
 fortran.start.encap: gfortran$(exeext)
 fortran.rest.encap:
 
-fortran.srcinfo: doc/gfortran.info
-	-cp -p $^ $(srcdir)/fortran
-
 fortran.tags: force
 	cd $(srcdir)/fortran; etags -o TAGS.sub *.c *.h; \
 	etags --include TAGS.sub --include ../TAGS.sub
 
-fortran.info: doc/gfortran.info doc/gfc-internals.info
+fortran.info: info-gfortran info-gfc-internals
 fortran.dvi: doc/gfortran.dvi doc/gfc-internals.dvi
 
+info-gfortran:
+	+ if [ x$(SPHINX_BUILD) = xsphinx-build ]; then \
+	  make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/fortran/doc/gfortran BUILDDIR=$(objdir)/doc/fortran/info; \
+	else true; fi
+
 F95_HTMLFILES = $(build_htmldir)/gfortran
 
 fortran.html: $(F95_HTMLFILES)/index.html
@@ -154,9 +156,10 @@ fortran.install-pdf: $(F95_PDFFILES)
 	  $(INSTALL_DATA) "$$d$$p" "$(DESTDIR)$(pdfdir)/gcc/$$f"; \
 	done
 
-F95_MANFILES = doc/gfortran.1
+man-fortran:
+	+ make -C $(srcdir)/../doc man SOURCEDIR=$(srcdir)/fortran/doc/gfortran BUILDDIR=$(objdir)/doc/fortran/man
 
-fortran.man: $(F95_MANFILES)
+fortran.man: man-fortran
 
 fortran.srcman: $(F95_MANFILES)
 	-cp -p $^ $(srcdir)/doc
@@ -186,13 +189,6 @@ GFORTRAN_TEXI = \
   $(srcdir)/doc/include/gcc-common.texi \
   gcc-vers.texi
 
-doc/gfortran.info: $(GFORTRAN_TEXI)
-	if [ x$(BUILD_INFO) = xinfo ]; then \
-	  rm -f doc/gfortran.info-*; \
-	  $(MAKEINFO) -I $(srcdir)/doc/include -I $(srcdir)/fortran \
-	    -o $@ $<; \
-	else true; fi
-
 doc/gfortran.dvi: $(GFORTRAN_TEXI)
 	$(TEXI2DVI) -I $(srcdir)/fortran -I $(abs_docdir)/include -o $@ $<
 
@@ -217,11 +213,9 @@ GFC_INTERNALS_TEXI = \
   $(srcdir)/doc/include/gcc-common.texi \
   gcc-vers.texi
 
-doc/gfc-internals.info: $(GFC_INTERNALS_TEXI)
-	if [ x$(BUILD_INFO) = xinfo ]; then \
-	  rm -f doc/gfc-internals.info-*; \
-	  $(MAKEINFO) -I $(srcdir)/doc/include -I $(srcdir)/fortran \
-	    -o $@ $<; \
+info-gfc-internals:
+	+ if [ x$(SPHINX_BUILD) = xsphinx-build ]; then \
+	  make -C $(srcdir)/../doc info SOURCEDIR=$(srcdir)/fortran/doc/gfc-internals BUILDDIR=$(objdir)/doc/gfc-internals/info; \
 	else true; fi
 
 doc/gfc-internals.dvi: $(GFC_INTERNALS_TEXI)
@@ -256,9 +250,13 @@ fortran.install-plugin:
 
 fortran.install-info: $(DESTDIR)$(infodir)/gfortran.info
 
+$(DESTDIR)$(infodir)/gfortran.info: doc/fortran/info/texinfo/gfortran.info installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+
 fortran.install-man: $(DESTDIR)$(man1dir)/$(GFORTRAN_INSTALL_NAME)$(man1ext)
 
-$(DESTDIR)$(man1dir)/$(GFORTRAN_INSTALL_NAME)$(man1ext): doc/gfortran.1 \
+$(DESTDIR)$(man1dir)/$(GFORTRAN_INSTALL_NAME)$(man1ext): doc/fortran/man/man/gfortran.1 \
 		installdirs
 	-rm -f $@
 	-$(INSTALL_DATA) $< $@
@@ -286,12 +284,6 @@ fortran.mostlyclean:
 fortran.clean:
 fortran.distclean:
 	-rm -f fortran/config.status fortran/Makefile
-
-fortran.extraclean:
-fortran.maintainer-clean:
-	-rm -f doc/gfortran.info* fortran/gfortran.*aux
-	-rm -f $(docobjdir)/gfortran.1
-
 #\f
 # Stage hooks:
 # The toplevel makefile has already created stage?/fortran at this point.
diff --git a/gcc/genhooks.c b/gcc/genhooks.c
index ebe0d0954e6..84635bd5c08 100644
--- a/gcc/genhooks.c
+++ b/gcc/genhooks.c
@@ -48,212 +48,74 @@ upstrdup (const char *in)
   return ret;
 }
 
-/* Struct for 'start hooks' which start a sequence of consecutive hooks
-   that are defined in target.def and to be documented in tm.texi.  */
-struct s_hook
-{
-  char *name;
-  int pos;
-};
-
-static hashval_t
-s_hook_hash (const void *p)
-{
-  const struct s_hook *s_hook = (const struct s_hook *)p;
-  return htab_hash_string (s_hook->name);
-}
+/* Emit shared .rst.in file that is used by the corresponding
+   .. include:: tm.rst.in
+     :start-after: [HOOK_NAME]
+     :end-before: [HOOK_NAME]
 
-static int
-s_hook_eq_p (const void *p1, const void *p2)
-{
-  return (strcmp (((const struct s_hook *) p1)->name, 
-		  ((const struct s_hook *) p2)->name) == 0);
-}
-
-/* Read the documentation file with name IN_FNAME, perform substitutions
-   to incorporate information from hook_array, and emit the result on stdout.
-   Hooks defined with DEFHOOK / DEFHOOKPOD are emitted at the place of a
-   matching @hook in the input file; if there is no matching @hook, the
-   hook is emitted after the hook that precedes it in target.def .
-   Usually, the emitted hook documentation starts with the hook
-   signature, followed by the string from the doc field.
-   The documentation is bracketed in @deftypefn / @deftypevr and a matching
-   @end.
-   While emitting the doc field, an @findex entry is added
-   to the affected paragraph.
    If the doc field starts with '*', the leading '*' is stripped, and the doc
    field is otherwise emitted unaltered; no function signature/
    @deftypefn/deftypevr/@end is emitted.
    In particular, a doc field of "*" means not to emit any ocumentation for
    this target.def / hook_array entry at all (there might be documentation
    for this hook in the file named IN_FNAME, though).
-   A doc field of 0 is used to append the hook signature after the previous
-   hook's signture, so that one description can be used for a group of hooks.
-   When the doc field is "", @deftypefn/@deftypevr and the hook signature
-   is emitted, but not the matching @end.  This allows all the free-form
+
+   This allows all the free-form
    documentation to be placed in IN_FNAME, to work around GPL/GFDL
    licensing incompatibility issues.  */
+
 static void
-emit_documentation (const char *in_fname)
+emit_documentation (void)
 {
-  int i, j;
-  char buf[1000];
-  htab_t start_hooks = htab_create (99, s_hook_hash, s_hook_eq_p, (htab_del) 0);
-  FILE *f;
-
-  /* Enter all the start hooks in start_hooks.  */
-  f = fopen (in_fname, "r");
-  if (!f)
-    {
-      perror ("");
-      fatal ("Couldn't open input file");
-    }
-  while (fscanf (f, "%*[^@]"), buf[0] = '\0',
-	 fscanf (f, "@%5[^ \n]", buf) != EOF)
-    {
-      void **p;
-      struct s_hook *shp;
-
-      if (strcmp (buf, "hook") != 0)
-	continue;
-      buf[0] = '\0';
-      fscanf (f, "%999s", buf);
-      shp = XNEW (struct s_hook);
-      shp->name = upstrdup (buf);
-      shp->pos = -1;
-      p = htab_find_slot (start_hooks, shp, INSERT);
-      if (*p != HTAB_EMPTY_ENTRY)
-	fatal ("Duplicate placement for hook %s\n", shp->name);
-      *(struct s_hook **) p = shp;
-    }
-  fclose (f);
   /* For each hook in hook_array, if it is a start hook, store its position.  */
-  for (i = 0; i < (int) (sizeof hook_array / sizeof hook_array[0]); i++)
+  for (int i = 0; i < (int) (sizeof hook_array / sizeof hook_array[0]); i++)
     {
-      struct s_hook sh, *shp;
-      void *p;
-
       if (!hook_array[i].doc || strcmp (hook_array[i].doc, "*") == 0)
 	continue;
-      sh.name = upstrdup (hook_array[i].name);
-      p = htab_find (start_hooks, &sh);
-      if (p)
-	{
-	  shp = (struct s_hook *) p;
-	  if (shp->pos >= 0)
-	    fatal ("Duplicate hook %s\n", sh.name);
-	  shp->pos = i;
-	}
+      const char *hook_name = upstrdup (hook_array[i].name);
+      printf ("[%s]\n", hook_name);
+      /* Print header.  Function-valued hooks have a parameter list,
+	 unlike POD-valued ones.  */
+      const char *deftype = hook_array[i].param ? "function" : "c:var";
+      printf (".. %s:: ", deftype);
+      if (strchr (hook_array[i].type, ' '))
+	printf ("%s", hook_array[i].type);
       else
-	fatal ("No place specified to document hook %s\n", sh.name);
-      free (sh.name);
-    }
-  /* Copy input file to stdout, substituting @hook directives with the
-     corresponding hook documentation sequences.  */
-  f = fopen (in_fname, "r");
-  if (!f)
-    {
-      perror ("");
-      fatal ("Couldn't open input file");
-    }
-  for (;;)
-    {
-      struct s_hook sh, *shp;
-      int c = getc (f);
-      char *name;
-
-      if (c == EOF)
-	break;
-      if (c != '@')
-	{
-	  putchar (c);
-	  continue;
-	}
-      buf[0] = '\0';
-      fscanf (f, "%5[^ \n]", buf);
-      if (strcmp (buf, "hook") != 0)
+	printf ("%s", hook_array[i].type);
+      printf (" %s", hook_name);
+      if (hook_array[i].param)
 	{
-	  printf ("@%s", buf);
-	  continue;
+	  const char *q, *e;
+	  /* Print the parameter list, with the parameter names
+	     enclosed in @var{}.  */
+	  printf (" ");
+	  for (q = hook_array[i].param; (e = strpbrk (q, " *,)"));
+	       q = e + 1)
+	    /* Type names like 'int' are followed by a space, sometimes
+	       also by '*'.  'void' should appear only in "(void)".  */
+	    if (*e == ' ' || *e == '*' || *q == '(')
+	      printf ("%.*s", (int) (e - q + 1), q);
+	    else
+	      printf ("%.*s%c", (int) (e - q), q, *e);
 	}
-      fscanf (f, "%999s", buf);
-      sh.name = name = upstrdup (buf);
-      shp = (struct s_hook *) htab_find (start_hooks, &sh);
-      if (!shp || shp->pos < 0)
-	fatal ("No documentation for hook %s\n", sh.name);
-      i = shp->pos;
-      do
+
+      printf ("\n");
+      if (hook_array[i].doc[0])
 	{
-	  const char *q, *e;
-	  const char *deftype;
 	  const char *doc, *p_end;
-
-	  /* A leading '*' means to output the documentation string without
-	     further processing.  */
-	  if (*hook_array[i].doc == '*')
-	    printf ("%s", hook_array[i].doc + 1);
-	  else
+	  printf ("\n");
+	  /* Print each documentation paragraph in turn.  */
+	  for (doc = hook_array[i].doc; *doc; doc = p_end)
 	    {
-	      if (i != shp->pos)
-		printf ("\n\n");
-
-	      /* Print header.  Function-valued hooks have a parameter list, 
-		 unlike POD-valued ones.  */
-	      deftype = hook_array[i].param ? "deftypefn" : "deftypevr";
-	      printf ("@%s {%s} ", deftype, hook_array[i].docname);
-	      if (strchr (hook_array[i].type, ' '))
-		printf ("{%s}", hook_array[i].type);
-	      else
-		printf ("%s", hook_array[i].type);
-	      printf (" %s", name);
-	      if (hook_array[i].param)
-		{
-		  /* Print the parameter list, with the parameter names
-		     enclosed in @var{}.  */
-		  printf (" ");
-		  for (q = hook_array[i].param; (e = strpbrk (q, " *,)"));
-		       q = e + 1)
-		    /* Type names like 'int' are followed by a space, sometimes
-		       also by '*'.  'void' should appear only in "(void)".  */
-		    if (*e == ' ' || *e == '*' || *q == '(')
-		      printf ("%.*s", (int) (e - q + 1), q);
-		    else
-		      printf ("@var{%.*s}%c", (int) (e - q), q, *e);
-		}
-	      /* POD-valued hooks sometimes come in groups with common
-		 documentation.*/
-	      for (j = i + 1;
-		   j < (int) (sizeof hook_array / sizeof hook_array[0])
-		   && hook_array[j].doc == 0 && hook_array[j].type; j++)
-		{
-		  char *namex = upstrdup (hook_array[j].name);
-
-		  printf ("\n@%sx {%s} {%s} %s",
-			  deftype, hook_array[j].docname,
-			  hook_array[j].type, namex);
-		}
-	      if (hook_array[i].doc[0])
-		{
-		  printf ("\n");
-		  /* Print each documentation paragraph in turn.  */
-		  for (doc = hook_array[i].doc; *doc; doc = p_end)
-		    {
-		      /* Find paragraph end.  */
-		      p_end = strstr (doc, "\n\n");
-		      p_end = (p_end ? p_end + 2 : doc + strlen (doc));
-		      printf ("%.*s", (int) (p_end - doc), doc);
-		    }
-		  printf ("\n@end %s", deftype);
-		}
+	      /* Find paragraph end.  */
+	      p_end = strstr (doc, "\n");
+	      p_end = (p_end ? p_end + 1 : doc + strlen (doc));
+	      printf ("  %.*s", (int) (p_end - doc), doc);
 	    }
-	  if (++i >= (int) (sizeof hook_array / sizeof hook_array[0])
-	      || !hook_array[i].doc)
-	    break;
-	  free (name);
-	  sh.name = name = upstrdup (hook_array[i].name);
+	  printf ("\n");
 	}
-      while (!htab_find (start_hooks, &sh));
-      free (name);
+
+      printf ("\n[%s]\n\n", hook_name);
     }
 }
 
@@ -314,8 +176,8 @@ main (int argc, char **argv)
 {
   progname = "genhooks";
 
-  if (argc >= 3)
-    emit_documentation (argv[2]);
+  if (argc == 1)
+    emit_documentation ();
   else
     emit_init_macros (argv[1]);
   return 0;


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-06-24 14:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-24 14:06 [gcc(refs/users/marxin/heads/sphinx-v2)] Build system integration Martin Liska
  -- strict thread matches above, loose matches on Subject: below --
2021-06-23 11:51 Martin Liska
2021-06-23 11:27 Martin Liska
2021-06-23 11:24 Martin Liska
2021-06-23 10:24 Martin Liska
2021-06-23 10:22 Martin Liska

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).