Makefile 3.5 KB

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