2 # Be silent per default, but 'make V=1' will show all compiler calls.
10 ###############################################################################
26 ###############################################################################
27 # Define all object files.
29 OBJ
= $(SRC
:.c
=.o
) $(ASRC
:.S
=.o
)
31 ###############################################################################
34 TGT_CFLAGS
+= -mmcu
=$(MCU
) $(OPT
) $(CSTD
) -g
35 TGT_CFLAGS
+= $(ARCH_FLAGS
)
36 TGT_CFLAGS
+= -Wextra
-Wshadow
-Wimplicit-function-declaration
-Wimplicit-fallthrough
=1
37 TGT_CFLAGS
+= -Wredundant-decls
-Wstrict-prototypes
38 TGT_CFLAGS
+= -fshort-enums
-funsigned-bitfields
39 TGT_CFLAGS
+= -fno-common
-ffunction-sections
-fdata-sections
42 ###############################################################################
43 # C & C++ preprocessor common flags
45 TGT_CPPFLAGS
+= -MMD
-MP
-MF .dep
/$(@F
:%.o
=%.d
)
46 TGT_CPPFLAGS
+= -Wall
-Wundef
47 TGT_CPPFLAGS
+= -DF_CPU
=$(F_CPU
)UL
$(CDEFS
) $(CINCS
)
49 ###############################################################################
52 TGT_LDFLAGS
+= $(ARCH_FLAGS
)
53 TGT_LDFLAGS
+= -Wl
,-Map
=$(TARGET
).map
,--cref
54 TGT_LDFLAGS
+= -Wl
,--gc-sections
56 ###############################################################################
60 AVRDUDE_WRITE_FLASH
= -U flash
:w
:$(TARGET
).hex
61 AVRDUDE_BASIC
= -p
$(MCU
) -P
$(AVRDUDE_PORT
) -c
$(AVRDUDE_PROGRAMMER
)
62 AVRDUDE_FLAGS
= $(AVRDUDE_BASIC
) $(AVRDUDE_NO_VERIFY
) $(AVRDUDE_VERBOSE
)
64 ###############################################################################
66 .SUFFIXES
: .elf .hex .lss .map .sym
69 .PHONY
: elf hex lss sym size
76 @
#$(QP)printf " SIZE $(TARGET).elf\n"
77 $(Q
)$(SIZE
) $(TARGET
).elf
82 $(AVRDUDE
) $(AVRDUDE_FLAGS
) $(AVRDUDE_WRITE_FLASH
)
85 $(AVRDUDE
) $(AVRDUDE_FLAGS
) -u
-U hfuse
:w
:$(HFUSE
):m
-U lfuse
:w
:$(LFUSE
):m
88 @
$(QP
)printf
" OBJCOPY $(*).hex\n"
89 $(Q
)$(OBJCOPY
) -Oihex
-R .eeprom
$< $@
91 # Create extended listing file from ELF output file.
93 @
$(QP
)printf
" OBJDUMP $@\n"
94 $(Q
)$(OBJDUMP
) -h
-S
$< > $@
96 # Create a symbol table from ELF output file.
98 @
$(QP
)printf
" NM $@\n"
101 # Link: create ELF output file from object files.
103 @
$(QP
)printf
" LD $@\n"
104 $(Q
)$(LD
) $(TGT_CFLAGS
) $(CFLAGS
) $(TGT_LDFLAGS
) $(LDFLAGS
) $^
$(LDLIBS
) -o
$@
107 # Compile: create object files from C source files.
109 @
$(QP
)printf
" CC $<\n"
110 $(Q
)$(CC
) $(TGT_CFLAGS
) $(CFLAGS
) $(TGT_CPPFLAGS
) $(CPPFLAGS
) -o
$@
-c
$<
112 # Target: clean project.
113 .PHONY
: clean distclean dist
115 @
$(QP
)printf
" CLEAN\n"
116 $(Q
)$(RM
) $(OBJ
) $(SRC
:.c
=.s
) .dep
/* $(TARGET
).elf \
117 $(TARGET
).hex
$(TARGET
).lss
$(TARGET
).map
$(TARGET
).sym
120 @
$(QP
)printf
" DISTCLEAN\n"
121 $(Q
)$(RM
) $(TARGET
).
tar.gz
124 tar cvfz
$(TARGET
).
tar.gz \
126 $(TARGET
).hex
$(TARGET
).eep
128 # Include the dependency files.
129 -include $(shell mkdir .dep
2>/dev
/null
) $(wildcard .dep
/*)