I hacked up a makefile soon after finding the IDE insanely annoying. I doubt mine is remotely general purpose, but I do have an upload target folks might want to use as an example. It can be found in the tarball with all the source for my project:
http://home.comcast.net/~tomhorsley/hardware/arduino/software.html
(the microcode subdir is the place to find the makefile).
I replaced all the tools with stubs that logged their arguments then ran the original tool and used the IDE to find out how the heck it invoked all the tools, then turned those commands into a makefile. (Which was a heck of a lot simpler than decrypting the IDE java code).