0

I need to create links for multiple directories in a Makefile.

The links (for all files in ./topdir/) should go from ./anotherdir/<file> to ./topdir/<file>.

I tried:

create-links: ./topdir/*/
    @for f in $^; do  \
        echo "this is my path: [$${f}]" && \
        DIR=$(shell basename $${f}) && \
        echo "make link from ./anotherdir/$(DIR)" ;\
    done

There are those files in ./topdir

dir1
dir2
file1
file2

f gets assigned correctly with both dirs and their relative path (e.g. ./topdir/dir1).

I only need the dirname without the path. This is what basename should do.

But DIR is always empty. Why?

1 Answer 1

1

$(shell basename $${f}) is processed by Make before it runs the recipe; it isn’t handled in the loop. You need to run everything using the shell:

    @for f in $^; do  \
        echo "this is my path: [$${f}]" && \
        DIR=$$(basename $${f}) && \
        echo "make link from ./anotherdir/$(DIR)" ;\
    done

or

    @for f in $^; do  \
        echo "this is my path: [$${f}]" && \
        DIR=$${f##*/} && \
        echo "make link from ./anotherdir/$(DIR)" ;\
    done
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .