[nautilus-actions] NACT manuals: makefile rewriting



commit fb5e9956f93910456fd513fd84feb372f068aed8
Author: Pierre Wieser <pwieser trychlos org>
Date:   Wed Jan 25 22:02:56 2012 +0100

    NACT manuals: makefile rewriting
    
    Install and distribute even if manuals have not just been built.
    Fix a second part of #668181.

 ChangeLog               |   10 +-
 docs/nact/Makefile.am   |  407 +++++++++++++++++++++++++---------------------
 m4/na-enable-manuals.m4 |    2 -
 3 files changed, 229 insertions(+), 190 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 4eb29f5..83691af 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,10 +1,16 @@
 2012-01-25 Pierre Wieser <pwieser trychlos org>
 
-	* run-distcheck.sh: Deletes the rest part of an aborded build.
+	* m4/na-enable-manuals.m4: Remove ENABLE_MANUALS conditional.
+
+	* docs/nact/Makefile.am: Another rewriting.
+	Install and distribute manuals even if not just built.
+	Fix part of #668181.
+
+	* run-distcheck.sh: Deletes the remaining part of an aborded build.
 
 2012-01-23 Pierre Wieser <pwieser trychlos org>
 
-	* run-autogen.sh: Deletes the rest part of an aborded build.
+	* run-autogen.sh: Deletes the remaining part of an aborded build.
 
 2012-01-22 Pierre Wieser <pwieser trychlos org>
 
diff --git a/docs/nact/Makefile.am b/docs/nact/Makefile.am
index d03f239..741dcc6 100644
--- a/docs/nact/Makefile.am
+++ b/docs/nact/Makefile.am
@@ -29,33 +29,29 @@
 # from Migrating your documentation to gnome-doc-utils
 # http://live.gnome.org/GnomeDocUtilsMigrationHowTo
 #
-# This produces the Nautilus-Actions Configuration Tool (NACT) Users's Manual.
-# As a user's manual, it may be translated.
-# Default is to produce DocBook XML documents, suitable for Yelp, the
-# Gnome help system.
+# The gnome-doc-utils packages produces the Nautilus-Actions Configuration
+# Tool (NACT) Users's Manual as DocBook XML documents, suitable for Yelp,
+# the Gnome help system.
 #
 # --enable-html-manuals (resp. --enable-pdf-manuals) are configure options
 # which produce HTML (resp. PDF) formats. These options are always enabled
 # when making distcheck, so that all output formats for all known locales
 # are always included in the distributed tarball.
 #
-# Note that gnome-doc-tool generates and distributes the translated xml
-# files in docs/nact/<lang>/. When installing, g-d-t installs these help
-# files in <datadir>/gnome/help/nautilus-actions-config-tool/<lang>.
-# At install time, missing tranlated images are replace with symlinks to
+# At install time, gnome-doc-utils installs these help files
+# in <datadir>/gnome/help/nautilus-actions-config-tool/<lang>.
+# Missing tranlated images are replaced with symlinks to
 # ../../C/figures/<image.png>.
 #
-# Also, do not confuse gnome-doc-utils which targets the help documentation
+# Do not confuse gnome-doc-utils which targets the help documentation
 # of the Gnome (i.e. gui) applications, and that we are using here to
 # generate html and pdf NACT user's manuals, with gtk-doc which rather
 # targets the developer documentation (see docs/reference).
 #
-# Note 1. Do not use the $(NULL) syntax here as this may prevent Damned-Lies
+# Do not use the $(NULL) syntax here as this may prevent Damned-Lies
 # to correctly generate POT files (cf. mail of Claude Paroz 2010-08-29
 # http://mail.gnome.org/archives/gnome-i18n/2010-August/msg00229.html).
 
-if ENABLE_MANUALS
-
 include $(top_srcdir)/gnome-doc-utils.make
 
 DOC_MODULE = nautilus-actions-config-tool
@@ -85,17 +81,14 @@ opt_verbose =
 
 all-local: all-manuals all-html-manuals all-pdf-manuals
 
-.PHONY: all-manuals
 all-manuals: all-html-manuals all-pdf-manuals
 
 install-data-local: install-manuals
 
-.PHONY: install-manuals
 install-manuals: install-html-manuals install-pdf-manuals
 
 uninstall-local: uninstall-manuals
 
-.PHONY: uninstall-manuals
 uninstall-manuals: uninstall-html-manuals uninstall-pdf-manuals
 
 # doc-dist-hook is the dist hook from gnome-doc-utils.make
