-# TeX中間ファイルの拡張子
-# .aux: 相互参照
-# .fls: tex -recorderで生成されるファイルリスト
-# .lof: 図リスト(\tableoffigures)
-# .lot: 表リスト(\tableoftables)
-# .out: hyperrefパッケージ
-# .toc: 目次(\tableofcontents)
-# .log: ログ
-TEX_INT := .aux .fls .lof .lot .out .toc .log
-# 索引中間ファイルの拡張子
-# .idx: auxから作成
-# .ind: idxから作成
-# .ilg: 索引ログ
-IND_INT := .idx .ind .ilg
-# BiBTeX中間ファイルの拡張子
-# .bbl: auxから作成
-# .blg: BiBTeXログ
-BIB_INT := .bbl .blg
-
-ALL_INTERFILES = $(addprefix *,$(TEX_INT) $(IND_INT) $(BIB_INT) .d .*_prev)
-
-.SECONDARY: $(wildcard ALL_INTERFILES)
-
-# \tableofcontents命令をTeXファイルから検索する
-toc = \
- $(shell \
- $(SED) -e '/^\s*%/d' -e 's/\([^\]\)\s*%.*/\1/g' $(BASE).tex $(intex) | \
- $(SED) -e '/\\begin{verbatim}/,/\\end{verbatim}/d' | \
- $(SED) -n -e 's/.*\(\\tableofcontents\)/\1/p' \
- )
-
-# \listoffigures命令をTeXファイルから検索する
-lof = \
- $(shell \
- $(SED) -e '/^\s*%/d' -e 's/\([^\]\)\s*%.*/\1/g' $(BASE).tex $(intex) | \
- $(SED) -e '/\\begin{verbatim}/,/\\end{verbatim}/d' | \
- $(SED) -n -e 's/.*\(\\listoffigures\)/\1/p' \
- )
-
-# \listoftables命令をTeXファイルから検索する
-lot = \
- $(shell \
- $(SED) -e '/^\s*%/d' -e 's/\([^\]\)\s*%.*/\1/g' $(BASE).tex $(intex) | \
- $(SED) -e '/\\begin{verbatim}/,/\\end{verbatim}/d' | \
- $(SED) -n -e 's/.*\(\\listoftables\)/\1/p' \
- )
-
-# \makeindex命令をTeXファイルから検索する
-makeindex = \
- $(shell \
- $(SED) -e '/^\s*%/d' -e 's/\([^\]\)\s*%.*/\1/g' $(BASE).tex $(intex) | \
- $(SED) -e '/\\begin{verbatim}/,/\\end{verbatim}/d' | \
- $(SED) -n -e 's/.*\(\\makeindex\)/\1/p' \
- )
-
-# \bibliography命令で読み込まれる文献データベースファイルをTeXファイルから検索する
-bibdb = \
- $(addsuffix .bib,$(basename $(strip $(shell \
- $(SED) -e '/^\s*%/d' -e 's/\([^\]\)\s*%.*/\1/g' $(BASE).tex $(intex) | \
- $(SED) -e '/\\begin{verbatim}/,/\\end{verbatim}/d' | \
- $(SED) -n -e 's/\\bibliography\(\[[^]]*\]\)\{0,1\}{[^}]*}/&\n/pg' | \
- $(SED) -n -e 's/.*{\([^}]*\)}$$/\1/p' | \
- $(SED) -e 's/,/ /g' \
- ))))
-
-# hyperrefパッケージ読み込みをTeXファイルから検索する
-hyperref = \
- $(shell \
- $(SED) -e '/^\s*%/d' -e 's/\([^\]\)\s*%.*/\1/g' $(BASE).tex $(intex) | \
- $(SED) -e '/\\begin{verbatim}/,/\\end{verbatim}/d' | \
- $(SED) -n -e 's/.*\(\\usepackage\(\[[^]]*\]\)\{0,1\}{hyperref}\)/\1/p'\
- )
-
-# $(BASE).texで使われるLaTeX中間ファイル
-INTERFILES = \
- $(strip \
- $(if $(toc),$(BASE).toc) \
- $(if $(lof),$(BASE).lof) \
- $(if $(lot),$(BASE).lot) \
- $(if $(makeindex),$(BASE).ind) \
- $(if $(bibdb),$(BASE).bbl) \
- $(if $(hyperref),$(BASE).out) \
- )
-
-INTERFILES_PREV = $(addsuffix _prev,$(INTERFILES))
-
-# \include命令で読み込まれるTeXファイル
-includetex = \
- $(strip $(addsuffix .tex,$(shell \
- $(SED) -e '/^\s*%/d' -e 's/\([^\]\)\s*%.*/\1/g' $(BASE).tex | \
- $(SED) -e '/\\begin{verbatim}/,/\\end{verbatim}/d' | \
- $(SED) -n -e 's/\\include\(\[[^]]*\]\)\{0,1\}{[^}]*}/&\n/pg' | \
- $(SED) -n -e 's/.*{\([^}]*\)}$$/\1/p' \
- )))
-
-# \input命令で読み込まれるTeXファイル
-define get_inputtex
- $(strip $(shell \
- $(SED) -e '/^\s*%/d' -e 's/\([^\]\)\s*%.*/\1/g' $1 | \
- $(SED) -e '/\\begin{verbatim}/,/\\end{verbatim}/d' | \
- $(SED) -n -e 's/\\input\(\[[^]]*\]\)\{0,1\}{[^}]*}/&\n/pg' | \
- $(SED) -n -e 's/.*{\([^}]*\)}$$/\1/p' \
+# .flsファイルから、INPUTファイルを取得。ただし、$TEXMFDISTのファイルを除く
+# 取得は、1回のmake実行につき1回だけ行われる
+INPUTFILES = $(INPUTFILESre)
+
+INPUTFILESre = $(eval INPUTFILES := \
+ $(sort $(filter-out $(BASE).tex $(BASE).aux, $(shell \
+ $(SED) -n -e 's/^INPUT \(.\{1,\}\)/\1/p' $(BASE).fls | \
+ $(GREP) -v `$(KPSEWHICH) -expand-var '$$TEXMFROOT'` \
+ ))))
+
+# .flsファイルから、OUTPUTファイルを取得。ただし、$TEXMFDISTのファイルを除く
+# 取得は、1回のmake実行につき1回だけ行われる
+OUTPUTFILES = $(OUTFILESre)
+
+OUTFILESre = $(eval OUTPUTFILES := \
+ $(sort $(filter-out $(BASE).aux $(BASE).dvi $(BASE).log,$(shell \
+ $(SED) -n -e 's/^OUTPUT \(.\{1,\}\)/\1/p' $(BASE).fls | \
+ $(GREP) -v `$(KPSEWHICH) -expand-var '$$TEXMFROOT'` \
+ ))))
+
+# $(BASE).texで読み込まれる中間ファイルを$(BASE).flsから取得する
+# .idxは、.indへ置換
+LATEXINTERFILES = \
+ $(sort $(subst .idx,.ind, \
+ $(filter $(addprefix $(BASE),$(LATEXINTEXT)),$(INPUTFILES) $(OUTPUTFILES)) \