Guest User

makefile

a guest
Sep 4th, 2017
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Make 2.95 KB | None | 0 0
  1. # Project name - generate based on project directory
  2. TARGET = $(lastword $(subst /, ,$(CURDIR)))
  3.  
  4. # MCU type
  5. MCU = atmega1281
  6.  
  7. # Processor frequency
  8. # This will define a symbol, F_CPU, in all source code files equal to the
  9. # processor frequency. You can then use this symbol in your source code to
  10. # calculate timings.
  11. F_CPU = 16000000
  12.  
  13. # C source files (look for all files ending in '.c')
  14. CSRC = $(wildcard *.c)
  15.  
  16. # define object files (all '.c' files will be compiled into corresponding '.o' files)
  17. OBJS = $(CSRC:.c=.o)
  18.  
  19. # Optimization level, can be [0, 1, 2, 3, s].
  20. # 0 = turn off optimization.
  21. # s = optimize for size.
  22. OPT = s
  23.  
  24. # Compiler flags
  25. CFLAGS = -std=gnu99 -g
  26. CFLAGS += -mmcu=$(MCU)
  27. CFLAGS += -DF_CPU=$(F_CPU)UL
  28. CFLAGS += -Wall -Wstrict-prototypes
  29. CFLAGS += -O$(OPT)
  30.  
  31. # Define programs and commands
  32. CC = "/c/Users/Shane Reynolds/Documents/CDU_embeddedSystems/CDUEmbeddedToolbox/avr_tools/bin/avr-gcc"
  33. OBJCOPY = "/c/Users/Shane Reynolds/Documents/CDU_embeddedSystems/CDUEmbeddedToolbox/avr_tools/bin/avr-objcopy"
  34. OBJDUMP = "/c/Users/Shane Reynolds/Documents/CDU_embeddedSystems/CDUEmbeddedToolbox/avr_tools/bin/avr-objdump"
  35. SIZE = "/c/Users/Shane Reynolds/Documents/CDU_embeddedSystems/CDUEmbeddedToolbox/avr_tools/bin/avr-size"
  36. REMOVE = rm -f
  37. AVRDUDE = "/c/Users/Shane Reynolds/Documents/CDU_embeddedSystems/CDUEmbeddedToolbox/avr_tools/bin/avrdude"
  38.  
  39. # Create final output files (.hex, .eep) from ELF output file.
  40. %.hex: %.elf
  41.     @echo
  42.     @echo "=================================="
  43.     @echo "Creating hex file for Flash: " $@
  44.     @echo "=================================="
  45.     #$(OBJCOPY) -R .eeprom -O ihex $< $@
  46.     $(OBJCOPY) -j .text -j .data -R .eeprom -O ihex $< $@
  47.  
  48. # Link: create ELF binary output file from all object files.
  49. .SECONDARY : $(TARGET).elf
  50. .PRECIOUS : $(OBJS)
  51. %.elf: $(OBJS)
  52.     @echo
  53.     @echo "=================================="
  54.     @echo "Linking: " $@
  55.     @echo "=================================="
  56.     $(CC) $(CFLAGS) -o $@ $^
  57.  
  58. # Compile: create object files from all C source files.
  59. %.o: %.c
  60.     @echo
  61.     @echo "=================================="
  62.     @echo "Compiling: " $<
  63.     @echo "=================================="
  64.     $(CC) -c $(CFLAGS) $< -o $@
  65.    
  66. all: build size finished
  67.  
  68. build: $(TARGET).hex
  69.  
  70. finished:
  71.     @echo "Errors: none"
  72.     @echo
  73.    
  74. size:
  75.     @echo
  76.     @echo "=================================="
  77.     @echo "Compiled program size:"
  78.     @echo "=================================="
  79.     $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf
  80.  
  81. program: $(TARGET).hex
  82.     @echo
  83.     @echo "=================================="
  84.     @echo "Programming flash memory: " $<
  85.     @echo "=================================="
  86.     $(AVRDUDE) -c arduino -p $(MCU) -P $(PORT) -b 57600 -U flash:w:$<
  87.  
  88. clean:
  89.     @echo
  90.     @echo "=================================="
  91.     @echo "Cleaning project:"
  92.     @echo "=================================="
  93.     $(REMOVE) $(TARGET).elf
  94.     $(REMOVE) $(TARGET).hex
  95.     $(REMOVE) $(OBJS)
  96.  
  97. # Listing of phony targets.
  98. .PHONY : all build finished size program clean
Advertisement
Add Comment
Please, Sign In to add comment