# -*- Makefile -*-
-PROJECT=timer-demo
-DEVICE =atmega328p
-F_CPU =16000000UL
-INC =-I.
-AVRDUDE=avrdude -c usbasp -p $(DEVICE) -C $(AVR_DIR)\etc\avrdude.conf
-
-CC=avr-gcc
-LD=avr-gcc
-OBJCOPY=avr-objcopy
-CFLAGS =-Wall -Os -mcall-prologues -mmcu=$(DEVICE) -DF_CPU=$(F_CPU)
-LDFLAGS=-Wall -mmcu=$(DEVICE)
+PROJECT := timer-demo
+DEVICE := atmega328p
+F_CPU := 16000000UL
+INC := -I.
+AVRDUDE := avrdude -c usbasp -p $(DEVICE) -C $(AVR_DIR)\etc\avrdude.conf
+
+CC := avr-gcc
+LD := avr-gcc
+OBJCOPY := avr-objcopy
+RM := del >NUL
+CFLAGS :=-Wall -Wstrict-prototypes -Wmissing-prototypes -Wcast-align -Wshadow \
+ -std=gnu99 -fshort-enums -pedantic-errors -Os -mcall-prologues \
+ -mmcu=$(DEVICE) -DF_CPU=$(F_CPU)
+LDFLAGS := -Wall -mmcu=$(DEVICE)
+
+V := @
+Q := $(V:1=)
+QUIET_CC = $(Q:@=@echo CC $@ &)$(CC)
+QUIET_LD = $(Q:@=@echo LD $@ &)$(LD)
+QUIET_OBJCOPY = $(Q:@=@echo OBJCOPY $@ &)$(OBJCOPY)
+QUIET_AVRDUDE = $(Q:@=@echo AVRDUDE $@ &)$(AVRDUDE)
all: $(PROJECT).hex
%.hex: %.elf
- $(OBJCOPY) -j .text -j .data -O ihex $< $@
+ $(QUIET_OBJCOPY) -j .text -j .data -O ihex $< $@
%.elf: %.o
- $(LD) $(LDFLAGS) $< -o $@
+ $(QUIET_LD) $(LDFLAGS) $< -o $@
%.o: %.c
- $(CC) $(CFLAGS) $(INC) -c $<
+ $(QUIET_CC) $(CFLAGS) $(INC) -c $<
flash: $(PROJECT).hex
- $(AVRDUDE) -U flash:w:$<:i
\ No newline at end of file
+ $(QUIET_AVRDUDE) -U flash:w:$<:i
+
+clean:
+ -@$(RM) $(addprefix $(PROJECT), .elf .hex)
+
+.PHONY: clean
+.SECONDARY: $(addsuffix .elf, $(PROJECT))