recursive wildcard target in makefile

C

crimaniak

Hi all!

I have .cpp sources in c/ directory of project and want to
generate .dep files for every .cpp in temp/ directory.

For example:
c/tester.cpp produced temp/tester.dep
c/lib1/file.cpp produced temp/lib1/file.dep
and so on.

makefile in c/ directory

I can collect names to generate:

CPP_SOURCES = $(wildcard *.cpp */*.cpp */*/*.cpp */*/*/*.cpp)
DEPS = $(patsubst %,../temp/%,$(patsubst %.cpp,%.dep, $(CPP_SOURCES)))

But I can't write rule for this case. Here is first variant I write:

%.dep: ../c/%.cpp
g++ -MM -MF $@ $(INCLUDES) $<
g++ -MM -MT $@ $(INCLUDES) $< >> $@

But this case valid only for c/*.cpp and not valid for any
subdirectory like c/lib1/*.cpp. I want to make something like this:

%.dep: $(patsubst ../temp/%,./%, $%*.cpp)

How to write it right? temp/lib1/file.dep must depends on c/lib1/
file.cpp and so on.
 
R

red floyd

Hi all!

I have .cpp sources in c/ directory of project and want to
generate .dep files for every .cpp in temp/ directory.

For example:
c/tester.cpp produced temp/tester.dep
c/lib1/file.cpp produced temp/lib1/file.dep
and so on.

makefile in c/ directory

I can collect names to generate:

CPP_SOURCES = $(wildcard *.cpp */*.cpp */*/*.cpp */*/*/*.cpp)
DEPS = $(patsubst %,../temp/%,$(patsubst %.cpp,%.dep, $(CPP_SOURCES)))

But I can't write rule for this case. Here is first variant I write:

%.dep: ../c/%.cpp
        g++ -MM -MF $@ $(INCLUDES) $<
        g++ -MM -MT $@ $(INCLUDES) $< >> $@

But this case valid only for c/*.cpp and not valid for any
subdirectory like c/lib1/*.cpp. I want to make something like this:

%.dep: $(patsubst ../temp/%,./%, $%*.cpp)

How to write it right? temp/lib1/file.dep must depends on c/lib1/
file.cpp and so on.

Off topic. You question applies to a specific toolset, not the C++
language. Makefiles
are not part of the language.

I'd try either comp.unix.programer or gnu.g++.help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top