1 # WinAVR Sample makefile written by Eric B. Weddington, Jörg Wunsch, et al.
2 # Released to the Public Domain
3 # Please read the make user manual!
5 # Additional material for this makefile was submitted by:
13 # Adopted to our needs for FREMO Clock by
14 # Bernd Wisotzki, Martin Pischky and Stefan Seibt
18 # make all = Make software.
20 # make clean = Clean out built project files.
22 # make version = shows adapted version string from sysdef.h
24 # make coff = Convert ELF to AVR COFF (for use with AVR Studio 3.x or VMLAB).
26 # make extcoff = Convert ELF to AVR Extended COFF (for use with AVR Studio
29 # make program = Download the hex file to the device, using avrdude. Please
30 # customize the avrdude settings below first!
32 # make program-flash = Download the flash hex file only
34 # make program-eeprom = Download the eeprom hex file only
36 # make program-fuses = Download the fusese only
38 # make filename.s = Just compile filename.c into the assembler code only
40 # make doxygen = run doxygen to build documentation
42 # make umlet = generate fremoclock.uxf.pdf from fremoclock.uxf
44 # To rebuild project do "make clean all".
47 # LOCONET_DIR = ../loconet
49 USER_DIR = ./20_UserInterface
51 # Output directory for all files needed for build process (.d,.lst,.o)
54 # Add make targets where no dependicy file generation is necassary
55 NODEPS := clean version program-fuses gccversion
57 vpath %.h $(CORE_DIR):$(USER_DIR):$(LOCONET_DIR)
58 vpath %.c $(CORE_DIR):$(USER_DIR):$(LOCONET_DIR)
61 # When changing this, also adopt the fuses as needed, see AVRDUDE_FUSES below
67 # usually defined here, see sysdef.h for now!
70 # Output format. (can be srec, ihex, binary)
73 # determines the target program version from a string defined in sysdef.h
74 # adapt this to whatever you need
76 PROG_VERSION = $(if $(wildcard $(V_F)),$(shell sed -n '/VERSION/p' $(V_F) | sed 's/^[^"]*"//;s/".*//;s/\./_/g'),"???")
78 # Target file name (without extension).
79 TARGET = fremoclock_v$(PROG_VERSION)
81 # Optimization level, can be [0, 1, 2, 3, s]. 0 turns off optimization.
82 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
85 # List C source files here. (C dependencies are automatically generated.)
88 # If there is more than one source file, append them above, or modify and
89 # uncomment the following:
90 # SRC += lcd.c ln_sw_uart.c uart.c
91 # SRC += ln_buf.c Timer.c HwTimerAvr.c
92 # SRC += DigitalOutputAvr.c
95 SRC += Timer.c SysHwTimer.c
96 SRC += lcd.c PushButton.c
98 SRC += UserInterfaceCommonData.c UserSettings.c
99 SRC += UserInterfaceMenu.c UserInterfaceLcd.c
100 SRC += UserInterfaceMenuNormal.c UserInterfaceLcdNormal.c
101 SRC += UserInterfaceMenuProgram.c UserInterfaceLcdProgram.c
103 # You can also wrap lines by appending a backslash to the end of the line:
107 # List Assembler source files here.
108 # Make them always end in a capital .S. Files ending in a lowercase .s
109 # will not be considered source files but generated files (assembler
110 # output from the compiler), and will be deleted upon "make clean"!
111 # Even though the DOS/Win* filesystem matches both .s and .S the same,
112 # it will preserve the spelling of the filenames, and gcc itself does
113 # care about how the name is spelled on its command-line.
116 # List any extra directories to look for include files here.
117 # Each directory must be seperated by a space.
118 EXTRAINCDIRS = $(LOCONET_DIR) $(CORE_DIR) $(USER_DIR)
120 # Optional compiler flags.
121 # -g: generate debugging information (for GDB, or for COFF conversion)
122 # -O*: optimization level
123 # -f...: tuning, see gcc manual and avr-libc documentation
124 # -Wall...: warning level
125 # -Wa,...: tell GCC to pass this to the assembler.
126 # -ahlms: create assembler listing
127 #-funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
129 -funsigned-bitfields -fpack-struct -fshort-enums \
130 -Wall -Wstrict-prototypes \
131 -Wa,-adhlns=$(join $(BUILD_DIR),$(basename $(notdir $<)).lst) \
132 $(patsubst %,-I%,$(EXTRAINCDIRS))
134 # Optional debugging information
137 # Set a "language standard" compiler flag.
138 # Unremark just one line below to set the language standard to use.
139 # gnu99 = C99 + GNU extensions. See GCC manual for more information.
141 #CFLAGS += -std=gnu89
145 # Optional assembler flags.
146 # -Wa,...: tell GCC to pass this to the assembler.
147 # -ahlms: create listing
148 # -gstabs: have the assembler create line number information; note that
149 # for use in COFF files, additional information about filenames
150 # and function names needs to be present in the assembler source
151 # files -- see avr-libc docs [FIXME: not yet described there]
152 ASFLAGS = -Wa,-adhlns=$(join $(BUILD_DIR),$(basename $(notdir $<)).lst),-gstabs
154 # Optional linker flags.
155 # -Wl,...: tell GCC to pass this to linker.
156 # -Map: create map file
157 # --cref: add cross reference to map file
158 LDFLAGS = -Wl,-Map=$(BUILD_DIR)$(TARGET).map,--cref
160 # Additional libraries
162 # Minimalistic printf version
163 #LDFLAGS += -Wl,-u,vfprintf -lprintf_min
165 # Floating point printf version (requires -lm below)
166 #LDFLAGS += -Wl,-u,vfprintf -lprintf_flt
171 # Programming support using avrdude. Settings and variables.
173 # Programming hardware: alf avr910 avrisp bascom bsd
174 # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
177 # to get a full listing.
179 # AVRDUDE_PROGRAMMER = stk500
180 # AVRDUDE_PROGRAMMER = avrispmkII
181 AVRDUDE_PROGRAMMER = avrispv2
183 # programmer connected to serial device
184 # AVRDUDE_PORT = com1
185 # programmer connected to usb device
187 # programmer connected to parallel port
188 # AVRDUDE_PORT = lpt1
190 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
191 AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
193 AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
194 #AVRDUDE_FLAGS += -b 4
196 # Uncomment the following if you want avrdude's erase cycle counter.
197 # Note that this counter needs to be initialized first using -Yn,
198 # see avrdude manual.
201 # Uncomment the following if you do /not/ wish a verification to be
202 # performed after programming the device.
205 # Increase verbosity level. Please use this when submitting bug
206 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
207 # to submit bug reports.
208 #AVRDUDE_FLAGS += -v -v
211 # avr fuses read from sample clock with ATmega168-20PU
212 # for the Atmega168 the bits 3-7 are "don't care", some AVRDUDE want them "0",
213 # some "1". So uses 0xFF or 0x07 for efuse:
214 #AVRDUDE_FUSES = -U efuse:w:0xFF:m -U hfuse:w:0xDC:m -U lfuse:w:0xFF:m
215 AVRDUDE_FUSES = -U efuse:w:0x07:m -U hfuse:w:0xDC:m -U lfuse:w:0xFF:m
216 #FIXME: EESAVE should be set to preserve EEPROM when programming => hfuse=0xD4
218 # ---------------------------------------------------------------------------
220 # Define directories, if needed (not used anymore)
221 #DIRAVR = c:/Programme/winavr
222 #DIRAVRBIN = $(DIRAVR)/bin
223 #DIRAVRUTILS = $(DIRAVR)/utils/bin
225 #DIRLIB = $(DIRAVR)/avr/lib
227 # Define programs and commands.
232 OBJCOPY = avr-objcopy
233 OBJDUMP = avr-objdump
237 # Programming support using avrdude.
240 # umlet (see http://www.umlet.com)
241 UMLET = "C:\Program Files\Umlet_14.2\Umlet.exe"
247 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
248 ELFSIZE = $(SIZE) -A $(BUILD_DIR)$(TARGET).elf
249 FUNSIZE = $(SIZEX) -m $(MCU) -f 8192 -t 500 $(BUILD_DIR)$(TARGET).elf
253 MSG_ERRORS_NONE = Errors: none
254 MSG_BEGIN = -------- begin --------
255 MSG_END = -------- end --------
256 MSG_SIZE_BEFORE = Size before:
257 MSG_SIZE_AFTER = Size after:
258 MSG_COFF = Converting to AVR COFF:
259 MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
260 MSG_FLASH = Creating load file for Flash:
261 MSG_EEPROM = Creating load file for EEPROM:
262 MSG_EXTENDED_LISTING = Creating Extended Listing:
263 MSG_SYMBOL_TABLE = Creating Symbol Table:
264 MSG_LINKING = Linking:
265 MSG_COMPILING = Compiling:
266 MSG_ASSEMBLING = Assembling:
267 MSG_CLEANING = Cleaning project:
269 # Define all object files.
270 OBJ = $(foreach nn,$(SRC:.c=.o),$(join $(BUILD_DIR),$(nn))) $(foreach nn,$(ASRC:.S=.o),$(join $(BUILD_DIR),$(nn)))
272 # Define all listing files.
273 #LST = $(ASRC:.S=.lst) $(join $(BUILD_DIR),$(SRC:.c=.lst))
275 # Combine all necessary flags and optional flags.
276 # Add target processor to flags.
277 ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
278 ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
281 all: begin gccversion sizebefore $(TARGET).elf $(TARGET).hex $(TARGET).eep \
282 $(TARGET).lss $(TARGET).sym sizeafter finished end
283 #all: begin sizebefore $(TARGET).lss $(TARGET).hex sizeafter finished end
286 # AVR Studio 3.x does not check make's exit code but relies on
287 # the following magic strings to be generated by the compile job.
293 @echo $(MSG_ERRORS_NONE)
299 # Display size of file.
301 @if [ -f $(BUILD_DIR)$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
304 @if [ -f $(BUILD_DIR)$(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
307 @if [ -f $(BUILD_DIR)$(TARGET).elf ]; then echo; $(FUNSIZE); echo; fi
309 # Display compiler version information.
314 @echo $(PROG_VERSION)
316 # Convert ELF to COFF for use in debugging / simulating in
317 # AVR Studio or VMLAB.
318 # This section is marked deprecated as if the cof file format is no longer
319 # supported in avr-objcopy which has been replaced by the elf format
320 #COFFCONVERT=$(OBJCOPY) --debugging \
321 # --change-section-address .data-0x800000 \
322 # --change-section-address .bss-0x800000 \
323 # --change-section-address .noinit-0x800000 \
324 # --change-section-address .eeprom-0x810000
328 # @echo $(MSG_COFF) $(TARGET).cof
329 # $(COFFCONVERT) -O coff-avr $(BUILD_DIR)$< $(BUILD_DIR)$(TARGET).cof
331 #extcoff: $(TARGET).elf
333 # @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
334 # $(COFFCONVERT) -O coff-ext-avr $(BUILD_DIR)$< $(BUILD_DIR)$(TARGET).cof
336 # Program the device.
337 program: $(TARGET).hex $(TARGET).eep
338 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM) $(AVRDUDE_FUSES)
340 program-flash: $(TARGET).hex
341 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
343 program-eeprom: $(TARGET).eep
344 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_EEPROM)
347 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_FUSES)
352 @echo "PROG_VERSION=$(PROG_VERSION)"
353 ( cat Doxyfile ; echo "PROJECT_NUMBER=$(PROG_VERSION)" ) | doxygen -
358 #umlet -action=convert -format=pdf -filename=fremoclock.uxf
359 $(UMLET) -action=convert -format=pdf -filename=fremoclock.uxf
363 # uisp -dprog=avr910 -dserial=com2 -dspeed=115200 -dpart=M8 --upload if=$(TARGET).hex --hash=32 -v
365 # Create final output files (.hex, .eep) from ELF output file.
368 @echo $(MSG_FLASH) $@
369 $(OBJCOPY) -O $(FORMAT) -R .eeprom $(BUILD_DIR)$< $@
373 @echo $(MSG_EEPROM) $@
374 -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
375 --change-section-lma .eeprom=0 -O $(FORMAT) $(BUILD_DIR)$< $@
377 # Create extended listing file from ELF output file.
380 @echo $(MSG_EXTENDED_LISTING) $@
381 $(OBJDUMP) -h -S $(BUILD_DIR)$< > $(BUILD_DIR)$@
383 # Create a symbol table from ELF output file.
386 @echo $(MSG_SYMBOL_TABLE) $@
387 avr-nm -n $(BUILD_DIR)$< > $(BUILD_DIR)$@
389 # Link: create ELF output file from object files.
390 .SECONDARY : $(TARGET).elf
394 @echo $(MSG_LINKING) $@
395 $(CC) $(ALL_CFLAGS) $(OBJ) --output $(BUILD_DIR)$@ $(LDFLAGS)
397 # Compile: create object files from C source files.
398 $(BUILD_DIR)%.o : %.c
400 @echo $(MSG_COMPILING) $<
401 @$(MDIR) $(BUILD_DIR)
402 $(CC) -c $(ALL_CFLAGS) $< -o $@
404 # Compile: create assembler files from C source files.
405 $(BUILD_DIR)%.s : %.c
406 @$(MDIR) $(BUILD_DIR)
407 $(CC) -S $(ALL_CFLAGS) $< -o $@
409 # Assemble: create object files from assembler source files.
410 $(BUILD_DIR)%.o : %.S
412 @echo $(MSG_ASSEMBLING) $<
413 @$(MDIR) $(BUILD_DIR)
414 $(CC) -c $(ALL_ASFLAGS) $< -o $@
416 # Target: clean project.
417 clean: begin clean_list finished end
421 @echo $(MSG_CLEANING)
422 $(REMOVE) $(TARGET).hex
423 $(REMOVE) $(TARGET).eep
424 $(REMOVE) $(BUILD_DIR)
427 # Automatically generate C source code dependencies.
428 # (Code originally taken from the GNU make user manual and modified
429 # (See README.txt Credits).)
431 # Note that this will work with sh (bash) and sed that is shipped with WinAVR
432 # (see the SHELL variable defined above).
433 # This may not work with other shells or other seds.
436 @$(MDIR) $(BUILD_DIR)
437 set -e; $(CC) -MM $(ALL_CFLAGS) $< \
438 | sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > $(BUILD_DIR)$@; \
439 [ -s $(BUILD_DIR)$@ ] || rm -f $(BUILD_DIR)$@
441 # Don't create dependencies when we're cleaning, for instance.
442 # Boy what a good hint!
443 ifeq (0, $(words $(findstring $(MAKECMDGOALS), $(NODEPS))))
444 # Remove the '-' if you want to see the dependency files generated.
445 -include $(SRC:.c=.d)
448 # Listing of phony targets.
449 .PHONY : all begin finish end sizebefore sizeafter gccversion coff extcoff \
450 clean clean_list program program-flash program-eeprom program-fuses version\