Actions

EmSys

Makefile ARM C Template

From EdWiki

  1. #########################################################################
  2. #									#
  3. #                   Template Makefile for C Programs                    #
  4. #									#
  5. #########################################################################
  6.  
  7. # This file is meant to be used as a template (in other words, a starting
  8. # point) for any Makefile that you write.  Modify it to suit your needs,
  9. # making sure that the file is called "Makefile"; in most cases, all you
  10. # need to do is replace every occurrence of "template" with the name of
  11. # your file.
  12. #
  13. # Every Makefile should have the targets "all" and "clean", at a minimum.
  14. # See chapter 14 of the GNU Make Reference for other suggestions on how
  15. # Makefiles should be written.
  16. #
  17. # Please note that every line that is indented (or, in the language of
  18. # Makefiles, the command part of the rules) is done so with TAB
  19. # characters, NOT with spaces.  This is important and a subtle trap for
  20. # the unwary!
  21.  
  22.  
  23. all:		template.elf
  24.  
  25. template.elf:	template.o
  26. template.o:	template.c template.h
  27.  
  28. clean:
  29. 	-rm -f template.elf template.o
  30.  
  31.  
  32. # The following variables and implicit rules are required for the GNU
  33. # Assembler and the GNU Compiler for ARM.  You probably do not need to
  34. # modify anything here.
  35.  
  36. AS        = arm-none-eabi-as
  37. CC        = arm-none-eabi-gcc
  38. LD        = arm-none-eabi-ld
  39.  
  40. ASFLAGS   = --gdwarf2
  41. CFLAGS    = -O2 -g -Wall
  42. LDFLAGS   =
  43. LOADLIBES =
  44. LDLIBS    = -lc
  45.  
  46. # Compile C code (.c) to an object file (.o)
  47.  
  48. %.o: %.c
  49. 	$(CC) -c -mcpu=arm7tdmi $(CFLAGS) $< -o $@
  50.  
  51. # Assemble ARM assembly language source (.s) to an object file (.o)
  52.  
  53. %.o: %.s
  54. 	$(AS) -marm7tdmi $(ASFLAGS) $< -o $@
  55.  
  56. # Link files into an ARM executable (.elf), using the GNU Compiler.
  57.  
  58. %.elf:
  59. 	$(CC) $(LDFLAGS) $+ $(LOADLIBES) $(LDLIBS) -o $@
  60.  
  61.  
  62. # Miscellaneous rules
  63.  
  64. .PHONY:	all clean
  65. .DEFAULT:
  66. .SUFFIXES:

Reference

GNU Make Reference