sources from initial AVR turn-on for TeleTerra
[fw/altos] / avr / tmp / makefile
1 # Hey Emacs, this is a -*- makefile -*-
2 #
3 # WinAVR Sample makefile written by Eric B. Weddington, Jörg Wunsch, et al.
4 # Released to the Public Domain
5 # Please read the make user manual!
6 #
7 # Additional material for this makefile was submitted by:
8 #  Tim Henigan
9 #  Peter Fleury
10 #  Reiner Patommel
11 #  Sander Pool
12 #  Frederik Rouleau
13 #  Markus Pfaff
14 #
15 # On command line:
16 #
17 # make all = Make software.
18 #
19 # make clean = Clean out built project files.
20 #
21 # make coff = Convert ELF to AVR COFF (for use with AVR Studio 3.x or VMLAB).
22 #
23 # make extcoff = Convert ELF to AVR Extended COFF (for use with AVR Studio
24 #                4.07 or greater).
25 #
26 # make program = Download the hex file to the device, using avrdude.  Please
27 #                customize the avrdude settings below first!
28 #
29 # make filename.s = Just compile filename.c into the assembler code only
30 #
31 # To rebuild project do "make clean" then "make all".
32 #
33
34
35 # MCU name
36 MCU = attiny48
37
38 # Output format. (can be srec, ihex, binary)
39 FORMAT = ihex
40
41 # Target file name (without extension).
42 TARGET = test_lcd
43
44
45 # List C source files here. (C dependencies are automatically generated.)
46 SRC = $(TARGET).c lcd.c
47
48
49 # List Assembler source files here.
50 # Make them always end in a capital .S.  Files ending in a lowercase .s
51 # will not be considered source files but generated files (assembler
52 # output from the compiler), and will be deleted upon "make clean"!
53 # Even though the DOS/Win* filesystem matches both .s and .S the same,
54 # it will preserve the spelling of the filenames, and gcc itself does
55 # care about how the name is spelled on its command-line.
56 ASRC = 
57
58
59
60 # Optimization level, can be [0, 1, 2, 3, s]. 
61 # 0 = turn off optimization. s = optimize for size.
62 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
63 OPT = s
64
65 # Debugging format.
66 # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
67 # AVR (extended) COFF requires stabs, plus an avr-objcopy run.
68 DEBUG = dwarf-2
69
70 # List any extra directories to look for include files here.
71 #     Each directory must be seperated by a space.
72 EXTRAINCDIRS = 
73
74
75 # Compiler flag to set the C Standard level.
76 # c89   - "ANSI" C
77 # gnu89 - c89 plus GCC extensions
78 # c99   - ISO C99 standard (not yet fully implemented)
79 # gnu99 - c99 plus GCC extensions
80 CSTANDARD = -std=gnu99
81
82 # Place -D or -U options here
83 CDEFS =
84
85 # Place -I options here
86 CINCS =
87
88
89 # Compiler flags.
90 #  -g*:          generate debugging information
91 #  -O*:          optimization level
92 #  -f...:        tuning, see GCC manual and avr-libc documentation
93 #  -Wall...:     warning level
94 #  -Wa,...:      tell GCC to pass this to the assembler.
95 #    -adhlns...: create assembler listing
96 CFLAGS = -g$(DEBUG)
97 CFLAGS += $(CDEFS) $(CINCS)
98 CFLAGS += -O$(OPT)
99 CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
100 CFLAGS += -Wall -Wstrict-prototypes
101 CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
102 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
103 CFLAGS += $(CSTANDARD)
104
105
106
107 # Assembler flags.
108 #  -Wa,...:   tell GCC to pass this to the assembler.
109 #  -ahlms:    create listing
110 #  -gstabs:   have the assembler create line number information; note that
111 #             for use in COFF files, additional information about filenames
112 #             and function names needs to be present in the assembler source
113 #             files -- see avr-libc docs [FIXME: not yet described there]
114 ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs 
115
116
117
118 #Additional libraries.
119
120 # Minimalistic printf version
121 PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
122
123 # Floating point printf version (requires MATH_LIB = -lm below)
124 PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
125
126 PRINTF_LIB = 
127
128 # Minimalistic scanf version
129 SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
130
131 # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
132 SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
133
134 SCANF_LIB = 
135
136 MATH_LIB = -lm
137
138 # External memory options
139
140 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
141 # used for variables (.data/.bss) and heap (malloc()).
142 #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
143
144 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
145 # only used for heap (malloc()).
146 #EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
147
148 EXTMEMOPTS =
149
150 # Linker flags.
151 #  -Wl,...:     tell GCC to pass this to linker.
152 #    -Map:      create map file
153 #    --cref:    add cross reference to  map file
154 LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
155 LDFLAGS += $(EXTMEMOPTS)
156 LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
157
158
159
160
161 # Programming support using avrdude. Settings and variables.
162
163 # Programming hardware: alf avr910 avrisp bascom bsd 
164 # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
165 #
166 # Type: avrdude -c ?
167 # to get a full listing.
168 #
169 AVRDUDE_PROGRAMMER = usbtiny
170
171 # com1 = serial port. Use lpt1 to connect to parallel port.
172 #AVRDUDE_PORT = com1    # programmer connected to serial device
173
174 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
175 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
176
177
178 # Uncomment the following if you want avrdude's erase cycle counter.
179 # Note that this counter needs to be initialized first using -Yn,
180 # see avrdude manual.
181 #AVRDUDE_ERASE_COUNTER = -y
182
183 # Uncomment the following if you do /not/ wish a verification to be
184 # performed after programming the device.
185 #AVRDUDE_NO_VERIFY = -V
186
187 # Increase verbosity level.  Please use this when submitting bug
188 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> 
189 # to submit bug reports.
190 #AVRDUDE_VERBOSE = -v -v
191
192 AVRDUDE_FLAGS = -p $(MCU) -c $(AVRDUDE_PROGRAMMER)
193 AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
194 AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
195 AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
196
197
198
199 # ---------------------------------------------------------------------------
200
201 # Define directories, if needed.
202 #DIRAVR = c:/winavr
203 #DIRAVRBIN = $(DIRAVR)/bin
204 #DIRAVRUTILS = $(DIRAVR)/utils/bin
205 #DIRINC = .
206 #DIRLIB = $(DIRAVR)/avr/lib
207
208
209 # Define programs and commands.
210 SHELL = sh
211 CC = avr-gcc
212 OBJCOPY = avr-objcopy
213 OBJDUMP = avr-objdump
214 SIZE = avr-size
215 NM = avr-nm
216 AVRDUDE = avrdude
217 REMOVE = rm -f
218 COPY = cp
219
220
221
222
223 # Define Messages
224 # English
225 MSG_ERRORS_NONE = Errors: none
226 MSG_BEGIN = -------- begin --------
227 MSG_END = --------  end  --------
228 MSG_SIZE_BEFORE = Size before: 
229 MSG_SIZE_AFTER = Size after:
230 MSG_COFF = Converting to AVR COFF:
231 MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
232 MSG_FLASH = Creating load file for Flash:
233 MSG_EEPROM = Creating load file for EEPROM:
234 MSG_EXTENDED_LISTING = Creating Extended Listing:
235 MSG_SYMBOL_TABLE = Creating Symbol Table:
236 MSG_LINKING = Linking:
237 MSG_COMPILING = Compiling:
238 MSG_ASSEMBLING = Assembling:
239 MSG_CLEANING = Cleaning project:
240
241
242
243
244 # Define all object files.
245 OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) 
246
247 # Define all listing files.
248 LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
249
250
251 # Compiler flags to generate dependency files.
252 GENDEPFLAGS = -Wp,-M,-MP,-MT,$(*F).o,-MF,.dep/$(@F).d
253
254
255 # Combine all necessary flags and optional flags.
256 # Add target processor to flags.
257 ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
258 ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
259
260
261
262
263
264 # Default target.
265 all: begin gccversion sizebefore build sizeafter finished end
266
267 build: elf hex eep lss sym
268
269 elf: $(TARGET).elf
270 hex: $(TARGET).hex
271 eep: $(TARGET).eep
272 lss: $(TARGET).lss 
273 sym: $(TARGET).sym
274
275
276
277 # Eye candy.
278 # AVR Studio 3.x does not check make's exit code but relies on
279 # the following magic strings to be generated by the compile job.
280 begin:
281         @echo
282         @echo $(MSG_BEGIN)
283
284 finished:
285         @echo $(MSG_ERRORS_NONE)
286
287 end:
288         @echo $(MSG_END)
289         @echo
290
291
292 # Display size of file.
293 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
294 ELFSIZE = $(SIZE) -A $(TARGET).elf
295 sizebefore:
296         @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
297
298 sizeafter:
299         @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
300
301
302
303 # Display compiler version information.
304 gccversion : 
305         @$(CC) --version
306
307
308
309 # Program the device.  
310 program: $(TARGET).hex $(TARGET).eep
311         $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
312
313
314
315
316 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
317 COFFCONVERT=$(OBJCOPY) --debugging \
318 --change-section-address .data-0x800000 \
319 --change-section-address .bss-0x800000 \
320 --change-section-address .noinit-0x800000 \
321 --change-section-address .eeprom-0x810000 
322
323
324 coff: $(TARGET).elf
325         @echo
326         @echo $(MSG_COFF) $(TARGET).cof
327         $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
328
329
330 extcoff: $(TARGET).elf
331         @echo
332         @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
333         $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
334
335
336
337 # Create final output files (.hex, .eep) from ELF output file.
338 %.hex: %.elf
339         @echo
340         @echo $(MSG_FLASH) $@
341         $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
342
343 %.eep: %.elf
344         @echo
345         @echo $(MSG_EEPROM) $@
346         -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
347         --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
348
349 # Create extended listing file from ELF output file.
350 %.lss: %.elf
351         @echo
352         @echo $(MSG_EXTENDED_LISTING) $@
353         $(OBJDUMP) -h -S $< > $@
354
355 # Create a symbol table from ELF output file.
356 %.sym: %.elf
357         @echo
358         @echo $(MSG_SYMBOL_TABLE) $@
359         $(NM) -n $< > $@
360
361
362
363 # Link: create ELF output file from object files.
364 .SECONDARY : $(TARGET).elf
365 .PRECIOUS : $(OBJ)
366 %.elf: $(OBJ)
367         @echo
368         @echo $(MSG_LINKING) $@
369         $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
370
371
372 # Compile: create object files from C source files.
373 %.o : %.c
374         @echo
375         @echo $(MSG_COMPILING) $<
376         $(CC) -c $(ALL_CFLAGS) $< -o $@ 
377
378
379 # Compile: create assembler files from C source files.
380 %.s : %.c
381         $(CC) -S $(ALL_CFLAGS) $< -o $@
382
383
384 # Assemble: create object files from assembler source files.
385 %.o : %.S
386         @echo
387         @echo $(MSG_ASSEMBLING) $<
388         $(CC) -c $(ALL_ASFLAGS) $< -o $@
389
390
391
392 # Target: clean project.
393 clean: begin clean_list finished end
394
395 clean_list :
396         @echo
397         @echo $(MSG_CLEANING)
398         $(REMOVE) $(TARGET).hex
399         $(REMOVE) $(TARGET).eep
400         $(REMOVE) $(TARGET).obj
401         $(REMOVE) $(TARGET).cof
402         $(REMOVE) $(TARGET).elf
403         $(REMOVE) $(TARGET).map
404         $(REMOVE) $(TARGET).obj
405         $(REMOVE) $(TARGET).a90
406         $(REMOVE) $(TARGET).sym
407         $(REMOVE) $(TARGET).lnk
408         $(REMOVE) $(TARGET).lss
409         $(REMOVE) $(OBJ)
410         $(REMOVE) $(LST)
411         $(REMOVE) $(SRC:.c=.s)
412         $(REMOVE) $(SRC:.c=.d)
413         $(REMOVE) .dep/*
414
415
416
417 # Include the dependency files.
418 -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
419
420
421 # Listing of phony targets.
422 .PHONY : all begin finish end sizebefore sizeafter gccversion \
423 build elf hex eep lss sym coff extcoff \
424 clean clean_list program
425