Project

General

Profile

Revision 1499

implemented recursive makefile system

View differences:

branches/wireless/code/makefile_root.mk
1
# This is makefile_root.mk
2
#
3
# Make global makefile changes here
4
#
5
###################################
6

  
7
# Hey Emacs, this is a -*- makefile -*-
8
#----------------------------------------------------------------------------
9
# WinAVR Makefile Template written by Eric B. Weddington, J?rg Wunsch, et al.
10
#
11
# Released to the Public Domain
12
#
13
# Additional material for this makefile was written by:
14
# Peter Fleury
15
# Tim Henigan
16
# Colin O'Flynn
17
# Reiner Patommel
18
# Markus Pfaff
19
# Sander Pool
20
# Frederik Rouleau
21
#
22
#----------------------------------------------------------------------------
23
# On command line:
24
#
25
# make all = Make software.
26
#
27
# make clean = Clean out built project files.
28
#
29
# make coff = Convert ELF to AVR COFF.
30
#
31
# make extcoff = Convert ELF to AVR Extended COFF.
32
#
33
# make program = Download the hex file to the device, using avrdude.
34
#                Please customize the avrdude settings below first!
35
#
36
# make debug = Start either simulavr or avarice as specified for debugging,
37
#              with avr-gdb or avr-insight as the front end for debugging.
38
#
39
# make library = Build the library, then make software
40
#
41
# make filename.s = Just compile filename.c into the assembler code only.
42
#
43
# make filename.i = Create a preprocessed source file for use in submitting
44
#                   bug reports to the GCC project.
45
#
46
# To rebuild project do "make clean" then "make all".
47
#----------------------------------------------------------------------------
48

  
49
#if you want your code to work on the Firefly++ and not Firefly+
50
#then add the -DFFPP line to CDEFS
51
CDEFS =
52
#-DFFPP
53

  
54
# MCU name
55
MCU = atmega128
56

  
57
# Processor frequency.
58
#     This will define a symbol, F_CPU, in all source code files equal to the
59
#     processor frequency. You can then use this symbol in your source code to
60
#     calculate timings. Do NOT tack on a 'UL' at the end, this will be done
61
#     automatically to create a 32-bit value in your source code.
62
F_CPU = 8000000
63

  
64
# Output format. (can be srec, ihex, binary)
65
FORMAT = ihex
66

  
67
# List C source files here. (C dependencies are automatically generated.)
68
SRC = $(wildcard *.c)
69

  
70
# List Assembler source files here.
71
#     Make them always end in a capital .S.  Files ending in a lowercase .s
72
#     will not be considered source files but generated files (assembler
73
#     output from the compiler), and will be deleted upon "make clean"!
74
#     Even though the DOS/Win* filesystem matches both .s and .S the same,
75
#     it will preserve the spelling of the filenames, and gcc itself does
76
#     care about how the name is spelled on its command-line.
77
ASRC =
78

  
79
# Optimization level, can be [0, 1, 2, 3, s].
80
#     0 = turn off optimization. s = optimize for size.
81
#     (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
82
OPT = s
83

  
84
# Debugging format.
85
#     Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
86
#     AVR Studio 4.10 requires dwarf-2.
87
#     AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
88
DEBUG =
89

  
90
# Compiler flag to set the C Standard level.
91
#     c89   = "ANSI" C
92
#     gnu89 = c89 plus GCC extensions
93
#     c99   = ISO C99 standard (not yet fully implemented)
94
#     gnu99 = c99 plus GCC extensions
95
CSTANDARD = -std=gnu99
96

  
97
# Place -D or -U options here
98
CDEFS += -DF_CPU=$(F_CPU)UL
99
CDEFS += -DFFP
100
# for wireless library
101
ifdef USE_WIRELESS
102
	CDEFS += -DROBOT
103
endif
104

  
105
# Place -I, -L options here
106
CINCS = -I$(COLONYROOT)/code/lib/include/libdragonfly
107
CINCS += -L$(COLONYROOT)/code/lib/bin
108
ifdef USE_WIRELESS
109
  CINCS += -I$(COLONYROOT)/code/lib/include/libwireless
