fremoclock  1_3A01
FREMO Clock - Software for UTG
Makefile
Go to the documentation of this file.
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!
4 #
5 # Additional material for this makefile was submitted by:
6 # Tim Henigan
7 # Peter Fleury
8 # Reiner Patommel
9 # Sander Pool
10 # Frederik Rouleau
11 # Markus Pfaff
12 #
13 # Adopted to our needs for FREMO Clock by
14 # Bernd Wisotzki, Martin Pischky and Stefan Seibt
15 #
16 # On command line:
17 #
18 # make all = Make software.
19 #
20 # make clean = Clean out built project files.
21 #
22 # make version = shows adapted version string from sysdef.h
23 #
24 # make coff = Convert ELF to AVR COFF (for use with AVR Studio 3.x or VMLAB).
25 #
26 # make extcoff = Convert ELF to AVR Extended COFF (for use with AVR Studio
27 # 4.07 or greater).
28 #
29 # make program = Download the hex file to the device, using avrdude. Please
30 # customize the avrdude settings below first!
31 #
32 # make program-flash = Download the flash hex file only
33 #
34 # make program-eeprom = Download the eeprom hex file only
35 #
36 # make program-fuses = Download the fusese only
37 #
38 # make filename.s = Just compile filename.c into the assembler code only
39 #
40 # make doxygen = run doxygen to build documentation
41 #
42 # make umlet = generate fremoclock.uxf.pdf from fremoclock.uxf
43 #
44 # To rebuild project do "make clean all".
45 #
46 
47 # LOCONET_DIR = ../loconet
48 CORE_DIR = ./80_Core
49 USER_DIR = ./20_UserInterface
50 
51 # Output directory for all files needed for build process (.d,.lst,.o)
52 BUILD_DIR := ./build/
53 
54 # Add make targets where no dependicy file generation is necassary
55 NODEPS := clean version program-fuses gccversion
56 
57 vpath %.h $(CORE_DIR):$(USER_DIR):$(LOCONET_DIR)
58 vpath %.c $(CORE_DIR):$(USER_DIR):$(LOCONET_DIR)
59 
60 # MCU name
61 # When changing this, also adopt the fuses as needed, see AVRDUDE_FUSES below
62 #MCU = atmega48
63 MCU = atmega168
64 #MCU = atmega128
65 
66 # Processor frequency
67 # usually defined here, see sysdef.h for now!
68 #F_CPU = 16000000
69 
70 # Output format. (can be srec, ihex, binary)
71 FORMAT = ihex
72 
73 # determines the target program version from a string defined in sysdef.h
74 # adapt this to whatever you need
75 V_F = sysdef.h
76 PROG_VERSION = $(if $(wildcard $(V_F)),$(shell sed -n '/VERSION/p' $(V_F) | sed 's/^[^"]*"//;s/".*//;s/\./_/g'),"???")
77 
78 # Target file name (without extension).
79 TARGET = fremoclock_v$(PROG_VERSION)
80 
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.)
83 OPT = s
84 
85 # List C source files here. (C dependencies are automatically generated.)
86 SRC = main.c
87 
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
93 # SRC += AdcInput.c
94 SRC += uart.c
95 SRC += Timer.c SysHwTimer.c
96 SRC += lcd.c PushButton.c
97 SRC += ClockKernel.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
102 
103 # You can also wrap lines by appending a backslash to the end of the line:
104 #SRC += baz.c \
105 #xyzzy.c
106 
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.
114 ASRC =
115 
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)
119 
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
128 CFLAGS = -O$(OPT) \
129 -funsigned-bitfields -fpack-struct -fshort-enums \
130 -Wall -Wstrict-prototypes \
131 -Wa,-adhlns=$(join $(BUILD_DIR),$(basename $(notdir $<)).lst) \
132 $(patsubst %,-I%,$(EXTRAINCDIRS))
133 
134 # Optional debugging information
135 #CFLAGS += -g
136 
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.
140 #CFLAGS += -std=c89
141 #CFLAGS += -std=gnu89
142 #CFLAGS += -std=c99
143 CFLAGS += -std=gnu99
144 
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
153 
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
159 
160 # Additional libraries
161 
162 # Minimalistic printf version
163 #LDFLAGS += -Wl,-u,vfprintf -lprintf_min
164 
165 # Floating point printf version (requires -lm below)
166 #LDFLAGS += -Wl,-u,vfprintf -lprintf_flt
167 
168 # -lm = math library
169 LDFLAGS += -lm
170 
171 # Programming support using avrdude. Settings and variables.
172 
173 # Programming hardware: alf avr910 avrisp bascom bsd
174 # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
175 #
176 # Type: avrdude -c ?
177 # to get a full listing.
178 #
179 # AVRDUDE_PROGRAMMER = stk500
180 # AVRDUDE_PROGRAMMER = avrispmkII
181 AVRDUDE_PROGRAMMER = avrispv2
182 
183 # programmer connected to serial device
184 # AVRDUDE_PORT = com1
185 # programmer connected to usb device
186 AVRDUDE_PORT = usb
187 # programmer connected to parallel port
188 # AVRDUDE_PORT = lpt1
189 
190 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
191 AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
192 
193 AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
194 #AVRDUDE_FLAGS += -b 4
195 
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.
199 #AVRDUDE_ERASE += -y
200 
201 # Uncomment the following if you do /not/ wish a verification to be
202 # performed after programming the device.
203 #AVRDUDE_FLAGS += -V
204 
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
209 
210 # avrdude fuses
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
217 
218 # ---------------------------------------------------------------------------
219 
220 # Define directories, if needed (not used anymore)
221 #DIRAVR = c:/Programme/winavr
222 #DIRAVRBIN = $(DIRAVR)/bin
223 #DIRAVRUTILS = $(DIRAVR)/utils/bin
224 #DIRINC = .
225 #DIRLIB = $(DIRAVR)/avr/lib
226 
227 # Define programs and commands.
228 SHELL = sh
229 
230 CC = avr-gcc
231 
232 OBJCOPY = avr-objcopy
233 OBJDUMP = avr-objdump
234 SIZE = avr-size
235 SIZEX = avr-sizex
236 
237 # Programming support using avrdude.
238 AVRDUDE = avrdude
239 
240 # umlet (see http://www.umlet.com)
241 UMLET = "C:\Program Files\Umlet_14.2\Umlet.exe"
242 
243 REMOVE = rm -Rf
244 COPY = cp
245 MDIR = mkdir -p
246 
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
250 
251 # Define Messages
252 # English
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:
268 
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)))
271 
272 # Define all listing files.
273 #LST = $(ASRC:.S=.lst) $(join $(BUILD_DIR),$(SRC:.c=.lst))
274 
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)
279 
280 # Default target.
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
284 
285 # Eye candy.
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.
288 begin:
289  @echo
290  @echo $(MSG_BEGIN)
291 
292 finished:
293  @echo $(MSG_ERRORS_NONE)
294 
295 end:
296  @echo $(MSG_END)
297  @echo
298 
299 # Display size of file.
300 sizebefore:
301  @if [ -f $(BUILD_DIR)$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
302 
303 sizeafter:
304  @if [ -f $(BUILD_DIR)$(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
305 
306 functionsize:
307  @if [ -f $(BUILD_DIR)$(TARGET).elf ]; then echo; $(FUNSIZE); echo; fi
308 
309 # Display compiler version information.
310 gccversion :
311  @$(CC) --version
312 
313 version:
314  @echo $(PROG_VERSION)
315 
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
325 #
326 #coff: $(TARGET).elf
327 # @echo
328 # @echo $(MSG_COFF) $(TARGET).cof
329 # $(COFFCONVERT) -O coff-avr $(BUILD_DIR)$< $(BUILD_DIR)$(TARGET).cof
330 #
331 #extcoff: $(TARGET).elf
332 # @echo
333 # @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
334 # $(COFFCONVERT) -O coff-ext-avr $(BUILD_DIR)$< $(BUILD_DIR)$(TARGET).cof
335 
336 # Program the device.
337 program: $(TARGET).hex $(TARGET).eep
338  $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM) $(AVRDUDE_FUSES)
339 
340 program-flash: $(TARGET).hex
341  $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
342 
343 program-eeprom: $(TARGET).eep
344  $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_EEPROM)
345 
346 program-fuses:
347  $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_FUSES)
348 
349 doxygen:
350  @echo $(MSG_BEGIN)
351  #doxygen Doxyfile
352  @echo "PROG_VERSION=$(PROG_VERSION)"
353  ( cat Doxyfile ; echo "PROJECT_NUMBER=$(PROG_VERSION)" ) | doxygen -
354  @echo $(MSG_END)
355 
356 umlet:
357  @echo $(MSG_BEGIN)
358  #umlet -action=convert -format=pdf -filename=fremoclock.uxf
359  $(UMLET) -action=convert -format=pdf -filename=fremoclock.uxf
360  @echo $(MSG_END)
361 
362 #program:
363 # uisp -dprog=avr910 -dserial=com2 -dspeed=115200 -dpart=M8 --upload if=$(TARGET).hex --hash=32 -v
364 
365 # Create final output files (.hex, .eep) from ELF output file.
366 %.hex: %.elf
367  @echo
368  @echo $(MSG_FLASH) $@
369  $(OBJCOPY) -O $(FORMAT) -R .eeprom $(BUILD_DIR)$< $@
370 
371 %.eep: %.elf
372  @echo
373  @echo $(MSG_EEPROM) $@
374  -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
375  --change-section-lma .eeprom=0 -O $(FORMAT) $(BUILD_DIR)$< $@
376 
377 # Create extended listing file from ELF output file.
378 %.lss: %.elf
379  @echo
380  @echo $(MSG_EXTENDED_LISTING) $@
381  $(OBJDUMP) -h -S $(BUILD_DIR)$< > $(BUILD_DIR)$@
382 
383 # Create a symbol table from ELF output file.
384 %.sym: %.elf
385  @echo
386  @echo $(MSG_SYMBOL_TABLE) $@
387  avr-nm -n $(BUILD_DIR)$< > $(BUILD_DIR)$@
388 
389 # Link: create ELF output file from object files.
390 .SECONDARY : $(TARGET).elf
391 .PRECIOUS : $(OBJ)
392 %.elf: $(OBJ)
393  @echo
394  @echo $(MSG_LINKING) $@
395  $(CC) $(ALL_CFLAGS) $(OBJ) --output $(BUILD_DIR)$@ $(LDFLAGS)
396 
397 # Compile: create object files from C source files.
398 $(BUILD_DIR)%.o : %.c
399  @echo
400  @echo $(MSG_COMPILING) $<
401  @$(MDIR) $(BUILD_DIR)
402  $(CC) -c $(ALL_CFLAGS) $< -o $@
403 
404 # Compile: create assembler files from C source files.
405 $(BUILD_DIR)%.s : %.c
406  @$(MDIR) $(BUILD_DIR)
407  $(CC) -S $(ALL_CFLAGS) $< -o $@
408 
409 # Assemble: create object files from assembler source files.
410 $(BUILD_DIR)%.o : %.S
411  @echo
412  @echo $(MSG_ASSEMBLING) $<
413  @$(MDIR) $(BUILD_DIR)
414  $(CC) -c $(ALL_ASFLAGS) $< -o $@
415 
416 # Target: clean project.
417 clean: begin clean_list finished end
418 
419 clean_list :
420  @echo
421  @echo $(MSG_CLEANING)
422  $(REMOVE) $(TARGET).hex
423  $(REMOVE) $(TARGET).eep
424  $(REMOVE) $(BUILD_DIR)
425  $(REMOVE) doxygen
426 
427 # Automatically generate C source code dependencies.
428 # (Code originally taken from the GNU make user manual and modified
429 # (See README.txt Credits).)
430 #
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.
434 #
435 %.d: %.c
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)$@
440 
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)
446 endif
447 
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\
451  doxygen umlet