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