makefile problems

This is a discussion on makefile problems within the C++ Programming forums, part of the General Programming Boards category; Hi,
I'm playing around with makefiles on Linux and I can't quite figure out what's wrong with this one:
Code:
...

You have a circular reference, and that's why make drops the target. This is in your makefile, although not explicitly:

Code:

debug : debug

It actually looks like this:

Code:

debug: $(DEBUG_PATH) $(DEBUG_PATH)/$(OBJS)

Remember, DEBUG_PATH=debug
Ditto for release.
You'll probably have to rename one of those...

Also, I've run into problems using directories as targets like that in makefiles under Windows. Seems whenever a file inside of that directory (but not subdirs) is modified, so is the directory. This made make always want to rebuild a fair portion of the project incorrectly.

Damn, I didn't even think of that... Thanks.
I also noticed another problem where I did cd debug on one line, then compiled on the next line, but I needed to do them on the same line (separated by a semicolon).
This works perfectly now:

BTW, since I'm not very experienced with writing makefiles, I'd like to know if the way I'm doing it here is the right way for making debug/release builds (i.e. two sections for each object file) or if there's a simpler way to do it that doesn't involve as much duplication?
I could imagine it getting very tedious and error prone to write it like this if you're working with a very large project with dozens or hundreds of files.

Having build variants in makefiles is generally tedious. The GNU autotools way is to have only one build target, and make the configure script set the necessary flags to switch between debug and release, then just run configure from different directories, i.e.

I don't think plain makefiles properly support this, although there are ways of passing variables from one target to another that may help you in streamlining the process a bit - look for Target-specific Variable Values in the make manual.

Other build systems have this stuff built in. Boost.Build, for example, has a feature called build variants which solves exactly the debug/release issue, as well as the single-threaded/multi-threaded and the static/dynamic linking issues, and probably some more.