Subject: Re: unique id for makefile target
To: George Georgalis <george@galis.org>
From: Steven M. Bellovin <smb@cs.columbia.edu>
List: netbsd-users
Date: 01/26/2007 14:47:15
On Fri, 26 Jan 2007 14:25:38 -0500
"George Georgalis" <george@galis.org> wrote:

> I'm developing a makefile target that does some
> administrative tasks.  Some targets modify /etc
> files. I'd like to generate a unique id when I make
> the target, so on it's completion, we can check for
> any files that have changed.
> 
> If this was shell, I'd use something like
> 
>  	lock=/tmp/${0}-$$ ; [ -e "$lock"] || touch $lock
> 
> but in a makefile target, a new shell is spawned for
> each line and $$ changes. the goal here is something like
> 
> newconf :
> 	touch /tmp/$@-$$$$
> 	.... files to change /etc ...
> 	@echo "The following files have been changed..."
> 	@find /etc -newer /tmp/$@-$$$$
> 	rm /tmp/$@-$$$$
> 
> but that won't work because $$$$ is different on
> each line. I could make a macro that uses "date +%s"
> but that would be expanded (to a new time) on each
> reference and a day-of-the-week id would be exposed
> to a race condition, and other problems if run near
> midnight.
> 

This seems to work:

FILE!=date +%s.$$$$

foo:
        echo $(FILE)
        echo $(FILE)



		--Steve Bellovin, http://www.cs.columbia.edu/~smb