Makefile 3.3 KB

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