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