-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
46 lines (34 loc) · 999 Bytes
/
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
.SUFFIXES:
TARGET = beeper
MCU = attiny85
DUDE_MCU = attiny85
PROGR = avrisp
PORT = /dev/ttyS0
CC = avr-gcc
OBJCOPY = avr-objcopy
DUDE = avrdude
CFLAGS = -Wall -Werror -Os -DF_CPU=8000000UL
PFLAGS = -b 19200
SRCDIR = src
OBJDIR = obj
BINDIR = bin
SOURCES := $(wildcard $(SRCDIR)/*.c)
HEADERS := $(wildcard $(SRCDIR)/*.h)
OBJECTS := $(SOURCES:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
.PHONY: all
all: $(BINDIR)/$(TARGET).hex
$(BINDIR)/$(TARGET).hex: $(BINDIR)/$(TARGET).elf $(MAKEFILE_LIST)
$(OBJCOPY) -j .text -j .data -O ihex $< $@
$(BINDIR)/$(TARGET).elf: $(OBJECTS) $(MAKEFILE_LIST) | $(BINDIR)
$(CC) -mmcu=$(MCU) $(CFLAGS) -o $@ $(OBJECTS)
$(OBJDIR)/%.o: $(SRCDIR)/%.c $(HEADERS) $(MAKEFILE_LIST) | $(OBJDIR)
$(CC) -mmcu=$(MCU) $(CFLAGS) -o $@ -c $<
$(OBJDIR) $(BINDIR):
mkdir $@
.PHONY: flash
flash: $(BINDIR)/$(TARGET).hex
$(DUDE) -c $(PROGR) -p $(DUDE_MCU) -P $(PORT) $(PFLAGS) -U flash:w:$<
.PHONY: clean
clean:
rm -rf $(OBJDIR)
rm -rf $(BINDIR)