Search current directory last when looking for dependencies using GNU make and VPATH

404 views Asked by At

This is a GNU Make dependency resolution issue.

My problem is that I copy the source files from a remote file server to a scratch disk (which speeds up the build process by 50%). If the file copy fails, I want to use the source files from the file server, else I want to read them from the scratch disk.

I have tried to use the vpath mechanism, but the problem is that, as far as I understand, make will by default start looking for the source files in the current directory and only if it fails to find the files there, look in the directories listed with vpath.

Is it possible to have make first look in the vpath directories before looking in the current directory? Or perhaps only look in the vpath directories (and explicitly and dynamically add the current directory to vpath)?

Only way I can think of is to temporary change directory so that make always will fail to find the source files.

1

There are 1 answers

0
Beta On

Look at the path to the source directory on the server. Suppose it's "/server/someplace/src/". And suppose you don't have a "src" directory in the current directory (if you do, we just have to tweak this method). Just make sure that the path to the source directory on the scratch disk ends in "/src/", such as "/scratch/wednesday/src/". Then you can do this:

SCRATCH_PATH = /scratch/wednesday/
SERVER_PATH = /server/someplace/

VPATH = $(SCRATCH_PATH) $(SERVER_PATH)

%.o: src/%.cc
    $(CC) blah blah blah