Hi Folks -
I'm trying to rework the windows build structure and I'm running into a problem with make. Basically, what I'm trying to do is to test whether a file exists in a given location and if so, copy it, and if not, copy a default from elsewhere. This should look like here:
foo.here: if $(file-exists locationA/foo.locA) cp locationA/foo.locA foo.here else cp locationB/foo.locB foo.here endif
I think you get the idea. My problem is that I can't seem to find a reliable way of expressing the line
if $(file-exists locationA/foo.locA)
in any reasonable way (i.e., by using make's functions). Any ideas how to convince make to determine whether the file exists or not?
Thanks, - Andreas
Andreas Raab schrieb:
Hi Folks -
I'm trying to rework the windows build structure and I'm running into a problem with make. Basically, what I'm trying to do is to test whether a file exists in a given location and if so, copy it, and if not, copy a default from elsewhere. This should look like here:
foo.here: if $(file-exists locationA/foo.locA) cp locationA/foo.locA foo.here else cp locationB/foo.locB foo.here endif
I think you get the idea. My problem is that I can't seem to find a reliable way of expressing the line
if $(file-exists locationA/foo.locA)
in any reasonable way (i.e., by using make's functions). Any ideas how to convince make to determine whether the file exists or not?
I think you have to use the $(wildcard ...) function to test for file existence.
Alternatively, you could specify a vpath (http://www.gnu.org/software/make/manual/html_node/Directory-Search.html)
- Bert -
Bert Freudenberg wrote:
I think you get the idea. My problem is that I can't seem to find a reliable way of expressing the line
if $(file-exists locationA/foo.locA)
in any reasonable way (i.e., by using make's functions). Any ideas how to convince make to determine whether the file exists or not?
I think you have to use the $(wildcard ...) function to test for file existence.
That's what I tried but I couldn't get it to work. It seems that no variation of
ifneq (,$(wildcard locationA/foo.locA)) @echo foo.locA exists else @echo foo.locA does NOT exist endif
works properly due to the way the "failure" case needs to be specified (i.e., the result of the $wildcard function is not just "empty").
Alternatively, you could specify a vpath (http://www.gnu.org/software/make/manual/html_node/Directory-Search.html)
Tried that, too, but there is a real problm if foo.locA exists in multiple places (and it's hard to rule out that it exists *somewhere* in the search path). If it does, it will be picked up not only from locationA but possibly also from some other locations.
Cheers, - Andreas
On Mon, Sep 04, 2006 at 07:58:01PM -0700, Andreas Raab wrote:
I'm trying to rework the windows build structure and I'm running into a problem with make. Basically, what I'm trying to do is to test whether a file exists in a given location and if so, copy it, and if not, copy a default from elsewhere. This should look like here:
foo.here: if $(file-exists locationA/foo.locA) cp locationA/foo.locA foo.here else cp locationB/foo.locB foo.here endif
If the tool chain is using bash, or if there is a /bin/test available, then the following should work:
FOO-AT-A=locationA/foo.locA FOO-AT-B=locationB/foo.locB foo.here: if test -r $(FOO-AT-A) ; \ then \ cp "$(FOO-AT-A)" $@; \ else \ cp "$(FOO-AT-B)" $@; \ fi
Dave
vm-dev@lists.squeakfoundation.org