Started all over. The repo was just too messy.
[cerebrum.git] / Makefile
blob73b2c51b47cbf9dc5255409e7ca0a15a8aeaa028
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 <<<<<<< HEAD
11 MCU = atmega328p
12 =======
13 MCU = atmega328
14 >>>>>>> feeeea7... Converted to plain c. Added a makefile.
16 # Target file name (without extension).
17 TARGET = cerebrum_firmware
19 # Programming hardware: type avrdude -c ?
20 # to get a full listing.
21 <<<<<<< HEAD
22 AVRDUDE_PROGRAMMER = stk500v1
24 AVRDUDE_PORT = /dev/arduino0 -b 57600
25 =======
26 # AVRDUDE_PROGRAMMER = dapa
27 AVRDUDE_PROGRAMMER = stk500v2
28 # AVRDUDE_PROGRAMMER = dt006
30 AVRDUDE_PORT = /dev/ttyUSB0 # not really needed for usb
31 >>>>>>> feeeea7... Converted to plain c. Added a makefile.
33 ############# Don't need to change below here for most purposes (Elliot)
35 # Optimization level, can be [0, 1, 2, 3, s]. 0 turns off optimization.
36 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
37 OPT = s
39 # Output format. (can be srec, ihex, binary)
40 FORMAT = ihex
42 # List C source files here. (C dependencies are automatically generated.)
43 <<<<<<< HEAD
44 SRC = $(TARGET).c uart.c
45 =======
46 SRC = $(TARGET).c
48 # If there is more than one source file, append them above, or modify and
49 # uncomment the following:
50 #SRC += foo.c bar.c
52 # You can also wrap lines by appending a backslash to the end of the line:
53 #SRC += baz.c \
54 #xyzzy.c
57 >>>>>>> feeeea7... Converted to plain c. Added a makefile.
59 # List Assembler source files here.
60 # Make them always end in a capital .S. Files ending in a lowercase .s
61 # will not be considered source files but generated files (assembler
62 # output from the compiler), and will be deleted upon "make clean"!
63 # Even though the DOS/Win* filesystem matches both .s and .S the same,
64 # it will preserve the spelling of the filenames, and gcc itself does
65 # care about how the name is spelled on its command-line.
66 ASRC =
69 # List any extra directories to look for include files here.
70 # Each directory must be seperated by a space.
71 EXTRAINCDIRS =
74 # Optional compiler flags.
75 # -g: generate debugging information (for GDB, or for COFF conversion)
76 # -O*: optimization level
77 # -f...: tuning, see gcc manual and avr-libc documentation
78 # -Wall...: warning level
79 # -Wa,...: tell GCC to pass this to the assembler.
80 # -ahlms: create assembler listing
81 CFLAGS = -g -O$(OPT) \
82 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums \
83 -Wall -Wstrict-prototypes \
84 -Wa,-adhlns=$(<:.c=.lst) \
85 $(patsubst %,-I%,$(EXTRAINCDIRS))
88 # Set a "language standard" compiler flag.
89 # Unremark just one line below to set the language standard to use.
90 # gnu99 = C99 + GNU extensions. See GCC manual for more information.
91 #CFLAGS += -std=c89
92 #CFLAGS += -std=gnu89
93 #CFLAGS += -std=c99
94 <<<<<<< HEAD
95 CFLAGS += -std=gnu99 -DF_CPU=16000000
96 =======
97 CFLAGS += -std=gnu99
98 >>>>>>> feeeea7... Converted to plain c. Added a makefile.
102 # Optional assembler flags.
103 # -Wa,...: tell GCC to pass this to the assembler.
104 # -ahlms: create listing
105 # -gstabs: have the assembler create line number information; note that
106 # for use in COFF files, additional information about filenames
107 # and function names needs to be present in the assembler source
108 # files -- see avr-libc docs [FIXME: not yet described there]
109 ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
113 # Optional linker flags.
114 # -Wl,...: tell GCC to pass this to linker.
115 # -Map: create map file
116 # --cref: add cross reference to map file
117 LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
121 # Additional libraries
123 # Minimalistic printf version
124 #LDFLAGS += -Wl,-u,vfprintf -lprintf_min
126 # Floating point printf version (requires -lm below)
127 #LDFLAGS += -Wl,-u,vfprintf -lprintf_flt
129 # -lm = math library
130 LDFLAGS += -lm
133 # Programming support using avrdude. Settings and variables.
136 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
137 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
139 AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
141 # Uncomment the following if you want avrdude's erase cycle counter.
142 # Note that this counter needs to be initialized first using -Yn,
143 # see avrdude manual.
144 #AVRDUDE_ERASE += -y
146 # Uncomment the following if you do /not/ wish a verification to be
147 # performed after programming the device.
148 #AVRDUDE_FLAGS += -V
150 # Increase verbosity level. Please use this when submitting bug
151 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
152 # to submit bug reports.
153 #AVRDUDE_FLAGS += -v -v
155 <<<<<<< HEAD
156 =======
157 #Run while cable attached or don't
158 AVRDUDE_FLAGS += -E reset #keep chip disabled while cable attached
159 #AVRDUDE_FLAGS += -E noreset
161 #AVRDUDE_WRITE_FLASH = -U lfuse:w:0x04:m #run with 8 Mhz clock
163 #AVRDUDE_WRITE_FLASH = -U lfuse:w:0x21:m #run with 1 Mhz clock #default clock mode
165 #AVRDUDE_WRITE_FLASH = -U lfuse:w:0x01:m #run with 1 Mhz clock no start up time
167 # ---------------------------------------------------------------------------
169 # Define directories, if needed.
170 DIRAVR = c:/winavr
171 DIRAVRBIN = $(DIRAVR)/bin
172 DIRAVRUTILS = $(DIRAVR)/utils/bin
173 DIRINC = .
174 DIRLIB = $(DIRAVR)/avr/lib
177 >>>>>>> feeeea7... Converted to plain c. Added a makefile.
178 # Define programs and commands.
179 SHELL = sh
181 CC = avr-gcc
183 OBJCOPY = avr-objcopy
184 OBJDUMP = avr-objdump
185 SIZE = avr-size
188 # Programming support using avrdude.
189 AVRDUDE = avrdude
192 REMOVE = rm -f
193 COPY = cp
195 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
196 ELFSIZE = $(SIZE) -A $(TARGET).elf
200 # Define Messages
201 # English
202 MSG_ERRORS_NONE = Errors: none
203 MSG_BEGIN = -------- begin --------
204 MSG_END = -------- end --------
205 MSG_SIZE_BEFORE = Size before:
206 MSG_SIZE_AFTER = Size after:
207 MSG_COFF = Converting to AVR COFF:
208 MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
209 MSG_FLASH = Creating load file for Flash:
210 MSG_EEPROM = Creating load file for EEPROM:
211 MSG_EXTENDED_LISTING = Creating Extended Listing:
212 MSG_SYMBOL_TABLE = Creating Symbol Table:
213 MSG_LINKING = Linking:
214 MSG_COMPILING = Compiling:
215 MSG_ASSEMBLING = Assembling:
216 MSG_CLEANING = Cleaning project:
221 # Define all object files.
222 OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
224 # Define all listing files.
225 LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
227 # Combine all necessary flags and optional flags.
228 # Add target processor to flags.
229 ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
230 ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
234 # Default target: make program!
235 all: begin gccversion sizebefore $(TARGET).elf $(TARGET).hex $(TARGET).eep \
236 $(TARGET).lss $(TARGET).sym sizeafter finished end
237 # $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
239 # Eye candy.
240 # AVR Studio 3.x does not check make's exit code but relies on
241 # the following magic strings to be generated by the compile job.
242 begin:
243 @echo
244 @echo $(MSG_BEGIN)
246 finished:
247 @echo $(MSG_ERRORS_NONE)
249 end:
250 @echo $(MSG_END)
251 @echo
254 # Display size of file.
255 sizebefore:
256 @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
258 sizeafter:
259 @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
263 # Display compiler version information.
264 gccversion :
265 @$(CC) --version
270 # Convert ELF to COFF for use in debugging / simulating in
271 # AVR Studio or VMLAB.
272 COFFCONVERT=$(OBJCOPY) --debugging \
273 --change-section-address .data-0x800000 \
274 --change-section-address .bss-0x800000 \
275 --change-section-address .noinit-0x800000 \
276 --change-section-address .eeprom-0x810000
279 coff: $(TARGET).elf
280 @echo
281 @echo $(MSG_COFF) $(TARGET).cof
282 $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
285 extcoff: $(TARGET).elf
286 @echo
287 @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
288 $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
293 # Program the device.
294 program: $(TARGET).hex $(TARGET).eep
295 <<<<<<< HEAD
296 ./pokedtr
297 =======
298 >>>>>>> feeeea7... Converted to plain c. Added a makefile.
299 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
304 # Create final output files (.hex, .eep) from ELF output file.
305 %.hex: %.elf
306 @echo
307 @echo $(MSG_FLASH) $@
308 $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
310 %.eep: %.elf
311 @echo
312 @echo $(MSG_EEPROM) $@
313 -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
314 --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
316 # Create extended listing file from ELF output file.
317 %.lss: %.elf
318 @echo
319 @echo $(MSG_EXTENDED_LISTING) $@
320 $(OBJDUMP) -h -S $< > $@
322 # Create a symbol table from ELF output file.
323 %.sym: %.elf
324 @echo
325 @echo $(MSG_SYMBOL_TABLE) $@
326 avr-nm -n $< > $@
330 # Link: create ELF output file from object files.
331 .SECONDARY : $(TARGET).elf
332 .PRECIOUS : $(OBJ)
333 %.elf: $(OBJ)
334 @echo
335 @echo $(MSG_LINKING) $@
336 $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
339 # Compile: create object files from C source files.
340 %.o : %.c
341 @echo
342 @echo $(MSG_COMPILING) $<
343 $(CC) -c $(ALL_CFLAGS) $< -o $@
346 # Compile: create assembler files from C source files.
347 %.s : %.c
348 $(CC) -S $(ALL_CFLAGS) $< -o $@
351 # Assemble: create object files from assembler source files.
352 %.o : %.S
353 @echo
354 @echo $(MSG_ASSEMBLING) $<
355 $(CC) -c $(ALL_ASFLAGS) $< -o $@
362 # Target: clean project.
363 clean: begin clean_list finished end
365 clean_list :
366 @echo
367 @echo $(MSG_CLEANING)
368 $(REMOVE) $(TARGET).hex
369 $(REMOVE) $(TARGET).eep
370 $(REMOVE) $(TARGET).obj
371 $(REMOVE) $(TARGET).cof
372 $(REMOVE) $(TARGET).elf
373 $(REMOVE) $(TARGET).map
374 $(REMOVE) $(TARGET).obj
375 $(REMOVE) $(TARGET).a90
376 $(REMOVE) $(TARGET).sym
377 $(REMOVE) $(TARGET).lnk
378 $(REMOVE) $(TARGET).lss
379 $(REMOVE) $(OBJ)
380 $(REMOVE) $(LST)
381 $(REMOVE) $(SRC:.c=.s)
382 $(REMOVE) $(SRC:.c=.d)
383 $(REMOVE) *~
385 # Automatically generate C source code dependencies.
386 # (Code originally taken from the GNU make user manual and modified
387 # (See README.txt Credits).)
389 # Note that this will work with sh (bash) and sed that is shipped with WinAVR
390 # (see the SHELL variable defined above).
391 # This may not work with other shells or other seds.
393 %.d: %.c
394 set -e; $(CC) -MM $(ALL_CFLAGS) $< \
395 | sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > $@; \
396 [ -s $@ ] || rm -f $@
399 # Remove the '-' if you want to see the dependency files generated.
400 -include $(SRC:.c=.d)
404 # Listing of phony targets.
405 .PHONY : all begin finish end sizebefore sizeafter gccversion coff extcoff \
406 clean clean_list program