Debian Codegraph @

doc/examples/asmdemo/Makefile

raw
1 # Hey Emacs, this is a -*- makefile -*-
2
3 # AVR-GCC Makefile template, derived from the WinAVR template (which
4 # is public domain), believed to be neutral to any flavor of "make"
5 # (GNU make, BSD make, SysV make)
6
7
8 MCU = attiny13
9 #MCU = attiny45
10 FORMAT = ihex
11 TARGET = asmdemo
12 SRC = $(TARGET).c
13 ASRC = isrs.S
14 OPT = s
15
16 # Name of this Makefile (used for "make depend").
17 MAKEFILE = Makefile
18
19 # Compiler flag to set the C Standard level.
20 # c89 - "ANSI" C
21 # gnu89 - c89 plus GCC extensions
22 # c99 - ISO C99 standard (not yet fully implemented)
23 # gnu99 - c99 plus GCC extensions
24 CSTANDARD = -std=gnu99
25
26 # Place -D or -U options here
27 CDEFS =
28
29 # Place -I options here
30 CINCS =
31
32
33 CDEBUG = -g
34 CWARN = -Wall -Wstrict-prototypes
35 CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
36 #CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
37 CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA)
38
39
40 #ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
41
42
43 #Additional libraries.
44
45 # Minimalistic printf version
46 PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
47
48 # Floating point printf version (requires MATH_LIB = -lm below)
49 PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
50
51 PRINTF_LIB =
52
53 # Minimalistic scanf version
54 SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
55
56 # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
57 SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
58
59 SCANF_LIB =
60
61 MATH_LIB = -lm
62
63 # External memory options
64
65 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
66 # used for variables (.data/.bss) and heap (malloc()).
67 #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
68
69 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
70 # only used for heap (malloc()).
71 #EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
72
73 EXTMEMOPTS =
74
75 #LDMAP = $(LDFLAGS) -Wl,-Map=$(TARGET).map,--cref
76 LDFLAGS = $(EXTMEMOPTS) $(LDMAP) $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
77
78
79 # Programming support using avrdude. Settings and variables.
80
81 AVRDUDE_PROGRAMMER = stk500v2
82 AVRDUDE_PORT = /dev/cuaa1
83
84 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
85 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
86
87
88 # Uncomment the following if you want avrdude's erase cycle counter.
89 # Note that this counter needs to be initialized first using -Yn,
90 # see avrdude manual.
91 #AVRDUDE_ERASE_COUNTER = -y
92
93 # Uncomment the following if you do /not/ wish a verification to be
94 # performed after programming the device.
95 #AVRDUDE_NO_VERIFY = -V
96
97 # Increase verbosity level. Please use this when submitting bug
98 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
99 # to submit bug reports.
100 #AVRDUDE_VERBOSE = -v -v
101
102 AVRDUDE_BASIC = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
103 AVRDUDE_FLAGS = $(AVRDUDE_BASIC) $(AVRDUDE_NO_VERIFY) $(AVRDUDE_VERBOSE) $(AVRDUDE_ERASE_COUNTER)
104
105
106 CC = avr-gcc
107 OBJCOPY = avr-objcopy
108 OBJDUMP = avr-objdump
109 SIZE = avr-size
110 NM = avr-nm
111 AVRDUDE = avrdude
112 REMOVE = rm -f
113 MV = mv -f
114
115 # Define all object files.
116 OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
117
118 # Define all listing files.
119 LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
120
121 # Combine all necessary flags and optional flags.
122 # Add target processor to flags.
123 ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
124 ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
125
126
127 # Default target.
128 all: build
129
130 build: elf hex eep
131
132 elf: $(TARGET).elf
133 hex: $(TARGET).hex
134 eep: $(TARGET).eep
135 lss: $(TARGET).lss
136 sym: $(TARGET).sym
137
138
139 # Program the device.
140 program: $(TARGET).hex $(TARGET).eep
141 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
142
143
144
145
146 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
147 COFFCONVERT=$(OBJCOPY) --debugging \
148 --change-section-address .data-0x800000 \
149 --change-section-address .bss-0x800000 \
150 --change-section-address .noinit-0x800000 \
151 --change-section-address .eeprom-0x810000
152
153
154 coff: $(TARGET).elf
155 $(COFFCONVERT) -O coff-avr $(TARGET).elf $(TARGET).cof
156
157
158 extcoff: $(TARGET).elf
159 $(COFFCONVERT) -O coff-ext-avr $(TARGET).elf $(TARGET).cof
160
161
162 .SUFFIXES: .elf .hex .eep .lss .sym
163
164 .elf.hex:
165 $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
166
167 .elf.eep:
168 -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
169 --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
170
171 # Create extended listing file from ELF output file.
172 .elf.lss:
173 $(OBJDUMP) -h -S $< > $@
174
175 # Create a symbol table from ELF output file.
176 .elf.sym:
177 $(NM) -n $< > $@
178
179
180
181 # Link: create ELF output file from object files.
182 $(TARGET).elf: $(OBJ)
183 $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
184
185
186 # Compile: create object files from C source files.
187 .c.o:
188 $(CC) -c $(ALL_CFLAGS) $< -o $@
189
190
191 # Compile: create assembler files from C source files.
192 .c.s:
193 $(CC) -S $(ALL_CFLAGS) $< -o $@
194
195
196 # Assemble: create object files from assembler source files.
197 .S.o:
198 $(CC) -c $(ALL_ASFLAGS) $< -o $@
199
200
201
202 # Target: clean project.
203 clean:
204 $(REMOVE) $(TARGET).hex $(TARGET).eep $(TARGET).cof $(TARGET).elf \
205 $(TARGET).map $(TARGET).sym $(TARGET).lss \
206 $(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d)
207
208 depend:
209 if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \
210 then \
211 sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \
212 $(MAKEFILE).$$$$ && \
213 $(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \
214 fi
215 echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \
216 >> $(MAKEFILE); \
217 $(CC) -M -mmcu=$(MCU) $(CDEFS) $(CINCS) $(SRC) $(ASRC) >> $(MAKEFILE)
218
219 .PHONY: all build elf hex eep lss sym program coff extcoff clean depend
220
221