Makefile 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 nmea.o settings.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)) --param=min-pagesize=0
  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. $(OBJCOPY) -j .text -j .data -O $(HEXFMT) $< $@
  87. %.bin: %.elf
  88. @echo
  89. $(OBJCOPY) -j .text -j .data -O binary $< $@
  90. # Create extended listing file from ELF output file.
  91. %.lst: %.elf
  92. @echo
  93. $(OBJDUMP) -h -S -C $< > $@
  94. # Create a symbol table from ELF output file.
  95. %.sym: %.elf
  96. @echo
  97. $(NM) -n $< > $@
  98. # Display size of file.
  99. size:
  100. @echo
  101. $(SIZE) $(PROJECT).elf
  102. $(SIZE) $(PROJECT).hex
  103. # Link: create ELF output file from object files.
  104. %.elf: $(AOBJ) $(COBJ)
  105. @echo
  106. @echo Linking...
  107. $(CC) $(CFLAGS) $(AOBJ) $(COBJ) --output $@
  108. # Compile: create object files from C source files. ARM or Thumb(-2)
  109. $(COBJ) : $(OBJDIR)/%.o : %.c
  110. @echo
  111. @echo $< :
  112. $(CC) -c $(CFLAGS) $< -o $@
  113. # Assemble: create object files from assembler source files. ARM or Thumb(-2)
  114. $(AOBJ) : $(OBJDIR)/%.o : %.S
  115. @echo
  116. @echo $< :
  117. $(CC) -c $(ALL_ASFLAGS) $< -o $@
  118. # Target: clean project.
  119. clean:
  120. @echo
  121. rm -f -r $(OBJDIR) | exit 0
  122. # Include the dependency files.
  123. -include $(shell mkdir $(OBJDIR) 2>/dev/null) $(wildcard $(OBJDIR)/*.d)
  124. install: all
  125. $(AVRDUDE) -U flash:w:$(PROJECT).hex
  126. reset:
  127. $(AVRDUDE)