Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Current working directory of makefile

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?

like image 814
Shashwat Avatar asked Nov 14 '13 18:11

Shashwat


People also ask

How do I get the current working directory in makefile?

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)) .

Where is the makefile located?

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.

How do I find the working directory?

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.

What is Abspath in makefile?

That's what abspath does. It creates an absolute path. That means it must be anchored at the root.


1 Answers

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
like image 141
ArtemB Avatar answered Sep 23 '22 16:09

ArtemB