summaryrefslogtreecommitdiff
path: root/n/avr/rs232/Makefile.avr
blob: 6a4324db57e1d793aa8bf8ab5d8207956555d676 (plain)
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
# Makefile.avr 1.6
#
# Flags. {{{1

CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET)
CPPFLAGS = $(DEFS) -MMD $(INCLUDES) \
	   $(if $(CONFIGFILE), $(CONFIGFILE:%=-include %))
INCLUDES = -Imodules
LDFLAGS = $(CFLAGS)

CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump

# Main rules. {{{1

all: elf lst hex

.PHONY: all clean elf lst doc text hex srec bin eeprom ehex esrec ebin

# Rules for modules. {{{1

VPATH = $(MODULES:%=modules/%)

modules_checkout: modules_co

modules_co: $(MODULES:%=modules_co.%)

$(MODULES:%=modules_co.%):
	mkdir -p modules
	cd modules && cvs co $(@:modules_co.%=%)

modules_update: modules_up

modules_up: $(MODULES:%=modules_up.%)

$(MODULES:%=modules_up.%):
	cd modules/$(@:modules_up.%=%) && cvs up

# General rules. {{{1

ELFS = $(PROGS:%=%.elf)
OBJECTS = $(filter %.o,$(foreach prog,$(PROGS),$($(prog)_OBJECTS)))

elf: $(ELFS)
lst: $(PROGS:%=%.lst)

# Great piece of rules which only works in make 3.80+.
# define PROG_template
# $(1).elf: $$($(1)_OBJECTS)
# endef
#
# $(foreach prog,$(PROGS),$(eval $(call PROG_template,$(prog))))

$(ELFS):
	$(LINK.o) $^ $(LDLIBS) -o $@

%.lst: %.elf
	$(OBJDUMP) -h -S $< > $@

# Dependency checking.
-include $(OBJECTS:%.o=%.d)

clean:
	rm -f *.o *.d $(ELFS) *.lst *.map *.bak *~
	rm -f $(DOC) *.exd $(EXTRA_CLEAN_FILES) $(TEXTS) $(EEPROMS)

# Rules for building the doc. {{{1

doc: $(DOC)

%.html: %.txt %.exd
	aft $<

%.exd: $(EXTRACTDOC)
	test -n "$^" && extractdoc $^ > $@ || true

# Rules for building the .text rom images. {{{1

TEXTS = $(PROGS:%=%.hex) $(PROGS:%=%.bin) $(PROGS:%=%.srec)

text: hex bin srec

hex: $(PROGS:%=%.hex)
bin: $(PROGS:%=%.bin)
srec: $(PROGS:%=%.srec)

%.hex: %.elf
	$(OBJCOPY) -j .text -j .data -O ihex $< $@

%.srec: %.elf
	$(OBJCOPY) -j .text -j .data -O srec $< $@

%.bin: %.elf
	$(OBJCOPY) -j .text -j .data -O binary $< $@

# Rules for building the .eeprom rom images. {{{1

EEPROMS = $(PROGS:%=%_eeprom.hex) $(PROGS:%=%_eeprom.bin) \
	  $(PROGS:%=%_eeprom.srec)

eeprom: ehex ebin esrec

ehex: $(PROGS:%=%_eeprom.hex)
ebin: $(PROGS:%=%_eeprom.bin)
esrec: $(PROGS:%=%_eeprom.srec)

%_eeprom.hex: %.elf
	$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@

%_eeprom.srec: %.elf
	$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O srec $< $@

%_eeprom.bin: %.elf
	$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O binary $< $@