Makefile 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. ### Project name (also used for output file name)
  2. PROJECT = glg
  3. ### Firmware version string, embedded in the boot log record
  4. FW_VERSION_NUM = 1.0.0
  5. GIT_HASH := $(shell git describe --always --dirty --abbrev=8 2>/dev/null || echo unknown)
  6. ### Source files and search directory
  7. CSRC = main.c uart0.c uart1.c ff.c mmc.c 1wire.c ds18b20.c expander.c I2C.c xprintf.c gpx.c ffunicode.c display.c working_modes.o timec.o nmea.o settings.o menu.o syslog.o autopause.o
  8. ASRC = stime.S
  9. VPATH =
  10. ### Target device
  11. DEVICE = atmega644p
  12. ### Device memory sizes, for the size report below (bytes)
  13. FLASH_SIZE = 65536
  14. RAM_SIZE = 4096
  15. EEPROM_SIZE = 2048
  16. ### Flash available to this app, i.e. FLASH_SIZE minus the Optiboot bootloader
  17. ### section actually reserved on this device: optiboot/Makefile.1284 forces
  18. ### -DBIGBOOT for the atmega644p target, which hardcodes __BOOT_SIZE__ to
  19. ### 1024 bytes in optiboot.c's "#if BIGBOOT" branch - confirmed independently
  20. ### by the programmed high fuse (hfuse=0x14, optiboot/Makefile:736): BOOTSZ1:
  21. ### BOOTSZ0 = 1:0 = "10", the 644P's 512-word (1024-byte) boot size option,
  22. ### boot address 0x7E00 (word) = 0xFC00 (byte). Re-check both if the fuse
  23. ### settings or optiboot's BIGBOOT option for this target ever change.
  24. FLASH_APP_SIZE = 64512
  25. ### Bootloader port
  26. PROGPORT ?= /dev/ttyUSB0
  27. ### Optimization level (0, 1, 2, 3, 4 or s)
  28. OPTIMIZE = s
  29. ### C Standard level (c89, gnu89, c99 or gnu99)
  30. #CSTD = c99
  31. ### Include dirs, library dirs and definitions
  32. LIBS =
  33. LIBDIRS =
  34. INCDIRS =
  35. DEFS = F_CPU=7372800
  36. DEFS += 'FW_VERSION="$(FW_VERSION_NUM)+$(GIT_HASH)"'
  37. # DEFS += LEDR_UART
  38. ADEFS =
  39. ifeq ($(LCD),graphic)
  40. CSRC += UC1601S-I2C.c
  41. DEFS += LCD_GRAPHIC
  42. endif
  43. ifeq ($(LCD),alnum)
  44. CSRC += HD44780-I2C.c
  45. DEFS += LCD_ALNUM
  46. endif
  47. ### Warning contorls
  48. WARNINGS = all extra
  49. ### Output directory
  50. OBJDIR = obj
  51. ### Output file format (hex, bin or both) and debugger type
  52. OUTPUT = hex
  53. HEXFMT = ihex
  54. DEBUG = dwarf-2
  55. ### Programs to build porject
  56. CC = avr-gcc
  57. OBJCOPY = avr-objcopy
  58. OBJDUMP = avr-objdump
  59. SIZE = avr-size
  60. NM = avr-nm
  61. AVRDUDE = avrdude -c arduino -b 230400 -P $(PROGPORT) -p $(DEVICE)
  62. # Define all object files
  63. COBJ = $(CSRC:.c=.o)
  64. AOBJ = $(ASRC:.S=.o)
  65. COBJ := $(addprefix $(OBJDIR)/,$(COBJ))
  66. AOBJ := $(addprefix $(OBJDIR)/,$(AOBJ))
  67. PROJECT := $(OBJDIR)/$(PROJECT)
  68. # Flags for C files
  69. #CFLAGS += -std=$(CSTD)
  70. CFLAGS += -g$(DEBUG)
  71. CFLAGS += -mmcu=$(DEVICE)
  72. CFLAGS += -O$(OPTIMIZE) -mcall-prologues
  73. CFLAGS += $(addprefix -W,$(WARNINGS)) --param=min-pagesize=0
  74. CFLAGS += $(addprefix -I,$(INCDIRS))
  75. CFLAGS += $(addprefix -D,$(DEFS))
  76. CFLAGS += -Wp,-MM,-MP,-MT,$(OBJDIR)/$(*F).o,-MF,$(OBJDIR)/$(*F).d
  77. # Assembler flags
  78. ASFLAGS += $(addprefix -D,$(ADEFS)) -Wa,-gstabs,-g$(DEBUG)
  79. ALL_ASFLAGS = -mmcu=$(DEVICE) -I. -x assembler-with-cpp $(ASFLAGS)
  80. # Linker flags
  81. LDFLAGS += -Wl,-Map,$(PROJECT).map
  82. # Default target.
  83. all: version build size
  84. ifeq ($(OUTPUT),hex)
  85. build: elf hex lst sym
  86. hex: $(PROJECT).hex
  87. else
  88. ifeq ($(OUTPUT),bin)
  89. build: elf bin lst sym
  90. bin: $(PROJECT).bin
  91. else
  92. ifeq ($(OUTPUT),both)
  93. build: elf hex bin lst sym
  94. hex: $(PROJECT).hex
  95. bin: $(PROJECT).bin
  96. else
  97. $(error "Invalid format: $(OUTPUT)")
  98. endif
  99. endif
  100. endif
  101. elf: $(PROJECT).elf
  102. lst: $(PROJECT).lst
  103. sym: $(PROJECT).sym
  104. # Display compiler version information.
  105. version :
  106. @$(CC) --version
  107. # Create final output file from ELF output file.
  108. %.hex: %.elf
  109. @echo
  110. # $(OBJCOPY) -j .text -j .data -j .eeprom -j .fuse -O $(HEXFMT) $< $@
  111. $(OBJCOPY) -j .text -j .data -O $(HEXFMT) $< $@
  112. %.bin: %.elf
  113. @echo
  114. $(OBJCOPY) -j .text -j .data -O binary $< $@
  115. # Create extended listing file from ELF output file.
  116. %.lst: %.elf
  117. @echo
  118. $(OBJDUMP) -h -S -C $< > $@
  119. # Create a symbol table from ELF output file.
  120. %.sym: %.elf
  121. @echo
  122. $(NM) -n $< > $@
  123. # Display size of file, with a device-specific (DEVICE) usage summary.
  124. size:
  125. @echo
  126. $(SIZE) $(PROJECT).elf
  127. $(SIZE) $(PROJECT).hex
  128. @echo
  129. @$(SIZE) -A $(PROJECT).elf | awk '\
  130. $$1==".text" || $$1==".data" { prog += $$2 } \
  131. $$1==".data" || $$1==".bss" || $$1==".noinit" { ram += $$2 } \
  132. END { \
  133. printf "Program: %6d bytes (%5.1f%% of %d byte flash on $(DEVICE), %d bytes reserved for the bootloader)\n", prog, prog*100.0/$(FLASH_APP_SIZE), $(FLASH_APP_SIZE), $(FLASH_SIZE) - $(FLASH_APP_SIZE); \
  134. printf "Data: %6d bytes (%5.1f%% of %d byte RAM on $(DEVICE))\n", ram, ram*100.0/$(RAM_SIZE), $(RAM_SIZE); \
  135. }'
  136. # Link: create ELF output file from object files.
  137. %.elf: $(AOBJ) $(COBJ)
  138. @echo
  139. @echo Linking...
  140. $(CC) $(CFLAGS) $(AOBJ) $(COBJ) --output $@
  141. # Compile: create object files from C source files. ARM or Thumb(-2)
  142. $(COBJ) : $(OBJDIR)/%.o : %.c
  143. @echo
  144. @echo $< :
  145. $(CC) -c $(CFLAGS) $< -o $@
  146. # Assemble: create object files from assembler source files. ARM or Thumb(-2)
  147. $(AOBJ) : $(OBJDIR)/%.o : %.S
  148. @echo
  149. @echo $< :
  150. $(CC) -c $(ALL_ASFLAGS) $< -o $@
  151. # Target: clean project.
  152. clean:
  153. @echo
  154. rm -f -r $(OBJDIR) | exit 0
  155. # Include the dependency files.
  156. -include $(shell mkdir $(OBJDIR) 2>/dev/null) $(wildcard $(OBJDIR)/*.d)
  157. install: all
  158. $(AVRDUDE) -U flash:w:$(PROJECT).hex
  159. reset:
  160. $(AVRDUDE)