I have a Makefile like this:
baud=19200
src=dimmer
avrType=attiny13
programmerDev=/dev/ttyUSB003
programmerType=stk500v1
object:
avr-gcc -g -DF_CPU=$(avrFreq) -Wall -Os -mmcu=$(avrType) -c -o $(src).o $(src).cpp
read:
@for memory in calibration eeprom efuse flash fuse hfuse lfuse lock signature application apptable boot prodsig usersig; do \
avrdude -p $(avrType) -c$(programmerType) -P$(programmerDev) -b$(baud) -v -U $$memory:r:./$(avrType).$$memory.hex:i; \
done
Which works as intended. When I type make read several files are extracted from the microcontroller. This can take a little while because of the slow connection and data size, so I was thinking it would be nice to be able to just type make read flash, but I can’t figure out how to do that.
Of course I can make entries like read_flash, read_hfuse … but I have a feeling it can be done smarter.
I also want to be able to run a command like make read all which will execute every file in turn from the controller.
Now I am new to creating Makfile’s, so maybe I am on the wrong track all together. Please feel free to explain how it should be done.
I am on Linux.
If a highly GNU-specific makefile is acceptable to you (and I’d argue that it’s much better to use a portable
make, such as GNU’s, than writing portable makefiles), you can implement this rather easily:If the first argument in the command line is “read”, this sets the
WANTvariable to the list of arguments after the first. It then turns those names into no-op targets and makes thereadtarget invoke theread-onefunction for each name, or for$(ALL)if no name was specified.I use variations of this quite often, for things like
make print VARIABLE..., which will just print$(VARIABLE)ormake help TOPICto display information about a target.