Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

using `notdir' inside a loop in a makefile

308 views
Skip to first unread message

Jeff Williams

unread,
Apr 3, 2000, 3:00:00 AM4/3/00
to dj...@delorie.com
Would someone please explain why the following makefile fragment
doesn't behave as expected? Something about using `notdir' inside
the `for' loop isn't working as desired.

subdirs = ./dir1/foo.1 ./dir2/bar.2
test:
for k in $(subdirs) ; do \
echo $$k ; \
echo $(notdir $$k) ; \
done

Here's the output I get:

% make test
for k in ./dir1/foo.1 ./dir2/bar.2 ; do \
echo $k ; \
echo $k ; \
done

/dir1/foo.1
/dir1/foo.1
/dir2/bar.2
/dir2/bar.2

but the output I *want* is

/dir1/foo.1
foo.1
/dir2/bar.2
bar.2

TIA---jtw


Eli Zaretskii

unread,
Apr 3, 2000, 3:00:00 AM4/3/00
to
Jeff Williams wrote:
>
> Would someone please explain why the following makefile fragment
> doesn't behave as expected? Something about using `notdir' inside
> the `for' loop isn't working as desired.
>
> subdirs = ./dir1/foo.1 ./dir2/bar.2
> test:
> for k in $(subdirs) ; do \
> echo $$k ; \
> echo $(notdir $$k) ; \
> done

There's no way this is going to work, because $(notdir) is a Make function,
while $$k is only expanded when the shell is run by Make. So when Make comes
to expand $(notdir), it sees $$k as its argument, and that expands to itself
(since it has no leading directories).

You want to use `basename $$k` instead.

0 new messages