summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2018-05-31 10:56:17 +0200
committerDaniel Friesel <derf@finalrewind.org>2018-05-31 10:56:17 +0200
commitd040ed5eecb104c201b330c468df3b6d8c59b7f1 (patch)
tree7ea3bf6e09734f742af1814487dd8a53a62388af /Makefile
Initial commit. Working static light, but no rgbfade yet
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile72
1 files changed, 72 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..5475f99
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,72 @@
+MCU_AVRDUDE ?= t2313
+MCU_AVRGCC ?= attiny2313a
+AVRDUDE_PROGRAMMER ?= usbasp
+
+AVRCC ?= avr-gcc
+AVRCXX ?= avr-g++
+AVRFLASH ?= avrdude
+AVRNM ?= avr-nm
+AVROBJCOPY ?= avr-objcopy
+AVROBJDUMP ?= avr-objdump
+
+MCU_FLAGS = -mmcu=${MCU_AVRGCC} -DF_CPU=8000000UL
+
+SHARED_FLAGS = ${MCU_FLAGS} -I. -Os -Wall -Wextra -pedantic
+SHARED_FLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
+SHARED_FLAGS += -flto -mstrict-X
+
+ifeq (${LANG},DE)
+ SHARED_FLAGS += -DLANG_DE
+endif
+
+CFLAGS += ${SHARED_FLAGS} -std=c11
+CXXFLAGS += ${SHARED_FLAGS} -std=c++11 -fno-rtti -fno-exceptions
+
+ASFLAGS += ${MCU_FLAGS} -wA,--warn
+LDFLAGS += -Wl,--gc-sections
+
+#AVRFLAGS += -U lfuse:w:0xe4:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m
+AVRFLAGS += -U flash:w:build/main.hex
+#AVRFLAGS += -U eeprom:w:main.eep
+
+HEADERS = $(wildcard src/*.h)
+ASFILES = $(wildcard src/*.S)
+CFILES = $(wildcard src/*.c)
+CXXFILES = $(wildcard src/*.cc)
+OBJECTS = ${CFILES:src/%.c=build/%.o} ${CXXFILES:src/%.cc=build/%.o} ${ASFILES:src/%.S=build/%.o}
+
+all: build build/main.elf
+
+build:
+ mkdir -p build
+
+build/%.hex: build/%.elf
+ ${AVROBJCOPY} -O ihex -R .eeprom $< $@
+
+build/%.eep: build/%.elf
+ ${AVROBJCOPY} -j .eeprom --set-section-flags=.eeprom="alloc,load" \
+ --change-section-lma .eeprom=0 -O ihex $< $@
+
+build/%.o: src/%.cc ${HEADERS}
+ ${AVRCXX} ${CXXFLAGS} -o $@ $< -c -Wl,-Map=main.map,--cref
+
+build/%.o: src/%.c ${HEADERS}
+ ${AVRCC} ${CFLAGS} -o $@ $< -c -Wl,-Map=main.map,--cref
+
+build/main.elf: ${OBJECTS}
+ ${AVRCXX} ${CXXFLAGS} -o $@ $^ ${LDFLAGS}
+ @echo
+ @avr-size --format=avr --mcu=${MCU_AVRGCC} $@
+
+flash: program
+
+program: build/main.hex #main.eep
+ ${AVRFLASH} -p ${MCU_AVRDUDE} -c ${AVRDUDE_PROGRAMMER} ${AVRFLAGS}
+
+secsize: build/main.elf
+ ${AVROBJDUMP} -hw -j.text -j.bss -j.data $<
+
+funsize: build/main.elf
+ ${AVRNM} --print-size --size-sort $<
+
+.PHONY: all program secsize funsize