110
endif
111

  
112
#---------------- Compiler Options ----------------
113
#  -g*:          generate debugging information
114
#  -O*:          optimization level
115
#  -f...:        tuning, see GCC manual and avr-libc documentation
116
#  -Wall...:     warning level
117
#  -Wa,...:      tell GCC to pass this to the assembler.
118
#    -adhlns...: create assembler listing
119
CFLAGS =
120
# CFLAGS = -g$(DEBUG)
121
CFLAGS += $(CDEFS) $(CINCS)
122
CFLAGS += -O$(OPT)
123
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
124
CFLAGS += -Wall -Wstrict-prototypes
125
CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
126
CFLAGS += $(CSTANDARD)
127

  
128
#---------------- Assembler Options ----------------
129
#  -Wa,...:   tell GCC to pass this to the assembler.
130
#  -ahlms:    create listing
131
#  -gstabs:   have the assembler create line number information; note that
132
#             for use in COFF files, additional information about filenames
133
#             and function names needs to be present in the assembler source
134
#             files -- see avr-libc docs [FIXME: not yet described there]
135
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
136

  
137

  
138
#---------------- Library Options ----------------
139
# Minimalistic printf version
140
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
141

  
142
# Floating point printf version (requires MATH_LIB = -lm below)
143
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
144

  
145
# If this is left blank, then it will use the Standard printf version.
146
PRINTF_LIB =
147
#PRINTF_LIB = $(PRINTF_LIB_MIN)
148
#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
149

  
150

  
151
# Minimalistic scanf version
152
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
153

  
154
# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
155
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
156

  
157
# If this is left blank, then it will use the Standard scanf version.
158
SCANF_LIB =
159
#SCANF_LIB = $(SCANF_LIB_MIN)
160
#SCANF_LIB = $(SCANF_LIB_FLOAT)
161

  
162
MATH_LIB = -lm
163

  
164
#---------------- External Memory Options ----------------
165

  
166
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
167
# used for variables (.data/.bss) and heap (malloc()).
168
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
169

  
170
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
171
# only used for heap (malloc()).
172
#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
173

  
174
EXTMEMOPTS =
175

  
176
#---------------- Linker Options ----------------
177
#  -Wl,...:     tell GCC to pass this to linker.
178
#    -Map:      create map file
179
#    --cref:    add cross reference to  map file
180
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
181
LDFLAGS += $(EXTMEMOPTS)
182
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
183
ifdef USE_WIRELESS
184
	LDFLAGS += -lwireless
185
endif
186
LDFLAGS += -ldragonfly
187

  
188

  
189

  
190
#---------------- Programming Options (avrdude) ----------------
191

  
192
# Programming hardware: alf avr910 avrisp bascom bsd
193
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
194
#
195
# Type: avrdude -c ?
196
# to get a full listing.
197
#
198
AVRDUDE_PROGRAMMER = avrisp
199

  
200
# programmer connected to serial device
201

  
202
AVRDUDE_WRITE_FLASH = -b 57600 -U flash:w:$(TARGET).hex
203
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
204

  
205

  
206
# Uncomment the following if you want avrdude's erase cycle counter.
207
# Note that this counter needs to be initialized first using -Yn,
208
# see avrdude manual.
209
#AVRDUDE_ERASE_COUNTER = -y
210

  
211
# Uncomment the following if you do /not/ wish a verification to be
212
# performed after programming the device.
213
#AVRDUDE_NO_VERIFY = -V
214

  
215
# Increase verbosity level.  Please use this when submitting bug
216
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
217
# to submit bug reports.
218
#AVRDUDE_VERBOSE = -v -v
219

  
220
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
221
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
222
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
223
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
224

  
225
#don't check for device signature
226
AVRDUDE_FLAGS += -F
227

  
228

  
229

  
230
#---------------- Debugging Options ----------------
231

  
232
# For simulavr only - target MCU frequency.
233
DEBUG_MFREQ = $(F_CPU)
234

  
235
# Set the DEBUG_UI to either gdb or insight.
236
# DEBUG_UI = gdb
237
DEBUG_UI = insight
238

  
239
# Set the debugging back-end to either avarice, simulavr.
240
DEBUG_BACKEND = avarice
241
#DEBUG_BACKEND = simulavr
242

  
243
# GDB Init Filename.
244
GDBINIT_FILE = __avr_gdbinit
245

  
246
# When using avarice settings for the JTAG
247
JTAG_DEV = /dev/com1
248

  
249
# Debugging port used to communicate between GDB / avarice / simulavr.
250
DEBUG_PORT = 4242
251

  
252
# Debugging host used to communicate between GDB / avarice / simulavr, normally
253
#     just set to localhost unless doing some sort of crazy debugging when
254
#     avarice is running on a different computer.
255
DEBUG_HOST = localhost
256

  
257

  
258

  
259
#============================================================================
260

  
261

  
262
# Define programs and commands.
263
SHELL = sh
264
CC = avr-gcc
265
OBJCOPY = avr-objcopy
266
OBJDUMP = avr-objdump
267
SIZE = avr-size
268
NM = avr-nm
269
AVRDUDE = avrdude
270
REMOVE = rm -f
271
REMOVEDIR = rm -rf
272
COPY = cp
273
WINSHELL = cmd
274

  
275

  
276
# Define Messages
277
# English
278
MSG_ERRORS_NONE = Errors: none
279
MSG_BEGIN = -------- begin --------
280
MSG_END = --------  end  --------
281
MSG_SIZE_BEFORE = Size before:
282
MSG_SIZE_AFTER = Size after:
283
MSG_COFF = Converting to AVR COFF:
284
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
285
MSG_FLASH = Creating load file for Flash:
286
MSG_EEPROM = Creating load file for EEPROM:
287
MSG_EXTENDED_LISTING = Creating Extended Listing:
288
MSG_SYMBOL_TABLE = Creating Symbol Table:
289
MSG_LINKING = Linking:
290
MSG_COMPILING = Compiling:
291
MSG_ASSEMBLING = Assembling:
292
MSG_CLEANING = Cleaning project:
293
MSG_LIBRARY_BUILD = Building library:
294
MSG_LIBRARY_CHECK = Checking if we need to rebuild the library:
295

  
296

  
297

  
298
# Define all object files.
299
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
300

  
301
# Define all listing files.
302
LST = $(SRC:.c=.lst) $(ASRC:.S=.lst)
303

  
304

  
305
# Compiler flags to generate dependency files.
306
GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
307

  
308

  
309
# Combine all necessary flags and optional flags.
310
# Add target processor to flags.
311
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
312
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
313

  
314

  
315

  
316

  
317

  
318
# Default target.
319
all: begin gccversion lib sizebefore build sizeafter checksize end
320

  
321
build: elf hex eep lss sym
322

  
323
elf: $(TARGET).elf
324
hex: $(TARGET).hex
325
eep: $(TARGET).eep
326
lss: $(TARGET).lss
327
sym: $(TARGET).sym
328

  
329

  
330

  
331
# Eye candy.
332
# AVR Studio 3.x does not check make's exit code but relies on
333
# the following magic strings to be generated by the compile job.
334
begin:
335
	@echo
