From 49b7c7e46d042219087737ef695bc17063b3fd42 Mon Sep 17 00:00:00 2001
From: j8takagi <j8takagi@nifty.com>
Date: Sat, 14 Jun 2014 13:31:49 +0900
Subject: [PATCH] =?utf8?q?Texinfo=E3=81=AE=E4=BE=9D=E5=AD=98=E9=96=A2?=
 =?utf8?q?=E4=BF=82=E3=82=92=E8=A1=A8=E3=81=99.d=E3=83=95=E3=82=A1?=
 =?utf8?q?=E3=82=A4=E3=83=AB=E3=82=92=E8=87=AA=E5=8B=95=E4=BD=9C=E6=88=90?=
 =?utf8?q?=E3=81=99=E3=82=8B=E6=A9=9F=E8=83=BD=E3=82=92=E8=BF=BD=E5=8A=A0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=utf8
Content-Transfer-Encoding: 8bit

---
 doc/.gitignore                |  1 +
 doc/Makefile                  |  2 ++
 doc/casl2_spec/Makefile       |  6 ++--
 doc/casl2_spec/casl2_spec.dep | 55 -----------------------------------
 doc/texinfo.mk                | 55 +++++++++++++++++++++++++++++------
 5 files changed, 53 insertions(+), 66 deletions(-)
 delete mode 100644 doc/casl2_spec/casl2_spec.dep

diff --git a/doc/.gitignore b/doc/.gitignore
index 6154d47..f8fc444 100644
--- a/doc/.gitignore
+++ b/doc/.gitignore
@@ -20,3 +20,4 @@ casl2_spec.html
 *.toc
 *.tp
 *.vr
+*.d
diff --git a/doc/Makefile b/doc/Makefile
index bb4c096..dc8c378 100644
--- a/doc/Makefile
+++ b/doc/Makefile
@@ -7,6 +7,8 @@ CSS := style.css
 prefix ?= ~
 infodir ?= $(prefix)/share/info
 
+TEXITARGETS := install.html manual.html
+
 INSTALL-INFO-TARGETS := yacasl2.info
 
 .PHONY: base all info html htmls pdf casl2_spec distclean clean
diff --git a/doc/casl2_spec/Makefile b/doc/casl2_spec/Makefile
index 17b62cf..cc9ada7 100644
--- a/doc/casl2_spec/Makefile
+++ b/doc/casl2_spec/Makefile
@@ -5,6 +5,8 @@ SED := sed
 
 CSS := style.css
 
+TEXITARGETS := casl2_spec.html
+
 .PHONY: all clean distclean
 
 all: casl2_spec.html casl2_spec.pdf
@@ -14,10 +16,10 @@ clean: texinfo-clean
 	$(MAKE) -C img clean
 
 distclean: clean texinfo-distclean
-	$(RM) *.html *.pdf
+	$(RM) *.d *.html *.pdf
 	$(MAKE) -C img distclean
 
-include casl2_spec.dep
+#include casl2_spec.dep
 
 include texinfo.mk
 
diff --git a/doc/casl2_spec/casl2_spec.dep b/doc/casl2_spec/casl2_spec.dep
deleted file mode 100644
index d2fe284..0000000
--- a/doc/casl2_spec/casl2_spec.dep
+++ /dev/null
@@ -1,55 +0,0 @@
-casl2_spec.html: img/1_1-01.png
-casl2_spec.html: img/1_2-00.png
-casl2_spec.html: img/1_2-01.png
-casl2_spec.html: img/1_2-02.png
-casl2_spec.html: img/1_2-03.png
-casl2_spec.html: img/1_2-04.png
-casl2_spec.html: img/1_2-05.png
-casl2_spec.html: img/1_2-06.png
-casl2_spec.html: img/1_2-07.png
-casl2_spec.html: img/1_2-08.png
-casl2_spec.html: img/1_3-01.png
-casl2_spec.html: img/2_1-01.png
-casl2_spec.html: img/2_2-01.png
-casl2_spec.html: img/2_3-01.png
-casl2_spec.html: img/2_3-02.png
-casl2_spec.html: img/2_3-03.png
-casl2_spec.html: img/2_3-04.png
-casl2_spec.html: img/2_3-05.png
-casl2_spec.html: img/2_4-01.png
-casl2_spec.html: img/2_4-02.png
-casl2_spec.html: img/2_4-03.png
-casl2_spec.html: img/2_4-04.png
-casl2_spec.html: img/r_1-01.png
-casl2_spec.html: img/r_1-02.png
-casl2_spec.html: img/r_1-03.png
-casl2_spec.html: img/r_1-04.png
-casl2_spec.html: img/r_1-05.png
-
-casl2_spec.pdf: img/1_1-01.eps
-casl2_spec.pdf: img/1_2-00.eps
-casl2_spec.pdf: img/1_2-01.eps
-casl2_spec.pdf: img/1_2-02.eps
-casl2_spec.pdf: img/1_2-03.eps
-casl2_spec.pdf: img/1_2-04.eps
-casl2_spec.pdf: img/1_2-05.eps
-casl2_spec.pdf: img/1_2-06.eps
-casl2_spec.pdf: img/1_2-07.eps
-casl2_spec.pdf: img/1_2-08.eps
-casl2_spec.pdf: img/1_3-01.eps
-casl2_spec.pdf: img/2_1-01.eps
-casl2_spec.pdf: img/2_2-01.eps
-casl2_spec.pdf: img/2_3-01.eps
-casl2_spec.pdf: img/2_3-02.eps
-casl2_spec.pdf: img/2_3-03.eps
-casl2_spec.pdf: img/2_3-04.eps
-casl2_spec.pdf: img/2_3-05.eps
-casl2_spec.pdf: img/2_4-01.eps
-casl2_spec.pdf: img/2_4-02.eps
-casl2_spec.pdf: img/2_4-03.eps
-casl2_spec.pdf: img/2_4-04.eps
-casl2_spec.pdf: img/r_1-01.eps
-casl2_spec.pdf: img/r_1-02.eps
-casl2_spec.pdf: img/r_1-03.eps
-casl2_spec.pdf: img/r_1-04.eps
-casl2_spec.pdf: img/r_1-05.eps
diff --git a/doc/texinfo.mk b/doc/texinfo.mk
index 3ba0cf8..c75c261 100644
--- a/doc/texinfo.mk
+++ b/doc/texinfo.mk
@@ -2,28 +2,64 @@
 
 CP := cp
 DVIPDFMX := dvipdfmx
