aboutsummaryrefslogtreecommitdiff
path: root/code/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'code/Makefile')
-rw-r--r--code/Makefile45
1 files changed, 45 insertions, 0 deletions
diff --git a/code/Makefile b/code/Makefile
new file mode 100644
index 0000000..0bc81a8
--- /dev/null
+++ b/code/Makefile
@@ -0,0 +1,45 @@
+TARGET = main
+
+MCU = attiny24
+F_CPU = 8000000UL
+
+CC = avr-gcc
+CFLAGS = -Os -Wall -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char
+
+LDFLATS = -Wl,-Map,$(TARGET).map
+LDFLAGS += -Wl,--gc-sections
+TARGET_ARCH = -mmcu=$(MCU)
+
+OBJCOPY = avr-objcopy
+OBJSIZE = avr-size
+
+AVRDUDE = avrdude
+ADFLAGS = -c usbasp -p t24
+
+SRC=$(wildcard src/*.c) $(wildcard src/*/*.c) $(wildcard src/*/*/*.c)
+OBJ=$(patsubst %.c, %.o, $(SRC))
+ASM=$(patsubst %.c, %.s, $(SRC))
+
+all: $(OBJ) $(TARGET).hex summary upload
+
+%.o: %.c
+ $(CC) $(CFLAGS) -DF_CPU=$(F_CPU) -mmcu=$(MCU) -c -o $@ $<
+
+%.s: %.c
+ $(CC) -S $(CFLAGS) -DF_CPU=$(F_CPU) -mmcu=$(MCU) $< -o $@
+
+%.elf: $(OBJ)
+ $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ -o $@
+
+%.hex: %.elf
+ $(OBJCOPY) -j .text -j .data -O ihex $< $@
+
+summary: $(OBJ) $(TARGET).hex
+ @echo ----------------------------------------------------------------------
+ @$(OBJSIZE) $(OBJ) $(TARGET).hex
+
+upload: $(TARGET).hex
+ $(AVRDUDE) $(ADFLAGS) -U flash:w:$<
+
+clean:
+ rm -f $(OBJ) $(HEX) $(ASM)