Re: .mak file for directory with source code in subdirectories

Henrik Carlqvist <[email protected]>
Newsgroups gmane.comp.gnu.utils
Organization SunSITE.dk - Supporting Open source
Message-ID <[email protected]>
"earthwormgaz" <[email protected]> wrote:
> So, I have my list of sources ...
> 
> SRCS = \
>   example/file.cpp
>   different/example/file.cpp

Lets make things simple, something like:

SRCS = $(wildcard *.cpp */*.cpp */*/*.cpp */*/*/*.cpp)
 
> I then have the following ...
> OBJS := $(patsubst %.cpp, $(BLD)/%.o, $(SRCS))

My guess is that you want to replace it with something like:

OBJS = $(patsubst %.cpp, $(BLD)/%.o, $(notdir $(SRCS)))

> In the example I copied this from, the files were all in the same
> subdirectory, and the author had used this trick ...
> 
> vpath %.cpp code/directory

So you could add all your directories as searchable with vpath, or
write one rule for each of your source directory that describes how to
make an .o file from a .cpp file.

One way to get the vpath right might be:

empty:=
space:= $(empty) $(empty)

vpath %.cpp $(subst $(space),:,$(sort $(dir $(SRCS))))

I haven't tried the above in any Makefile myself, but I think it should
work. If it still has some bug I hope that it at least will give you some
inspiration on how to fix your Makefile.

regards Henrik
-- 
The address in the header is only to prevent spam. My real address is:
hc8(at)uthyres.com Examples of addresses which go to spammers:
[email protected] root@localhost
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.