Makefile 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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
  5. ASRC = stime.S
  6. VPATH =
  7. ### Target device
  8. DEVICE = atmega644pa
  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=8000000
  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. # Define all object files
  35. COBJ = $(CSRC:.c=.o)
  36. AOBJ = $(ASRC:.S=.o)
  37. COBJ := $(addprefix $(OBJDIR)/,$(COBJ))
  38. AOBJ := $(addprefix $(OBJDIR)/,$(AOBJ))
  39. PROJECT := $(OBJDIR)/$(PROJECT)
  40. # Flags for C files
  41. #CFLAGS += -std=$(CSTD)
  42. CFLAGS += -g$(DEBUG)
  43. CFLAGS += -mmcu=$(DEVICE)
  44. CFLAGS += -O$(OPTIMIZE) -mcall-prologues
  45. CFLAGS += $(addprefix -W,$(WARNINGS))
  46. CFLAGS += $(addprefix -I,$(INCDIRS))
  47. CFLAGS += $(addprefix -D,$(DEFS))
  48. CFLAGS += -Wp,-MM,-MP,-MT,$(OBJDIR)/$(*F).o,-MF,$(OBJDIR)/$(*F).d
  49. # Assembler flags
  50. ASFLAGS += $(addprefix -D,$(ADEFS)) -Wa,-gstabs,-g$(DEBUG)
  51. ALL_ASFLAGS = -mmcu=$(DEVICE) -I. -x assembler-with-cpp $(ASFLAGS)
  52. # Linker flags
  53. LDFLAGS += -Wl,-Map,$(PROJECT).map
  54. # Default target.
  55. all: version build size
  56. ifeq ($(OUTPUT),hex)
  57. build: elf hex lst sym
  58. hex: $(PROJECT).hex
  59. else
  60. ifeq ($(OUTPUT),bin)
  61. build: elf bin lst sym
  62. bin: $(PROJECT).bin
  63. else
  64. ifeq ($(OUTPUT),both)
  65. build: elf hex bin lst sym
  66. hex: $(PROJECT).hex
  67. bin: $(PROJECT).bin
  68. else
  69. $(error "Invalid format: $(OUTPUT)")
  70. endif
  71. endif
  72. endif
  73. elf: $(PROJECT).elf
  74. lst: $(PROJECT).lst
  75. sym: $(PROJECT).sym
  76. # Display compiler version information.
  77. version :
  78. @$(CC) --version
  79. # Create final output file from ELF output file.
  80. %.hex: %.elf
  81. @echo
  82. $(OBJCOPY) -j .text -j .data -j .eeprom -j .fuse -O $(HEXFMT) $< $@
  83. %.bin: %.elf
  84. @echo
  85. $(OBJCOPY) -j .text -j .data -O binary $< $@
  86. # Create extended listing file from ELF output file.
  87. %.lst: %.elf
  88. @echo
  89. $(OBJDUMP) -h -S -C $< > $@
  90. # Create a symbol table from ELF output file.
  91. %.sym: %.elf
  92. @echo
  93. $(NM) -n $< > $@
  94. # Display size of file.
  95. size:
  96. @echo
  97. $(SIZE) $(PROJECT).elf
  98. # Link: create ELF output file from object files.
  99. %.elf: $(AOBJ) $(COBJ)
  100. @echo
  101. @echo Linking...
  102. $(CC) $(CFLAGS) $(AOBJ) $(COBJ) --output $@
  103. # Compile: create object files from C source files. ARM or Thumb(-2)
  104. $(COBJ) : $(OBJDIR)/%.o : %.c
  105. @echo
  106. @echo $< :
  107. $(CC) -c $(CFLAGS) $< -o $@
  108. # Assemble: create object files from assembler source files. ARM or Thumb(-2)
  109. $(AOBJ) : $(OBJDIR)/%.o : %.S
  110. @echo
  111. @echo $< :
  112. $(CC) -c $(ALL_ASFLAGS) $< -o $@
  113. # Target: clean project.
  114. clean:
  115. @echo
  116. rm -f -r $(OBJDIR) | exit 0
  117. # Include the dependency files.
  118. -include $(shell mkdir $(OBJDIR) 2>/dev/null) $(wildcard $(OBJDIR)/*.d)