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