make ".if exists" problem/question

M. Warner Losh imp at bsdimp.com
Fri Aug 26 05:55:22 GMT 2005


Yes.  The thing to keep in mind is that much of the .if stuff is done
at parsing or rule construction time.  So if you change something
(creating a file, say), then that condition won't be re-evaluated.

For the specific example given, one could replace much of the goo
with:

target: foobar

foobar:
	touch foobar

if you wanted to create foobar.  Otherwise, I'd be tempted not to use
.if exists.  I'd be tempted to do something more like:

target:
	@-if [ -f foobar ]; then cat foobar; else touch foobar; fi

where you have the shell check.

The primary use of exists() I've seen is:

.if exists(foo.mk)
.include "foo.mk"
.endif

although I have seen others.

Warner


More information about the freebsd-current mailing list