I have the following directory structure
project
|-- Makefile
|-- data
|-- report.tex
|-- plot_1.eps
One of the rules in the Makefile
executes latex data/report.tex
. As the working directory is project
, I'm getting report.dvi and other output files there only. How do I get those in ./data
?
Also, I've included plot_1.eps
in the report. But still its expecting the path data/plot_1.eps
. Do we need to give the file path relative to the current working directory from where latex
is executed? Or location of report.tex
?
In the Makefile
, I tried
reportdvi: outputparser
cd data
latex report.tex
cd ..
But this didn't change the working directory and the problem persists. What to do?
You can use shell function: current_dir = $(shell pwd) . Or shell in combination with notdir , if you need not absolute path: current_dir = $(notdir $(shell pwd)) .
This makefile should be located in the src directory. Note that it also includes a rule for cleaning up your source and object directories if you type make clean. The . PHONY rule keeps make from doing something with a file named clean.
Windows current directoryWhile in Windows Explorer, the current working directory is shown at the top of the Explorer window in a file address bar. For example, if you were in the System32 folder, you would see "C:\Windows\System32" or "Computer > C:>Windows\System32" depending on your version of Windows.
That's what abspath does. It creates an absolute path. That means it must be anchored at the root.
It's a common 'gotcha' in makefiles. Each command is executed in its own shell, so "cd" only happens within that shell, but subsequent command is run again from make's current directory.
What you want to do is to either put all commands on one line (and you don't need "cd .."):
cd data && latex report.tex
or use \
at the end of the line to tell make to concatenate the lines and pass them all to the shell. Note that you still need ;
or &&
to separate commands.
cd data && \
latex report.tex
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With