How does one copile arduino code from cmd and also make files?

Can arduino sketches be compiled from cmd and use any arduino toolchain version,and how do you point the files to compile from a sertain arduino ide?

Recent versions of Arduino (1.5+?) have some options for running as a cmd rather GUI mode:

For older versions, there are assorted "Arduino using Makefile" type efforts, but they are less ... official.