Skip to content

Instantly share code, notes, and snippets.

@en0
Last active August 29, 2015 13:57
Show Gist options
  • Save en0/9614596 to your computer and use it in GitHub Desktop.
Save en0/9614596 to your computer and use it in GitHub Desktop.
Makefile for Arduino
TARGET=Blink
LIB=core.a
CORE_INC=/usr/share/arduino/hardware/arduino/cores/arduino/
PLAT_INC=/usr/share/arduino/hardware/arduino/variants/mega/
F_CPU=16000000L
FORMAT=ihex
MCU=atmega328p
ISP=arduino
PORT=/dev/ttyACM0
BAUD=115200
CC=avr-gcc
CXX=avr-g++
AS=avr-as
LD=avr-ld
OBJCOPY=avr-objcopy
OBJDUMP=avr-objdump
SIZE=avr-size
NM=avr-nm
AVRDUDE = avrdude -D
MV=mv -f
RM=rm -f
INC=-I. -I$(PLAT_INC) -I$(CORE_INC)
SOPT = -mmcu=$(MCU)
CWARN = -Wall -Wstrict-prototypes -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -fno-exceptions -ffunction-sections -fdata-sections
CFLAGS = $(SOPT) -DF_CPU=$(F_CPU) -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101 -Os $(CWARN)
CXXFLAGS = $(SOPT) -DF_CPU=$(F_CPU) -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101 -Os
ASFLAGS = $(SOPT)
LDFLAGS =
OBJ=$(patsubst %.c, %.c.o, $(wildcard *.c))\
$(patsubst %.cpp, %.cpp.o, $(wildcard *.cpp))\
$(patsubst %.s, %.s.o, $(wildcard *.s))
$(TARGET).hex : $(TARGET)
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
$(TARGET) : $(OBJ) $(LIB)
$(CC) $(CFLAGS) -o $@ $^
%.c.o : %.c
$(CC) -I. -I$(INC) -c $(CFLAGS) -o $@ $<
%.cpp.o : %.cpp
$(CC) -I. -I$(INC) -c $(CXXFLAGS) -o $@ $<
%.s.o : %.s
$(AS) $(ASFLAGS) -o $@ $<
.PHONY : clean
clean :
$(RM) $(TARGET) $(TARGET).hex $(OBJ)
.PHONY : install
install : $(TARGET).hex
$(AVRDUDE) -p$(MCU) -c$(ISP) -P$(PORT) -b$(BAUD) -Uflash:w:$<:i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment