From bb7cab2aa07a49db5d2e126e67b4e2e8ac8007d9 Mon Sep 17 00:00:00 2001 From: John Mandereau Date: Wed, 20 Aug 2008 15:19:59 +0200 Subject: [PATCH] Clean up .xref-map files generation - write these files in (top-build-dir)/out/xref-maps/, with language used as name suffix if different from English: this is cleaner than writing them in out-www subdirectories and creating symlinks, mainly because it avoids hardcoding manual names in a bunch of makefiles; - buildscripts/extract_texi_filenames.py: write "@documentlanguage" as output file suffix if not "en", create output directory if necessary, and fix minor nitpicks; - remove all hardcoded manual names in makefiles. --- Documentation/de/user/GNUmakefile | 11 --------- Documentation/es/user/GNUmakefile | 11 --------- Documentation/fr/user/GNUmakefile | 10 -------- Documentation/user/GNUmakefile | 5 +--- buildscripts/extract_texi_filenames.py | 34 +++++++++++++++++--------- input/lsr/GNUmakefile | 11 +-------- lilypond-texi2html.init | 6 +++-- make/doclang-rules.make | 8 +++--- make/doclang-targets.make | 2 +- make/doclang-vars.make | 25 +++++++++++-------- stepmake/stepmake/texinfo-rules.make | 10 ++++---- stepmake/stepmake/texinfo-targets.make | 2 +- stepmake/stepmake/texinfo-vars.make | 8 +++++- 13 files changed, 62 insertions(+), 81 deletions(-) diff --git a/Documentation/de/user/GNUmakefile b/Documentation/de/user/GNUmakefile index 810efc38e7..fb4ca861ff 100644 --- a/Documentation/de/user/GNUmakefile +++ b/Documentation/de/user/GNUmakefile @@ -2,14 +2,3 @@ ISOLANG = de depth = ../../.. LOCALSTEPMAKE_TEMPLATES = lilypond ly doclang include $(depth)/make/stepmake.make - - -local-WWW-1: $(XREF_MAP_FILES) $(outdir)/lilypond-snippets.xref-map \ - $(outdir)/music-glossary.xref-map \ - $(outdir)/lilypond-internals.xref-map - -$(outdir)/lilypond-snippets.xref-map: - ln -sf ../../../../input/lsr/$@ $@ - -$(outdir)/lilypond-internals.xref-map $(outdir)/music-glossary.xref-map: - ln -sf ../../../user/$@ $@ diff --git a/Documentation/es/user/GNUmakefile b/Documentation/es/user/GNUmakefile index d51764115b..1728b63e7c 100644 --- a/Documentation/es/user/GNUmakefile +++ b/Documentation/es/user/GNUmakefile @@ -2,14 +2,3 @@ ISOLANG = es depth = ../../.. LOCALSTEPMAKE_TEMPLATES = lilypond ly doclang include $(depth)/make/stepmake.make - - -local-WWW-1: $(XREF_MAP_FILES) $(outdir)/lilypond-snippets.xref-map \ - $(outdir)/music-glossary.xref-map \ - $(outdir)/lilypond-internals.xref-map - -$(outdir)/lilypond-snippets.xref-map: - ln -sf ../../../../input/lsr/$@ $@ - -$(outdir)/lilypond-internals.xref-map $(outdir)/music-glossary.xref-map: - ln -sf ../../../user/$@ $@ diff --git a/Documentation/fr/user/GNUmakefile b/Documentation/fr/user/GNUmakefile index f32ebf319f..cff64c97e9 100644 --- a/Documentation/fr/user/GNUmakefile +++ b/Documentation/fr/user/GNUmakefile @@ -2,13 +2,3 @@ ISOLANG = fr depth = ../../.. LOCALSTEPMAKE_TEMPLATES = lilypond ly doclang include $(depth)/make/stepmake.make - -local-WWW-1: $(XREF_MAP_FILES) $(outdir)/lilypond-snippets.xref-map \ - $(outdir)/music-glossary.xref-map \ - $(outdir)/lilypond-internals.xref-map - -$(outdir)/lilypond-snippets.xref-map: - ln -sf ../../../../input/lsr/$@ $@ - -$(outdir)/lilypond-internals.xref-map $(outdir)/music-glossary.xref-map: - ln -sf ../../../user/$@ $@ diff --git a/Documentation/user/GNUmakefile b/Documentation/user/GNUmakefile index b930b98e16..688b32c42e 100644 --- a/Documentation/user/GNUmakefile +++ b/Documentation/user/GNUmakefile @@ -125,16 +125,13 @@ $(outdir)/%/source: mkdir -p $(dir $@) ln -sf $(depth)/.. $(@) -local-WWW-1: $(MASTER_TEXI_FILES) $(MASTER_TEXI_FILES:%.texi=%.xref-map) $(outdir)/lilypond-snippets.xref-map $(PDF_FILES) info +local-WWW-1: $(MASTER_TEXI_FILES) $(PDF_FILES) info local-WWW-2: $(HTML_FILES) $(DEEP_HTML_FILES) $(source-links) $(outdir)/%.bib: %.bib ln -f $< $@ -$(outdir)/lilypond-snippets.xref-map: - ln -fs ../../../input/lsr/$@ $@ - # lilypond.texi deps $(top-build-dir)/mf/$(outconfbase)/feta16list.ly: $(MAKE) -C $(top-src-dir)/mf diff --git a/buildscripts/extract_texi_filenames.py b/buildscripts/extract_texi_filenames.py index beea07e433..6b89954b25 100755 --- a/buildscripts/extract_texi_filenames.py +++ b/buildscripts/extract_texi_filenames.py @@ -1,6 +1,6 @@ #!@PYTHON@ # -*- coding: utf-8 -*- -# extrace_texi_filenames.py +# extract_texi_filenames.py # USAGE: extract_texi_filenames.py [-o OUTDIR] FILES # @@ -14,8 +14,9 @@ # which is then used for the filename/anchor. # # If this script is run on a file texifile.texi, it produces a file -# texifile.xref-map with tab-separated entries of the form +# texifile[.LANG].xref-map with tab-separated entries of the form # NODE\tFILENAME\tANCHOR +# LANG is the document language in case it's not 'en' # Note: The filename does not have any extension appended! # This file can then be used by our texi2html init script to determine # the correct file name and anchor for external refs @@ -25,8 +26,6 @@ import re import os import getopt -#import langdefs - optlist, args = getopt.getopt (sys.argv[1:],'o:') files = args @@ -35,6 +34,11 @@ for x in optlist: if x[0] == '-o': outdir = x[1] +if not os.path.isdir (outdir): + if os.path.exists (outdir): + os.unlink (outdir) + os.makedirs (outdir) + include_re = re.compile (r'@include ((?!../lily-).*?)\.texi$', re.M) whitespaces = re.compile (r'\s+') section_translation_re = re.compile (r'@(node|(?:unnumbered|appendix)(?:(?:sub){0,2}sec)?|top|chapter|(?:sub){0,2}section|(?:major|chap|(?:sub){0,2})heading|translationof) (.*?)\s*\n') @@ -42,22 +46,30 @@ section_translation_re = re.compile (r'@(node|(?:unnumbered|appendix)(?:(?:sub){ def expand_includes (m, filename): filepath = os.path.join (os.path.dirname (filename), m.group(1)) + '.texi' if os.path.exists (filepath): - return extract_sections (filepath) + return extract_sections (filepath)[1] else: print "Unable to locate include file " + filepath return '' +lang_re = re.compile (r'^@documentlanguage (.+)', re.M) + def extract_sections (filename): result = '' f = open (filename, 'r') page = f.read () f.close() + # Search document language + m = lang_re.search (page) + if m and m.group (1) != 'en': + lang_suffix = '.' + m.group (1) + else: + lang_suffix = '' # Replace all includes by their list of sections and extract all sections page = include_re.sub (lambda m: expand_includes (m, filename), page) sections = section_translation_re.findall (page) for sec in sections: result += "@" + sec[0] + " " + sec[1] + "\n" - return result + return (lang_suffix, result) # Convert a given node name to its proper file name (normalization as explained # in the texinfo manual: @@ -101,10 +113,10 @@ def create_texinfo_anchor (title): return texinfo_file_name (remove_texinfo (title)) unnumbered_re = re.compile (r'unnumbered.*') -def process_sections (filename, page): +def process_sections (filename, lang_suffix, page): sections = section_translation_re.findall (page) - # TODO: Don't rely on the file having a 4-letter extension (texi)!!! - p = os.path.join (outdir, filename) [:-5] + '.xref-map' + basename = os.path.splitext (os.path.basename (filename))[0] + p = os.path.join (outdir, basename) + lang_suffix + '.xref-map' f = open (p, 'w') this_title = '' @@ -152,5 +164,5 @@ def process_sections (filename, page): for filename in files: print "extract_texi_filenames.py: Processing %s" % filename - sections = extract_sections (filename) - process_sections (filename, sections) + (lang_suffix, sections) = extract_sections (filename) + process_sections (filename, lang_suffix, sections) diff --git a/input/lsr/GNUmakefile b/input/lsr/GNUmakefile index 97e188eb88..f91dacd38d 100644 --- a/input/lsr/GNUmakefile +++ b/input/lsr/GNUmakefile @@ -57,19 +57,10 @@ local-clean: rm -f $(INFO_IMAGES_DIR) local-WWW-1: info $(outdir)/lilypond-snippets.pdf \ - $(outdir)/lilypond-snippets.texi \ - $(outdir)/lilypond-snippets.xref-map \ - $(outdir)/lilypond.xref-map \ - $(outdir)/lilypond-learning.xref-map + $(outdir)/lilypond-snippets.texi local-WWW-2: $(outdir)/lilypond-snippets/index.html \ $(outdir)/lilypond-snippets-big-page.html \ $(source-links) -%.xref-map: %.texi - $(PYTHON) $(buildscript-dir)/extract_texi_filenames.py $< - -$(outdir)/lilypond.xref-map $(outdir)/lilypond-learning.xref-map: - ln -sf ../../../Documentation/user/$@ $@ - .SECONDARY: diff --git a/lilypond-texi2html.init b/lilypond-texi2html.init index 3ed3fcc6da..fdb02c1682 100644 --- a/lilypond-texi2html.init +++ b/lilypond-texi2html.init @@ -328,7 +328,8 @@ sub split_at_numbered_sections($$$) sub lilypond_init_map () { my ($docu_dir, $docu_name) = split_texi_filename ($Texi2HTML::THISDOC{'input_file_name'}); - my $map_filename = "$docu_dir/${docu_name}.xref-map"; + my $map_filename = main::locate_include_file ("${docu_name}.$Texi2HTML::THISDOC{current_lang}.xref-map") + || main::locate_include_file ("${docu_name}.xref-map"); $node_to_filename_map = load_map_file ($map_filename); } push @Texi2HTML::Config::command_handler_init, \&lilypond_init_map; @@ -442,7 +443,8 @@ sub lilypond_external_href($$$) # Load the map if we haven't done so already if (!exists($translated_books{$map_name})) { my ($docu_dir, $docu_name) = split_texi_filename ($Texi2HTML::THISDOC{'input_file_name'}); - my $map_filename = "$docu_dir/${map_name}.xref-map"; + my $map_filename = main::locate_include_file ("${map_name}.$Texi2HTML::THISDOC{current_lang}.xref-map") + || main::locate_include_file ("${map_name}.xref-map"); $translated_books{$map_name} = load_map_file ($map_filename); } diff --git a/make/doclang-rules.make b/make/doclang-rules.make index 201e49fd93..91f09c47a1 100644 --- a/make/doclang-rules.make +++ b/make/doclang-rules.make @@ -1,9 +1,9 @@ -$(outdir)/%/index.html: $(outdir)/%.texi $(outdir)/%.xref-map $(OUT_PNG_IMAGES) $(outdir)/version.itexi +$(outdir)/%/index.html: $(outdir)/%.texi $(XREF_MAPS_DIR)/%.$(ISOLANG).xref-map $(OUT_PNG_IMAGES) $(outdir)/version.itexi mkdir -p $(dir $@) $(TEXI2HTML) --I=$(outdir) $(TEXI2HTML_FLAGS) --output=$(dir $@) --prefix=index --split=section $(TEXI2HTML_INIT) $< cp $(top-src-dir)/Documentation/lilypond*.css $(dir $@) -$(outdir)/%-big-page.html: $(outdir)/%.texi $(outdir)/%.xref-map $(OUT_PNG_IMAGES) $(outdir)/version.itexi +$(outdir)/%-big-page.html: $(outdir)/%.texi $(XREF_MAPS_DIR)/%.$(ISOLANG).xref-map $(OUT_PNG_IMAGES) $(outdir)/version.itexi $(TEXI2HTML) --I=$(outdir) -D bigpage $(TEXI2HTML_FLAGS) --output=$@ $(TEXI2HTML_INIT) $< cp $(top-src-dir)/Documentation/lilypond*.css $(dir $@) @@ -21,8 +21,8 @@ $(outdir)/version.%: $(top-src-dir)/VERSION $(outdir)/%.png: $(top-build-dir)/Documentation/user/$(outdir)/%.png ln -f $< $@ -$(outdir)/%.xref-map: $(outdir)/%.texi - $(PYTHON) $(buildscript-dir)/extract_texi_filenames.py $< +$(XREF_MAPS_DIR)/%.$(ISOLANG).xref-map: $(outdir)/%.texi + $(PYTHON) $(buildscript-dir)/extract_texi_filenames.py -o $(XREF_MAPS_DIR) $< # This makes sure lilypond-doc gettext domain has been compiled # before lilypond-book runs diff --git a/make/doclang-targets.make b/make/doclang-targets.make index 72e8ada4ad..7f8f6799b0 100644 --- a/make/doclang-targets.make +++ b/make/doclang-targets.make @@ -1,6 +1,6 @@ default: -local-WWW-1: $(MASTER_TEXI_FILES) $(PDF_FILES) $(XREF_MAP_FILES) +local-WWW-1: $(MASTER_TEXI_FILES) $(PDF_FILES) $(XREF_MAPS_FILES) # BIG_PAGE_HTML_FILES is defined differently in each language makefile local-WWW-2: $(DEEP_HTML_FILES) $(BIG_PAGE_HTML_FILES) diff --git a/make/doclang-vars.make b/make/doclang-vars.make index f7b25ae284..bd5d7d372c 100644 --- a/make/doclang-vars.make +++ b/make/doclang-vars.make @@ -5,6 +5,14 @@ LANGS = $(shell $(PYTHON) $(buildscript-dir)/langdefs.py) SOURCE_PNG_IMAGES=$(shell ls $(top-src-dir)/Documentation/user/*.png) OUT_PNG_IMAGES=$(SOURCE_PNG_IMAGES:$(top-src-dir)/Documentation/user/%.png=$(outdir)/%.png) $(outdir)/context-example.png +TELY_FILES := $(call src-wildcard,*.tely) +MASTER_TEXI_FILES := $(TELY_FILES:%.tely=$(outdir)/%.texi) +DEEP_HTML_FILES := $(TELY_FILES:%.tely=$(outdir)/%/index.html) +PDF_FILES := $(TELY_FILES:%.tely=$(outdir)/%.pdf) + +ITELY_FILES := $(call src-wildcard,*.itely) +ITEXI_FILES := $(call src-wildcard,*.itexi) + DOCUMENTATION_INCLUDES = \ -I $(top-src-dir)/Documentation/user \ -I $(top-build-dir)/Documentation/user/$(outdir) @@ -13,18 +21,15 @@ LILYPOND_BOOK_INCLUDES += $(DOCUMENTATION_INCLUDES) MAKEINFO_FLAGS += --force --enable-encoding $(DOCUMENTATION_INCLUDES) MAKEINFO = LANG= $(MAKEINFO_PROGRAM) $(MAKEINFO_FLAGS) +# texi2html xref map files +XREF_MAPS_DIR=$(top-build-dir)/out/xref-maps +XREF_MAPS_FILES=$(TELY_FILES:%.tely=$(XREF_MAPS_DIR)/%.$(ISOLANG).xref-map) + +# texi2html flags TEXI2HTML_INIT= --init-file=$(top-src-dir)/lilypond-texi2html.init TEXI2HTML_LANG=--lang=$(ISOLANG) -TEXI2HTML_FLAGS += $(TEXI2HTML_LANG) $(DOCUMENTATION_INCLUDES) +TEXI2HTML_FLAGS += $(TEXI2HTML_LANG) $(DOCUMENTATION_INCLUDES) \ + -I $(XREF_MAPS_DIR) TEXI2HTML = LANG= $(TEXI2HTML_PROGRAM) TEXI2PDF_FLAGS += -q --batch $(DOCUMENTATION_INCLUDES) - -TELY_FILES := $(call src-wildcard,*.tely) -MASTER_TEXI_FILES := $(TELY_FILES:%.tely=$(outdir)/%.texi) -DEEP_HTML_FILES := $(TELY_FILES:%.tely=$(outdir)/%/index.html) -PDF_FILES := $(TELY_FILES:%.tely=$(outdir)/%.pdf) -XREF_MAP_FILES := $(TELY_FILES:%.tely=$(outdir)/%.xref-map) - -ITELY_FILES := $(call src-wildcard,*.itely) -ITEXI_FILES := $(call src-wildcard,*.itexi) diff --git a/stepmake/stepmake/texinfo-rules.make b/stepmake/stepmake/texinfo-rules.make index fc23bcb3fd..b44b6300ec 100644 --- a/stepmake/stepmake/texinfo-rules.make +++ b/stepmake/stepmake/texinfo-rules.make @@ -26,12 +26,12 @@ endif $(outdir)/%.info: $(outdir)/%.texi $(outdir)/$(INFO_IMAGES_DIR).info-images-dir.dep $(outdir)/version.itexi $(MAKEINFO) -I$(outdir) --output=$@ $< -$(outdir)/%-big-page.html: $(outdir)/%.texi $(outdir)/%.xref-map $(outdir)/version.itexi +$(outdir)/%-big-page.html: $(outdir)/%.texi $(XREF_MAPS_DIR)/%.xref-map $(outdir)/version.itexi $(TEXI2HTML) --I=$(outdir) -D bigpage --output=$@ $(TEXI2HTML_INIT) $< cp $(top-src-dir)/Documentation/lilypond*.css $(dir $@) -$(outdir)/%.html: $(outdir)/%.texi $(outdir)/%.xref-map $(outdir)/version.itexi +$(outdir)/%.html: $(outdir)/%.texi $(XREF_MAPS_DIR)/%.xref-map $(outdir)/version.itexi $(TEXI2HTML) --I=$(outdir) --output=$@ $(TEXI2HTML_INIT) $< cp $(top-src-dir)/Documentation/lilypond*.css $(dir $@) @@ -44,7 +44,7 @@ $(outdir)/%.pdf.omf: %.texi $(outdir)/%.ps.gz.omf: %.texi $(call GENERATE_OMF,ps.gz) -$(outdir)/%/index.html: $(outdir)/%.texi $(outdir)/%.xref-map $(outdir)/version.itexi +$(outdir)/%/index.html: $(outdir)/%.texi $(XREF_MAPS_DIR)/%.xref-map $(outdir)/version.itexi mkdir -p $(dir $@) $(TEXI2HTML) --I=$(outdir) --output=$(dir $@) --prefix=index --split=section $(TEXI2HTML_INIT) $< cp $(top-src-dir)/Documentation/lilypond*.css $(dir $@) @@ -59,8 +59,8 @@ $(outdir)/%.texi: %.texi rm -f $@ cp $< $@ -%.xref-map: %.texi - $(PYTHON) $(buildscript-dir)/extract_texi_filenames.py $< +$(XREF_MAPS_DIR)/%.xref-map: $(outdir)/%.texi + $(PYTHON) $(buildscript-dir)/extract_texi_filenames.py -o $(XREF_MAPS_DIR) $< $(outdir)/version.%: $(top-src-dir)/VERSION diff --git a/stepmake/stepmake/texinfo-targets.make b/stepmake/stepmake/texinfo-targets.make index 8b6669af21..6d25079ebe 100644 --- a/stepmake/stepmake/texinfo-targets.make +++ b/stepmake/stepmake/texinfo-targets.make @@ -2,7 +2,7 @@ default: $(INFO_FILES) -local-WWW-2: $(addprefix $(outdir)/,$(TEXI_FILES:.texi=.html)) +local-WWW-1: $(XREF_MAPS_FILES) local-doc: $(OUTTXT_FILES) diff --git a/stepmake/stepmake/texinfo-vars.make b/stepmake/stepmake/texinfo-vars.make index d0ffdf90d6..1a67332d4b 100644 --- a/stepmake/stepmake/texinfo-vars.make +++ b/stepmake/stepmake/texinfo-vars.make @@ -13,10 +13,16 @@ TEXINFO_PAPERSIZE_OPTION= $(if $(findstring $(PAPERSIZE),a4),,-t @afourpaper) MAKEINFO_FLAGS = --enable-encoding MAKEINFO = LANG= $(MAKEINFO_PROGRAM) $(MAKEINFO_FLAGS) +# texi2html xref map files +XREF_MAPS_DIR=$(top-build-dir)/out/xref-maps +XREF_MAPS_FILES=$(INFO_DOCS:%=$(XREF_MAPS_DIR)/%.xref-map) + +# texi2html flags ifneq ($(ISOLANG),) TEXI2HTML_LANG = --lang=$(ISOLANG) endif -TEXI2HTML_FLAGS += --css-ref=lilypond.css $(DOCUMENTATION_INCLUDES) +TEXI2HTML_FLAGS += --css-ref=lilypond.css $(DOCUMENTATION_INCLUDES) \ + --I=$(XREF_MAPS_DIR) TEXI2HTML_INIT = --init-file=$(top-src-dir)/lilypond-texi2html.init TEXI2HTML = $(TEXI2HTML_PROGRAM) $(TEXI2HTML_FLAGS) $(TEXI2HTML_LANG) -- 2.39.2