Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 26f35d9188
Fetching contributors…

Cannot retrieve contributors at this time

file 98 lines (71 sloc) 2.788 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98

# set these to your chip and arduino home.

DEVICE := atmega328p
CLOCK := 16000000L
PORT := /dev/cu.usbmodem*

ARDUINO_HOME := /Applications/Arduino.app/Contents/Resources/Java

# everything below here should be the same everywhere.

ARDUINO_TOOLS := $(ARDUINO_HOME)/hardware/tools
ARDUINO_CORES := $(ARDUINO_HOME)/hardware/arduino/cores/arduino
ARDUINO_BIN := $(ARDUINO_TOOLS)/avr/bin
ARDUINO_ETC := $(ARDUINO_TOOLS)/avr/etc
CC := $(ARDUINO_BIN)/avr-gcc
CXX := $(ARDUINO_BIN)/avr-g++
AR := $(ARDUINO_BIN)/avr-ar
OBJCOPY := $(ARDUINO_BIN)/avr-objcopy
AVRDUDE := $(ARDUINO_BIN)/avrdude

CC_DEBUG := -g
CC_OPTIMIZE := -Os
CC_TWEAKS := \
  -ffunction-sections \
  -fdata-sections \
  -fpack-struct \
  -fshort-enums
CC_PLATFORM := -mmcu=$(DEVICE) -DF_CPU=$(CLOCK)
CC_INCLUDES := \
  -I$(ARDUINO_TOOLS)/avr/avr-4/include \
  -I$(ARDUINO_CORES) \
  -I$(ARDUINO_HOME)/hardware/arduino/variants/standard

CC_OPTIONS := $(CC_DEBUG) $(CC_OPTIMIZE) $(CC_TWEAKS) $(CC_PLATFORM) $(CC_INCLUDES) -Wall -Werror -Wno-sign-compare

CXX_TWEAKS := \
  -fno-exceptions

CXX_OPTIONS := $(CC_OPTIONS) $(CXX_TWEAKS)

OBJ = $(addprefix $(TARGET)/, $(SOURCE:.cpp=.o))
TEST_OBJ = $(addprefix $(TARGET)/, $(TEST_SOURCE:.cpp=.o))

AVRDUDE_PROGRAMMER := arduino
AVRDUDE_WRITE_FLASH := -U flash:w:$(TARGET)/$(BIN).hex
AVRDUDE_FLAGS := -C $(ARDUINO_ETC)/avrdude.conf -F -p $(DEVICE) -P $(PORT) -c $(AVRDUDE_PROGRAMMER) -b 115200 -D

# basic rules.

$(TARGET):
mkdir -p $(TARGET)

clean:
rm -rf $(TARGET)

vpath %.c $(ARDUINO_CORES)
vpath %.cpp $(ARDUINO_CORES)

$(TARGET)/%.s: %.cpp
$(CXX) -S $(CXX_OPTIONS) $< -o $@

$(TARGET)/%.o: %.cpp
$(CXX) -c -MMD $(CXX_OPTIONS) $< -o $@
$(TARGET)/%.o: %.c
$(CC) -c -MMD $(CC_OPTIONS) $< -o $@

.PHONY: clean

# making the arduino library.

LIBARDUINO_C_SOURCE := $(addprefix $(ARDUINO_CORES)/, \
  WInterrupts.c wiring.c wiring_analog.c wiring_digital.c wiring_pulse.c \
  wiring_shift.c)
LIBARDUINO_CXX_SOURCE := \
  CDC.cpp HardwareSerial.cpp HID.cpp IPAddress.cpp new.cpp \
  Stream.cpp USBCore.cpp WMath.cpp
# things i don't care about: Print.cpp Tone.cpp WString.cpp

LIBARDUINO_LIB := $(TARGET)/libarduino.a
LIBARDUINO_OBJ := $(addprefix $(TARGET)/, $(notdir $(LIBARDUINO_C_SOURCE:.c=.o) $(LIBARDUINO_CXX_SOURCE:.cpp=.o)))

$(LIBARDUINO_LIB): $(LIBARDUINO_OBJ)
$(AR) rcs $@ $+

# program the device.

upload: $(TARGET)/$(BIN).hex #$(TARGET)/$(BIN).eep
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)

wut:
$(AVRDUDE) $(AVRDUDE_FLAGS) -U flash:w:sketch_lcd.cpp.hex:i

%.hex: %.elf
$(OBJCOPY) -O ihex -R .eeprom $< $@

%.eep: %.elf
$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O ihex $< $@
Something went wrong with that request. Please try again.