title: How do I make a makefile with a source folder?
body: <p>I want to make a modular makefile with a PATH parameter but I can't figure out how.</p>
  
  <p>This is what I had before:</p>
  
  <pre><code>CC=
  CFLAGS=-c -stack-protect
  LDFLAGS=
  SOURCES=
  SSOURCES=
  OBJECTS=$(SOURCES:.cpp=.o)
  SOBJECTS=$(SSOURCES:.s=.o)
  DEBUGFLAGS=-g -DDEBUG
  EXECUTABLE=
  
  all: CC += -DNDEBUG
  all: $(SOURCES) $(SSOURCES) $(EXECUTABLE)
  
  $(EXECUTABLE): $(OBJECTS) $(SOBJECTS)
          $(CC) $(LDFLAGS) $(OBJECTS) $(SOBJECTS) -o $@
  
  .cpp.o:
          $(CC) $(CFLAGS) $&lt; -o $@
  
  .s.o:
          $(CC) $(CFLAGS) $&lt; -o $@
  
  debug: CFLAGS += $(DEBUGFLAGS)
  debug: $(SOURCES) $(SSOURCES) $(LDFLAGS) $(EXECUTABLE)
          $(CC) $(LDFLAGS) $(OBJECTS) $(SOBJECTS) -o $(EXECUTABLE)
  
  clean:
          rm -rf *o $(OBJECTS) $(SOBJECTS)
  </code></pre>
  
  <p>And this is what I'm trying to do more or less:</p>
  
  <pre><code>PATH=
  CC=
  CFLAGS=-c -stack-protect
  LDFLAGS=
  SOURCES=./src1 ./src1
  SSOURCES=./src1 ./src2
  FSOURCES=$(SOURCES:./=$(PATH))
  FSSOURCES=$(SSOURCES:./=$(PATH))
  OBJECTS=$(SOURCES:.cpp=.o)
  SOBJECTS=$(SSOURCES:.s=.o)
  DEBUGFLAGS=-g -DDEBUG
  EXECUTABLE=
  
  all: CC += -DNDEBUG
  all: $(FSOURCES) $(FSSOURCES) $(EXECUTABLE)
  
  $(EXECUTABLE): $(OBJECTS) $(SOBJECTS)
          $(CC) $(LDFLAGS) $(OBJECTS) $(SOBJECTS) -o $@
  
  .cpp.o:
          $(CC) $(CFLAGS) $&lt; -o $@
  
  .s.o:
          $(CC) $(CFLAGS) $&lt; -o $@
  
  debug: CFLAGS += $(DEBUGFLAGS)
  debug: $(FSOURCES) $(FSSOURCES) $(LDFLAGS) $(EXECUTABLE)
          $(CC) $(LDFLAGS) $(OBJECTS) $(SOBJECTS) -o $(EXECUTABLE)
  
  clean:
          rm -rf *o $(OBJECTS) $(SOBJECTS)
  </code></pre>
  
  <p>How can I make this work?</p>