/
Makefile
92 lines (77 loc) · 2.78 KB
/
Makefile
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
#
# Copyright © 2019 Keith Packard <keithp@keithp.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
SNEK_ROOT = ..
SNEK_LOCAL_SRC = \
snek-duino.c \
snek-duino-eeprom.c \
snek-duino-serial.c
SNEK_LOCAL_INC = snek-duino.h
SNEK_LOCAL_BUILTINS = snek-duino.builtin
include ../snek-install.defs
HEX=snek-duino-$(SNEK_VERSION).hex
CC=avr-gcc
CFLAGS=-Os -DF_CPU=16000000UL -mmcu=atmega328p -I. -g -fno-jump-tables $(SNEK_CFLAGS)
LDFLAGS=-Wl,-uvfprintf -lprintf_flt -lm \
-Wl,--defsym -Wl,__TEXT_REGION_LENGTH__=0x8000 \
-Wl,--defsym -Wl,__DATA_REGION_LENGTH__=0x7a0 \
-Wl,--defsym -Wl,__EEPROM_REGION_LENGTH__=0x400 \
-Wl,-Map=snek-duino-$(SNEK_VERSION).map
ISP = usbtiny
#ISP = avrisp2
#
# lfuse: 0xff
# CKDIV8: 1 no divide by 8
# CKOUT: 1 no clock output
# SUT1: 1 crystal osc, slow startup
# SUT0: 1 crystal osc, slow startup
# CKSEL3: 1 low swing osc, 8-16MHz
# CKSEL2: 1 low swing osc, 8-16MHz
# CKSEL1: 1 low swing osc, 8-16MHz
# CKSEL0: 1 crystal osc
# hfuse:
# RSTDISBL: 1 reset enabled
# DWEN: 1 debug wire disabled
# SPIEN: 0 SPI program enabled
# WDTON: 1 watch dog disabled
# EESAVE: 0 EEPROM saved across chip erase
# BOOTSZ1: 1 256 words
# BOOTSZ0: 1 256 words
# BOOTRST: 1 boot to address 0
# efuse:
# BODLEVEL2 1 brown out 2.5-2.9V
# BODLEVEL1 0 brown out 2.5-2.9V
# BODLEVEL0 1 brown out 2.5-2.9V
all: $(HEX) snek-duino-install
snek-duino-$(SNEK_VERSION).hex: snek-duino-$(SNEK_VERSION)
avr-objcopy -O ihex -R .eeprom snek-duino-$(SNEK_VERSION) $@
snek-duino-$(SNEK_VERSION): $(SNEK_OBJ)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
@awk '/__data_load_end/{printf("ROM used: %d bytes\n", strtonum($$1)); }' snek-duino.map
snek-duino-install: snek-duino-install.in
sed -e 's;@SHAREDIR@;$(SHAREDIR);g' $^ > $@
set-fuse:
avrdude -F -V -c $(ISP) -p ATMEGA328P -U lfuse:w:0xff:m
avrdude -F -V -c $(ISP) -p ATMEGA328P -U hfuse:w:0xd7:m
avrdude -F -V -c $(ISP) -p ATMEGA328P -U efuse:w:0xfd:m
load: snek-duino.hex
avrdude -F -V -c $(ISP) -p ATMEGA328P -U flash:w:snek-duino.hex
install: snek-duino-install snek-duino.hex snek-duino-install.1
install -d $(DESTDIR)$(BINDIR)
install snek-duino-install $(DESTDIR)$(BINDIR)
install -d $(DESTDIR)$(SHAREDIR)
install snek-duino.hex $(DESTDIR)$(SHAREDIR)
install -d $(DESTDIR)$(MANDIR)/man1
install snek-duino-install.1 $(DESTDIR)$(MANDIR)/man1
clean::
rm -f snek-duino $(HEX) snek-duino.map snek-duino-install