There, I fixed it! It does compile, though I did not yet test it. I
[cerebrum.git] / Makefile
blob21c537994599ee347690ec96aacb29b84573eb84
1 # WinAVR Sample makefile written by Eric B. Weddington, Jörg Wunsch, et al.
2 # Modified (bringing often-changed options to the top) by Elliot Williams
4 # make all = Make software and program
5 # make clean = Clean out built project files.
6 # make program = Download the hex file to the device, using avrdude. Please
7 # customize the avrdude settings below first!
9 # Microcontroller Type
10 MCU = atmega2560
12 # Target file name (without extension).
13 TARGET = cerebrum_firmware
15 # Programming hardware: type avrdude -c ?
16 # to get a full listing.
17 AVRDUDE_PROGRAMMER = stk500v2
19 AVRDUDE_PORT = /dev/ttyACM0 -b 115200
21 ############# Don't need to change below here for most purposes (Elliot)
23 # Optimization level, can be [0, 1, 2, 3, s]. 0 turns off optimization.
24 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
25 OPT = s
27 # Output format. (can be srec, ihex, binary)
28 FORMAT = ihex
30 # List C source files here. (C dependencies are automatically generated.)
31 SRC = $(TARGET).c uart.c
33 # List Assembler source files here.
34 # Make them always end in a capital .S. Files ending in a lowercase .s
35 # will not be considered source files but generated files (assembler
36 # output from the compiler), and will be deleted upon "make clean"!
37 # Even though the DOS/Win* filesystem matches both .s and .S the same,
38 # it will preserve the spelling of the filenames, and gcc itself does
39 # care about how the name is spelled on its command-line.
40 ASRC =
43 # List any extra directories to look for include files here.
44 # Each directory must be seperated by a space.
45 EXTRAINCDIRS =
48 # Optional compiler flags.
49 # -g: generate debugging information (for GDB, or for COFF conversion)
50 # -O*: optimization level
51 # -f...: tuning, see gcc manual and avr-libc documentation
52 # -Wall...: warning level
53 # -Wa,...: tell GCC to pass this to the assembler.
54 # -ahlms: create assembler listing
55 CFLAGS = -g -O$(OPT) \
56 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums \
57 -Wall -Wstrict-prototypes \
58 -Wa,-adhlns=$(<:.c=.lst) \
59 $(patsubst %,-I%,$(EXTRAINCDIRS))
62 # Set a "language standard" compiler flag.
63 # Unremark just one line below to set the language standard to use.
64 # gnu99 = C99 + GNU extensions. See GCC manual for more information.
65 #CFLAGS += -std=c89
66 #CFLAGS += -std=gnu89
67 #CFLAGS += -std=c99
68 CFLAGS += -std=gnu99 -DF_CPU=16000000UL
72 # Optional assembler flags.
73 # -Wa,...: tell GCC to pass this to the assembler.
74 # -ahlms: create listing
75 # -gstabs: have the assembler create line number information; note that
76 # for use in COFF files, additional information about filenames
77 # and function names needs to be present in the assembler source
78 # files -- see avr-libc docs [FIXME: not yet described there]
79 ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
83 # Optional linker flags.
84 # -Wl,...: tell GCC to pass this to linker.
85 # -Map: create map file
86 # --cref: add cross reference to map file
87 LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
91 # Additional libraries
93 # Minimalistic printf version
94 #LDFLAGS += -Wl,-u,vfprintf -lprintf_min
96 # Floating point printf version (requires -lm below)
97 #LDFLAGS += -Wl,-u,vfprintf -lprintf_flt
99 # -lm = math library
100 LDFLAGS += -lm
103 # Programming support using avrdude. Settings and variables.
106 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
107 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
109 AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
111 # Uncomment the following if you want avrdude's erase cycle counter.
112 # Note that this counter needs to be initialized first using -Yn,
113 # see avrdude manual.
114 #AVRDUDE_ERASE += -y
116 # Uncomment the following if you do /not/ wish a verification to be
117 # performed after programming the device.
118 #AVRDUDE_FLAGS += -V
120 # Increase verbosity level. Please use this when submitting bug
121 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
122 # to submit bug reports.
123 #AVRDUDE_FLAGS += -v -v
125 # Define programs and commands.
126 SHELL = sh
128 CC = avr-gcc
130 OBJCOPY = avr-objcopy
131 OBJDUMP = avr-objdump
132 SIZE = avr-size
135 # Programming support using avrdude.
136 AVRDUDE = avrdude
139 REMOVE = rm -f
140 COPY = cp
142 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
143 ELFSIZE = $(SIZE) -A $(TARGET).elf
147 # Define Messages
148 # English
149 MSG_ERRORS_NONE = Errors: none
150 MSG_BEGIN = -------- begin --------
151 MSG_END = -------- end --------
152 MSG_SIZE_BEFORE = Size before:
153 MSG_SIZE_AFTER = Size after:
154 MSG_COFF = Converting to AVR COFF:
155 MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
156 MSG_FLASH = Creating load file for Flash:
157 MSG_EEPROM = Creating load file for EEPROM:
158 MSG_EXTENDED_LISTING = Creating Extended Listing:
159 MSG_SYMBOL_TABLE = Creating Symbol Table:
160 MSG_LINKING = Linking:
161 MSG_COMPILING = Compiling:
162 MSG_ASSEMBLING = Assembling:
163 MSG_CLEANING = Cleaning project:
168 # Define all object files.
169 OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
171 # Define all listing files.
172 LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
174 # Combine all necessary flags and optional flags.
175 # Add target processor to flags.
176 ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
177 ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
181 # Default target: make program!
182 all: begin gccversion sizebefore $(TARGET).elf $(TARGET).hex $(TARGET).eep \
183 $(TARGET).lss $(TARGET).sym sizeafter finished end
184 # $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
186 # Eye candy.
187 # AVR Studio 3.x does not check make's exit code but relies on
188 # the following magic strings to be generated by the compile job.
189 begin:
190 @echo
191 @echo $(MSG_BEGIN)
193 finished:
194 @echo $(MSG_ERRORS_NONE)
196 end:
197 @echo $(MSG_END)
198 @echo
201 # Display size of file.
202 sizebefore:
203 @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
205 sizeafter:
206 @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
210 # Display compiler version information.
211 gccversion :
212 @$(CC) --version
217 # Convert ELF to COFF for use in debugging / simulating in
218 # AVR Studio or VMLAB.
219 COFFCONVERT=$(OBJCOPY) --debugging \
220 --change-section-address .data-0x800000 \
221 --change-section-address .bss-0x800000 \
222 --change-section-address .noinit-0x800000 \
223 --change-section-address .eeprom-0x810000
226 coff: $(TARGET).elf
227 @echo
228 @echo $(MSG_COFF) $(TARGET).cof
229 $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
232 extcoff: $(TARGET).elf
233 @echo
234 @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
235 $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
240 # Program the device.
241 program: $(TARGET).hex $(TARGET).eep
242 # ./pokedtr
243 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
248 # Create final output files (.hex, .eep) from ELF output file.
249 %.hex: %.elf
250 @echo
251 @echo $(MSG_FLASH) $@
252 $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
254 %.eep: %.elf
255 @echo
256 @echo $(MSG_EEPROM) $@
257 -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
258 --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
260 # Create extended listing file from ELF output file.
261 %.lss: %.elf
262 @echo
263 @echo $(MSG_EXTENDED_LISTING) $@
264 $(OBJDUMP) -h -S $< > $@
266 # Create a symbol table from ELF output file.
267 %.sym: %.elf
268 @echo
269 @echo $(MSG_SYMBOL_TABLE) $@
270 avr-nm -n $< > $@
274 # Link: create ELF output file from object files.
275 .SECONDARY : $(TARGET).elf
276 .PRECIOUS : $(OBJ)
277 %.elf: $(OBJ)
278 @echo
279 @echo $(MSG_LINKING) $@
280 $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
283 # Compile: create object files from C source files.
284 %.o : %.c
285 @echo
286 @echo $(MSG_COMPILING) $<
287 $(CC) -c $(ALL_CFLAGS) $< -o $@
290 # Compile: create assembler files from C source files.
291 %.s : %.c
292 $(CC) -S $(ALL_CFLAGS) $< -o $@
295 # Assemble: create object files from assembler source files.
296 %.o : %.S
297 @echo
298 @echo $(MSG_ASSEMBLING) $<
299 $(CC) -c $(ALL_ASFLAGS) $< -o $@
306 # Target: clean project.
307 clean: begin clean_list finished end
309 clean_list :
310 @echo
311 @echo $(MSG_CLEANING)
312 $(REMOVE) $(TARGET).hex
313 $(REMOVE) $(TARGET).eep
314 $(REMOVE) $(TARGET).obj
315 $(REMOVE) $(TARGET).cof
316 $(REMOVE) $(TARGET).elf
317 $(REMOVE) $(TARGET).map
318 $(REMOVE) $(TARGET).obj
319 $(REMOVE) $(TARGET).a90
320 $(REMOVE) $(TARGET).sym
321 $(REMOVE) $(TARGET).lnk
322 $(REMOVE) $(TARGET).lss
323 $(REMOVE) $(OBJ)
324 $(REMOVE) $(LST)
325 $(REMOVE) $(SRC:.c=.s)
326 $(REMOVE) $(SRC:.c=.d)
327 $(REMOVE) *~
329 # Automatically generate C source code dependencies.
330 # (Code originally taken from the GNU make user manual and modified
331 # (See README.txt Credits).)
333 # Note that this will work with sh (bash) and sed that is shipped with WinAVR
334 # (see the SHELL variable defined above).
335 # This may not work with other shells or other seds.
337 %.d: %.c
338 set -e; $(CC) -MM $(ALL_CFLAGS) $< \
339 | sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > $@; \
340 [ -s $@ ] || rm -f $@
343 # Remove the '-' if you want to see the dependency files generated.
344 -include $(SRC:.c=.d)
348 # Listing of phony targets.
349 .PHONY : all begin finish end sizebefore sizeafter gccversion coff extcoff \
350 clean clean_list program