Makefile 3.5 KB

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