Makefile 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. # The architecture configuration
  2. ARCH = attiny13
  3. AVRDUDE_ARCH = t13
  4. AVRDUDE_SPEED = 1
  5. PROGRAMMER = avrisp2
  6. PROGPORT = usb
  7. TOPRAMMER_ID = attiny13dip8
  8. # The toolchain definitions
  9. CC = avr-gcc
  10. OBJCOPY = avr-objcopy
  11. SIZE = avr-size
  12. READELF = avr-readelf
  13. SPARSE = sparse
  14. TOPRAMMER = toprammer
  15. AVRDUDE = avrdude
  16. DEBUG = 0 # Debug build: make DEBUG=1
  17. V = @ # Verbose build: make V=1
  18. C = 0 # Sparsechecker build: make C=1
  19. Q = $(V:1=)
  20. QUIET_CC = $(Q:@=@echo ' CC '$@;)$(CC)
  21. QUIET_DEPEND = $(Q:@=@echo ' DEPEND '$@;)$(CC)
  22. QUIET_OBJCOPY = $(Q:@=@echo ' OBJCOPY '$@;)$(OBJCOPY)
  23. QUIET_SIZE = $(Q:@=@echo ' SIZE '$@;)$(SIZE)
  24. QUIET_READELF = $(Q:@=@echo ' READELF '$@;)$(READELF)
  25. ifeq ($(C),1)
  26. QUIET_SPARSE = $(Q:@=@echo ' SPARSE '$@;)$(SPARSE)
  27. else
  28. QUIET_SPARSE = @/bin/true
  29. endif
  30. CFLAGS = -mmcu=$(ARCH) -std=gnu99 -g0 -Os -Wall -DDEBUG=$(DEBUG) \
  31. "-Dinline=inline __attribute__((__always_inline__))"
  32. SPARSEFLAGS = $(CFLAGS) -I "/usr/lib/avr/include" -D__AVR_ARCH__=4 \
  33. -D__AVR_ATmega8__=1 -D__ATTR_PROGMEM__="" -Dsignal=dllexport \
  34. -Dexternally_visible=dllexport
  35. # The fuse bits
  36. LFUSE = F1
  37. HFUSE = FF
  38. F_CPU = 4800000
  39. SRCS = main.c
  40. NAME = tinybeeper
  41. ELF = $(NAME).elf
  42. BIN = $(NAME).bin
  43. HEX = $(NAME).hex
  44. EEP = $(NAME).eep.hex
  45. CFLAGS += -DF_CPU=$(F_CPU)
  46. .SUFFIXES:
  47. .PHONY: all avrdude install_flash install_eeprom install reset writefuse clean distclean
  48. .DEFAULT_GOAL := all
  49. DEPS = $(sort $(patsubst %.c,dep/%.d,$(1)))
  50. OBJS = $(sort $(patsubst %.c,obj/%.o,$(1)))
  51. # Generate dependencies
  52. $(call DEPS,$(SRCS)): dep/%.d: %.c
  53. @mkdir -p $(dir $@)
  54. $(QUIET_DEPEND) -o $@.tmp -MM -MG -MT "$@ $(patsubst dep/%.d,obj/%.o,$@)" $(CFLAGS) $< && mv -f $@.tmp $@
  55. -include $(call DEPS,$(SRCS))
  56. # Generate object files
  57. $(call OBJS,$(SRCS)): obj/%.o:
  58. @mkdir -p $(dir $@)
  59. $(QUIET_SPARSE) $(SPARSEFLAGS) $<
  60. $(QUIET_CC) -o $@ -c $(CFLAGS) $<
  61. all: $(HEX)
  62. %.s: %.c
  63. $(QUIET_CC) $(CFLAGS) -S $*.c
  64. $(ELF): $(call OBJS,$(SRCS))
  65. $(QUIET_CC) $(CFLAGS) -o $(ELF) $(call OBJS,$(SRCS)) $(LDFLAGS)
  66. $(HEX): $(ELF)
  67. $(QUIET_OBJCOPY) -R.eeprom -O ihex $(ELF) $(HEX)
  68. $(QUIET_OBJCOPY) -R.eeprom -O binary $(ELF) $(BIN)
  69. $(QUIET_OBJCOPY) -j.eeprom --set-section-flags=.eeprom="alloc,load" \
  70. --change-section-lma .eeprom=0 -O ihex $(ELF) $(EEP)
  71. $(QUIET_SIZE) $(ELF)
  72. $(QUIET_READELF) -S $(ELF) | egrep '(Name|text|eeprom|data|bss)'
  73. avrdude:
  74. $(AVRDUDE) -B $(AVRDUDE_SPEED) -p $(AVRDUDE_ARCH) \
  75. -c $(PROGRAMMER) -P $(PROGPORT) -t
  76. install_flash:
  77. $(AVRDUDE) -B $(AVRDUDE_SPEED) -p $(AVRDUDE_ARCH) \
  78. -c $(PROGRAMMER) -P $(PROGPORT) -U flash:w:$(HEX)
  79. install_eeprom:
  80. $(AVRDUDE) -B $(AVRDUDE_SPEED) -p $(AVRDUDE_ARCH) \
  81. -c $(PROGRAMMER) -P $(PROGPORT) -U eeprom:w:$(EEP)
  82. install: all install_flash install_eeprom
  83. toprammer_install: all
  84. $(TOPRAMMER) -c $(TOPRAMMER_ID) -x
  85. echo "0x0000: $(LFUSE)$(HFUSE)" | $(TOPRAMMER) -c $(TOPRAMMER_ID) -I hex -F -
  86. $(TOPRAMMER) -c $(TOPRAMMER_ID) -I ihex -P $(HEX)
  87. # Reset the microcontroller through avrdude
  88. reset:
  89. $(AVRDUDE) -B $(AVRDUDE_SPEED) -p $(AVRDUDE_ARCH) \
  90. -c $(PROGRAMMER) -P $(PROGPORT) \
  91. -U signature:r:/dev/null:i -q -q
  92. writefuse:
  93. $(AVRDUDE) -B $(AVRDUDE_SPEED) -p $(AVRDUDE_ARCH) \
  94. -c $(PROGRAMMER) -P $(PROGPORT) -q -q \
  95. -U lfuse:w:0x$(LFUSE):m \
  96. -U hfuse:w:0x$(HFUSE):m
  97. clean:
  98. -rm -Rf dep obj *~ *.pyc $(ELF)
  99. distclean: clean
  100. -rm -f *.s $(HEX) $(BIN) $(EEP)