@@ -104,225 +97,254 @@ uninstall-manuals: uninstall-html-manuals uninstall-pdf-manuals
 # the distributed .omf.in file
 dist-hook: doc-dist-hook dist-manuals-hook
 
-.PHONY: dist-manuals-hook
 dist-manuals-hook: dist-html-manuals-hook dist-pdf-manuals-hook
 
-# Build HTML manuals as $(srcdir)/<lang>/<module>.html
+# Build HTML manuals as $(builddir)/<lang>/<module>.html
 #
 # We have two alternative for generating HTML manual:
 # - gnome-doc-tool (from gnome-doc-utils package)
 # - db2html (from docbook-utils package)
-# The actual tool to be used may be specified as an argument of 
+# The actual tool to be used may be specified as an argument of
 # --enable-html-manuals configure option. It defaults to gnome-doc-tool.
 #
 # gnome-doc-tool <format> -o <dir> -d0 nautilus-actions-config-tool.xml
 # - format: output format (html)
 # - dir: output directory
 # -d0: nochunks
+#
 # The produced output is very close of what Yelp gives, with in particular
 # a summary in each chapter while db2html does not produce it.
+#
 # As of v 0.20.1:
-# - there is no icon for notes and tips (see #636175).
 # - does not produce the legal and abstract sections in top of the document
 # - does not honor external links: they are converted to simple links
 #   which target the same frame window.
+# - embeds references to 'admon-xxx' images (which are the equivalent
+#   of db2html's 'stylesheet-images' ones), but does not provide them
+#   (see https://bugzilla.gnome.org/show_bug.cgi?id=636175)
+#   and so we 'manually' copy them as a "admon/" subdirectory
+#   the same way db2html does
+# - does not honor the base directory of the source document, only
+#   searching for extern entities in the current working directory
+#   (see https://bugzilla.gnome.org/show_bug.cgi?id=664784)
+#
 # gnome-doc-tool is so our preferred tool for its proximity with Yelp
 # and the summary in top of the chapters.
 #
 # db2html --nochunks nautilus-actions-config-tool.xml
-# Generate the html document(s). 
-# As of 0.6.14:
+# Generate the html document(s).
+#
+# As of 0.6.14.29:
 # - does produce the legal and abstract sections in top of the document
-# - creates a nautilus-actions-config-tool/stylesheet-images subdirectory
+# - creates a stylesheet-images/ subdirectory
 # - does not honor external links: they are converted to simple links
 #   which target the same frame window
-# - may create docbook2html-dir(.junk) subdirectories
+# - may create docbook2html-dir(.junk) subdirectories when it is run
+#   without argument
+#   (see https://bugzilla.redhat.com/show_bug.cgi?id=756930)
+# - begins by emptying the target directory, even if it also contains
+#   the source file
+#
+# When building HTML and PDF formats from XML sources, note that the
+# .xml documents default to be read from <srcdir> for the C version,
+# and from <builddir> for translated ones.
 
 MANUALS_HTML = $(MANUALS_XML:%.xml=%.html)
 
 MAINTAINERCLEANFILES += $(MANUALS_HTML)
 
-.PHONY: all-html-manuals
-
 if ENABLE_HTML_MANUALS
 all-html-manuals: $(MANUALS_HTML)
 else
 all-html-manuals:
 endif
 
-# - do not use '--copy_graphics' here (see #636175)
-# - admon-* icons will be installed in admon/ subdir
-#
 # The rule here is: only rebuild html/ files if corresponding xml has changed
-# .xml themselves are distributed, so are not modified when compiling from a
-# distribution (though this is not the intended use).
+# .xml themselves are distributed, so are not modified when building a
+# distribution.
 #
-# pwd=/home/pierre/data/eclipse/nautilus-actions/nautilus-actions-3.1.5/_build/docs/nact
-# target=C/nautilus-actions-config-tool.html
-# source=/home/pierre/net/eclipse/nautilus-actions/docs/nact/C/nautilus-actions-config-tool.xml
-#
-# db2html 0.6.14 bugs and work-arounds:
-# - '*.junk' and 'docbook2html-dir/' are subdirectories left by db2html when
-#   it is run without argument (see https://bugzilla.redhat.com/show_bug.cgi?id=756930)
-# - stylesheet-images directory is not created in the output directory
-#   (see https://bugzilla.redhat.com/show_bug.cgi?id=756928)
-#
-# gnome-doc-tool 0.20 bugs and work-arounds:
-# - g-d-t does not honor the base directory of the source document, only
-#   searching for extern entities in the current working directory
-#   (see https://bugzilla.gnome.org/show_bug.cgi?id=664784)
+# 'bis' (Build In Source) variable is set to 'yes' if builddir = srcdir.
 
 $(MANUALS_HTML): %.html: %.xml
