how to use not "also" symbolic link time, but "only"

View: New views
7 Messages — Rating Filter:   Alert me  

how to use not "also" symbolic link time, but "only"

by Mark Galeck (CW) :: Rate this Message:

| View Threaded | Show Only this Message

Hello,

If I have a target that is a soft symlink, the natural way to write the rule would be:

MAKEFILE := $(lastword $(MAKEFILE_LIST))

from: $(MAKEFILE)
        ln -sf to $@

Except it does not work, if Makefile changes and becomes newer than "to", "from" is rebuilt all the time.  I want to only consider the timestamp of the link file, not in addition to the timestamp of the linked file, but instead of.  

How to do this?  Clearly it has to depend on the Makefile, since if you change the rule to a different "to" file, the link must rebuild.  But that also causes it to always rebuild.

How to correctly write a rule for a symlink?  

Mark  


_______________________________________________
Help-make mailing list
Help-make@...
https://lists.gnu.org/mailman/listinfo/help-make

Re: how to use not "also" symbolic link time, but "only"

by Paul Smith-20 :: Rate this Message:

| View Threaded | Show Only this Message

On Fri, 2012-04-13 at 09:07 -0700, Mark Galeck (CW) wrote:
> from: $(MAKEFILE)
> ln -sf to $@
>
> Except it does not work, if Makefile changes and becomes newer than
> "to", "from" is rebuilt all the time.  I want to only consider the
> timestamp of the link file, not in addition to the timestamp of the
> linked file, but instead of.  

Your question is not very clear (to me).  However there is no way in GNU
make to consider only the timestamp of the symbolic link and ignore the
timestamp of the file the link points to.

Obviously you can "touch" the target file ("from") to bring it up to
date, then it will be newer than the makefile.  That's how any normal
target would work, without adding symlinks into the mix; the same
procedure works here.

I assume there's some reason you don't want to do that.



_______________________________________________
Help-make mailing list
Help-make@...
https://lists.gnu.org/mailman/listinfo/help-make

RE: how to use not "also" symbolic link time, but "only"

by Mark Galeck (CW) :: Rate this Message:

| View Threaded | Show Only this Message

>Your question is not very clear (to me).

I just want a way to correctly write a rule for a make target, that is a soft symlink.  It seems to me there is currently no way to do that.  If I (as I should) depend on the Makefile, then the target will always rebuild, which is not correct.  

>Obviously you can "touch" the target file ("from")

Of course not I can't :)   A file such as "from" is typically a version-controlled file, which is read-only, unless I need to change something, which I clearly don't, then I can check it out and edit it.  Cannot just go around the filesystem and touch source files because I want to.  

What I do want, is for make to create me a symlink, and I want to do it "correctly" by make standards, that means, rebuild the symlink only when necessary - when the name of the target changes (change to Makefile), or when the symlink does not exist.  

It seems to me this is a natural thing to do, and it seems to me there is no way to do it?

Mark


_______________________________________________
Help-make mailing list
Help-make@...
https://lists.gnu.org/mailman/listinfo/help-make

RE: how to use not "also" symbolic link time, but "only"

by Mark Galeck (CW) :: Rate this Message:

| View Threaded | Show Only this Message

>that means, rebuild the symlink only when necessary - when the name of the target changes (change to Makefile), or when the symlink does not exist.  

Or, when there is a forced rebuild "-B" - that's what the "-f" in ln -sf , is for.  


_______________________________________________
Help-make mailing list
Help-make@...
https://lists.gnu.org/mailman/listinfo/help-make

Re: how to use not "also" symbolic link time, but "only"

by Bryan Ischo-4 :: Rate this Message:

| View Threaded | Show Only this Message

On 04/13/12 09:47, Mark Galeck (CW) wrote:
> It seems to me this is a natural thing to do, and it seems to me there
> is no way to do it?

I think many people, myself included, avoid using symlinks for reasons
like this.  As unusual file system constructs with unusual usage
semantics, they tend to cause problems when they are used in any but the
most simple ways.  Not only that, they're highly non-portable.

I realize that doesn't help you if you absolutely need to create
symlinks using make for some reason, but I hope you might at least
consider whether or not managing symlinks is really a job you want to
leave to make, or even be doing at all as part of your build process.

I personally use commands like this sometimes:

from: $(MAKEFILE)
           ln -sf to $@ >/dev/null 2>&1

All this does is prevent me from seeing the unnecessary 'ln' command
executions, which has the disadvantage of hiding errors that could
legitimately occur, but at least I can forget about this little wart
rule and never be bothered by it again.

In my particular case, I have rules for creating directories on-demand,
and those rules were difficult to work in a way that didn't sometimes
'mkdir' a directory that already existed.  It was easier to just send
the mkdir output to null and never worry about it.  I am sure that
occasionally I am wasting some CPU by running a mkdir command, but it
would be impossible for me to perceive it since these commands run so fast.

Bryan


_______________________________________________
Help-make mailing list
Help-make@...
https://lists.gnu.org/mailman/listinfo/help-make

RE: how to use not "also" symbolic link time, but "only"

by Mark Galeck (CW) :: Rate this Message:

| View Threaded | Show Only this Message

Aha!  see-no-evil... :)

No, I am a completely anti- see-no-evil type person.  I'd rather see it.   The problem is of course, as you might have guessed it, is that I have a gazillion of links, not one, and in some situations the makefiles have -L flag enabled.  So you see where I am going with this....

At this point the best solution seems to be , put a comment in the makefile and in the manual, that "if you change the name of the target of the link", you must rebuild by hand.  In other words, drop "MAKEFILE" from the prerequisites.  People will look at this and will say "Mark I thought you can handle this".  

Yes some people say links are a wart, I am not a guru enough to judge such things, I am just a larval-stage wannabe...

Mark

>
from: $(MAKEFILE)
           ln -sf to $@ >/dev/null 2>&1


_______________________________________________
Help-make mailing list
Help-make@...
https://lists.gnu.org/mailman/listinfo/help-make

Re: how to use not "also" symbolic link time, but "only"

by Michael Ludwig-6 :: Rate this Message:

| View Threaded | Show Only this Message

Bryan Ischo schrieb am 13.04.2012 um 10:05 (-0700):

> In my particular case, I have rules for creating directories
> on-demand, and those rules were difficult to work in a way that
> didn't sometimes 'mkdir' a directory that already existed.

Not a problem using mkdir -p :

$ mkdir -p a/b/c
$ mkdir -p a/b/c
$ mkdir -p a/b/c

On Windows:

$ if not exist a\b\c md a\b\c
$ if not exist a\b\c md a\b\c
$ if not exist a\b\c md a\b\c

> It was easier to just send the mkdir output to null and never worry
> about it.

Maybe less clean, but effectively the same thing.
--
Michael Ludwig

_______________________________________________
Help-make mailing list
Help-make@...
https://lists.gnu.org/mailman/listinfo/help-make