Makefile 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #
  2. # Generic and Simple GNU ARM Makefile
  3. #
  4. # Desinged for the gnu-arm-none-eabi tool chain
  5. #
  6. # Features
  7. # - create hex file
  8. # - create assembler listing (.dis)
  9. #
  10. # Limitations
  11. # - only C-files supported
  12. # - no automatic dependency checking (call 'make clean' if any .h files are changed)
  13. #
  14. # Targets:
  15. # make
  16. # create hex file, no upload
  17. # make upload
  18. # create and upload hex file
  19. # make clean
  20. # delete all generated files
  21. #
  22. # Note:
  23. # Display list make database: make -p -f/dev/null | less
  24. #
  25. #================================================
  26. # External tools
  27. # The base directory of gcc-arm-none-eabi
  28. # Can be empty on Ubuntu and installed gcc-arm-none-eabi
  29. # If set, GCCBINPATH must contain a "/" at the end.
  30. GCCBINPATH:=/usr/bin/
  31. #================================================
  32. # Project Information
  33. # The name for the project
  34. TARGETNAME:=plu
  35. # The source files of the project
  36. SRC:=$(wildcard *.c)
  37. # The CPU architecture (will be used for -mcpu)
  38. # for the LPC804, can we use "cortex-m0plus" instead of "cortex-m0"?
  39. MCPU:=cortex-m0plus
  40. # Include directory for the system include files
  41. SYSINC:=../lpc_chip_804/inc
  42. SYSSRC:=$(wildcard ../lpc_chip_804/src/*.c)
  43. # Include directory for the u8g2 include files
  44. #U8G2INC:=../../../../csrc/
  45. #U8G2SRC:=$(wildcard ../../../../csrc/*.c)
  46. # directory for FatFS
  47. #FFINC:=../fatfs
  48. #FFSRC:=$(wildcard ../fatfs/*.c)
  49. # Directory for the linker script
  50. LDSCRIPTDIR:=.
  51. # Name of the linker script (must be the "keep" script, because the other script is not always working)
  52. LDSCRIPT:=lpc804.ld
  53. #================================================
  54. # Main part of the Makefile starts here. Usually no changes are needed.
  55. # Internal Variable Names
  56. LIBNAME:=$(TARGETNAME).a
  57. ELFNAME:=$(TARGETNAME).elf
  58. HEXNAME:=$(TARGETNAME).hex
  59. DISNAME:=$(TARGETNAME).dis
  60. MAPNAME:=$(TARGETNAME).map
  61. OBJ:=$(SRC:.c=.o) $(SYSSRC:.c=.o) $(U8G2SRC:.c=.o) $(FFSRC:.c=.o)
  62. # Replace standard build tools by arm tools
  63. CC:=$(GCCBINPATH)arm-none-eabi-gcc
  64. AR:=$(GCCBINPATH)arm-none-eabi-ar
  65. OBJCOPY:=$(GCCBINPATH)arm-none-eabi-objcopy
  66. OBJDUMP:=$(GCCBINPATH)arm-none-eabi-objdump
  67. SIZE:=$(GCCBINPATH)arm-none-eabi-size
  68. # Common flags
  69. COMMON_FLAGS = -mthumb -mcpu=$(MCPU)
  70. COMMON_FLAGS += -Wall -I. -I$(SYSINC) -I$(U8G2INC)
  71. # define stack size (defaults to 0x0100)
  72. # COMMON_FLAGS += -D__STACK_SIZE=0x0100
  73. # COMMON_FLAGS += -Os -flto
  74. COMMON_FLAGS += -Os
  75. # COMMON_FLAGS += -fstack-protector
  76. # COMMON_FLAGS += -finstrument-functions
  77. # Do not use stand libs startup code. Uncomment this for gcclib procedures
  78. # memcpy still works, but might be required for __aeabi_uidiv
  79. # COMMON_FLAGS += -nostdlib
  80. # remove unused data and function
  81. COMMON_FLAGS += -ffunction-sections -fdata-sections
  82. # COMMON_FLAGS += -ffunction-sections -fdata-sections -fshort-wchar
  83. # C flags
  84. CFLAGS:=$(COMMON_FLAGS) -std=gnu99
  85. # LD flags
  86. # remove unreferenced procedures and variables, but keep "arm_stack_area" and __isr_vector
  87. GC:=-Wl,--gc-sections -Wl,--undefined=arm_stack_area -Wl,--undefined=__isr_vector
  88. MAP:=-Wl,-Map=$(MAPNAME)
  89. LFLAGS:=$(COMMON_FLAGS) $(GC) $(MAP)
  90. #LDLIBS:=--specs=nano.specs -L$(LDSCRIPTDIR) -T $(LDSCRIPT)
  91. LDLIBS:=--specs=nosys.specs -L$(LDSCRIPTDIR) -T $(LDSCRIPT)
  92. # Additional Suffixes
  93. .SUFFIXES: .elf .hex .bin .dis
  94. # Targets
  95. .PHONY: all
  96. all: plu.c $(DISNAME) $(HEXNAME)
  97. $(SIZE) $(ELFNAME)
  98. .PHONY: upload
  99. upload: $(DISNAME) $(HEXNAME) $(ELFNAME)
  100. $(SIZE) $(ELFNAME)
  101. .PHONY: clean
  102. clean:
  103. $(RM) $(OBJ) $(HEXNAME) $(ELFNAME) $(LIBNAME) $(DISNAME) $(MAPNAME) libssp.a libssp_nonshared.a plu.c
  104. # implicit rules
  105. .elf.hex:
  106. $(OBJCOPY) -O ihex $< $@
  107. # explicit rules
  108. plu.c: Makefile plu.bex plu.bms
  109. ./pluc plu.bex plu.bms -oc plu.c
  110. $(ELFNAME): $(LIBNAME)($(OBJ)) libssp.a libssp_nonshared.a plu.c
  111. $(LINK.o) $(LFLAGS) $(LIBNAME) $(LDLIBS) -o $@
  112. $(DISNAME): $(ELFNAME)
  113. $(OBJDUMP) -D -S $< > $@
  114. # create empty ssp libs for -fstack-protector-all -fstack-protector
  115. libssp.a:
  116. $(AR) rcs $@
  117. libssp_nonshared.a:
  118. $(AR) rcs $@