Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is dependency on a symlink possible in a Makefile?

I need a couple of symlinks in my project.

From src/openlayers, folders img and theme have to be symlinked in contrib/openlayers. The contrib/openlayers folder should also be created automatically.

.PHONY: run
run: contrib/openlayers/theme contrib/openlayers/img
   ../bin/pserve development.ini --reload

contrib/openlayers/theme:
    ln -s src/openlayers/theme $@

contrib/openlayers/img:
    ln -s src/openlayers/img $@

But this rule tries to create symlinks every time. (I put -f flag to ln, so it re-creates the symlinks every time.)

like image 731
culebrón Avatar asked Apr 16 '12 20:04

culebrón


People also ask

Can you symlink to another symlink?

In general, no. Technically, there will be a very slight performance hit for the indirection, but it won't be noticeable to your application. As an example, most shared libraries are symlinks to symlinks (e.g. libQtCore.so -> libQtCore. so.

Does du follow symlinks?

The -L option tells du to process symbolic links by using the file or directory which the symbolic link references, rather than the link itself.

Does symlink work both ways?

Symlinks can be bidirectional, if they are "hard" symlinks. However, in general symlinks are unidirectional, and the information about the link is only stored in the symlink itself.

Which command follows symlinks?

In order to follow symbolic links, you must specify ls -L or provide a trailing slash. For example, ls -L /etc and ls /etc/ both display the files in the directory that the /etc symbolic link points to. Other shell commands that have differences due to symbolic links are du, find, pax, rm and tar.


1 Answers

In case you ever you run into this problem in spite of your symlink pointing correctly to an existing file: also keep in mind that "make" looks at the mtime of the destination file of the symlink, and not at the mtime of the symbolic link itself.

Therefore, if the rule that calls "ln -s" has any dependency that is newer than the file your symbolic links points at, then "make" has to rerun the commands in that rule each time. It will do so again and again because creating a symlink that points to a file does not update the mtime of that file.

You may be able to use the "touch" command to ensure that the destination of your link has a more recent mtime than your dependency.

like image 109
Markus Kuhn Avatar answered Sep 23 '22 15:09

Markus Kuhn