Separating your files into different folders is a good choice. But you should also separate your source files from your header files. Your folder structure should look like this:
project-dir
+--Makefile
+--bin
+--docs
| +--API
+--include
| +--common
| | +--gt_types.h
| +--kernel
| | +--gt_kernel.h
...
+--src
| +--kernel
| | +--gt_kernel.cc
...
Your makefile should contain rules for compiling a .cc to .o, but in a general way (note the use of tabs):
$(OBJDIR)/%.o : %.cc
$(CXX) -c $(CPPFLAGS) $(CCFLAGS) -o $@ $<
The VPATH is used to tell make where to look for files that are on the right side of a rule, i.e. %.cc will match any file in the VPATH directory that ends in .cc.
Note that GNU make provides a better way than setting VPATH:
SOURCES += main.cc kernel/gt_kernel.ccSEARCH_DIRS = $(sort $(dir $(SOURCES)))vpath %.cc $(addprefix machine/$(TARGET)/$(SRCDIR)/, $(SEARCH_DIRS))vpath %.cc $(addprefix $(SRCDIR)/, $(SEARCH_DIRS))
A common problem when using VPATH are include files. As there are no default dependencies of your .cc files from the header files, you have to create them manually:
$(DEPDIR)/%.d: %.cc @set -e; rm -f $@; $(CXX) -MM $(CPPFLAGS) $< > $@.$$$$; sed 's,\($*\)\.o[ :]*,$(OBJDIR)/\1.o $(DEPDIR)/$@ : ,g' < $@.$$$$ > $@; echo -e "\t\$$(CXX) -c \$$(CPPFLAGS) \$$(CCFLAGS) -o \$$@ \$$<" >> $@; rm -f $@.$$$$
Then include the dependency in your Makefile (put this in the last line):
sinclude $(addprefix $(DEPDIR)/, $(addsuffix .d, $(sort $(basename $(notdir $(SOURCES))))))
Note that $(DEPDIR) is a variable that contains the directory to place dependency files, i.e. use "DEPDIR = dep".
Another option is to use qmake made by Trolltech.
http://www.trolltech.com/Just cd into your project directory and type:
qmake -project
qmake
make
The first line creates a .pro file.
The second line creates a Makefile.
The third one creates your application.