Subject: Re: unique id for makefile target
To: None <netbsd-users@NetBSD.org>
From: George Georgalis <george@galis.org>
List: netbsd-users
Date: 01/26/2007 16:47:27
On Fri, Jan 26, 2007 at 02:47:15PM -0500, Steven M. Bellovin wrote:
>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)
>

that's it! thanks!

// George


-- 
George Georgalis, systems architect, administrator <IXOYE><