+DVIPDFMX_FLAGS ?=
+ECHO := echo
 INSTALL-INFO := install-info
+MAKEINFO_FLAGS ?=
 MKDIR := mkdir
 RMR := rm -rf
+SED := sed
 TEX := ptex
 TEXI2DVI := TEX=$(TEX) texi2dvi
-
-DVIPDFMX_FLAGS ?=
-MAKEINFO_FLAGS ?=
 TEXI2DVI_FLAGS ?= -q --texinfo=@afourpaper
+MV := mv
+
+# \includeコマンドで読み込まれるファイル
+intexi = $(strip $(shell $(SED) -n -e 's/@include \(.*\)/\1/pg' $<))
+
+# \imageコマンドで読み込まれるファイル
+imagetexi = $(strip $(shell $(SED) -n -e 's/.*@image{\([^,]*\)\(,[^,]*,[^,]*,[^,]*,\([^,}]*\)\)}.*/\1\3/p' $<))
+
+# 依存関係を自動生成し、dファイルに格納
+%.d: %.texi
+	@$(ECHO) '$@ is created by scanning $<.'
+    # texiファイルと出力ファイルの依存関係
+	@$(ECHO) '$(foreach ext,.html _html .pdf .xml .info .txt .d,$(subst .texi,$(ext),$<)): $<' >$@
+    # includeファイルの依存関係
+	$(if $(intexi),@( \
+      $(ECHO) >>$@; \
+      $(ECHO) '# Include Files' >>$@; \
+      $(ECHO) '$(foreach ext,.html _html .info .pdf .xml .txt,$<),$(subst .texi,$(ext),$<): $(intexi)') >>$@)
+  # imageファイルの依存関係
+  # Docbookは未定義
+	$(if $(imagetexi),@( \
+      $(ECHO) >>$@; \
+      $(ECHO) '# Image Files: HTML, HTML split, Info' >>$@; \
+      $(ECHO) '$(foreach ext,.html _html .info,$(subst .texi,$(ext),$<)): $(imagetexi)' >>$@))
+	$(if $(imagetexi),@( \
+      $(ECHO) >>$@; \
+      $(ECHO) '# Imagefiles: DVI -> PDF' >>$@; \
+      $(ECHO) '$(subst .texi,.pdf,$<): $(addsuffix .eps,$(basename $(imagetexi)))' >>$@))
+
+# 変数TEXITARGETSで指定されたターゲットファイルに対応するdファイルをインクルード
+# .dファイルからヘッダファイルの依存関係を取得する
+# ターゲットに clean が含まれている場合は除く
+ifeq (,$(filter %clean,$(MAKECMDGOALS)))
+  -include $(addsuffix .d,$(basename $(TEXITARGETS)))
+endif
 
 %.info: %.texi
 	$(MAKEINFO) $(MAKEINFO_FLAGS) -o $@ $<
 
-%.html: %.texi $(CSS)
+%.html: %.texi
 	$(MAKEINFO) -o $@ --no-split --html --css-include=$(CSS) $<
-	$(SED) -i.bak -e 's!dir\.html#Top!\.\./!g'  -e 's!src="\(.*\)\.png"!src="\1.svg"!g' $@ && $(RM) $@.bak
 
-%_html: %.texi $(CSS)
+%_html: %.texi
 	if test ! -e $@; then $(MKDIR) $@; fi
 	$(CP) $(CSS) $@/
 	$(MAKEINFO) -o $@ --html --css-ref=$(CSS) $<
-	$(SED) -i.bak -e 's!\.\./dir/index\.html!\.\./\.\./!g' -e 's!src="\(.*\)\.png"!src="\1.svg"!g' $@/*.html && $(RM) $@/*.html.bak
+
+%.html %_html: $(CSS)
 
 %.pdf: %.dvi
 	$(DVIPDFMX) $(DVIPDFMXFLAGS) $<
@@ -35,9 +71,10 @@ TEXI2DVI_FLAGS ?= -q --texinfo=@afourpaper
 	@$(MAKEINFO) --docbook -o $@ $<
 
 texinfo-distclean: texinfo-clean
-	@$(RMR) *_html *.info *.html *.pdf  *.dvi *.txt
+	$(RMR) *_html *.info *.html *.pdf  *.dvi *.txt
 
 texinfo-clean: texinfo-textmp-clean
+	$(RM) *.d
 
 texinfo-textmp-clean:
-	@$(RM) *.aux *.cp *.cps *.fn *.ky *.log *.pg *.pgs *.tmp *.toc *.tp *.vr
+	$(RM) *.aux *.cp *.cps *.fn *.ky *.log *.pg *.pgs *.tmp *.toc *.tp *.vr
-- 
2.18.0