title: Makefile with files in different directories
body: <p>I am new using gcc in Ubuntu, so I am trying to create a Makefile. My project folder is called "project" inside of this folder I have three more folders: sources, headers, objects (empty).</p>
  
  <p>My Makefile should be able to create the object files in the folder "objects". However, I want my executable and Makefile in the main folder: "project" then I can clean the executable and the object files.
  How can I compile the program including these folders? This is my Makefile as an example. The folder "project" is in my home folder.</p>
  
  <pre><code> CFLAGS= -ansi -pedantic -Wall -c
  all:    project
  
  project: ./objects/main.o ./objects/factorial.o ./objects/gcd.o ./objects/greatestNumber.o ./objects/primeNumbers.o
      gcc -o project ./objects/main.o ./objects/factorial.o ./objects/gcd.o ./objects/greatestNumber.o ./objects/primeNumbers.o
  
  main.o: ./sources/main.c
      gcc $(CFLAGS) ./sources/main.c
  
  factorial.o: ./sources/factorial.c ./headers/factorial.h
      gcc $(CFLAGS) ./sources/factorial.c
  
  gcd.o: ./sources/gcd.c ./headers/gcd.h
      gcc $(CFLAGS) ./sources/gcd.c
  
  greatestNumber.o: ./sources/greatestNumber.c ./headers/greatestNumber.h
      gcc $(CFLAGS) ./sources/greatestNumber.c
  
  primeNumbers.o: ./sources/primeNumbers.c ./headers/primeNumbers.h
      gcc $(CFLAGS) ./sources/primeNumbers.c
  
  clean:
      rm -f ./objects/main.o ./objects/factorial.o ./objects/gcd.o ./objects/greatestNumber.o ./objects/primeNumbers.o project
  </code></pre>
  
  <p>Thanks</p>