How to get makefile to depend on any files inside a folder

旧城冷巷雨未停 提交于 2019-12-11 08:10:57

问题


I have a simple makefile that I use to build some latex files. The syntax looks like this:

pdf: thesis.tex chapters/a.tex chapters/b.tex chapters/c.tex
    latexmk -pdf -pdflatex="pdflatex thesis.tex

open:
    open thesis.pdf

The files inside chapters folder can increase further with d.tex, e.tex and may even contain subfolders f\section1.tex, f\section2.tex etc.

I manually add all the requried tex files inside my thesis.tex like this which is not a problem.

\input{chapters/a.tex}
\input{chapters/b.tex}
\input{chapters/c.tex}
\input{chapters/d.tex}
\input{chapters/e.tex}
  1. How can I get make target pdf to depend upon any file changes inside chapters and its subdirectories?
  2. How do I write inter task dependency in makefile. If target open depends upon target pdf, how do I write it?

回答1:


open: pdf will sort-of do what you want for your second question.

Though it would be better to not use the phony pdf target for this.

Instead have a thesis.pdf: target which depends on the right prerequisites and have both pdf: thesis.pdf and open: thesis.pdf targets.

For the first question you can either use something like:

SRCS := $(shell find chapters -name '*.tex')

or use from here:

rwildcard=$(strip $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d)))

SRCS := $(call rwildcard,chapters,*.tex)

and then:

thesis.pdf: thesis.tex $(SRCS)

to use that variable as the prereq.

If you wanted to get even fancier you could write a script to pull out the actual filenames from the \input{} directives in thesis.tex and use that as your SRCS variable (but that's probably not worth the effort unless you know you will have other, unrelated, .tex files).



来源:https://stackoverflow.com/questions/26852692/how-to-get-makefile-to-depend-on-any-files-inside-a-folder

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!