Sha*_*wat 12 makefile working-directory
我有以下目录结构
project
|-- Makefile
|-- data
|-- report.tex
|-- plot_1.eps
Run Code Online (Sandbox Code Playgroud)
Makefile执行中的一条规则latex data/report.tex.作为工作目录project,我只在那里获得report.dvi和其他输出文件.我如何获得这些./data?
另外,我已将其纳入plot_1.eps报告中.但仍然期待着这条道路data/plot_1.eps.我们是否需要从latex执行的位置提供相对于当前工作目录的文件路径?还是位置report.tex?
在Makefile,我试过
reportdvi: outputparser
cd data
latex report.tex
cd ..
Run Code Online (Sandbox Code Playgroud)
但这并未改变工作目录,问题仍然存在.该怎么办?
Art*_*emB 26
这是makefile中常见的"陷阱".每个命令都在自己的shell中执行,因此"cd"仅在该shell中发生,但后续命令再次从make的当前目录运行.
你想要做的是将所有命令放在一行(你不需要"cd .."):
cd data && latex report.tex
Run Code Online (Sandbox Code Playgroud)
或者\在行尾使用告诉make连接行并将它们全部传递给shell.请注意,您仍然需要;或&&分离命令.
cd data && \
latex report.tex
Run Code Online (Sandbox Code Playgroud)