Well, that was a much better way of doing things.
obj/%.o : obj/%.cpp
$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) -o obj/$*.o $@ $<
That seems to do exactly what I want it to do.
On 10/6/06, Lloyd Brown <[EMAIL PROTECTED]> wrote:
I'm certainly not a Makefile guru, but I don't think that you *have* to
do the trick with the include. I often use something like this to
create .o files from .c files, without having to list them individually:
> %.o: %.c $(HEADERFILES)
> $(CC) $(FLAGS) -c -o $@ $<
Unfortunately, it has been long enough, I'm not *entirely* sure what all
these placeholders mean, but I do know this syntax works. For example,
if I write a file and save it as "test.c", I can immediately type "make
test.o", and it will try to compile. I don't have to modify the
Makefile at all. The only thing is that I usually put the .c, the .h,
and the .o files all in the same directory; my projects are still pretty
small.
I guess what I'm saying is that something like this might work for you:
> obj/%.o: src/%.cpp
> $(CPP) $(FLAGS) -c -o $@ $<
You'll probably then just have to use the "obj/somefile.o" as the target
instead of just "somefile.o".
I hope that I both understood the question, and that this helps. If
not, let the list know, and we can try again. Let us know if it works
too.
Thanks, and good luck,
Lloyd Brown
Daniel Dilts wrote:
> Given a directory ./src that has an arbitrary number of .cpp files, and
a
> directory ./obj that will contain the object files, I am trying to
create a
> Makefile that will automatically create all of the .o files, regardless
of
> what files are added/removed from ./src.
>
> My thought is to use an included Makefile that has the rules to create
each
> of the .o files.
>
> To create the .o files I use g++ -MM src/*cpp > Makefile.obj to create
the
> included file.
>
> My Makefile looks like this:
>
> target : ...
>
> Makefile.obj : dummy
> g++ -MM src/*cpp > Makefile.obj
>
> .PHONY : dummy
> dummy :
> -@ ls > /dev/null 2> /dev/null
>
> include Makefile.obj
>
>
>
> I'm trying to make sure that Makefile.obj is recreated each time that
make
> is run. The dummy target is the only way I can think of making sure
that
> the Makefile.obj target is always run, but this seems like a really bad
way
> of doing this. The problem (not a big deal in this case) is that the
> Makefile.obj target gets run 2-3 times.
>
> Also, on a sidenote, this creates a file with the format:
> file.o: file.cpp ...
>
> I'm also trying to figure out how to prepend "obj/" to each line in the
> file.
> --------------------
> BYU Unix Users Group http://uug.byu.edu/
> The opinions expressed in this message are the responsibility of their
> author. They are not endorsed by BYU, the BYU CS Department or BYU-UUG.
> ___________________________________________________________________
> List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list
>
>
>
--------------------
BYU Unix Users Group
http://uug.byu.edu/
The opinions expressed in this message are the responsibility of their
author. They are not endorsed by BYU, the BYU CS Department or BYU-UUG.
___________________________________________________________________
List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list
--------------------
BYU Unix Users Group
http://uug.byu.edu/
The opinions expressed in this message are the responsibility of their
author. They are not endorsed by BYU, the BYU CS Department or BYU-UUG.
___________________________________________________________________
List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list