Skip to content

Instantly share code, notes, and snippets.

@yellowcrescent
Created December 11, 2016 01:17
Show Gist options
  • Save yellowcrescent/ed2af51d1b57cde1c64ecb8e633d6b4e to your computer and use it in GitHub Desktop.
Save yellowcrescent/ed2af51d1b57cde1c64ecb8e633d6b4e to your computer and use it in GitHub Desktop.
avr makefile for arduino
# Trying to build a fucking makefile
# jacob AVR makefile
BUILDNAME=BLINKTEST
## Program names
CC=avr-gcc
CXX=avr-g++
OBJ2HEX=avr-objcopy
UISP=avrdude
## Programmer type
PROGHW=bsd
PROGPORT=/dev/parport0
PROGPART=ATMEGA328P
### Arduino shit
ARDUINO_HOME=/opt/Arduino
ARDUINO=-DARDUINO=10612 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR
ARDUINO_OBJS=hooks.o abi.o WInterrupts.o wiring.o wiring_analog.o wiring_digital.o wiring_pulse.o wiring_shift.o HardwareSerial.o new.o Print.o Stream.o Tone.o USBCore.o WMath.o WString.o CDC.o
## Project & Device parameters
TARGET=$(BUILDNAME)
DEVICE=atmega328p
XTAL=1000000L
EXTRA_CFLAGS=-DF_CPU=$(XTAL) \
-I$(ARDUINO_HOME)/hardware/arduino/avr/cores/arduino \
-I$(ARDUINO_HOME)/hardware/arduino/avr/libraries \
-I$(ARDUINO_HOME)/hardware/arduino/avr/variants/standard
## Compilation & Programming parameters
#CFLAGS=-g -Os -Wall -mcall-prologues -mmcu=$(DEVICE) $(EXTRA_CFLAGS)
#CFLAGS=-Os -Wall -mmcu=$(DEVICE) $(EXTRA_CFLAGS)
CFLAGS=-ffunction-sections -fdata-sections -g -w -Os -std=c99 -mmcu=$(DEVICE) -Wall $(EXTRA_CFLAGS) $(ARDUINO)
UISPARGS=-c $(PROGHW) -F -p $(PROGPART) -P $(PROGPORT) -U flash:w:
## Object list
OBJS = $(BUILDNAME).o
program : $(TARGET).hex
$(UISP) $(UISPARGS)$(TARGET).hex
.cpp.o:
$(CXX) -c $(CFLAGS) $< -o $@
.S.o:
$(CC) -x assembler-with-cpp -c $(CFLAGS) $< -o $@
.c.s:
$(CC) -S $(CFLAGS) $< -o $@
wiring_pulse.S.o: $(ARDUINO_HOME)/hardware/arduino/avr/cores/arduino/wiring_pulse.S
$(CC) -x assembler-with-cpp -c $(CFLAGS) $< -o $@
%.o: $(ARDUINO_HOME)/hardware/arduino/avr/cores/arduino/%.cpp
$(CXX) -c $(CFLAGS) $< -o $@
%.o: $(ARDUINO_HOME)/hardware/arduino/avr/cores/arduino/avr-libc/%.c
$(CC) -c $(CFLAGS) -o $@ $^
%.o: $(ARDUINO_HOME)/hardware/arduino/avr/cores/arduino/%.c
$(CC) -c $(CFLAGS) -o $@ $^
$(TARGET).bin: $(OBJS) $(ARDUINO_OBJS) wiring_pulse.S.o
$(CC) $(CFLAGS) -o $@ $(OBJS) $(ARDUINO_OBJS) wiring_pulse.S.o
$(TARGET).hex: $(TARGET).bin
$(OBJ2HEX) -j .text -j .data -R .eeprom -O ihex $< $@
clean :
rm -f *.hex *.obj *.o *.bin
all : $(TARGET).hex
#setfuse:
# $(UISP) -c $(PROGHW) -F -p $(PROGPART) -P $(PROGPORT) -U lfuse:w:0xff:m -U hfuse:w:0xd8:m
#$(UISP) -c $(PROGHW) -F -p $(PROGPART) -P $(PROGPORT) -U lfuse:w:0xff:m -U hfuse:w:0xd8:m -U efuse:w:0xfd:m
#checkfuse:
# ../checkfuse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment