Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Makefile 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. # Hey Emacs, this is a -*- makefile -*-
  2. # AVR-GCC Makefile template, derived from the WinAVR template (which
  3. # is public domain), believed to be neutral to any flavor of "make"
  4. # (GNU make, BSD make, SysV make)
  5. MCU = atmega328p
  6. FORMAT = ihex
  7. TARGET = keyboard-i2c-slave
  8. SRC = \
  9. $(TARGET).c \
  10. uno-matrix.c \
  11. ../serial.c \
  12. ../i2c-slave.c
  13. ASRC =
  14. OPT = s
  15. # Programming support using avrdude. Settings and variables.
  16. AVRDUDE_PROGRAMMER = arduino
  17. AVRDUDE_PORT = /dev/ttyACM0
  18. # Name of this Makefile (used for "make depend").
  19. MAKEFILE = Makefile
  20. # Debugging format.
  21. # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
  22. # AVR (extended) COFF requires stabs, plus an avr-objcopy run.
  23. DEBUG = stabs
  24. # Compiler flag to set the C Standard level.
  25. # c89 - "ANSI" C
  26. # gnu89 - c89 plus GCC extensions
  27. # c99 - ISO C99 standard (not yet fully implemented)
  28. # gnu99 - c99 plus GCC extensions
  29. CSTANDARD = -std=gnu99
  30. # Place -D or -U options here
  31. CDEFS =
  32. # Place -I options here
  33. CINCS =
  34. CDEBUG = -g$(DEBUG)
  35. CWARN = -Wall -Wstrict-prototypes
  36. CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
  37. #CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
  38. CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA) \
  39. -fno-aggressive-loop-optimizations
  40. #ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
  41. #Additional libraries.
  42. # Minimalistic printf version
  43. PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
  44. # Floating point printf version (requires MATH_LIB = -lm below)
  45. PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
  46. PRINTF_LIB =
  47. # Minimalistic scanf version
  48. SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
  49. # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
  50. SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
  51. SCANF_LIB =
  52. MATH_LIB = -lm
  53. # External memory options
  54. # 64 KB of external RAM, starting after internal RAM (ATmega128!),
  55. # used for variables (.data/.bss) and heap (malloc()).
  56. #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
  57. # 64 KB of external RAM, starting after internal RAM (ATmega128!),
  58. # only used for heap (malloc()).
  59. #EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
  60. EXTMEMOPTS =
  61. #LDMAP = $(LDFLAGS) -Wl,-Map=$(TARGET).map,--cref
  62. LDFLAGS = $(EXTMEMOPTS) $(LDMAP) $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
  63. AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
  64. #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
  65. # Uncomment the following if you want avrdude's erase cycle counter.
  66. # Note that this counter needs to be initialized first using -Yn,
  67. # see avrdude manual.
  68. #AVRDUDE_ERASE_COUNTER = -y
  69. # Uncomment the following if you do /not/ wish a verification to be
  70. # performed after programming the device.
  71. #AVRDUDE_NO_VERIFY = -V
  72. # Increase verbosity level. Please use this when submitting bug
  73. # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
  74. # to submit bug reports.
  75. #AVRDUDE_VERBOSE = -v -v
  76. AVRDUDE_BASIC = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
  77. AVRDUDE_FLAGS = $(AVRDUDE_BASIC) $(AVRDUDE_NO_VERIFY) $(AVRDUDE_VERBOSE) $(AVRDUDE_ERASE_COUNTER)
  78. CC = avr-gcc
  79. OBJCOPY = avr-objcopy
  80. OBJDUMP = avr-objdump
  81. SIZE = avr-size
  82. NM = avr-nm
  83. AVRDUDE = avrdude
  84. REMOVE = rm -f
  85. MV = mv -f
  86. # Define all object files.
  87. OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
  88. # Define all listing files.
  89. LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
  90. # Combine all necessary flags and optional flags.
  91. # Add target processor to flags.
  92. ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
  93. ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
  94. # Default target.
  95. all: build
  96. build: elf hex eep
  97. elf: $(TARGET).elf
  98. hex: $(TARGET).hex
  99. eep: $(TARGET).eep
  100. lss: $(TARGET).lss
  101. sym: $(TARGET).sym
  102. # Program the device.
  103. program: $(TARGET).hex $(TARGET).eep
  104. $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
  105. # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
  106. COFFCONVERT=$(OBJCOPY) --debugging \
  107. --change-section-address .data-0x800000 \
  108. --change-section-address .bss-0x800000 \
  109. --change-section-address .noinit-0x800000 \
  110. --change-section-address .eeprom-0x810000
  111. coff: $(TARGET).elf
  112. $(COFFCONVERT) -O coff-avr $(TARGET).elf $(TARGET).cof
  113. extcoff: $(TARGET).elf
  114. $(COFFCONVERT) -O coff-ext-avr $(TARGET).elf $(TARGET).cof
  115. .SUFFIXES: .elf .hex .eep .lss .sym
  116. .elf.hex:
  117. $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
  118. .elf.eep:
  119. -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
  120. --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
  121. # Create extended listing file from ELF output file.
  122. .elf.lss:
  123. $(OBJDUMP) -h -S $< > $@
  124. # Create a symbol table from ELF output file.
  125. .elf.sym:
  126. $(NM) -n $< > $@
  127. # Link: create ELF output file from object files.
  128. $(TARGET).elf: $(OBJ)
  129. $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
  130. # Compile: create object files from C source files.
  131. .c.o:
  132. $(CC) -c $(ALL_CFLAGS) $< -o $@
  133. # Compile: create assembler files from C source files.
  134. .c.s:
  135. $(CC) -S $(ALL_CFLAGS) $< -o $@
  136. # Assemble: create object files from assembler source files.
  137. .S.o:
  138. $(CC) -c $(ALL_ASFLAGS) $< -o $@
  139. # Target: clean project.
  140. clean:
  141. $(REMOVE) $(TARGET).hex $(TARGET).eep $(TARGET).cof $(TARGET).elf \
  142. $(TARGET).map $(TARGET).sym $(TARGET).lss \
  143. $(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d)
  144. depend:
  145. if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \
  146. then \
  147. sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \
  148. $(MAKEFILE).$$$$ && \
  149. $(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \
  150. fi
  151. echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \
  152. >> $(MAKEFILE); \
  153. $(CC) -M -mmcu=$(MCU) $(CDEFS) $(CINCS) $(SRC) $(ASRC) >> $(MAKEFILE)
  154. .PHONY: all build elf hex eep lss sym program coff extcoff clean depend