336
	@echo $(MSG_BEGIN)
337

  
338
end:
339
	@echo $(MSG_END)
340
	@echo
341

  
342

  
343
# Display size of file.
344
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
345
ELFSIZE = $(SIZE) -A $(TARGET).elf
346
AVRMEM = avr-mem.sh $(TARGET).elf $(MCU)
347

  
348
# Check RAM size (make sure under 4 kB)
349
AWK = $(shell if uname -s |grep -i w32 >/dev/null; then echo 'gawk'; else echo 'awk'; fi)
350
DATASIZE = avr-size -A main.elf | grep 'data' | $(AWK) '{ print $$2 }' > 1.tmp
351
BSSSIZE = avr-size -A main.elf | grep 'bss' | $(AWK) '{ print $$2 }' > 2.tmp
352
ADD = expr `cat 1.tmp` + `cat 2.tmp` > 3.tmp
353
CLEANSIZE = rm 1.tmp 2.tmp 3.tmp
354
checksize:
355
	@$(DATASIZE)
356
	@$(BSSSIZE)
357
	@$(ADD)
358
	@if test `cat 3.tmp` -gt 4096; \
359
	then echo "RAM size exceeded.  Make .data or .bss smaller.";echo;exit 1; \
360
	else echo ".data and .bss size fine";echo; fi
361
	@$(CLEANSIZE)
362

  
363
# Display size before
364
sizebefore:
365
	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
366
	$(AVRMEM) 2>/dev/null; echo; fi
367

  
368
# Display size after
369
sizeafter:
370
	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
371
	$(AVRMEM) 2>/dev/null; echo; fi
372

  
373

  
374

  
375
# Display compiler version information.
376
gccversion :
377
	@$(CC) --version
378
  
379
  
380
# Build the library
381
library:
382
	@echo $(MSG_LIBRARY_BUILD)
383
	@cd $(COLONYROOT)/code/projects/libdragonfly;make clean;make dist
384
	@cd $(COLONYROOT)/code/projects/libwireless/lib;make clean;make dist
385

  
386
# Check if library needs to be built
387
lib:
388
	@echo $(MSG_LIBRARY_CHECK)
389
	@cd $(COLONYROOT)/code/projects/libdragonfly;make dist
390
	@cd $(COLONYROOT)/code/projects/libwireless/lib;make dist
391

  
392

  
393
# Program the device.
394
program: $(TARGET).hex $(TARGET).eep
395
	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
396

  
397

  
398
# Generate avr-gdb config/init file which does the following:
399
#     define the reset signal, load the target file, connect to target, and set
400
#     a breakpoint at main().
401
gdb-config:
402
	@$(REMOVE) $(GDBINIT_FILE)
403
	@echo define reset >> $(GDBINIT_FILE)
404
	@echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
405
	@echo end >> $(GDBINIT_FILE)
406
	@echo file $(TARGET).elf >> $(GDBINIT_FILE)
407
	@echo target remote $(DEBUG_HOST):$(DEBUG_PORT)  >> $(GDBINIT_FILE)
408
ifeq ($(DEBUG_BACKEND),simulavr)
409
	@echo load  >> $(GDBINIT_FILE)
