makefile "strip" function not working

bash, makefile

Solution

The problem appears to be what `g++` generates with the `-M` option:

If there are many included files then the rule is split into several lines using ‘\’-newline

It appears as if `make`s `$(shell )` function removes the newlines, but the `\` characters stay in place, thus effectively escaping some of the extra whitespaces. If you add a rule like this:

echo:
    echo "$(DEP_LIST_FILTERED)"

and then `make echo`, you should see a list, something like this:

src.c /usr/include/c++/4.6/iostream \ /usr/include/c++/4.6/x86_64-linux-gnu/./bits/c++config.h \ /usr/include/c++/4.6/x86_64-linux-gnu/./bits/os_defines.h ...

So I think a possible fix here is simply to also filter-out the `\` strings:

DEP_LIST_FILTERED1 = $(filter-out \ , $(DEP_LIST_FILTERED))

echo1:
    echo "$(DEP_LIST_FILTERED1)"

Then `make echo1` displays I think what you want.

Problem

I want to define a variable in a makefile which should be a list of all the file dependencies in the project, separated by one space. I do this with: ``` DEP_LIST = $(shell g++ -M $(SRC_FILES) $(INC_DIRS)) ``` which outputs all of my project dependencies, e.g: ``` main.o: src/main.cpp /usr/include/stdc-predef.h /usr/include/c++/4.8/iostream /usr/include/x86_64-linux-gnu/c++/4.8/bits/c++config.h ... ``` I filter out the `xxx.o:` bits with ``` DEP_LIST_FILTERED = $(filter-out %.o:, $(DEP_LIST)) ``` which now outputs ``` src/main.cpp /usr/include/stdc-predef.h /usr/include/c++/4.8/iostream /usr/include/x86_64-linux-gnu/c++/4.8/bits/c++config.h ... ``` Looking good so far, now I just need to strip the double whitespace using: ``` DEP_LIST_STRIPPED = $(strip $(DEP_LIST_FILTERED)) ``` However this has no effect and the output is the same as previous. Presumably this has something to do with how my shell (bash) treats whitespace, but I can't find any info about it. Any ideas? EDIT: In case it's relevant, the reason I need to remove the double whitespace is that I want to pass the list to ctags in the form ``` ctags $(DEP_LIST_STRIPPED) -{options} ``` but in the current form it complains: ``` ctags: Warning: cannot open source file " /usr/include/c++/4.8/iostream" : No such file or directory ```

Original source