help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question about use of $(wildcard) and $(foreach)


From: Mike Shal
Subject: Re: Question about use of $(wildcard) and $(foreach)
Date: Mon, 16 Apr 2007 15:46:22 -0400

On 4/16/07, Rick Flower <address@hidden> 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 :).


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)))

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

Hope this helps,

-Mike




reply via email to

[Prev in Thread] Current Thread [Next in Thread]