410
endif
411
	@echo break main >> $(GDBINIT_FILE)
412

  
413
debug: gdb-config $(TARGET).elf
414
ifeq ($(DEBUG_BACKEND), avarice)
415
	@echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
416
	@$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
417
	$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
418
	@$(WINSHELL) /c pause
419

  
420
else
421
	@$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
422
	$(DEBUG_MFREQ) --port $(DEBUG_PORT)
423
endif
424
	@$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
425

  
426

  
427

  
428

  
429
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
430
COFFCONVERT=$(OBJCOPY) --debugging \
431
--change-section-address .data-0x800000 \
432
--change-section-address .bss-0x800000 \
433
--change-section-address .noinit-0x800000 \
434
--change-section-address .eeprom-0x810000
435

  
436

  
437
coff: $(TARGET).elf
438
	@echo
439
	@echo $(MSG_COFF) $(TARGET).cof
440
	$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
441

  
442

  
443
extcoff: $(TARGET).elf
444
	@echo
445
	@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
446
	$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
447

  
448

  
449

  
450
# Create final output files (.hex, .eep) from ELF output file.
451
%.hex: %.elf
452
	@echo
453
	@echo $(MSG_FLASH) $@
454
	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
455

  
456
%.eep: %.elf
457
	@echo
458
	@echo $(MSG_EEPROM) $@
459
	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
460
	--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
461

  
462
# Create extended listing file from ELF output file.
463
%.lss: %.elf
464
	@echo
465
	@echo $(MSG_EXTENDED_LISTING) $@
466
	$(OBJDUMP) -h -S $< > $@
467

  
468
# Create a symbol table from ELF output file.
469
%.sym: %.elf
470
	@echo
471
	@echo $(MSG_SYMBOL_TABLE) $@
472
	$(NM) -n $< > $@
473

  
474

  
475

  
476
# Link: create ELF output file from object files.
477
.SECONDARY : $(TARGET).elf
478
.PRECIOUS : $(OBJ)
479
%.elf: $(OBJ)
480
	@echo
481
	@echo $(MSG_LINKING) $@
482
	$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
483

  
484

  
485
# Compile: create object files from C source files.
486
%.o : %.c
487
	@echo
488
	@echo $(MSG_COMPILING) $<
489
	$(CC) -c $(ALL_CFLAGS) $< -o $@
490

  
491

  
492
# Compile: create assembler files from C source files.
493
%.s : %.c
494
	$(CC) -S $(ALL_CFLAGS) $< -o $@
495

  
496

  
497
# Assemble: create object files from assembler source files.
498
%.o : %.S
499
	@echo
500
	@echo $(MSG_ASSEMBLING) $<
501
	$(CC) -c $(ALL_ASFLAGS) $< -o $@
502

  
503
# Create preprocessed source for use in sending a bug report.
504
%.i : %.c
505
	$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
506

  
507

  
508
# Target: clean project.
509
clean: begin clean_list end
510

  
511
clean_list :
512
	@echo
513
	@echo $(MSG_CLEANING)
514
	$(REMOVE) $(TARGET).hex
515
	$(REMOVE) $(TARGET).eep
516
	$(REMOVE) $(TARGET).cof
517
	$(REMOVE) $(TARGET).elf
518
	$(REMOVE) $(TARGET).map
519
	$(REMOVE) $(TARGET).sym
520
	$(REMOVE) $(TARGET).lss
521
	$(REMOVE) $(OBJ)
522
	$(REMOVE) $(LST)
523
	$(REMOVE) $(SRC:.c=.s)
524
	$(REMOVE) $(SRC:.c=.d)
525
	$(REMOVEDIR) .dep
