I haven't had much luck finding a makefile that builds exactly how I want (libraries, dependencies, subfolders etc) so I've whipped one up myself and put it on my web page. Just thought I'd share it in case anyone else finds it useful:

http://www.ppl-pilot.com/arduino.aspx

Build targets include "any", "clean" and "rebuild". The first line hard-codes the location of the arduino folder to "C:/arduino-1.0", obviously that can be commented out if you want to set an environment variable instead.

If I may make a suggestion, break out F_CPU, ARDUINO, and microcontroller type into their own variables, at the top, and then add them into the CFLAGS and LINK_FLAGS lines. These are the things which people are most likely to customize and the microcontroller type and CPU frequency are ones which are likely to change frequently. For example, I have three different uC's I target (mega2560, atmega328p, and atmega8) and two different clock speeds (8Mhz and 16Mhz).

If you elect to support multiple clock speeds and/or CPU type, you might also take that into consideration for your obj location, as otherwise without a clean you'll get a bad build and changing requires rebuilding the whole project unless obj location is taken into consideration. Oh well, just good for thought.

Aside from that, most people are not likely to require debugging support to be compiled into the binary. As such, the '-g' flag isn't likely to benefit, as for as far as I know, it requires a JTAG device.

If you're feeling adventurous, you might also consider adding support for avrdude to support something like an 'upload' or 'install' target.

At any rate, over all the makefile looks good and easy to read. Kudos for breaking out the various core directories, project directories, and libraries.

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).

Thanks for the tips everyone, I've pulled out clock speed, mcu type and arduino defines and made a few of the other changes as well, will upload it to my page over the weekend. I've been trying to keep the build process the same as how the IDE does it, although now that I think about it I guess that's not necessarily the best option. Three things that are still bugging me:

1) The IDE clearly does some pre-processing during which it includes "Arduino.h" and adds some forward declarations. I've verified this by comparing my source files to the ones in the build folders, there's new code in there. Is there a command-line tool that does this?

2) Some of the libraries have sub folders that also need to be included, i.e. SD,, Ethernet and Wire all have a "utility" sub folder. In my makefile I include them manually, how does the the IDE know about them? Does it simply always check to see if a "utility" sub folder is present in each library? Are there any other sub folders it checks for?

3) Anyone know if there's any way to strip unused code from the elf? According to the docs you should be able to do it by placing libraries in their own lib files and specifying -ffunction-sections, -fdata-sections and --gc-sections. Tried that...didn't work