X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=latex_mk%2Flatex.mk;h=f97a273e0a0e2b7faf9e893f970767b00f977973;hb=13d64ebc5aba7b14c904495c4a8edf9e18315bf3;hp=19b15ad905f64e807ff96a60cb581e9236b76655;hpb=977ca41b2356288f6d8d8dbbee0c0f39e276f45c;p=makefiles.git diff --git a/latex_mk/latex.mk b/latex_mk/latex.mk index 19b15ad..f97a273 100644 --- a/latex_mk/latex.mk +++ b/latex_mk/latex.mk @@ -29,6 +29,10 @@ # all: $(TEXTARGETS) # # include latex.mk + +#debug +#SHELL = /bin/sh -x + .PHONY: tex-warning tex-clean tex-distclean # シェルコマンド @@ -46,6 +50,7 @@ DVIPDFMX := dvipdfmx EXTRACTBB := extractbb BIBTEX := pbibtex MENDEX := mendex +KPSEWHICH := kpsewhich #LaTeXオプション LATEXFLAG ?= @@ -68,7 +73,7 @@ BASE = $(basename $<) # .out: hyperrefパッケージ # .toc: 目次(\tableofcontents) # .log: ログ -TEX_INT := .aux .fls .lof .lot .out .toc .log +TEX_INT := .aux .lof .lot .out .toc .log # 索引中間ファイルの拡張子 # .idx: auxから作成 # .ind: idxから作成 @@ -79,110 +84,73 @@ IND_INT := .idx .ind .ilg # .blg: BiBTeXログ BIB_INT := .bbl .blg -ALL_INTERFILES = $(addprefix *,$(TEX_INT) $(IND_INT) $(BIB_INT) .d .*_prev) +ALL_INTERFILES = $(addprefix *,$(TEX_INT) $(IND_INT) $(BIB_INT) .fls .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' \ - ) +# ファイル名から拡張子を除いた部分 +BASE = $(basename $<) -# \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' \ - ) +# .flsファイルから、INPUT/OUTPUTファイルを取得。ただし、$TEXMFDISTのファイルを除く +IOFILES = \ + $(sort $(filter-out $(BASE).tex $(BASE).aux, \ + $(shell \ + $(SED) -n -e 's/^\(INPUT\|OUTPUT\) \(.\{1,\}\)/\2/gp' $(BASE).fls | \ + $(GREP) -v `$(KPSEWHICH) -expand-var '$$TEXMFROOT'` \ + ))) -# \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' \ +# .flsファイルから、INPUTファイルを取得。ただし、$TEXMFDISTのファイルを除く +INPUTFILES = \ + $(sort $(filter-out $(BASE).tex $(BASE).aux, \ + $(shell \ + $(SED) -n -e 's/^INPUT \(.\{1,\}\)/\1/gp' $(BASE).fls | \ + $(GREP) -v `$(KPSEWHICH) -expand-var '$$TEXMFROOT'` \ + ))) + +# $(BASE).texで使われるLaTeX中間ファイル +INTERFILES = \ + $(sort \ + $(subst .idx,.ind, \ + $(filter $(addprefix $(BASE),.lof .lot .out .toc .idx .ind .bbl),$(IOFILES)) \ + )) + +INTERFILES_PREV = $(addsuffix _prev,$(INTERFILES)) + +# TeXファイル - .tex +TEXFILES = $(filter %.tex,$(INPUTFILES)) + +# 画像ファイル - .pdf、.eps、.jpg/jpeg、.png、および.xbb +GRAPHICFILES = \ + $(sort \ + $(shell \ + $(SED) -e '/^\s*%/d' -e 's/\([^\]\)\s*%.*/\1/g' $(BASE).tex $(TEXFILES) | \ + $(SED) -e '/\\begin{verbatim}/,/\\end{verbatim}/d' | \ + $(SED) -n -e 's/\\includegraphics\(\[[^]]*\]\)\{0,1\}{[^}]*}/&\n/pg' | \ + $(SED) -n -e 's/.*{\([^}]*\)}$$/\1/p' \ + ) \ + $(filter %.pdf %.eps %.jpeg %.jpg %.png %.bmp,$(INPUTFILES)) \ ) +# そのほかの読み込みファイル +OTHERFILES = $(filter-out %.aux $(INTERFILES) $(TEXFILES) $(GRAPHICFILES),$(INPUTFILES)) + # \bibliography命令で読み込まれる文献データベースファイルをTeXファイルから検索する bibdb = \ - $(addsuffix .bib,$(basename $(strip $(shell \ - $(SED) -e '/^\s*%/d' -e 's/\([^\]\)\s*%.*/\1/g' $(BASE).tex $(intex) | \ + $(addsuffix .bib,$(basename $(sort $(shell \ + $(SED) -e '/^\s*%/d' -e 's/\([^\]\)\s*%.*/\1/g' $(BASE).tex $(TEXFILES) | \ $(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' \ - )) -endef - -inputtex = $(call get_inputtex,$(BASE).tex $(includetex)) - -# \include命令または\input命令で読み込まれるTeXファイル -intex = $(strip $(includetex) $(inputtex)) - -# \includegraphics命令で読み込まれるグラフィックファイル -ingraphics = \ - $(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/\\includegraphics\(\[[^]]*\]\)\{0,1\}{[^}]*}/&\n/pg' | \ - $(SED) -n -e 's/.*{\([^}]*\)}$$/\1/p' \ - )) - # LaTeX処理(コンパイル) LATEXCMD = $(LATEX) -interaction=batchmode $(LATEXFLAG) $(BASE).tex COMPILE.tex = $(ECHO) $(LATEXCMD); $(LATEXCMD) >/dev/null 2>&1 || ($(CAT) $(BASE).log; exit 1) +FLSCMD = $(LATEX) -interaction=nonstopmode -recorder $(BASE).tex +CREATE.fls = $(ECHO) $(FLSCMD); $(FLSCMD) 1>/dev/null 2>&1; $(RM) $(addprefix $(BASE),$(TEX_INT) $(IND_INT) $(BIB_INT) .dvi) + # 相互参照未定義の警告 WARN_UNDEFREF := 'There were undefined references\.' @@ -216,47 +184,54 @@ COMPILE.bib = $(ECHO) $(BIBTEXCMD); $(BIBTEXCMD) >/dev/null 2>&1 || ($(CAT) $(BA CMPPREV = $(CMP) $@ $< || $(CP) -p -v $< $@ # 依存関係を.dファイルに書き出す -%.d: %.tex - @$(ECHO) '$@ is created by scanning $<.' -# .dファイルの依存関係 - @$(ECHO) '$(BASE).d: $(BASE).tex' >$@ -# 中間ファイルの依存関係 - $(if $(INTERFILES),@( \ +%.d: %.fls_prev + @$(ECHO) '$@ is created by scanning $(subst _prev,,$^).' + # .dファイルの依存関係 + @$(ECHO) '$(BASE).d: $(BASE).fls_prev' >$@ + # \includeまたは\input命令で読み込まれるTeXファイルの依存関係 + $(if $(TEXFILES),@( \ $(ECHO); \ - $(ECHO) '# LaTeX Intermediate Files'; \ - $(ECHO) '$(BASE).dvi:: $(INTERFILES_PREV)'; \ - $(ECHO) ' @$$(COMPILE.tex)'; \ + $(ECHO) '# Files called from \include or \input - .tex'; \ + $(ECHO) '$(BASE).aux: $(TEXFILES)'; \ + ) >>$@) + # そのほかのファイル(TEXMFROOT以外にあるスタイルファイルなど)の依存関係 + $(if $(OTHERFILES),@( \ $(ECHO); \ - $(ECHO) '$(BASE).dvi:: $(BASE).aux'; \ - $(ECHO) ' @$$(COMPILES.tex)'; \ + $(ECHO) '# Files other'; \ + $(ECHO) '$(BASE).aux: $(OTHERFILES)'; \ ) >>$@) -# 画像ファイルの依存関係 - $(if $(ingraphics),@( \ + # 画像ファイルの依存関係 + $(if $(GRAPHICFILES),@( \ $(ECHO); \ $(ECHO) '# IncludeGraphic Files - .pdf, .eps, .jpeg/.jpg, .png'; \ $(ECHO) '# .xbb Files - .pdf, .jpeg/.jpg, .png'; \ - $(ECHO) '$(BASE).aux: $(ingraphics)'; \ - $(if $(filter-out %.eps,$(ingraphics)), \ + $(ECHO) '$(BASE).aux: $(GRAPHICFILES)'; \ + $(if $(filter-out %.eps,$(GRAPHICFILES)), \ $(ECHO); \ - $(ECHO) '$(BASE).aux: $(addsuffix .xbb,$(basename $(filter-out %.eps,$(ingraphics))))'; \ + $(ECHO) '$(BASE).aux: $(addsuffix .xbb,$(basename $(filter-out %.eps,$(GRAPHICFILES))))'; \ ) \ ) >>$@) - $(if $(intex),@( \ - $(ECHO); \ - $(ECHO) '# Files called from \include or \input - .tex'; \ - $(ECHO) '$(BASE).aux: $(intex)'; \ - ) >>$@) -# 文献処理用ファイルの依存関係 + # 文献処理用ファイルの依存関係 $(if $(bibdb),@( \ + $(ECHO); \ + $(ECHO) '# Bibliography files: .aux, BIBDB -> .bbl -> .div'; \ + $(ECHO) '$(BASE).bbl: $(bibdb) $(BASE).tex'; \ + ) >>$@) + # 中間ファイルの依存関係 + $(if $(strip $(INTERFILES) $(bibdb)),@( \ + $(ECHO); \ + $(ECHO) '# LaTeX Intermediate Files'; \ + $(ECHO) '$(BASE).dvi:: $(sort $(INTERFILES_PREV) $(if $(bibdb),$(BASE).bbl_prev))'; \ + $(ECHO) ' @$$(COMPILE.tex)'; \ $(ECHO); \ - $(ECHO) '# Bibliography files: .aux, BIBDB -> .bbl -> .div'; \ - $(ECHO) '$(BASE).bbl: $(bibdb) $(BASE).tex'; \ + $(ECHO) '$(BASE).dvi:: $(BASE).aux'; \ + $(ECHO) ' @$$(COMPILES.tex)'; \ ) >>$@) # 変数TEXTARGETSで指定されたターゲットファイルに対応する # .dファイルをインクルードし、依存関係を取得する # ターゲット末尾に clean、.xbb、.tex、.d が含まれている場合は除く -ifeq (,$(filter %clean %.xbb %.tex %.d,$(MAKECMDGOALS))) +ifeq (,$(filter %clean %.xbb %.tex %.d %.fls %.fls_prev,$(MAKECMDGOALS))) -include $(addsuffix .d,$(basename $(TEXTARGETS))) endif @@ -277,6 +252,9 @@ endif # バウンディング情報ファイル作成 # pdf、jpeg/jpg、pngファイルに対応 +extractbb: + $(MAKE) -s $(addsuffix .xbb,$(basename $(wildcard $(addprefix *,.pdf .jpg .jpeg .png)))) + %.xbb: %.pdf $(EXTRACTBB) $(EXTRACTBBFLAGS) $< @@ -289,6 +267,13 @@ endif %.xbb: %.png $(EXTRACTBB) $(EXTRACTBBFLAGS) $< +# ファイル一覧作成 +%.fls: %.tex + @-$(CREATE.fls) + +%.fls_prev: %.fls + @$(CMPPREV) + # 目次中間ファイル作成 %.toc: %.tex @$(MAKE) -s $(BASE).aux