526

  
527

  
528

  
529
# Include the dependency files.
530
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
531

  
532

  
533
# Listing of phony targets.
534
.PHONY : all begin finish end sizebefore sizeafter gccversion \
535
build elf hex eep lss sym coff extcoff \
536
clean clean_list program debug gdb-config
537

  
branches/wireless/code/projects/unit_tests/Makefile
1
########Update This Section########
2
#
3
#
1
# this is a local makefile
4 2

  
5 3
# Relative path to the root directory (containing lib directory)
6 4
ifndef COLONYROOT
7
COLONYROOT = ../../..
8
endif
5
COLONYROOT = ..
9 6

  
10 7
# Target file name (without extension).
11 8
TARGET = main
......
16 13
# com1 = serial port. Use lpt1 to connect to parallel port.
17 14
AVRDUDE_PORT = $(shell if uname -s |grep -i w32 >/dev/null; then echo 'COM4:'; else echo '/dev/ttyUSB0'; fi)
18 15

  
19
include $(COLONYROOT)/code/makefile_root.mk
16
else
17
COLONYROOT := ../$(COLONYROOT)
18
endif
19

  
20
include $(COLONYROOT)/Makefile
branches/wireless/code/projects/Makefile
1
# this is a local makefile
2

  
3
# Relative path to the root directory (containing lib directory)
4
ifndef COLONYROOT
5
COLONYROOT = ..
6

  
7
# Target file name (without extension).
8
TARGET = main
9

  
10
# Uncomment this to use the wireless library
11
USE_WIRELESS = 1
12

  
13
# com1 = serial port. Use lpt1 to connect to parallel port.
14
AVRDUDE_PORT = $(shell if uname -s |grep -i w32 >/dev/null; then echo 'COM4:'; else echo '/dev/ttyUSB0'; fi)
15

  
16
else
17
COLONYROOT := ../$(COLONYROOT)
18
endif
19

  
20
include $(COLONYROOT)/Makefile
branches/wireless/code/Makefile
1
# This is the root makefile
2
#
3
# Make global makefile changes here
4
#
5
###################################
6

  
7
# Relative path to the root directory (containing lib directory)
8
ifndef COLONYROOT
9
COLONYROOT := ..
10
else
11
COLONYROOT := ../$(COLONYROOT)
12
endif
13

  
14
# Hey Emacs, this is a -*- makefile -*-
15
#----------------------------------------------------------------------------
16
# WinAVR Makefile Template written by Eric B. Weddington, J?rg Wunsch, et al.
17
#
18
# Released to the Public Domain
19
#
20
# Additional material for this makefile was written by:
21
# Peter Fleury
22
# Tim Henigan
23
# Colin O'Flynn
24
# Reiner Patommel
25
# Markus Pfaff
26
# Sander Pool
27
# Frederik Rouleau
28
#
29
#----------------------------------------------------------------------------
30
# On command line:
31
#
32
# make all = Make software.
33
#
34
# make clean = Clean out built project files.
35
#
36
# make coff = Convert ELF to AVR COFF.
37
#
38
# make extcoff = Convert ELF to AVR Extended COFF.
39
#
40
# make program = Download the hex file to the device, using avrdude.
41
#                Please customize the avrdude settings below first!
42
#
43
# make debug = Start either simulavr or avarice as specified for debugging,
44
#              with avr-gdb or avr-insight as the front end for debugging.
45
#
46
# make library = Build the library, then make software
47
#
48
# make filename.s = Just compile filename.c into the assembler code only.
49
#
50
# make filename.i = Create a preprocessed source file for use in submitting
51
#                   bug reports to the GCC project.
52
#
53
# To rebuild project do "make clean" then "make all".
54
#----------------------------------------------------------------------------
55

  
56
#if you want your code to work on the Firefly++ and not Firefly+
57
#then add the -DFFPP line to CDEFS
58
CDEFS =
59
#-DFFPP
60

  
61
# MCU name
62
MCU = atmega128
63

  
64
# Processor frequency.
65
#     This will define a symbol, F_CPU, in all source code files equal to the
66
#     processor frequency. You can then use this symbol in your source code to
67
#     calculate timings. Do NOT tack on a 'UL' at the end, this will be done
68
#     automatically to create a 32-bit value in your source code.
69
F_CPU = 8000000
70

  
71
# Output format. (can be srec, ihex, binary)
72
FORMAT = ihex
73

  
74
# List C source files here. (C dependencies are automatically generated.)
75
SRC = $(wildcard *.c)
76

  
77
# List Assembler source files here.
78
#     Make them always end in a capital .S.  Files ending in a lowercase .s
79
#     will not be considered source files but generated files (assembler
80
#     output from the compiler), and will be deleted upon "make clean"!
81
#     Even though the DOS/Win* filesystem matches both .s and .S the same,
82
#     it will preserve the spelling of the filenames, and gcc itself does
83
#     care about how the name is spelled on its command-line.
84
ASRC =
85

  
86
# Optimization level, can be [0, 1, 2, 3, s].
87
#     0 = turn off optimization. s = optimize for size.
88
#     (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
89
OPT = s
90

  
91
# Debugging format.
92
#     Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
93
#     AVR Studio 4.10 requires dwarf-2.
94
#     AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
95
DEBUG =
96

  
97
# Compiler flag to set the C Standard level.
98
#     c89   = "ANSI" C
99
#     gnu89 = c89 plus GCC extensions
100
#     c99   = ISO C99 standard (not yet fully implemented)
101
#     gnu99 = c99 plus GCC extensions
102
CSTANDARD = -std=gnu99
103

  
104
# Place -D or -U options here
105
CDEFS += -DF_CPU=$(F_CPU)UL
106
CDEFS += -DFFP
107
# for wireless library
108
ifdef USE_WIRELESS
109
	CDEFS += -DROBOT
110
endif
111

  
112
# Place -I, -L options here
113
CINCS = -I$(COLONYROOT)/code/lib/include/libdragonfly
114
CINCS += -L$(COLONYROOT)/code/lib/bin
115
ifdef USE_WIRELESS
116
  CINCS += -I$(COLONYROOT)/code/lib/include/libwireless
