A mention on the Pragmatic Programmer

I was looking at my Google Analytics and noticed I was getting referrals from the Pragmatic Programmer site, specifically from an article in the April magazine issue entitled Advanced Arduino Hacking. Turns out they were using my Makefile.master as the basis of their article, which describes how to use the Arduino platform without having to use the not-very-good Arduino IDE. OK, I suppose that's a little unfair - the IDE is clearly meant for beginners but if you are an experienced developer or are working on more complex projects it becomes very limiting very quickly, as noted in the article.

There are a number of copies of my Makefile.master floating around, but I'm updating it fairly regularly, so I recommend you grab the original version. Compared to the version on the PragProg site, the current version (at time of writing) has the following improvements:

  • The only really platform-specific parts of the Makefile are those that deal with running the serial monitor used to connect to the Arduino. On Solaris I use tip whereas on Linux you'd probably want to use something such as screen. I've therefore added platform-specific sections to configure the serial monitor commands to the Makefile.master. I don't currently have settings for MacOS, if someone wants to provide some suggestions, I'll add them in.

  • I hit a linker bug when using the avr-libc floating-point library, the workaround being to specify -lm both first and last in the linker command-line arguments.

  • An optional EXTRA_FLAGS macro that can be used to specify any additional flags that you want passed to gcc/g++. I use this for enabling/disabling debugging, e.g. EXTRA_FLAGS=-DDEBUG in my project Makefile.

  • The automatic tracking of #include dependencies was being done via a separate invocation of the compiler, this has been collapsed into the main compilation step, thus halving the number of times the compiler is invoked. If you don't know what automatic dependency checking is, there's a good explanation here and also in the GNU make documentation.

  • The generated dependency files are stored in the build subdirectory of the project, but they do tend to clutter things up. I've therefore moved them all into hidden (dot) files.

One final note, the PragProg Makefile.master uses stty -f $(PORT) hupcl to trigger a reset on the arduino before uploading the hex image to it. Not only is that platform-specific, it's also unnecessary if you are using a recent-ish version of avrdude which will do the reset for you if you specify a programmer type of arduino rather than stk500.

Categories : Tech