-	@if test "$(opt_verbose)" = ""; then echo "  HTML   $@"; fi; \
-	( \
-	 dirxml=$<; dirxml=$${dirxml%/*}; cd $$dirxml; \
-	 fxml=$<; fxml=$${fxml##*/}; \
-	 if test "x$(WITH_DB2HTML)" = "xyes"; then \
-		cmd="db2html --output . --nochunks $$fxml"; \
-		if test "$(opt_verbose)" != ""; then echo "$$cmd"; fi; \
-		eval $$cmd || :; \
-		rm -fr stylesheet-images; \
-	    mv $(opt_verbose) $(DOC_MODULE)/stylesheet-images .; rmdir $(opt_verbose) $(DOC_MODULE); \
-	    find . -type d -name '*.junk' | xargs rm -fr; \
-	    find . -type d -name 'docbook2html-dir' | xargs rm -fr; \
-	 fi; \
-	 if test "x$(WITH_GDT)" = "xyes"; then \
-		 fhtml=$@; fhtml=$${fhtml##*/}; \
-		 cmd="gnome-doc-tool html -o . -d0 $$fxml"; \
-		 if test "$(opt_verbose)" != ""; then echo "$$cmd"; fi; \
-		 eval $$cmd; \
-		 if test -f $$fhtml; then \
-			 sed -i -e 's?url("admon?url("admon/admon?' $$fhtml; \
-			 admon_dir=/usr/share/gnome-doc-utils/icons/hicolor/48x48/status; \
-			 if test -d $$admon_dir; then \
-				lc=$${dirxml##*/}; \
-				if test "$$lc" = "C"; then \
-					cmd="$(mkinstalldirs) admon"; eval $$cmd; \
-					cmd="cp $(opt_verbose) $$admon_dir/*.png admon/"; eval $$cmd; \
-				else \
-					cmd="$(LN_S) -f ../C/admon"; eval $$cmd; \
-					if test "$(opt_verbose)" != ""; then echo $$cmd; fi; \
-				fi; \
-			fi; \
+	@ftarget=$@; \
+	if test "$(opt_verbose)" = ""; then echo "  HTML   $$ftarget"; fi; \
+	if test "$(abs_srcdir)" = "$(abs_builddir)"; then bis="yes"; else bis="no"; fi; \
+	lc=$${ftarget%/*}; \
+	if test "x$(WITH_DB2HTML)" = "xyes"; then $(call exec_db2html,$$ftarget,$$lc,$$bis); fi; \
+	if test "x$(WITH_GDT)" = "xyes"; then $(call exec_g_d_t,$$ftarget,$$lc,$$bis); fi; \
+	if test "$(opt_verbose)" = ""; then echo "  HTML   $$ftarget done"; fi
+
+# execute gnome-doc-tool
+# 1. make target
+# 2. locale
+# 3. "yes" if build in source
+exec_g_d_t = \
+	$(call install_xml,$(2),$(3)); \
+	fxml=$(DOC_MODULE).xml; \
+	(cd $(2); \
+	 cmd="gnome-doc-tool html -o . -d0 $$fxml"; \
+	 if test "$(opt_verbose)" != ""; then echo "$$cmd"; fi; \
+	 eval $$cmd >/dev/null; \
+	 fhtml=$(DOC_MODULE).html; \
+	 if test -f $$fhtml; then \
+		sed -i -e 's?url("admon?url("admon/admon?' $$fhtml; \
+		admon_dir=/usr/share/gnome-doc-utils/icons/hicolor/48x48/status; \
+		if test -d $$admon_dir; then \
+			$(MKDIR_P) admon; \
+			cmd="cp $(opt_verbose) $$admon_dir/*.png admon/"; eval $$cmd; \
 		fi; \
 	 fi; \
-	)
-
-# Install HTML manuals
-# in <htmldir>/<lang>/nact/ subdirectory; htmldir defaulting
-# to <pkgdocdir>/html
+	); \
+	$(call remove_xml,$(2),$(3))
+
+# execute db2html
+# 1. make target
+# 2. locale
+# 3. "yes" if build in source
+exec_db2html = \
+	cddir="$(2)"; \
+	output="."; \
+	fxml=$(DOC_MODULE).xml; \
+	if test "$(2)" = "C" -a "$(3)" = "no"; then \
+		cddir="."; \
+		output="C"; \
+		fxml=$(srcdir)/C/$$fxml; \
+	fi; \
+	cmd="(cd $$cddir && db2html --output $$output --nochunks $$fxml)"; \
+	if test "$(opt_verbose)" != ""; then echo "$$cmd"; fi; \
+	eval $$cmd >/dev/null; \
+	find . -type d -name '*.junk' | xargs rm -fr
+
+# install source .xml docs in builddir to be able to build C locale
+# 1. locale
+# 2. "yes" if build in source
+install_xml = \
+	if test "$(1)" = "C" -a "$(2)" = "no"; then $(MKDIR_P) C; cp $(srcdir)/C/*.xml C/; fi
+
+# remove .xml docs from builddir after having built C locale
+# 1. locale
+# 2. "yes" if build in source
+remove_xml = \
+	if test "$(1)" = "C" -a "$(2)" = "no"; then rm -f C/*.xml; fi
+
+# Install HTML manuals in <htmldir>/<lang>/nact/ subdirectory;
+# where <htmldir> defaults to <pkgdocdir>/html
 #
 # Note: we do honor here --htmldir autotools configuration option.
 #
-# Note: workaround against the bug #636175 (do not install admon-* icons)
-# Install admon icons as a admon/ subdirectory for C language
-# other languages are symlinked to this one
+# Manuals may be installed from builddir, if they just have been built,
+# or from srcdir, if they were not built but come from distribution.
 
-.PHONY: install-html-manuals
-install-html-manuals: install-html-figs
-	@for lc in C $(_DOC_REAL_LINGUAS); do \
-		if test "x$(htmldir)" = "x$(docdir)"; then \
-			_instdir="$(DESTDIR)$(pkgdocdir)/html/$$lc/nact"; \
-		else \
-			_instdir="$(DESTDIR)$(htmldir)/$$lc/nact"; \
+install-html-manuals:
+	@if test "x$(htmldir)" = "x$(docdir)"; then \
+		_instd="$(DESTDIR)$(pkgdocdir)/html"; \
+	else \
+		_instd="$(DESTDIR)$(htmldir)"; \
+	fi; \
+	echo "  Installing in $$_instd ..."; \
+	for lc in C $(_DOC_REAL_LINGUAS); do \
+		_instdir="$$_instd/$$lc/nact"; \
+		if test -f "$(builddir)/$$lc/$(DOC_MODULE).html"; then \
+			d="$(builddir)"; \
+		elif test -f "$(srcdir)/$$lc/$(DOC_MODULE).html"; then \
+			d="$(srcdir)"; \
 		fi; \
-		if test -f "$(srcdir)/$$lc/$(DOC_MODULE).html"; then d=$(srcdir); fi; \
-		if test -f "$(builddir)/$$lc/$(DOC_MODULE).html"; then d=$(builddir); fi; \
 		if test -f "$$d/$$lc/$(DOC_MODULE).html"; then \
-			if test "$(opt_verbose)" = ""; then echo "  Installing $$_instdir/$(DOC_MODULE).html ..."; fi; \
-			cp -p $(opt_verbose) "$$d/$$lc/$(DOC_MODULE).html" $$_instdir/; \
-			subdir="stylesheet-images"; \
-			if test -d "$$d/$$lc/$$subdir"; then \
-				if test "$(opt_verbose)" = ""; then echo "  Installing $$_instdir/$$subdir ..."; fi; \
-				cmd="cp -rp $(opt_verbose) \"$$d/$$lc/$$subdir\" $$_instdir/"; eval $$cmd; \
-				if test "$(opt_verbose)" != ""; then echo $$cmd; fi; \
-			fi; \
-			subdir="admon"; \
-			if test -d "$$d/$$lc/$$subdir"; then \
-				if test "$(opt_verbose)" = ""; then echo "  Installing $$_instdir/$$subdir ..."; fi; \
-				cmd="cp -rp $(opt_verbose) \"$$d/$$lc/$$subdir\" $$_instdir/"; eval $$cmd; \
-				if test "$(opt_verbose)" != ""; then echo $$cmd; fi; \
-			fi; \
-			if test -h "$$d/$$lc/$$subdir"; then \
-				if test "$(opt_verbose)" = ""; then echo "  Installing $$_instdir/$$subdir ..."; fi; \
-				cmd="(cd \"$$_instdir/$$lc/nact\" && $(LN_S) -f ../../C/nact/$$subdir)"; eval $$cmd; \
-				if test "$(opt_verbose)" != ""; then echo $$cmd; fi; \
-			fi; \
+			$(call install_html_doc,$$d,$$lc,$$_instdir); \
+			$(call install_html_images,$$d,$$lc,$$_instdir,"stylesheet-images"); \
+			$(call install_html_images,$$d,$$lc,$$_instdir,"admon"); \
+			$(call install_html_figs,$$d,$$lc,$$_instdir); \
 		fi; \
 	done
 
-# copied from gnome-doc-utils.make install-doc-figs target
-# modified to install the figures with html manuals
-.PHONY: install-html-figs
-install-html-figs:
-	@if test "x$(htmldir)" = "x$(docdir)"; then \
-		_instdir="$(DESTDIR)$(pkgdocdir)/html"; \
-	else \
-		_instdir="$(DESTDIR)$(htmldir)"; \
-	fi; \
-	list='$(patsubst C/%,%,$(_DOC_C_FIGURES))'; \
-	for lc in C $(_DOC_REAL_LINGUAS); do \
-	  if test "$(opt_verbose)" = ""; then echo "  Installing $$_instdir/$$lc/nact/figures ..."; fi; \
-	  if test -f "$(srcdir)/$$lc/$(DOC_MODULE).html"; then d=$(srcdir); fi; \
-	  if test -f "$(builddir)/$$lc/$(DOC_MODULE).html"; then d=$(builddir); fi; \
-	  if test -f "$$d/$$lc/$(DOC_MODULE).html"; then \
-		for fig in $$list; do \
-			figsymlink=false; \
-			if test -f "$(srcdir)/$$lc/$$fig" -a ! -h "$(srcdir)/$$lc/$$fig"; then \
-				figfile="$(srcdir)/$$lc/$$fig"; \
-			else \
-				figsymlink=true; \
-			fi; \
-			figdir="$$_instdir/$$lc/nact/$${fig%/*}"; \
-			if ! test -d "$$figdir"; then cmd="$(MKDIR_P) $$figdir"; eval $$cmd; fi; \
-			if $$figsymlink; then \
-				cmd="(cd $$figdir && $(LN_S) -f ../../../C/nact/$$fig)"; \
-			else \
-				cmd="$(INSTALL_DATA) $$figfile $$figdir/"; \
-			fi; \
+# installing html document
+# 1: source dir
+# 2: locale
+# 3: target dir
+install_html_doc = \
+	if test "$(opt_verbose)" = ""; then echo "    $(2)/nact/$(DOC_MODULE).html"; fi; \
+	$(MKDIR_P) $(3); \
+	cp -p $(opt_verbose) "$(1)/$(2)/$(DOC_MODULE).html" $(3)/
+
+# installing html images
+# 1: source dir
+# 2: locale
+# 3: target dir
+# 4: stylesheet-images or admon
+install_html_images = \
+	if grep -lq $(4) "$(1)/$(2)/$(DOC_MODULE).html"; then \
+		if test -d "$(1)/$(2)/$(4)"; then \
+			if test "$(opt_verbose)" = ""; then echo "    $(2)/nact/$(4)"; fi; \
+			cmd="cp -rp $(opt_verbose) \"$(1)/$(2)/$(4)\" $(3)/"; eval $$cmd; \
 			if test "$(opt_verbose)" != ""; then echo $$cmd; fi; \
-			eval $$cmd; \
-		done; \
-	  fi; \
+		fi; \
+	fi
+
+# installing user's manual figures
+# rebuilding list of figures here because I'm unable to pass it as a parameter
+# (it comes here as a single string in which I cannot walk through)
+# 1: source dir
+# 2: locale
+# 3: target dir
+install_html_figs = \
+	if test "$(opt_verbose)" = ""; then echo "    $(2)/nact/figures"; fi; \
+	figdir="$(3)/figures"; \
+	if ! test -d "$$figdir"; then $(MKDIR_P) "$$figdir"; fi; \
+	for fig in $(patsubst C/%,%,$(_DOC_C_FIGURES)); do \
+		figsrc=$(srcdir)/$(2)/$$fig; \
+		if test -f $${figsrc} -a ! -h $${figsrc}; then \
+			cmd="$(INSTALL_DATA) $${figsrc} $${figdir}/"; \
+		else \
+			cmd="(cd $${figdir} && $(LN_S) -f ../../../C/nact/$$fig)"; \
+		fi; \
+		if test "$(opt_verbose)" != ""; then echo $$cmd; fi; \
+		eval $$cmd; \
 	done
 
-.PHONY: uninstall-html-manuals
 uninstall-html-manuals:
 	@if test "x$(htmldir)" = "x$(docdir)"; then \
 		_instdir="$(DESTDIR)$(pkgdocdir)/html"; \
 	else \
 		_instdir="$(DESTDIR)$(htmldir)"; \
 	fi; \
-	find $$_instdir -type d -name 'admon' | xargs rm -fr $(opt_verbose); \
-	find $$_instdir -type l -name 'admon' | xargs rm -f $(opt_verbose); \
-	find $$_instdir -type d -name 'figures' | xargs rm -fr $(opt_verbose); \
-	find $$_instdir -type d -name 'stylesheet-images' | xargs rm -fr $(opt_verbose); \
-	find $$_instdir -type f -name '*.html' | xargs rm -f $(opt_verbose); \
-	find $$_instdir -type d | sort -r | xargs rmdir $(opt_verbose)
+	if test -d $$_instdir; then \
+		chmod -R u+w $$_instdir; \
+		find $$_instdir -type d -name 'admon' | xargs rm -fr $(opt_verbose); \
+		find $$_instdir -type d -name 'figures' | xargs rm -fr $(opt_verbose); \
+		find $$_instdir -type d -name 'stylesheet-images' | xargs rm -fr $(opt_verbose); \
+		find $$_instdir -type f -name '*.html' | xargs rm -f $(opt_verbose); \
+		find $$_instdir -type d | sort -r | xargs rmdir $(opt_verbose); \
+	fi
 
 # locale figures (_DOC_LC_FIGURES) are distributed by gnome-doc-utils
 # when they exist
-# - distribute admon-* icons as a C/ subdirectory
+# - distribute admon/ or stylesheet-images/ icons
 # - distribute *.html manuals
 
-.PHONY: dist-html-manuals-hook
 dist-html-manuals-hook:
 	@for lc in C $(_DOC_REAL_LINGUAS); do \
-		if test -f "$(srcdir)/$$lc/$(DOC_MODULE).html"; then d=$(srcdir); fi; \
-		if test -f "$(builddir)/$$lc/$(DOC_MODULE).html"; then d=$(builddir); fi; \
+		if test -f "$(builddir)/$$lc/$(DOC_MODULE).html"; then d=$(builddir); \
+		elif test -f "$(srcdir)/$$lc/$(DOC_MODULE).html"; then d=$(srcdir); fi; \
 		if test -f "$$d/$$lc/$(DOC_MODULE).html"; then \
+			if test "$(opt_verbose)" = ""; then echo "  Distributing $$lc/$(DOC_MODULE).html"; fi; \
 			cmd="cp $(opt_verbose) $$d/$$lc/$(DOC_MODULE).html $(distdir)/$$lc/"; eval $$cmd; \
-			if test -d "$$d/$$lc/stylesheet-images"; then \
-				echo "distributing stylesheet-images"; \
-				cmd="cp -rp $(opt_verbose) \"$$d/$$lc/stylesheet-images\" $(distdir)/$$lc/"; eval $$cmd; \
-			fi; \
-			if test -d "$$d/$$lc/admon" -o -h "$$d/$$lc/admon"; then \
-				echo "distributing admon"; \
-				cmd="cp -rp $(opt_verbose) \"$$d/$$lc/admon\" $(distdir)/$$lc/"; eval $$cmd; \
-			fi; \
+			$(call dist_html_images,$$d,$$lc,"stylesheet-images"); \
+			$(call dist_html_images,$$d,$$lc,"admon"); \
 		fi; \
 	done
 
+# distribute html images
+# 1. source dir
+# 2. locale
+# 3. image type (stylesheet-images or admon)
+dist_html_images = \
+	if grep -lq $(3) "$(1)/$(2)/$(DOC_MODULE).html"; then \
+		if test -d "$(1)/$(2)/$(3)"; then \
+			if test "$(opt_verbose)" = ""; then echo "  Distributing $(2)/$(3)"; fi; \
+			cmd="cp -rp $(opt_verbose) \"$(1)/$(2)/$(3)\" $(distdir)/$(2)/"; eval $$cmd; \
+		fi; \
+	fi
+
 # Build pdf manuals as $(srcdir)/<lang>/<module>.pdf
 #
 # The rule here is: only rebuild .pdf files if corresponding xml has changed
@@ -335,8 +357,6 @@ MANUALS_PDF = $(MANUALS_XML:%.xml=%.pdf)
 
 MAINTAINERCLEANFILES += $(MANUALS_PDF)
 
-.PHONY: all-pdf-manuals
-
 if ENABLE_PDF_MANUALS
 all-pdf-manuals: $(MANUALS_PDF)
 else
@@ -349,71 +369,83 @@ endif
 #
 # workaround against l10n bug #664768
 # pdflatex cannot generate some localized pdf
+#
+# As of dblatex 0.3.3:
+# - always create the output pdf in the same directory that the
+#   source xml
+#   (but we need to cd $$lc to mkdir figures)
+#
+# 'bis' (Build In Source) variable is set to 'yes' if builddir = srcdir.
 
 $(MANUALS_PDF): %.pdf: %.xml
-	@if test "$(opt_verbose)" = ""; then echo "  PDF    $@"; fi; \
-	( \
-	 dirxml=$<; dirxml=$${dirxml%/*}; cd $$dirxml; \
-	 fxml=$<; fxml=$${fxml##*/}; \
-	 lc=$@; \
-	 lc=$${lc%/*}; \
+	@ftarget=$@; \
+	if test "$(opt_verbose)" = ""; then echo "  PDF    $$ftarget"; fi; \
+	if test "$(abs_srcdir)" = "$(abs_builddir)"; then bis="yes"; else bis="no"; fi; \
+	lc=$${ftarget%/*}; \
+	$(call install_xml,$$lc,$$bis); \
+	list='$(patsubst C/%,%,$(_DOC_C_FIGURES))'; \
+	(cd $$lc; \
 	 $(MKDIR_P) figures; \
-	 list='$(patsubst C/%,%,$(_DOC_C_FIGURES))'; \
 	 for fig in $$list; do \
 		if test -f "$(srcdir)/$$lc/$$fig"; then d=$$lc; else d="C"; fi; \
 		if ! test -f $$fig; then \
 			cmd="(cd figures && $(LN_S) -f $(srcdir)/$$d/$$fig)"; eval $$cmd; \
 		fi; \
 	 done; \
-	 cmd="dblatex $$fxml"; eval $$cmd; \
+	 cmd="dblatex $(DOC_MODULE).xml"; eval $$cmd >/dev/null; \
 	 if ! test -f $(DOC_MODULE).pdf; then \
-	 	tmpdir=`dblatex -d $$fxml 2>&1 | grep 'not removed' | awk '{ print $$1 }'`; \
-	 	cp $$tmpdir/$(DOC_MODULE).pdf . || :; \
-	 	rm -fr $$tmpdir; \
+		echo "  PDF    $$ftarget recovering from dblatex error..."; \
+		tmpdir=`dblatex -d $(DOC_MODULE).xml 2>&1 | grep 'not removed' | awk '{ print $$1 }'`; \
+		cp $$tmpdir/$(DOC_MODULE).pdf . || :; \
+		rm -fr $$tmpdir; \
 	 fi; \
 	 find figures -type l | xargs rm -f; \
 	 rmdir figures 2>/dev/null || :; \
-	)
+	); \
+	$(call remove_xml,$$lc,$$bis); \
+	if test "$(opt_verbose)" = ""; then echo "  PDF    $$ftarget done"; fi
 
 # if --pdfdir has not been specified, then we default to PKGDOCDIR/pdf
 # in all case, we append the locale as a subdirectory level
 #
 # as pdf are monobloc documents, we do not create a per-document subdir
 
-.PHONY: install-pdf-manuals
 install-pdf-manuals:
 	@if test "$(pdfdir)" = "$(docdir)"; then \
 		_instdir=$(DESTDIR)$(pkgdocdir)/pdf; \
 	else \
 		_instdir=$(DESTDIR)$(pdfdir); \
 	fi; \
+	echo "  Installing in $$_instdir ... "; \
 	for lc in C $(_DOC_REAL_LINGUAS); do \
 		if test -f $(srcdir)/$$lc/$(DOC_MODULE).pdf; then d=$(srcdir); fi; \
 		if test -f $(builddir)/$$lc/$(DOC_MODULE).pdf; then d=$(builddir); fi; \
 		if test -f $$d/$$lc/$(DOC_MODULE).pdf; then \
-			if test "$(opt_verbose)" = ""; then echo "  Installing $$_instdir/$$lc/$(DOC_MODULE).pdf ..."; fi; \
+			if test "$(opt_verbose)" = ""; then echo "    $$lc/$(DOC_MODULE).pdf"; fi; \
 			if ! test -d $$_instdir/$$lc; then cmd="$(MKDIR_P) $$_instdir/$$lc"; eval $$cmd; fi; \
 			cmd="$(INSTALL_DATA) \"$$d/$$lc/$(DOC_MODULE).pdf\" \"$$_instdir/$$lc/\""; eval $$cmd; \
 			if test "$(opt_verbose)" != ""; then echo $$cmd; fi; \
 		fi; \
 	done
 
-.PHONY: uninstall-pdf-manuals
 uninstall-pdf-manuals:
 	@if test "$(pdfdir)" = "$(docdir)"; then \
 		_instdir=$(DESTDIR)$(pkgdocdir)/pdf; \
 	else \
 		_instdir=$(DESTDIR)$(pdfdir); \
 	fi; \
-	find $$_instdir -name '*.pdf' | xargs rm -f $(opt_verbose); \
-	find $$_instdir -type d | sort -r | xargs rmdir $(opt_verbose)
+	if test -d $$_instdir; then \
+		chmod -R u+w $$_instdir; \
+		find $$_instdir -name '*.pdf' | xargs rm -f $(opt_verbose); \
+		find $$_instdir -type d | sort -r | xargs rmdir $(opt_verbose); \
+	fi
 
-.PHONY: dist-pdf-manuals-hook
 dist-pdf-manuals-hook:
 	@for lc in C $(_DOC_REAL_LINGUAS); do \
-		if test -f $(srcdir)/$$lc/$(DOC_MODULE).pdf; then d=$(srcdir); fi; \
-		if test -f $(builddir)/$$lc/$(DOC_MODULE).pdf; then d=$(builddir); fi; \
+		if test -f $(builddir)/$$lc/$(DOC_MODULE).pdf; then d=$(builddir); \
+		elif test -f $(srcdir)/$$lc/$(DOC_MODULE).pdf; then d=$(srcdir); fi; \
 		if test -f "$$d/$$lc/$(DOC_MODULE).pdf"; then \
+			if test "$(opt_verbose)" = ""; then echo "  Distributing $$lc/$(DOC_MODULE).pdf"; fi; \
 			cmd="cp $$d/$$lc/$(DOC_MODULE).pdf $(distdir)/$$lc/"; eval $$cmd; \
 			if test "$(opt_verbose)" != ""; then echo $$cmd; fi; \
 		fi; \
@@ -425,7 +457,7 @@ dist-pdf-manuals-hook:
 # - clean deletes other files built with make
 # - distclean deletes files built by configure (none here)
 ##
-##  none of these target should delete any distributed file
+##  None of these target should delete any distributed file
 ##
 # - maintainer-clean should delete other files
 clean-local:
@@ -454,4 +486,7 @@ maintainer-clean-pdf:
 clean-doc-dir:
 	@:
 
-endif
+.PHONY: \
+	all-manuals install-manuals uninstall-manuals dist-manuals-hook \
+	all-html-manuals install-html-manuals uninstall-html-manuals dist-html-manuals-hook \
+	all-pdf-manuals install-pdf-manuals uninstall-pdf-manuals dist-pdf-manuals-hook
diff --git a/m4/na-enable-manuals.m4 b/m4/na-enable-manuals.m4
index af516f9..176cff1 100644
--- a/m4/na-enable-manuals.m4
+++ b/m4/na-enable-manuals.m4
@@ -51,8 +51,6 @@ AC_DEFUN([NA_ENABLE_MANUALS],[
 	
 	_CHECK_FOR_HTML_MANUALS
 	_CHECK_FOR_PDF_MANUALS
-
-	AM_CONDITIONAL([ENABLE_MANUALS], [test "${enable_html_manuals}" != "no" -o  "${enable_pdf_manuals}" != "no" ])
 ])
 
 AC_DEFUN([_AC_ARG_NA_ENABLE_HTML_MANUALS],[



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]