117
endif
118

  
119
#---------------- Compiler Options ----------------
120
#  -g*:          generate debugging information
121
#  -O*:          optimization level
122
#  -f...:        tuning, see GCC manual and avr-libc documentation
123
#  -Wall...:     warning level
124
#  -Wa,...:      tell GCC to pass this to the assembler.
125
#    -adhlns...: create assembler listing
126
CFLAGS =
127
# CFLAGS = -g$(DEBUG)
128
CFLAGS += $(CDEFS) $(CINCS)
129
CFLAGS += -O$(OPT)
130
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
131
CFLAGS += -Wall -Wstrict-prototypes
132
CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
133
CFLAGS += $(CSTANDARD)
134

  
135
#---------------- Assembler Options ----------------
136
#  -Wa,...:   tell GCC to pass this to the assembler.
137
#  -ahlms:    create listing
138
#  -gstabs:   have the assembler create line number information; note that
139
#             for use in COFF files, additional information about filenames
140
#             and function names needs to be present in the assembler source
141
#             files -- see avr-libc docs [FIXME: not yet described there]
142
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
143

  
144

  
145
#---------------- Library Options ----------------
146
# Minimalistic printf version
147
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
148

  
149
# Floating point printf version (requires MATH_LIB = -lm below)
150
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
151

  
152
# If this is left blank, then it will use the Standard printf version.
153
PRINTF_LIB =
154
#PRINTF_LIB = $(PRINTF_LIB_MIN)
155
#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
156

  
157

  
158
# Minimalistic scanf version
159
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
160

  
161
# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
162
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
163

  
164
# If this is left blank, then it will use the Standard scanf version.
165
SCANF_LIB =
166
#SCANF_LIB = $(SCANF_LIB_MIN)
167
#SCANF_LIB = $(SCANF_LIB_FLOAT)
168

  
169
MATH_LIB = -lm
170

  
171
#---------------- External Memory Options ----------------
172

  
173
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
174
# used for variables (.data/.bss) and heap (malloc()).
175
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
176

  
177
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
178
# only used for heap (malloc()).
179
#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
180

  
181
EXTMEMOPTS =
182

  
183
#---------------- Linker Options ----------------
184
#  -Wl,...:     tell GCC to pass this to linker.
185
#    -Map:      create map file
186
#    --cref:    add cross reference to  map file
187
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
188
LDFLAGS += $(EXTMEMOPTS)
189
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
190
ifdef USE_WIRELESS
191
	LDFLAGS += -lwireless
