Is dependency on a symlink possible in a Makefile?

gnu-make, makefile, symlink

Solution

Sure, this can work. Make treats everything like a file, including a symlink. It will check if the file exists (since you don't list any prerequisites, there is no timestamp comparison). In the case of a symlink it's really checking whatever the link points to, of course, not the link itself.

You don't show what happens when you do this but based on your description one of two things is happening: either (a) the contrib/openlayers directory doesn't exist so the ln command is generating an error and not creating the symlink so of course make will try to recreate it the next time it runs, or (b) your symlink is being created incorrectly and pointing to nothing, which means when make tries to see if it exists it fails and make will try to recreate it.

If, for example, your `src` directory is a sibling of your `contrib` directory, then your symlinks are just wrong; you'll get:

contrib/openlayers/theme -> src/openlayers/theme

Or, when the kernel tries to resolve it:

contrib/openlayers/src/openlayers/theme

It's highly unlikely that's what you want. I suggest you use something like this:

contrib/openlayers/theme:
        mkdir -p contrib/openlayers
        ln -s ../../src/openlayers/theme contrib/openlayers/theme

Then verify that the symlink, once created, actually points where you want it to go.

Problem

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

Original source

Related problems