Subject: Re: unique id for makefile target
To: None <netbsd-users@netbsd.org>
From: Christos Zoulas <christos@astron.com>
List: netbsd-users
Date: 01/27/2007 00:44:52
In article <20070126192538.GI21722@run.galis.org>,
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.
>
>Is the desired effect possible in a makefile target???
>

use the same shell:

newconf :
	@(touch /tmp/$@-$$$$; \
	.... files to change /etc ...; \
	echo "The following files have been changed..."; \
	find /etc -newer /tmp/$@-$$$$; \
	rm /tmp/$@-$$$$;)

christos