192
endif
193
LDFLAGS += -ldragonfly
194

  
195

  
196

  
197
#---------------- Programming Options (avrdude) ----------------
198

  
199
# Programming hardware: alf avr910 avrisp bascom bsd
200
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
201
#
202
# Type: avrdude -c ?
203
# to get a full listing.
204
#
205
AVRDUDE_PROGRAMMER = avrisp
206

  
207
# programmer connected to serial device
208

  
209
AVRDUDE_WRITE_FLASH = -b 57600 -U flash:w:$(TARGET).hex
210
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
211

  
212

  
213
# Uncomment the following if you want avrdude's erase cycle counter.
214
# Note that this counter needs to be initialized first using -Yn,
215
# see avrdude manual.
216
#AVRDUDE_ERASE_COUNTER = -y
217

  
218
# Uncomment the following if you do /not/ wish a verification to be
219
# performed after programming the device.
220
#AVRDUDE_NO_VERIFY = -V
221

  
222
# Increase verbosity level.  Please use this when submitting bug
223
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
224
# to submit bug reports.
225
#AVRDUDE_VERBOSE = -v -v
226

  
227
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
228
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
229
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
230
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
231

  
232
#don't check for device signature
233
AVRDUDE_FLAGS += -F
234

  
235

  
236

  
237
#---------------- Debugging Options ----------------
238

  
239
# For simulavr only - target MCU frequency.
240
DEBUG_MFREQ = $(F_CPU)
241

  
242
# Set the DEBUG_UI to either gdb or insight.
243
# DEBUG_UI = gdb
244
DEBUG_UI = insight
245

  
246
# Set the debugging back-end to either avarice, simulavr.
247
DEBUG_BACKEND = avarice
248
#DEBUG_BACKEND = simulavr
249

  
250
# GDB Init Filename.
251
GDBINIT_FILE = __avr_gdbinit
252

  
253
# When using avarice settings for the JTAG
254
JTAG_DEV = /dev/com1
255

  
256
# Debugging port used to communicate between GDB / avarice / simulavr.
257
DEBUG_PORT = 4242
258

  
259
# Debugging host used to communicate between GDB / avarice / simulavr, normally
260
#     just set to localhost unless doing some sort of crazy debugging when
261
#     avarice is running on a different computer.
262
DEBUG_HOST = localhost
263

  
264

  
265

  
266
#============================================================================
267

  
268

  
269
# Define programs and commands.
270
SHELL = sh
271
CC = avr-gcc
272
OBJCOPY = avr-objcopy
273
OBJDUMP = avr-objdump
274
SIZE = avr-size
275
NM = avr-nm
276
AVRDUDE = avrdude
277
REMOVE = rm -f
278
REMOVEDIR = rm -rf
279
COPY = cp
280
WINSHELL = cmd
281

  
282

  
283
# Define Messages
284
# English
285
MSG_ERRORS_NONE = Errors: none
286
MSG_BEGIN = -------- begin --------
287
MSG_END = --------  end  --------
288
MSG_SIZE_BEFORE = Size before:
289
MSG_SIZE_AFTER = Size after:
290
MSG_COFF = Converting to AVR COFF:
291
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
292
MSG_FLASH = Creating load file for Flash:
293
MSG_EEPROM = Creating load file for EEPROM:
294
MSG_EXTENDED_LISTING = Creating Extended Listing:
295
MSG_SYMBOL_TABLE = Creating Symbol Table:
296
MSG_LINKING = Linking:
297
MSG_COMPILING = Compiling:
298
MSG_ASSEMBLING = Assembling:
299
MSG_CLEANING = Cleaning project:
300
MSG_LIBRARY_BUILD = Building library:
301
MSG_LIBRARY_CHECK = Checking if we need to rebuild the library:
302

  
303

  
304

  
305
# Define all object files.
306
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
307

  
308
# Define all listing files.
309
LST = $(SRC:.c=.lst) $(ASRC:.S=.lst)
310

  
311

  
312
# Compiler flags to generate dependency files.
313
GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
314

  
315

  
316
# Combine all necessary flags and optional flags.
317
# Add target processor to flags.
318
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
319
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
320

  
321

  
322

  
323

  
324

  
325
# Default target.
326
all: begin gccversion lib sizebefore build sizeafter checksize end
327

  
328
build: elf hex eep lss sym
329

  
330
elf: $(TARGET).elf
331
hex: $(TARGET).hex
332
eep: $(TARGET).eep
333
lss: $(TARGET).lss
334
sym: $(TARGET).sym
335

  
336

  
337

  
338
# Eye candy.
339
# AVR Studio 3.x does not check make's exit code but relies on
340
# the following magic strings to be generated by the compile job.
341
begin:
342
	@echo
343
	@echo $(MSG_BEGIN)
344

  
345
end:
346
	@echo $(MSG_END)
347
	@echo
348

  
349

  
350
# Display size of file.
351
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
352
ELFSIZE = $(SIZE) -A $(TARGET).elf
353
AVRMEM = avr-mem.sh $(TARGET).elf $(MCU)
354

  
355
# Check RAM size (make sure under 4 kB)
356
AWK = $(shell if uname -s |grep -i w32 >/dev/null; then echo 'gawk'; else echo 'awk'; fi)
357
DATASIZE = avr-size -A main.elf | grep 'data' | $(AWK) '{ print $$2 }' > 1.tmp
358
BSSSIZE = avr-size -A main.elf | grep 'bss' | $(AWK) '{ print $$2 }' > 2.tmp
359
ADD = expr `cat 1.tmp` + `cat 2.tmp` > 3.tmp
360
CLEANSIZE = rm 1.tmp 2.tmp 3.tmp
361
checksize:
362
	@$(DATASIZE)
363
	@$(BSSSIZE)
364
	@$(ADD)
365
	@if test `cat 3.tmp` -gt 4096; \
366
	then echo "RAM size exceeded.  Make .data or .bss smaller.";echo;exit 1; \
367
	else echo ".data and .bss size fine";echo; fi
368
	@$(CLEANSIZE)
369

  
370
# Display size before
371
sizebefore:
372
	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
373
	$(AVRMEM) 2>/dev/null; echo; fi
374

  
375
# Display size after
376
sizeafter:
377
	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
378
	$(AVRMEM) 2>/dev/null; echo; fi
379

  
380

  
381

  
382
# Display compiler version information.
383
gccversion :
384
	@$(CC) --version
385
  
386
  
387
# Build the library
388
library:
389
	@echo $(MSG_LIBRARY_BUILD)
390
	@cd $(COLONYROOT)/code/projects/libdragonfly;make clean;make dist
391
	@cd $(COLONYROOT)/code/projects/libwireless/lib;make clean;make dist
392

  
393
# Check if library needs to be built
394
lib:
395
	@echo $(MSG_LIBRARY_CHECK)
396
	@cd $(COLONYROOT)/code/projects/libdragonfly;make dist
397
	@cd $(COLONYROOT)/code/projects/libwireless/lib;make dist
