title: Makefile: dynamic source file names and object directory
body: <p>Im currently trying to improve the makefile im using to build my c++ project using the sfml-framework. The folder structure of my project currently looks like this:</p>
  
  <ul>
  <li>Src/Header for Header Files</li>
  <li>Src/Source for .cpp Files</li>
  <li>Bin/ for the .exe</li>
  <li>Lib/ for the sfml library</li>
  </ul>
  
  <p>My current makefile:</p>
  
  <pre><code>CC  = g++ -g    
  
  SRC = Src/Source/  
  
  BIN = Bin/    
  
  INC = -I Lib/SFML/include/ -I Src/Header/    
  
  LIB = -L Lib/SFML/lib/ -lsfml-graphics-d -lsfml-window-d -lsfml-system-d
  
  EXE = Test     
  
  SOURCEFILES = $(SRC)Main.cpp $(SRC)Menu.cpp $(SRC)Button.cpp
  
  OBJ = $(SOURCEFILES:.cpp=.o)
  
  all: $(SOURCEFILES) $(EXE)
  
  $(EXE) : $(OBJ)
      $(CC) -o $(BIN)$(EXE).exe $(OBJ) $(LIB)
  
  .cpp.o:
      $(CC) -c $&lt; $(INC) -o $@
  </code></pre>
  
  <p>This makefile works fine, however there are a few things i would like to improve but could not get to work.</p>
  
  <ol>
  <li><p>It's currently nessecary to add all cpp files manually to the list of source files. Since the project is most likely going to grow fast in terms of file count and i kind of want to split the source files into different subdirectories this is going to be a mess very soon. I tried to get all cpp files in a directory with $(wildcard Src/Source/*.cpp) instead of listing them individually but it failed to even execute the makefile. What am i missing there?</p></li>
  <li><p>With my current makefile all .o files are placed at the same location as the .cpp file which is also something i dont really want. Is there a way to output all .o files in a extra \obj\ directory and link it into the .exe from there?</p></li>
  </ol>
  
  <p>Also since this is the first time im writing a makefile if there are some general improvements to my approach any advice is appreciated aswell.</p>