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