AVR build system

(avr) (Computer programming)

Generic makefile

I wanted to have a maintainable way to build all my AVR projects.

I ended up writing a Makefile that can be includeed from each program.

This allows a two line makefile to compile a project.

# Example Makefile for single file project
OBJ=blink.c.o
include ../genericMakefile

Features

CLI

make something.c.o # Compile the object file for a given 
make all.elf # Compile and link project
make clean # Remove generated binary files
make size # Show rom usage
make flash # Flash the program onto the rom (might require root)
make avrdude # Open avrdude cli (might require root)
make erase # Erase chip w/out flashing anything

Other examples

Include custom fuse settings in flash.

OBJ=test.c.o
FLASHOP= -U lfuse:w:0x22:m
include ../genericMakefile

Include prebuilt library.

OBJ=test.c.o
LIBS=lib.so
include ../genericMakefile

Compile assembly and link alongside c

OBJ=testasm.asm.o test.c.o
include ../genericMakefile

Override default F_CPU

F_CPU?=test.c.o
include ../genericMakefile

Prerequisites

Installation on arch linux

pacman -S make avr-gcc avr-libc avrdude

Installation on Debian based systems

apt install make avr-gcc avr-libc avrdude

Code

Makefile