Advertisement
Guest User

makefile

a guest
Dec 9th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Make 3.34 KB | None | 0 0
  1. #
  2. #  Generic and Simple Atmel AVR GNU Makefile
  3. #
  4. #  Desinged for the gnu-avr tool chain
  5. #
  6. #  Copyright  (c) 2012 Oliver Kraus (olikraus@gmail.com)
  7. #
  8. # Redistribution and use in source and binary forms, with or without modification, are
  9. # permitted provided that the following conditions are met:
  10. #
  11. # * Redistributions of source code must retain the above copyright notice, this list of
  12. # conditions and the following disclaimer.
  13. # * Redistributions in binary form must reproduce the above copyright notice, this list
  14. # of conditions and the following disclaimer in the documentation and/or other materials
  15. # provided with the distribution.
  16. #
  17. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  18. # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  19. # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20. # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  21. # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  22. # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23. # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  24. # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  25. # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  26. # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. #  
  29. #   Features
  30. #       - upload
  31. #       - create exe from library
  32. #       - create assembler listing (.dis)
  33. #
  34. #   Limitations
  35. #       - only C-files supported
  36. #       - no automatic dependency checking (call 'make clean' if any .h files are changed)
  37. #
  38. #   Targets:
  39. #       make
  40. #           create hex file, no upload
  41. #       make upload
  42. #           create and upload hex file
  43. #       make clean
  44. #           delete all generated files
  45. #
  46. #  Note:
  47. #   Display list make database: make -p -f/dev/null | less
  48.  
  49. # User defined values
  50. TARGETNAME = geneerinennimi
  51. MCU:=atmega328
  52. F_CPU:=8000000
  53. WORKDIR:=.
  54.  
  55. # Type: "avrdude -c ?" to get a full listing.
  56. AVRDUDE_PROGRAMMER := usbasp
  57. # com1 = serial port. Use lpt1 to connect to parallel port.
  58. AVRDUDE_PORT := usb
  59.  
  60. # Replace standard build tools by avr tools
  61. CC = avr-gcc
  62. AR  = @avr-ar
  63.  
  64. # Compile all .c files in all directories
  65. SRC = $(shell ls $(WORKDIR)/*.c 2>/dev/null)
  66.  
  67.  
  68. # Flags for the linker and the compiler
  69. COMMON_FLAGS = -DF_CPU=$(F_CPU) -mmcu=$(MCU) $(DOGDEFS)
  70. COMMON_FLAGS += -g -Os -Wall -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
  71. COMMON_FLAGS += -ffunction-sections -fdata-sections -Wl,--gc-sections
  72. COMMON_FLAGS += -Wl,--relax -mcall-prologues
  73. CFLAGS = $(COMMON_FLAGS) -std=gnu99  
  74.  
  75. OBJ = $(SRC:.c=.o)
  76.  
  77. .SUFFIXES: .elf .hex .dis
  78.  
  79. # Targets
  80. .PHONY: all
  81. all: $(TARGETNAME).dis $(TARGETNAME).hex
  82.     avr-size $(TARGETNAME).elf
  83.  
  84. .PHONY: upload
  85. upload: $(TARGETNAME).dis $(TARGETNAME).hex
  86.     avrdude -F -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -v -v -U flash:w:$(TARGETNAME).hex
  87.     avr-size $(TARGETNAME).elf
  88.  
  89. .PHONY: clean
  90. clean:
  91.     $(RM) $(TARGETNAME).hex $(TARGETNAME).elf $(TARGETNAME).a $(TARGETNAME).dis $(OBJ)
  92.  
  93. # implicit rules
  94. .elf.hex:
  95.     avr-objcopy -O ihex -R .eeprom $< $@
  96.  
  97. # explicit rules
  98. $(TARGETNAME).elf: $(TARGETNAME).a($(OBJ))
  99.     $(LINK.o) $(COMMON_FLAGS) $(TARGETNAME).a $(LOADLIBES) $(LDLIBS) -o $@
  100.  
  101. $(TARGETNAME).dis: $(TARGETNAME).elf
  102.     avr-objdump -S $< > $@
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement