Reputation: 2143
I have a problem where I want to create a variable that looks like this,
INCDIRS = -I dir0 -I dir1 -Idir2 -I dir3 ... -I dirN
where dir1, ... , dirN are the names of all the subdirectories some base directory, base_dir.
How would I go about building up this variable? Originally, I thought I could do the following,
INCDIRS = $(shell for x in `find base_dir -type -d -print`; do echo -I $x; done;)
but this just results in
INCDIRS = -I -I -I -I ... -I
If anyone could explain how to do this, or explain why my original command got the output that it did, I would greatly appreciate it. Thanks!
Upvotes: 1
Views: 129
Reputation: 15582
You could first get the list of directories, then add -I in front of each one:
SOURCE_DIRS := $(shell find base_dir -type d -print)
INCDIRS = $(addprefix -I,$(SOURCE_DIRS))
which may be better if you need $(SOURCE_DIRS) for something else.
Upvotes: 2
Reputation: 33126
You have two errors in your INCDIRS
assignment. One is in the find
command. It should be find -type d -print
(or just find -type d
; the -print
is superfluous here). The other error the use of $x
. You need to escape the $
with another $
:
INCDIRS = $(shell for x in `find base_dir -type d -print`; do echo -I $$x; done;)
Upvotes: 2