Makefile 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. # The architecture configuration
  2. ARCH := atmega8
  3. AVRDUDE_ARCH := m8
  4. AVRDUDE_SPEED := 1
  5. AVRDUDE_SLOW_SPEED := 100
  6. PROGRAMMER := avr910
  7. #PROGRAMMER := avrisp2
  8. PROGPORT := /dev/ttyUSB0
  9. #PROGPORT := usb
  10. # The fuse bits
  11. LFUSE := 0xFB
  12. HFUSE := 0xD9
  13. # Hardware parameters
  14. F_CPU := 3686400
  15. BINEXT :=
  16. NODEPS :=
  17. # The toolchain definitions
  18. CC := avr-gcc$(BINEXT)
  19. OBJCOPY := avr-objcopy$(BINEXT)
  20. SIZE := avr-size$(BINEXT)
  21. MKDIR := mkdir$(BINEXT)
  22. MV := mv$(BINEXT)
  23. RM := rm$(BINEXT)
  24. CP := cp$(BINEXT)
  25. ECHO := echo$(BINEXT)
  26. AVRDUDE := avrdude$(BINEXT)
  27. MYSMARTUSB := mysmartusb.py
  28. DOXYGEN := doxygen$(BINEXT)
  29. V := @ # Verbose build: make V=1
  30. O := s # Optimize flag
  31. Q := $(V:1=)
  32. QUIET_CC = $(Q:@=@$(ECHO) ' CC '$@;)$(CC)
  33. QUIET_DEPEND = $(Q:@=@$(ECHO) ' DEPEND '$@;)$(CC)
  34. QUIET_OBJCOPY = $(Q:@=@$(ECHO) ' OBJCOPY '$@;)$(OBJCOPY)
  35. QUIET_SIZE = $(Q:@=@$(ECHO) ' SIZE '$@;)$(SIZE)
  36. CFLAGS := -mmcu=$(ARCH) -std=c99 -g -O$(O) -Wall \
  37. "-Dinline=inline __attribute__((__always_inline__))" \
  38. -fshort-enums \
  39. -DF_CPU=$(F_CPU)
  40. LDFLAGS :=
  41. # Application code
  42. SRCS := main.c lcd.c morse.c buzzer.c
  43. NAME := morsedec
  44. BIN := $(NAME).bin
  45. HEX := $(NAME).hex
  46. EEP := $(NAME).eep.hex
  47. .SUFFIXES:
  48. .PHONY: all avrdude install_flash install_eeprom install reset writefuse doxygen clean distclean
  49. .DEFAULT_GOAL := all
  50. ifeq ($(BINEXT),.exe)
  51. HAVE_MYSMARTUSB :=
  52. else
  53. HAVE_MYSMARTUSB := $(shell $(MYSMARTUSB) -h >/dev/null 2>&1 && $(ECHO) 1)
  54. endif
  55. MYSMARTUSB_PWRCYCLE := \
  56. $(if $(HAVE_MYSMARTUSB), \
  57. $(MYSMARTUSB) -p0 $(PROGPORT) && \
  58. sleep 1 && \
  59. $(MYSMARTUSB) -p1 $(PROGPORT) \
  60. )
  61. MYSMARTUSB_PROGMODE := \
  62. $(if $(HAVE_MYSMARTUSB), \
  63. $(MYSMARTUSB) -mp $(PROGPORT) \
  64. )
  65. MYSMARTUSB_DATAMODE := \
  66. $(if $(HAVE_MYSMARTUSB), \
  67. $(MYSMARTUSB) -md $(PROGPORT) \
  68. )
  69. DEPS = $(sort $(patsubst %.c,dep/%.d,$(1)))
  70. OBJS = $(sort $(patsubst %.c,obj/%.o,$(1)))
  71. # Generate dependencies
  72. $(call DEPS,$(SRCS)): dep/%.d: %.c
  73. @$(MKDIR) -p $(dir $@)
  74. @$(MKDIR) -p obj
  75. $(QUIET_DEPEND) -o $@.tmp -MM -MT "$@ $(patsubst dep/%.d,obj/%.o,$@)" $(CFLAGS) $<
  76. @$(MV) -f $@.tmp $@
  77. ifeq ($(NODEPS),)
  78. -include $(call DEPS,$(SRCS))
  79. endif
  80. # Generate object files
  81. $(call OBJS,$(SRCS)): obj/%.o: %.c
  82. @$(MKDIR) -p $(dir $@)
  83. $(QUIET_CC) -o $@ -c $(CFLAGS) $<
  84. all: $(HEX)
  85. %.s: %.c
  86. $(QUIET_CC) $(CFLAGS) -S $*.c
  87. $(BIN): $(call OBJS,$(SRCS))
  88. $(QUIET_CC) $(CFLAGS) -o $(BIN) $(call OBJS,$(SRCS)) $(LDFLAGS) $(LDFLAGS)
  89. $(HEX): $(BIN)
  90. $(QUIET_OBJCOPY) -R.eeprom -O ihex $(BIN) $(HEX)
  91. # $(QUIET_OBJCOPY) -j.eeprom --set-section-flags=.eeprom="alloc,load" \
  92. # --change-section-lma .eeprom=0 -O ihex $(BIN) $(EEP)
  93. $(QUIET_SIZE) $(BIN)
  94. avrdude:
  95. $(call MYSMARTUSB_PROGMODE)
  96. $(AVRDUDE) -B $(AVRDUDE_SPEED) -p $(AVRDUDE_ARCH) \
  97. -c $(PROGRAMMER) -P $(PROGPORT) -t
  98. $(call MYSMARTUSB_PWRCYCLE)
  99. $(call MYSMARTUSB_DATAMODE)
  100. install_flash: all
  101. $(call MYSMARTUSB_PROGMODE)
  102. $(AVRDUDE) -B $(AVRDUDE_SPEED) -p $(AVRDUDE_ARCH) \
  103. -c $(PROGRAMMER) -P $(PROGPORT) \
  104. -U flash:w:$(HEX)
  105. $(call MYSMARTUSB_DATAMODE)
  106. install_eeprom: all
  107. $(call MYSMARTUSB_PROGMODE)
  108. $(AVRDUDE) -B $(AVRDUDE_SPEED) -p $(AVRDUDE_ARCH) \
  109. -c $(PROGRAMMER) -P $(PROGPORT) -U eeprom:w:$(EEP)
  110. $(call MYSMARTUSB_DATAMODE)
  111. install: install_flash
  112. $(call MYSMARTUSB_PWRCYCLE)
  113. # Reset the microcontroller through avrdude
  114. reset:
  115. $(call MYSMARTUSB_PROGMODE)
  116. $(AVRDUDE) -B $(AVRDUDE_SPEED) -p $(AVRDUDE_ARCH) \
  117. -c $(PROGRAMMER) -P $(PROGPORT) \
  118. -U signature:r:/dev/null:i -q -q
  119. $(call MYSMARTUSB_PWRCYCLE)
  120. writefuse:
  121. $(call MYSMARTUSB_PROGMODE)
  122. $(AVRDUDE) -B $(AVRDUDE_SLOW_SPEED) -p $(AVRDUDE_ARCH) \
  123. -c $(PROGRAMMER) -P $(PROGPORT) -q -q \
  124. -U lfuse:w:$(LFUSE):m \
  125. -U hfuse:w:$(HFUSE):m
  126. $(call MYSMARTUSB_DATAMODE)
  127. $(call MYSMARTUSB_PWRCYCLE)
  128. doxygen:
  129. -$(RM) -Rf doc
  130. $(MKDIR) doc
  131. $(DOXYGEN) Doxyfile
  132. $(CP) *.jpg doc/latex/
  133. $(CP) *.jpg doc/html/
  134. $(MAKE) -C doc/latex pdf
  135. $(MV) doc/latex/refman.pdf doc/README-morsedecoder.pdf
  136. clean:
  137. -$(RM) -rf obj dep $(BIN) doc/latex
  138. distclean: clean
  139. -$(RM) -rf $(patsubst %.c,%.s,$(SRCS)) $(HEX) $(EEP) doc