-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
135 lines (105 loc) · 3.35 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
MCU = attiny24
F_CPU = 1000000UL
TARGET = pocbee
SRC = $(TARGET).c
# asm sourcecode files
# eg. 'interrupts.S foobar/another.S'
ASRC =
# headers which should be considered when recompiling
# eg. 'global.h foobar/important.h'
HEADERS =
# include directories (used for both, c and asm)
# eg '. usbdrv/'
INCLUDES =
# use more debug-flags when compiling
DEBUG = 1
# avrdude programmer protocol
PROG = usbasp
# avrdude programmer device
DEV = usb
# further flags for avrdude
AVRDUDE_FLAGS =
####################################################
# 'make' configuration
####################################################
CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
AS = avr-as
SIZE = avr-size
CP = cp
RM = rm -f
RMDIR = rm -rf
MKDIR = mkdir
AVRDUDE = avrdude
# flags for automatic dependency handling
DEPFLAGS = -MD -MP -MF .dep/$(@F).d
# flags for the compiler (for .c files)
CFLAGS += -g -Os -mmcu=$(MCU) -DF_CPU=$(F_CPU) -std=gnu99 -fshort-enums $(DEPFLAGS)
CFLAGS += $(addprefix -I,$(INCLUDES))
# flags for the compiler (for .S files)
ASFLAGS += -g -mmcu=$(MCU) -DF_CPU=$(F_CPU) -x assembler-with-cpp $(DEPFLAGS)
ASFLAGS += $(addprefix -I,$(INCLUDES))
# flags for the linker
LDFLAGS += -mmcu=$(MCU)
# fill in object files
OBJECTS += $(SRC:.c=.o)
OBJECTS += $(ASRC:.S=.o)
# include config file
-include $(CURDIR)/config.mk
# include more debug flags, if $(DEBUG) is 1
#
# -Wstrict-prototypes -Wunreachable-code
ifeq ($(DEBUG),1)
CFLAGS += -Wall -W -Wchar-subscripts -Wmissing-prototypes
CFLAGS += -Wmissing-declarations -Wredundant-decls
CFLAGS += -Wshadow -Wbad-function-cast
CFLAGS += -Winline -Wpointer-arith -Wsign-compare
CFLAGS += -Wdisabled-optimization
CFLAGS += -Wcast-align -Wwrite-strings -Wnested-externs -Wundef
CFLAGS += -Wa,-adhlns=$(basename $@).lst
CFLAGS += -DDEBUG
endif
####################################################
# avrdude configuration
####################################################
AVRDUDE_MCU=$(MCU)
AVRDUDE_FLAGS += -p $(AVRDUDE_MCU)
####################################################
# make targets
####################################################
.PHONY: all clean distclean avrdude-terminal
# main rule
all: $(TARGET).hex
$(TARGET).elf: $(OBJECTS)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
# all objects (.o files)
$(OBJECTS): $(HEADERS)
# remove all compiled files
clean:
$(RM) $(foreach ext,elf hex eep.hex map,$(TARGET).$(ext)) \
$(foreach file,$(patsubst %.o,%,$(OBJECTS)),$(foreach ext,o lst lss,$(file).$(ext)))
# additionally remove the dependency makefile
distclean: clean
$(RMDIR) .dep
# avrdude-related targets
install program: program-$(TARGET)
avrdude-terminal:
$(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(DEV) -t
program-%: %.hex
$(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(DEV) -U flash:w:$<
program-eeprom-%: %.eep.hex
$(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(DEV) -U eeprom:w:$<
# special programming targets
%.hex: %.elf
$(OBJCOPY) -O ihex -R .eeprom $< $@
@echo "========================================"
@echo "$@ compiled for: $(MCU)"
@echo -n "size for $< is "
@$(SIZE) -A $@ | grep '\.sec1' | tr -s ' ' | cut -d" " -f2
@echo "========================================"
%.eep.hex: %.elf
$(OBJCOPY) --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O ihex -j .eeprom $< $@
%.lss: %.elf
$(OBJDUMP) -h -S $< > $@
-include $(shell $(MKDIR) .dep 2>/dev/null) $(wildcard .dep/*)