Last active
August 29, 2015 14:14
-
-
Save padcom/92f25ae198962b1bb91b to your computer and use it in GitHub Desktop.
Arduino base build file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Arduino Makefile 1.0 - Matthias Hryniszak | |
# ------------------------------------------------------------------------------ | |
# General settings | |
# ------------------------------------------------------------------------------ | |
LIBRARY=arduino | |
MCU=atmega328p | |
FREQUENCY=16000000 | |
# project settings | |
DEPS=$(wildcard *.h) # all header files | |
C_SOURCES=$(wildcard *.c) # all source files | |
CPP_SOURCES=$(wildcard *.cpp) # all source files | |
OBJECTS=${C_SOURCES:.c=.o} ${CPP_SOURCES:.cpp=.o} # all object files from source files | |
# ------------------------------------------------------------------------------ | |
# Compilation definition | |
# ------------------------------------------------------------------------------ | |
CC=avr-gcc | |
CXX=avr-g++ | |
CFLAGS=-c -Wall --std=gnu99 -g -Os -s -mmcu=$(MCU) -fdata-sections -ffunction-sections -I. -DF_CPU=$(FREQUENCY) -DARDUINO=106 | |
# ------------------------------------------------------------------------------ | |
# Compilation rules | |
# ------------------------------------------------------------------------------ | |
%.o: %.c $(DEPS) | |
$(CC) -c -o $@ $< $(CFLAGS) | |
%.o: %.cpp $(DEPS) | |
$(CXX) -c -o $@ $< $(CFLAGS) | |
lib$(LIBRARY).a: $(OBJECTS) | |
avr-ar rvs lib$(LIBRARY).a $(OBJECTS) | |
all: lib$(LIBRARY).a | |
clean: | |
rm -f $(OBJECTS) $(DFILES) lib$(LIBRARY).a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# AVR Makefile 1.0 - Matthias Hryniszak | |
# ------------------------------------------------------------------------------ | |
# General settings | |
# ------------------------------------------------------------------------------ | |
PROGRAM=avr-blink | |
MCU=atmega328p | |
FREQUENCY=16000000 | |
# avrdude settings | |
PROGRAMER=arduino | |
PROGRAMER_PORT=/dev/ttyACM0 | |
PROGRAMER_FLAGS= | |
# project settings | |
DEPS=$(wildcard *.h) # all header files | |
C_SOURCES=$(wildcard *.c) # all source files | |
CPP_SOURCES=$(wildcard *.cpp) # all source files | |
OBJECTS=${C_SOURCES:.c=.o} ${CPP_SOURCES:.cpp=.o} # all object files from source files | |
# libraries this project depends on | |
LIBRARIES=m arduino | |
# ------------------------------------------------------------------------------ | |
# Compilation definition | |
# ------------------------------------------------------------------------------ | |
CC=avr-gcc | |
CXX=avr-g++ | |
CFLAGS=-c -Wall --std=gnu99 -g -Os -s -mmcu=$(MCU) -fdata-sections -ffunction-sections -I. -Iarduino -DF_CPU=$(FREQUENCY) -DARDUINO=106 | |
LDFLAGS=-Larduino $(foreach library,$(LIBRARIES),-l$(library)) | |
# ------------------------------------------------------------------------------ | |
# Compilation rules | |
# ------------------------------------------------------------------------------ | |
%.o: %.c $(DEPS) | |
$(CC) -c -o $@ $< $(CFLAGS) | |
%.o: %.cpp $(DEPS) | |
$(CXX) -c -o $@ $< $(CFLAGS) | |
$(PROGRAM).elf: $(OBJECTS) | |
$(CC) -Os -s -Wl,--gc-sections -mmcu=$(MCU) -o $(PROGRAM).elf $(OBJECTS) $(LDFLAGS) | |
avr-size -C --mcu=$(MCU) -x $(PROGRAM).elf | |
%.hex: %.elf | |
avr-objcopy -j .text -j .data -O ihex $< $@ | |
all: $(PROGRAM).elf | |
load: $(PROGRAM).hex | |
avrdude -p $(MCU) -c $(PROGRAMER) -P $(PROGRAMER_PORT) $(PROGRAMER_FLAGS) -U flash:w:$(PROGRAM).hex:i | |
clean: | |
rm -f $(OBJECTS) $(DFILES) $(PROGRAM).elf $(PROGRAM).hex | |
terminal: | |
cu -l $(PROGRAMER_PORT) -s 9600 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment