Indeed. Makefiles exist for this soul purpose. If you want to learn how to make your own Makefiles (which are quite easy, actually) check out this site:
http://www.gnu.org/software/make/make.html
And if you want a nice tutorial on making Makefile's, check this out:
http://www.delorie.com/gnu/docs/make/make_4.html