398

  
399

  
400
# Program the device.
401
program: $(TARGET).hex $(TARGET).eep
402
	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
403

  
404

  
405
# Generate avr-gdb config/init file which does the following:
406
#     define the reset signal, load the target file, connect to target, and set
407
#     a breakpoint at main().
408
gdb-config:
409
	@$(REMOVE) $(GDBINIT_FILE)
410
	@echo define reset >> $(GDBINIT_FILE)
411
	@echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
412
	@echo end >> $(GDBINIT_FILE)
413
	@echo file $(TARGET).elf >> $(GDBINIT_FILE)
414
	@echo target remote $(DEBUG_HOST):$(DEBUG_PORT)  >> $(GDBINIT_FILE)
415
ifeq ($(DEBUG_BACKEND),simulavr)
416
	@echo load  >> $(GDBINIT_FILE)
417
endif
418
	@echo break main >> $(GDBINIT_FILE)
419

  
420
debug: gdb-config $(TARGET).elf
421
ifeq ($(DEBUG_BACKEND), avarice)
422
	@echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
423
	@$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
424
	$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
425
	@$(WINSHELL) /c pause
426

  
427
else
428
	@$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
429
	$(DEBUG_MFREQ) --port $(DEBUG_PORT)
430
endif
431
	@$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
432

  
433

  
434

  
435

  
436
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
437
COFFCONVERT=$(OBJCOPY) --debugging \
438
--change-section-address .data-0x800000 \
439
--change-section-address .bss-0x800000 \
440
--change-section-address .noinit-0x800000 \
441
--change-section-address .eeprom-0x810000
442

  
443

  
444
coff: $(TARGET).elf
445
	@echo
446
	@echo $(MSG_COFF) $(TARGET).cof
447
	$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
448

  
449

  
450
extcoff: $(TARGET).elf
451
	@echo
452
	@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
453
	$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
454

  
455

  
456

  
457
# Create final output files (.hex, .eep) from ELF output file.
458
%.hex: %.elf
459
	@echo
460
	@echo $(MSG_FLASH) $@
461
	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
462

  
463
%.eep: %.elf
464
	@echo
465
	@echo $(MSG_EEPROM) $@
466
	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
467
	--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
468

  
469
# Create extended listing file from ELF output file.
470
%.lss: %.elf
471
	@echo
472
	@echo $(MSG_EXTENDED_LISTING) $@
473
	$(OBJDUMP) -h -S $< > $@
474

  
475
# Create a symbol table from ELF output file.
476
%.sym: %.elf
477
	@echo
478
	@echo $(MSG_SYMBOL_TABLE) $@
479
	$(NM) -n $< > $@
480

  
481

  
482

  
483
# Link: create ELF output file from object files.
484
.SECONDARY : $(TARGET).elf
485
.PRECIOUS : $(OBJ)
486
%.elf: $(OBJ)
487
	@echo
488
	@echo $(MSG_LINKING) $@
489
	$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
490

  
491

  
492
# Compile: create object files from C source files.
493
%.o : %.c
494
	@echo
495
	@echo $(MSG_COMPILING) $<
496
	$(CC) -c $(ALL_CFLAGS) $< -o $@
497

  
498

  
499
# Compile: create assembler files from C source files.
500
%.s : %.c
501
	$(CC) -S $(ALL_CFLAGS) $< -o $@
502

  
503

  
504
# Assemble: create object files from assembler source files.
505
%.o : %.S
506
	@echo
507
	@echo $(MSG_ASSEMBLING) $<
508
	$(CC) -c $(ALL_ASFLAGS) $< -o $@
509

  
510
# Create preprocessed source for use in sending a bug report.
511
%.i : %.c
512
	$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
513

  
514

  
515
# Target: clean project.
516
clean: begin clean_list end
517

  
518
clean_list :
519
	@echo
520
	@echo $(MSG_CLEANING)
521
	$(REMOVE) $(TARGET).hex
522
	$(REMOVE) $(TARGET).eep
523
	$(REMOVE) $(TARGET).cof
524
	$(REMOVE) $(TARGET).elf
525
	$(REMOVE) $(TARGET).map
526
	$(REMOVE) $(TARGET).sym
527
	$(REMOVE) $(TARGET).lss
528
	$(REMOVE) $(OBJ)
529
	$(REMOVE) $(LST)
530
	$(REMOVE) $(SRC:.c=.s)
531
	$(REMOVE) $(SRC:.c=.d)
532
	$(REMOVEDIR) .dep
533

  
534

  
535

  
536
# Include the dependency files.
537
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
538

  
539

  
540
# Listing of phony targets.
541
.PHONY : all begin finish end sizebefore sizeafter gccversion \
542
build elf hex eep lss sym coff extcoff \
543
clean clean_list program debug gdb-config
544

  

Also available in: Unified diff