Mike Shal wrote:
On 4/16/07, Rick Flower <[EMAIL PROTECTED]> wrote:
I took a different approach and listed all of the possible paths in a
variable called "OBJDIRS" and wanted to write some makefile 'code' that
could pick out the only one that exists for the directory tree where
Make was invoked from.. Below is what I was trying but found that it
would only return a valid OBJDIR when the valid directory was at the end
of the list (IIRC) or other odd conditions:
OBJDIR =
OBJDIRS := \
../../${proc}/obj/${target) \
../../${target}/obj \
../../obj/${target}
First: note that you have "${target)" - you should probably use either
"${target}" or "$(target)", rather than mix and match your parens :).
Hmm.. Good catch.. I hadn't noticed that before.. I think that was one
of the problems I had..
find_files = $(if $(wildcard $(dir)),OBJDIR=${dir})
OBJDIR := $(foreach dir,$(OBJDIRS),$(find_files))
$(wildcard) already operates separately on each element in the list,
so you don't need to wrap it with a $(foreach) in this case. Also, you
wouldn't want OBJDIR= in the $(if) statement, since you aren't
actually executing statements there.
Anyway, this could probably be much simplified by just doing:
OBJDIR := $(firstword $(wildcard $(OBJDIRS)))
I tried that w/o the above fix for the typo in place and it didn't work
(nor did John's suggestion either).. Once I fixed the typo above to have
matching open/closing braces then it started working.. I wonder if this
could be caught during the parsing phase and have an error issued.. I
certainly didn't see it and it obviously had side effects..
The $(firstword) is used in case more than one directory exists - this
would just pick the first one. You probably also want to check if no
match was found and print an error, like:
ifeq (,$(OBJDIR))
$(error No directory found)
endif
Thanks.. I'll put that catch-all statement in as well.. Thanks again to
both Mike and John for quick answers!
-- Rick
_______________________________________________
Help-make mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-make