Makefile 2.8 KB

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