Remove tools - Create extra repository
[owSlave2.git] / DS2406 / Makefile
1 # Hey Emacs, this is a -*- makefile -*-
2 #----------------------------------------------------------------------------
3 # WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al.
4 #
5 # Released to the Public Domain
6 #
7 # Additional material for this makefile was written by:
8 # Peter Fleury
9 # Tim Henigan
10 # Colin O'Flynn
11 # Reiner Patommel
12 # Markus Pfaff
13 # Sander Pool
14 # Frederik Rouleau
15 # Carlos Lamas
16 #
17 #----------------------------------------------------------------------------
18 # On command line:
19 #
20 # make all = Make software.
21 #
22 # make clean = Clean out built project files.
23 #
24 # make coff = Convert ELF to AVR COFF.
25 #
26 # make extcoff = Convert ELF to AVR Extended COFF.
27 #
28 # make program = Download the hex file to the device, using avrdude.
29 #                Please customize the avrdude settings below first!
30 #
31 # make debug = Start either simulavr or avarice as specified for debugging, 
32 #              with avr-gdb or avr-insight as the front end for debugging.
33 #
34 # make filename.s = Just compile filename.c into the assembler code only.
35 #
36 # make filename.i = Create a preprocessed source file for use in submitting
37 #                   bug reports to the GCC project.
38 #
39 # To rebuild project do "make clean" then "make all".
40 #----------------------------------------------------------------------------
41
42
43 # MCU name
44 #MCU = attiny25
45 MCU = attiny84a
46
47
48 # Processor frequency.
49 #     This will define a symbol, F_CPU, in all source code files equal to the 
50 #     processor frequency. You can then use this symbol in your source code to 
51 #     calculate timings. Do NOT tack on a 'UL' at the end, this will be done
52 #     automatically to create a 32-bit value in your source code.
53 #     Typical values are:
54 #                       F_CPU =  1000000
55 #         F_CPU =  1843200
56 #         F_CPU =  2000000
57 #         F_CPU =  3686400
58 #         F_CPU =  4000000
59 #         F_CPU =  7372800
60 F_CPU =  8000000
61 #         F_CPU = 11059200
62 #         F_CPU = 14745600
63 #         F_CPU = 16000000
64 #         F_CPU = 18432000
65 #         F_CPU = 20000000
66 #         F_CPU = 8000000
67
68
69 # Output format. (can be srec, ihex, binary)
70 FORMAT = ihex
71
72
73 # Target file name (without extension).
74 TARGET = DS2423
75
76
77 # Object files directory
78 OBJDIR = obj
79
80
81 # List C source files here. (C dependencies are automatically generated.)
82 SRC = $(TARGET).c
83
84
85 # List C++ source files here. (C dependencies are automatically generated.)
86 CPPSRC = 
87
88
89 # List Assembler source files here.
90 #     Make them always end in a capital .S.  Files ending in a lowercase .s
91 #     will not be considered source files but generated files (assembler
92 #     output from the compiler), and will be deleted upon "make clean"!
93 #     Even though the DOS/Win* filesystem matches both .s and .S the same,
94 #     it will preserve the spelling of the filenames, and gcc itself does
95 #     care about how the name is spelled on its command-line.
96 ASRC = OWDS2423.S
97
98
99 # Optimization level, can be [0, 1, 2, 3, s]. 
100 #     0 = turn off optimization. s = optimize for size.
101 #     (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
102 OPT = s
103
104
105 # Debugging format.
106 #     Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
107 #     AVR Studio 4.10 requires dwarf-2.
108 #     AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
109 DEBUG = dwarf-2
110
111
112 # List any extra directories to look for include files here.
113 #     Each directory must be seperated by a space.
114 #     Use forward slashes for directory separators.
115 #     For a directory that has spaces, enclose it in quotes.
116 EXTRAINCDIRS = 
117
118
119 # Compiler flag to set the C Standard level.
120 #     c89   = "ANSI" C
121 #     gnu89 = c89 plus GCC extensions
122 #     c99   = ISO C99 standard (not yet fully implemented)
123 #     gnu99 = c99 plus GCC extensions
124 CSTANDARD = -std=gnu99
125
126
127 # Place -D or -U options here for C sources
128 CDEFS = -DF_CPU=$(F_CPU)UL
129
130
131 # Place -D or -U options here for C++ sources
132 CPPDEFS = -DF_CPU=$(F_CPU)UL
133 #CPPDEFS += -D__STDC_LIMIT_MACROS
134 #CPPDEFS += -D__STDC_CONSTANT_MACROS
135
136
137
138 #---------------- Compiler Options C ----------------
139 #  -g*:          generate debugging information
140 #  -O*:          optimization level
141 #  -f...:        tuning, see GCC manual and avr-libc documentation
142 #  -Wall...:     warning level
143 #  -Wa,...:      tell GCC to pass this to the assembler.
144 #    -adhlns...: create assembler listing
145 CFLAGS = -g$(DEBUG)
146 CFLAGS += $(CDEFS)
147 CFLAGS += -O$(OPT)
148 #CFLAGS += -mint8
149 #CFLAGS += -mshort-calls
150 CFLAGS += -funsigned-char
151 CFLAGS += -funsigned-bitfields
152 CFLAGS += -fpack-struct
153 CFLAGS += -fshort-enums
154 #CFLAGS += -fno-unit-at-a-time
155 CFLAGS += -Wall
156 CFLAGS += -Wstrict-prototypes
157 CFLAGS += -Wundef
158 #CFLAGS += -Wunreachable-code
159 #CFLAGS += -Wsign-compare
160 CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
161 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
162 CFLAGS += $(CSTANDARD)
163
164
165 #---------------- Compiler Options C++ ----------------
166 #  -g*:          generate debugging information
167 #  -O*:          optimization level
168 #  -f...:        tuning, see GCC manual and avr-libc documentation
169 #  -Wall...:     warning level
170 #  -Wa,...:      tell GCC to pass this to the assembler.
171 #    -adhlns...: create assembler listing
172 CPPFLAGS = -g$(DEBUG)
173 CPPFLAGS += $(CPPDEFS)
174 CPPFLAGS += -O$(OPT)
175 #CPPFLAGS += -mint8
176 #CPPFLAGS += -mshort-calls
177 CPPFLAGS += -funsigned-char
178 CPPFLAGS += -funsigned-bitfields
179 CPPFLAGS += -fpack-struct
180 CPPFLAGS += -fshort-enums
181 CPPFLAGS += -fno-exceptions
182 #CPPFLAGS += -fno-unit-at-a-time
183 CPPFLAGS += -Wall
184 #CPPFLAGS += -Wstrict-prototypes
185 CFLAGS += -Wundef
186 #CPPFLAGS += -Wunreachable-code
187 #CPPFLAGS += -Wsign-compare
188 CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
189 CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
190 #CPPFLAGS += $(CSTANDARD)
191
192
193 #---------------- Assembler Options ----------------
194 #  -Wa,...:   tell GCC to pass this to the assembler.
195 #  -ahlms:    create listing
196 #  -gstabs:   have the assembler create line number information; note that
197 #             for use in COFF files, additional information about filenames
198 #             and function names needs to be present in the assembler source
199 #             files -- see avr-libc docs [FIXME: not yet described there]
200 ASFLAGS = -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs 
201
202
203 #---------------- Library Options ----------------
204 # Minimalistic printf version
205 PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
206
207 # Floating point printf version (requires MATH_LIB = -lm below)
208 PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
209
210 # If this is left blank, then it will use the Standard printf version.
211 PRINTF_LIB = 
212 #PRINTF_LIB = $(PRINTF_LIB_MIN)
213 #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
214
215
216 # Minimalistic scanf version
217 SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
218
219 # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
220 SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
221
222 # If this is left blank, then it will use the Standard scanf version.
223 SCANF_LIB = 
224 #SCANF_LIB = $(SCANF_LIB_MIN)
225 #SCANF_LIB = $(SCANF_LIB_FLOAT)
226
227
228 MATH_LIB = -lm
229
230
231
232 #---------------- External Memory Options ----------------
233
234 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
235 # used for variables (.data/.bss) and heap (malloc()).
236 #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
237
238 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
239 # only used for heap (malloc()).
240 #EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
241
242 EXTMEMOPTS =
243
244
245
246 #---------------- Linker Options ----------------
247 #  -Wl,...:     tell GCC to pass this to linker.
248 #    -Map:      create map file
249 #    --cref:    add cross reference to  map file
250 LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
251 LDFLAGS += $(EXTMEMOPTS)
252 LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
253 #LDFLAGS += -T linker_script.x
254
255
256
257 #---------------- Programming Options (avrdude) ----------------
258
259 # Programming hardware: alf avr910 avrisp bascom bsd 
260 # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
261 #
262 # Type: avrdude -c ?
263 # to get a full listing.
264 #
265 AVRDUDE_PROGRAMMER = pony-stk200
266
267 # com1 = serial port. Use lpt1 to connect to parallel port.
268 AVRDUDE_PORT = lpt1
269
270 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
271 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
272
273
274 # Uncomment the following if you want avrdude's erase cycle counter.
275 # Note that this counter needs to be initialized first using -Yn,
276 # see avrdude manual.
277 #AVRDUDE_ERASE_COUNTER = -y
278
279 # Uncomment the following if you do /not/ wish a verification to be
280 # performed after programming the device.
281 #AVRDUDE_NO_VERIFY = -V
282
283 # Increase verbosity level.  Please use this when submitting bug
284 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> 
285 # to submit bug reports.
286 #AVRDUDE_VERBOSE = -v -v
287
288 AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
289 AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
290 AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
291 AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
292
293
294
295 #---------------- Debugging Options ----------------
296
297 # For simulavr only - target MCU frequency.
298 DEBUG_MFREQ = $(F_CPU)
299
300 # Set the DEBUG_UI to either gdb or insight.
301 DEBUG_UI = gdb
302 # DEBUG_UI = insight
303
304 # Set the debugging back-end to either avarice, simulavr.
305 #DEBUG_BACKEND = avarice
306 DEBUG_BACKEND = simulavr
307
308 # GDB Init Filename.
309 GDBINIT_FILE = __avr_gdbinit
310
311 # When using avarice settings for the JTAG
312 JTAG_DEV = /dev/com1
313
314 # Debugging port used to communicate between GDB / avarice / simulavr.
315 DEBUG_PORT = 4242
316
317 # Debugging host used to communicate between GDB / avarice / simulavr, normally
318 #     just set to localhost unless doing some sort of crazy debugging when 
319 #     avarice is running on a different computer.
320 DEBUG_HOST = localhost
321
322
323
324 #============================================================================
325
326
327 # Define programs and commands.
328 SHELL = sh
329 CC = avr-gcc
330 OBJCOPY = avr-objcopy
331 OBJDUMP = avr-objdump
332 SIZE = avr-size
333 NM = avr-nm
334 AVRDUDE = avrdude
335 REMOVE = rm -f
336 REMOVEDIR = rm -rf
337 COPY = cp
338 WINSHELL = cmd
339
340
341 # Define Messages
342 # English
343 MSG_ERRORS_NONE = Errors: none
344 MSG_BEGIN = -------- begin --------
345 MSG_END = --------  end  --------
346 MSG_SIZE_BEFORE = Size before: 
347 MSG_SIZE_AFTER = Size after:
348 MSG_COFF = Converting to AVR COFF:
349 MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
350 MSG_FLASH = Creating load file for Flash:
351 MSG_EEPROM = Creating load file for EEPROM:
352 MSG_EXTENDED_LISTING = Creating Extended Listing:
353 MSG_SYMBOL_TABLE = Creating Symbol Table:
354 MSG_LINKING = Linking:
355 MSG_COMPILING = Compiling C:
356 MSG_COMPILING_CPP = Compiling C++:
357 MSG_ASSEMBLING = Assembling:
358 MSG_CLEANING = Cleaning project:
359 MSG_CREATING_LIBRARY = Creating library:
360
361
362
363
364 # Define all object files.
365 OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o) 
366
367 # Define all listing files.
368 LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst) 
369
370
371 # Compiler flags to generate dependency files.
372 GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
373
374
375 # Combine all necessary flags and optional flags.
376 # Add target processor to flags.
377 ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
378 ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
379 ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
380
381
382
383
384
385 # Default target.
386 all: begin gccversion sizebefore build sizeafter end
387
388 # Change the build target to build a HEX file or a library.
389 build: elf hex eep lss sym
390 #build: lib
391
392
393 elf: $(TARGET).elf
394 hex: $(TARGET).hex
395 eep: $(TARGET).eep
396 lss: $(TARGET).lss
397 sym: $(TARGET).sym
398 LIBNAME=lib$(TARGET).a
399 lib: $(LIBNAME)
400
401
402
403 # Eye candy.
404 # AVR Studio 3.x does not check make's exit code but relies on
405 # the following magic strings to be generated by the compile job.
406
407 begin:
408         @echo
409         @echo $(MSG_BEGIN)
410
411 end:
412         @echo $(MSG_END)
413         @echo
414
415
416 # Display size of file.
417 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
418 ELFSIZE = $(SIZE) -A $(TARGET).elf
419 AVRMEM = avr-mem.sh $(TARGET).elf $(MCU)
420
421 sizebefore:
422         @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
423         $(AVRMEM) 2>/dev/null; echo; fi
424
425 sizeafter:
426         @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
427         $(AVRMEM) 2>/dev/null; echo; fi
428
429
430
431 # Display compiler version information.
432 gccversion : 
433         @$(CC) --version
434
435
436
437 # Program the device.  
438 program: $(TARGET).hex $(TARGET).eep
439         $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
440         $(AVRDUDE_WRITE_EEPROM)
441
442
443 # Generate avr-gdb config/init file which does the following:
444 #     define the reset signal, load the target file, connect to target, and set 
445 #     a breakpoint at main().
446 gdb-config: 
447         @$(REMOVE) $(GDBINIT_FILE)
448         @echo define reset >> $(GDBINIT_FILE)
449         @echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
450         @echo end >> $(GDBINIT_FILE)
451         @echo file $(TARGET).elf >> $(GDBINIT_FILE)
452         @echo target remote $(DEBUG_HOST):$(DEBUG_PORT)  >> $(GDBINIT_FILE)
453         ifeq ($(DEBUG_BACKEND),simulavr)
454         @echo load  >> $(GDBINIT_FILE)
455         endif
456         @echo break main >> $(GDBINIT_FILE)
457
458 debug: gdb-config $(TARGET).elf
459         ifeq ($(DEBUG_BACKEND), avarice)
460         @echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
461         @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
462         $(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
463         @$(WINSHELL) /c pause
464
465         else
466         @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
467         $(DEBUG_MFREQ) --port $(DEBUG_PORT)
468         endif
469         @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
470
471
472
473
474 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
475         COFFCONVERT = $(OBJCOPY) --debugging
476         COFFCONVERT += --change-section-address .data-0x800000
477         COFFCONVERT += --change-section-address .bss-0x800000
478         COFFCONVERT += --change-section-address .noinit-0x800000
479         COFFCONVERT += --change-section-address .eeprom-0x810000
480
481
482
483 coff: $(TARGET).elf
484         @echo
485         @echo $(MSG_COFF) $(TARGET).cof
486         $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
487
488
489 extcoff: $(TARGET).elf
490         @echo
491         @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
492         $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
493
494
495
496 # Create final output files (.hex, .eep) from ELF output file.
497 %.hex: %.elf
498         @echo
499         @echo $(MSG_FLASH) $@
500         $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
501
502 %.eep: %.elf
503         @echo
504         @echo $(MSG_EEPROM) $@
505         -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
506 --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
507
508 # Create extended listing file from ELF output file.
509 %.lss: %.elf
510         @echo
511         @echo $(MSG_EXTENDED_LISTING) $@
512         $(OBJDUMP) -h -S $< > $@
513
514 # Create a symbol table from ELF output file.
515 %.sym: %.elf
516         @echo
517         @echo $(MSG_SYMBOL_TABLE) $@
518         $(NM) -n $< > $@
519
520
521
522 # Create library from object files.
523 .SECONDARY : $(TARGET).a
524 .PRECIOUS : $(OBJ)
525 %.a: $(OBJ)
526         @echo
527         @echo $(MSG_CREATING_LIBRARY) $@
528         $(AR) $@ $(OBJ)
529
530
531 # Link: create ELF output file from object files.
532 .SECONDARY : $(TARGET).elf
533 .PRECIOUS : $(OBJ)
534 %.elf: $(OBJ)
535         @echo
536         @echo $(MSG_LINKING) $@
537         $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
538
539
540 # Compile: create object files from C source files.
541 $(OBJDIR)/%.o : %.c
542         @echo
543         @echo $(MSG_COMPILING) $<
544         $(CC) -c $(ALL_CFLAGS) $< -o $@
545
546
547 # Compile: create object files from C++ source files.
548 $(OBJDIR)/%.o : %.cpp
549         @echo
550         @echo $(MSG_COMPILING_CPP) $<
551         $(CC) -c $(ALL_CPPFLAGS) $< -o $@
552
553
554 # Compile: create assembler files from C source files.
555 %.s : %.c
556         $(CC) -S $(ALL_CFLAGS) $< -o $@
557
558
559 # Compile: create assembler files from C++ source files.
560 %.s : %.cpp
561         $(CC) -S $(ALL_CPPFLAGS) $< -o $@
562
563
564 # Assemble: create object files from assembler source files.
565 $(OBJDIR)/%.o : %.S
566         @echo
567         @echo $(MSG_ASSEMBLING) $<
568         $(CC) -c $(ALL_ASFLAGS) $< -o $@
569
570
571 # Create preprocessed source for use in sending a bug report.
572 %.i : %.c
573         $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
574
575
576 # Target: clean project.
577 clean: begin clean_list end
578
579 clean_list :
580         @echo
581         @echo $(MSG_CLEANING)
582         $(REMOVE) $(TARGET).hex
583         $(REMOVE) $(TARGET).eep
584         $(REMOVE) $(TARGET).cof
585         $(REMOVE) $(TARGET).elf
586         $(REMOVE) $(TARGET).map
587         $(REMOVE) $(TARGET).sym
588         $(REMOVE) $(TARGET).lss
589         $(REMOVEDIR) $(OBJDIR)
590         $(REMOVE) $(SRC:.c=.s)
591         $(REMOVE) $(SRC:.c=.d)
592         $(REMOVEDIR) .dep
593
594
595 # Create object files directory
596 $(shell mkdir $(OBJDIR) 2>/dev/null)
597
598
599 # Include the dependency files.
600 -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
601
602
603 # Listing of phony targets.
604 .PHONY : all begin finish end sizebefore sizeafter gccversion \
605 build elf hex eep lss sym coff extcoff \
606 clean clean_list program debug gdb-config
607