Makefile 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. ### Project name (also used for output file name)
  2. PROJECT = glg
  3. ### Source files and search directory
  4. CSRC = main.c uart0.c uart1.c ff.c mmc.c 1wire.c ds18b20.c expander.c HD44780-I2C.c I2C.c xprintf.c gpx.c ffunicode.c
  5. ASRC = stime.S
  6. VPATH =
  7. ### Target device
  8. DEVICE = atmega644p
  9. ### Optimization level (0, 1, 2, 3, 4 or s)
  10. OPTIMIZE = s
  11. ### C Standard level (c89, gnu89, c99 or gnu99)
  12. #CSTD = c99
  13. ### Include dirs, library dirs and definitions
  14. LIBS =
  15. LIBDIRS =
  16. INCDIRS =
  17. DEFS = F_CPU=7372800
  18. # DEFS += LEDR_UART
  19. ADEFS =
  20. ### Warning contorls
  21. WARNINGS = all extra
  22. ### Output directory
  23. OBJDIR = obj
  24. ### Output file format (hex, bin or both) and debugger type
  25. OUTPUT = hex
  26. HEXFMT = ihex
  27. DEBUG = dwarf-2
  28. ### Programs to build porject
  29. CC = avr-gcc
  30. OBJCOPY = avr-objcopy
  31. OBJDUMP = avr-objdump
  32. SIZE = avr-size
  33. NM = avr-nm
  34. AVRDUDE = avrdude -c usbasp -p $(DEVICE)
  35. # Define all object files
  36. COBJ = $(CSRC:.c=.o)
  37. AOBJ = $(ASRC:.S=.o)
  38. COBJ := $(addprefix $(OBJDIR)/,$(COBJ))
  39. AOBJ := $(addprefix $(OBJDIR)/,$(AOBJ))
  40. PROJECT := $(OBJDIR)/$(PROJECT)
  41. # Flags for C files
  42. #CFLAGS += -std=$(CSTD)
  43. CFLAGS += -g$(DEBUG)
  44. CFLAGS += -mmcu=$(DEVICE)
  45. CFLAGS += -O$(OPTIMIZE) -mcall-prologues
  46. CFLAGS += $(addprefix -W,$(WARNINGS))
  47. CFLAGS += $(addprefix -I,$(INCDIRS))
  48. CFLAGS += $(addprefix -D,$(DEFS))
  49. CFLAGS += -Wp,-MM,-MP,-MT,$(OBJDIR)/$(*F).o,-MF,$(OBJDIR)/$(*F).d
  50. # Assembler flags
  51. ASFLAGS += $(addprefix -D,$(ADEFS)) -Wa,-gstabs,-g$(DEBUG)
  52. ALL_ASFLAGS = -mmcu=$(DEVICE) -I. -x assembler-with-cpp $(ASFLAGS)
  53. # Linker flags
  54. LDFLAGS += -Wl,-Map,$(PROJECT).map
  55. # Default target.
  56. all: version build size
  57. ifeq ($(OUTPUT),hex)
  58. build: elf hex lst sym
  59. hex: $(PROJECT).hex
  60. else
  61. ifeq ($(OUTPUT),bin)
  62. build: elf bin lst sym
  63. bin: $(PROJECT).bin
  64. else
  65. ifeq ($(OUTPUT),both)
  66. build: elf hex bin lst sym
  67. hex: $(PROJECT).hex
  68. bin: $(PROJECT).bin
  69. else
  70. $(error "Invalid format: $(OUTPUT)")
  71. endif
  72. endif
  73. endif
  74. elf: $(PROJECT).elf
  75. lst: $(PROJECT).lst
  76. sym: $(PROJECT).sym
  77. # Display compiler version information.
  78. version :
  79. @$(CC) --version
  80. # Create final output file from ELF output file.
  81. %.hex: %.elf
  82. @echo
  83. $(OBJCOPY) -j .text -j .data -j .eeprom -j .fuse -O $(HEXFMT) $< $@
  84. %.bin: %.elf
  85. @echo
  86. $(OBJCOPY) -j .text -j .data -O binary $< $@
  87. # Create extended listing file from ELF output file.
  88. %.lst: %.elf
  89. @echo
  90. $(OBJDUMP) -h -S -C $< > $@
  91. # Create a symbol table from ELF output file.
  92. %.sym: %.elf
  93. @echo
  94. $(NM) -n $< > $@
  95. # Display size of file.
  96. size:
  97. @echo
  98. $(SIZE) $(PROJECT).elf
  99. # Link: create ELF output file from object files.
  100. %.elf: $(AOBJ) $(COBJ)
  101. @echo
  102. @echo Linking...
  103. $(CC) $(CFLAGS) $(AOBJ) $(COBJ) --output $@
  104. # Compile: create object files from C source files. ARM or Thumb(-2)
  105. $(COBJ) : $(OBJDIR)/%.o : %.c
  106. @echo
  107. @echo $< :
  108. $(CC) -c $(CFLAGS) $< -o $@
  109. # Assemble: create object files from assembler source files. ARM or Thumb(-2)
  110. $(AOBJ) : $(OBJDIR)/%.o : %.S
  111. @echo
  112. @echo $< :
  113. $(CC) -c $(ALL_ASFLAGS) $< -o $@
  114. # Target: clean project.
  115. clean:
  116. @echo
  117. rm -f -r $(OBJDIR) | exit 0
  118. # Include the dependency files.
  119. -include $(shell mkdir $(OBJDIR) 2>/dev/null) $(wildcard $(OBJDIR)/*.d)
  120. install: all
  121. $(AVRDUDE) -U flash:w:$(PROJECT).hex
  122. reset:
  123. $(AVRDUDE)
  124. fuses:
  125. $(AVRDUDE) -U lfuse:w:0xff:m -U hfuse:w:0x11:m -U efuse:w:0xfe:m -B100