Guest User

Makefile

a guest
Oct 16th, 2014
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Make 9.29 KB | None | 0 0
  1. # Copyright 2014, Jernej Kovacic
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14.  
  15.  
  16. #
  17. # Type "make help" for more details.
  18. #
  19.  
  20. # quiet build
  21. AD = @
  22.  
  23. TOOLCHAIN = arm-none-eabi-
  24. CC = $(TOOLCHAIN)gcc
  25. CXX = $(TOOLCHAIN)g++
  26. AS = $(TOOLCHAIN)as
  27. LD = $(TOOLCHAIN)ld
  28. OBJCOPY = $(TOOLCHAIN)objcopy
  29. SIZE = $(TOOLCHAIN)size
  30. AR = $(TOOLCHAIN)ar
  31. FLASHER = lm4flash
  32. TERM = pyterm
  33. TARGS= -p /dev/ttyACM0
  34.  
  35. INCLUDEFLAG = -I
  36. CPUFLAG = -mthumb -mcpu=cortex-m4
  37. FPUFLAG = -mfpu=fpv4-sp-d16 -mfloat-abi=hard
  38. WFLAG   = -Wall -Wextra -Werror -Wstrict-prototypes
  39.  
  40. CFLAGS  += -std=gnu99 $(WFLAG) $(CPUFLAG) $(FPUFLAG) -mlittle-endian -mthumb -mthumb-interwork -nostartfiles
  41. CFLAGS  += -ffunction-sections -fdata-sections -fno-builtin
  42. LDFLAGS += -nostdlib --gc-sections -static
  43.  
  44. # Additional C compiler flags to produce debugging symbols
  45. DEB_FLAG = -ggdb -g3 -DDEBUG
  46.  
  47. # Compiler/target path in FreeRTOS/Source/portable
  48. PORT_COMP_TARG = GCC/ARM_CM4F/
  49.  
  50. # Intermediate directory for all *.o and other files:
  51. OBJDIR = obj/
  52.  
  53. # FreeRTOS source base directory
  54. FREERTOS_SRC = FreeRTOS/Source/
  55.  
  56. # Directory with memory management source files
  57. FREERTOS_MEMMANG_SRC = $(FREERTOS_SRC)portable/MemMang/
  58.  
  59. # Directory with platform specific source files
  60. FREERTOS_PORT_SRC = $(FREERTOS_SRC)portable/$(PORT_COMP_TARG)
  61.  
  62. # Directory with HW drivers' source files
  63. DRIVERS_SRC = drivers/
  64.  
  65. # Directory with demo specific source (and header) files
  66. APP_SRC = app/
  67.  
  68. LIB_SRC = lib/
  69.  
  70. # Specify location of TivaWare
  71. TIVAWARE = TivaWare/
  72.  
  73. PART=TM4C123GH6PM
  74. CFLAGS +=-DTARGET_IS_BLIZZARD_RB1 -DPART_${PART}
  75.  
  76. # Object files to be linked into an application
  77. # Due to a large number, the .o files are arranged into logical groups:
  78.  
  79. FREERTOS_OBJS = queue.o list.o tasks.o
  80. # The following o. files are only necessary if
  81. # certain options are enabled in FreeRTOSConfig.h
  82. #FREERTOS_OBJS += timers.o
  83. #FREERTOS_OBJS += croutine.o
  84. #FREERTOS_OBJS += event_groups.o
  85.  
  86. # Only one memory management .o file must be uncommented!
  87. FREERTOS_MEMMANG_OBJS = heap_1.o
  88. #FREERTOS_MEMMANG_OBJS = heap_2.o
  89. #FREERTOS_MEMMANG_OBJS = heap_3.o
  90. #FREERTOS_MEMMANG_OBJS = heap_4.o
  91. #FREERTOS_MEMMANG_OBJS = heap_5.o
  92.  
  93. FREERTOS_PORT_OBJS = port.o
  94.  
  95. # DRIVERS_OBJS = sysctl.o systick.o nvic.o scb.o interrupt.o
  96. #Unnnecessary driver object files may be commented out
  97. DRIVERS_OBJS += led.o
  98. DRIVERS_OBJS += uart.o
  99. # DRIVERS_OBJS += watchdog.o
  100. # DRIVERS_OBJS += led.o
  101. # DRIVERS_OBJS += switch.o
  102.  
  103. APP_OBJS = startup.o init.o main.o
  104. # APP_OBJS += wdtask.o
  105. # APP_OBJS += print.o
  106. # APP_OBJS += receive.o
  107. # APP_OBJS += lightshow.o
  108. # nostdlib.o must be commented out if standard lib is going to be linked!
  109.  
  110. LIB_OBJS += nostdlib.o
  111. LIB_OBJS += printf.o
  112.  
  113. # All object files specified above are prefixed the intermediate directory
  114. OBJS = $(addprefix $(OBJDIR), $(FREERTOS_OBJS) $(FREERTOS_MEMMANG_OBJS) $(FREERTOS_PORT_OBJS) $(DRIVERS_OBJS) $(APP_OBJS) $(LIB_OBJS))
  115.  
  116. # Definition of the linker script and final targets
  117. LINKER_SCRIPT = $(addprefix $(APP_SRC), tiva.ld)
  118. ELF_IMAGE = image.elf
  119. TARGET = image.bin
  120.  
  121. # Include paths to be passed to $(CC) where necessary
  122. INC_FREERTOS = $(FREERTOS_SRC)include/
  123. INC_DRIVERS = $(DRIVERS_SRC)include/
  124. INC_LIB = $(LIB_SRC)include/
  125.  
  126. # Complete include flags to be passed to $(CC) where necessary
  127. INC_FLAGS = $(INCLUDEFLAG)$(INC_FREERTOS) $(INCLUDEFLAG)$(APP_SRC) $(INCLUDEFLAG)$(FREERTOS_PORT_SRC) $(INCLUDEFLAG)$(INC_DRIVERS) $(INCLUDEFLAG)$(INC_LIB) $(INCLUDEFLAG)$(TIVAWARE)
  128.  
  129. DEP_FRTOS_CONFIG = $(APP_SRC)/FreeRTOSConfig.h
  130. DEP_SETTINGS = $(DEP_FRTOS_CONFIG)
  131.  
  132.  
  133. #
  134. # Make rules:
  135. #
  136.  
  137. all : $(TARGET)
  138.  
  139. rebuild : clean all
  140.  
  141. $(TARGET) : $(OBJDIR) $(ELF_IMAGE)
  142.     $(AD)$(OBJCOPY) -O binary $(word 2,$^) $@
  143.  
  144. $(OBJDIR) :
  145.     $(AD)mkdir -p $@
  146.  
  147. $(ELF_IMAGE) : $(OBJS) $(LINKER_SCRIPT)
  148.     $(AD)$(LD) $(LDFLAGS) -L $(OBJDIR) -T $(LINKER_SCRIPT) $(OBJS) -o $@
  149.     $(SIZE) $(ELF_IMAGE)
  150.  
  151. debug : _debug_flags all
  152.  
  153. debug_rebuild : _debug_flags rebuild
  154.  
  155. _debug_flags :
  156.     $(eval CFLAGS += $(DEB_FLAG))
  157.  
  158. flash : $(TARGET)
  159.     $(FLASHER) $(TARGET)
  160.  
  161. term:
  162.     $(TERM) $(TARGS)
  163.  
  164. # FreeRTOS core
  165.  
  166. $(OBJDIR)queue.o : $(FREERTOS_SRC)queue.c $(DEP_FRTOS_CONFIG)
  167.     $(AD)$(CC) -c $(CFLAGS) $(INC_FLAGS) $< -o $@
  168.  
  169. $(OBJDIR)list.o : $(FREERTOS_SRC)list.c $(DEP_FRTOS_CONFIG)
  170.     $(AD)$(CC) -c $(CFLAGS) $(INC_FLAGS) $< -o $@
  171.  
  172. $(OBJDIR)tasks.o : $(FREERTOS_SRC)tasks.c $(DEP_FRTOS_CONFIG)
  173.     $(AD)$(CC) -c $(CFLAGS) $(INC_FLAGS) $< -o $@
  174.  
  175. $(OBJDIR)timers.o : $(FREERTOS_SRC)timers.c $(DEP_FRTOS_CONFIG)
  176.     $(AD)$(CC) -c $(CFLAGS) $(INC_FLAGS) $< -o $@
  177.  
  178. $(OBJDIR)croutine.o : $(FREERTOS_SRC)croutine.c $(DEP_FRTOS_CONFIG)
  179.     $(AD)$(CC) -c $(CFLAGS) $(INC_FLAGS) $< -o $@
  180.  
  181. $(OBJDIR)event_groups.o : $(FREERTOS_SRC)event_groups.c $(DEP_FRTOS_CONFIG)
  182.     $(AD)$(CC) -c $(CFLAGS) $(INC_FLAGS) $< -o $@
  183.  
  184.  
  185. # HW specific part, in FreeRTOS/Source/portable/$(PORT_COMP_TARGET)
  186.  
  187. $(OBJDIR)port.o : $(FREERTOS_PORT_SRC)port.c $(DEP_FRTOS_CONFIG)
  188.     $(AD)$(CC) -c $(CFLAGS) $(INC_FLAGS) $< -o $@
  189.  
  190.  
  191.  
  192.  
  193. # Rules for all MemMang implementations are provided
  194. # Only one of these object files must be linked to the final target
  195.  
  196. $(OBJDIR)heap_1.o : $(FREERTOS_MEMMANG_SRC)heap_1.c $(DEP_FRTOS_CONFIG)
  197.     $(AD)$(CC) -c $(CFLAGS) $(INC_FLAGS) $< -o $@
  198.  
  199. $(OBJDIR)heap_2.o : $(FREERTOS_MEMMANG_SRC)heap_2.c $(DEP_FRTOS_CONFIG)
  200.     $(AD)$(CC) -c $(CFLAGS) $(INC_FLAGS) $< -o $@
  201.  
  202. $(OBJDIR)heap_3.o : $(FREERTOS_MEMMANG_SRC)heap_3.c $(DEP_FRTOS_CONFIG)
  203.     $(AD)$(CC) -c $(CFLAGS) $(INC_FLAGS) $< -o $@
  204.  
  205. $(OBJDIR)heap_4.o : $(FREERTOS_MEMMANG_SRC)heap_4.c $(DEP_FRTOS_CONFIG)
  206.     $(AD)$(CC) -c $(CFLAGS) $(INC_FLAGS) $< -o $@
  207.  
  208. $(OBJDIR)heap_5.o : $(FREERTOS_MEMMANG_SRC)heap_5.c $(DEP_FRTOS_CONFIG)
  209.     $(AD)$(CC) -c $(CFLAGS) $(INC_FLAGS) $< -o $@
  210.  
  211. # Drivers
  212.  
  213. $(OBJDIR)sysctl.o : $(DRIVERS_SRC)sysctl.c $(DEP_BSP)
  214.     $(AD)$(CC) -c $(CFLAGS) $(INC_FLAGS) $< -o $@
  215.  
  216. $(OBJDIR)systick.o : $(DRIVERS_SRC)systick.c $(DEP_BSP)
  217.     $(AD)$(CC) -c $(CFLAGS) $(INC_FLAGS) $< -o $@
  218.  
  219. $(OBJDIR)nvic.o : $(DRIVERS_SRC)nvic.c $(DEP_BSP)
  220.     $(AD)$(CC) -c $(CFLAGS) $(INC_FLAGS) $< -o $@
  221.  
  222. $(OBJDIR)scb.o : $(DRIVERS_SRC)scb.c $(DEP_BSP)
  223.     $(AD)$(CC) -c $(CFLAGS) $(INC_FLAGS) $< -o $@
  224.  
  225. $(OBJDIR)interrupt.o : $(DRIVERS_SRC)interrupt.c
  226.     $(AD)$(CC) -c $(CFLAGS) $(INC_FLAGS) $< -o $@
  227.  
  228. $(OBJDIR)gpio.o : $(DRIVERS_SRC)gpio.c $(DEP_BSP)
  229.     $(AD)$(CC) -c $(CFLAGS) $(INC_FLAGS) $< -o $@
  230.  
  231. $(OBJDIR)uart.o : $(DRIVERS_SRC)uart.c $(DEP_BSP)
  232.     $(AD)$(CC) -c $(CFLAGS) $(INC_FLAGS) $< -o $@
  233.  
  234. $(OBJDIR)watchdog.o : $(DRIVERS_SRC)watchdog.c $(DEP_BSP)
  235.     $(AD)$(CC) -c $(CFLAGS) $(INC_FLAGS) $< -o $@
  236.  
  237. $(OBJDIR)led.o : $(DRIVERS_SRC)led.c $(DEP_BSP)
  238.     $(AD)$(CC) -c $(CFLAGS) $(INC_FLAGS) $< -o $@
  239.  
  240. $(OBJDIR)switch.o : $(DRIVERS_SRC)switch.c $(DEP_BSP)
  241.     $(AD)$(CC) -c $(CFLAGS) $(INC_FLAGS) $< -o $@
  242.  
  243. $(OBJDIR)fpu.o : $(DRIVERS_SRC)fpu.c $(DEP_BSP)
  244.     $(AD)$(CC) -c $(CFLAGS) $(INC_FLAGS) $< -o $@
  245.  
  246.  
  247. # Demo application
  248.  
  249. $(OBJDIR)startup.o : $(APP_SRC)startup.c $(DEP_SETTINGS)
  250.     $(AD)$(CC) -c $(CFLAGS) $(INC_FLAGS) $< -o $@
  251.  
  252. $(OBJDIR)handlers.o : $(APP_SRC)handlers.c $(DEP_SETTINGS)
  253.     $(AD)$(CC) -c $(CFLAGS) $(INC_FLAGS) $< -o $@
  254.  
  255. $(OBJDIR)init.o : $(APP_SRC)init.c $(DEP_SETTINGS)
  256.     $(AD)$(CC) -c $(CFLAGS) $(INC_FLAGS) $< -o $@
  257.  
  258. $(OBJDIR)main.o : $(APP_SRC)main.c $(DEP_SETTINGS)
  259.     $(AD)$(CC) -c $(CFLAGS) $(INC_FLAGS) $< -o $@
  260.  
  261. $(OBJDIR)wdtask.o : $(APP_SRC)wdtask.c $(DEP_SETTINGS)
  262.     $(AD)$(CC) -c $(CFLAGS) $(INC_FLAGS) $< -o $@
  263.  
  264. $(OBJDIR)print.o : $(APP_SRC)print.c $(DEP_SETTINGS)
  265.     $(AD)$(CC) -c $(CFLAGS) $(INC_FLAGS) $< -o $@
  266.  
  267. $(OBJDIR)receive.o : $(APP_SRC)receive.c $(DEP_SETTINGS)
  268.     $(AD)$(CC) -c $(CFLAGS) $(INC_FLAGS) $< -o $@
  269.  
  270. $(OBJDIR)lightshow.o : $(APP_SRC)lightshow.c $(DEP_SETTINGS)
  271.     $(AD)$(CC) -c $(CFLAGS) $(INC_FLAGS) $< -o $@
  272.  
  273. $(OBJDIR)nostdlib.o : $(LIB_SRC)nostdlib.c
  274.     $(AD)$(CC) -c $(CFLAGS) $< -o $@
  275.  
  276. $(OBJDIR)printf.o : $(LIB_SRC)printf.c
  277.     $(AD)$(CC) -c $(CFLAGS) $< -o $@
  278.  
  279. # Cleanup directives:
  280.  
  281. clean_obj :
  282.     $(AD)$(RM) -r $(OBJDIR)
  283.  
  284. clean_intermediate : clean_obj
  285.     $(AD)$(RM) *.elf
  286.     $(AD)$(RM) *.img
  287.    
  288. clean : clean_intermediate
  289.     $(AD)$(RM) *.bin
  290.  
  291.  
  292. # Short help instructions:
  293.  
  294. help :
  295.     @echo
  296.     @echo Valid targets:
  297.     @echo - all: builds missing dependencies and creates the target image \'$(IMAGE)\'.
  298.     @echo - rebuild: rebuilds all dependencies and creates the target image \'$(IMAGE)\'.
  299.     @echo - debug: same as \'all\', also includes debugging symbols to \'$(ELF_IMAGE)\'.
  300.     @echo - debug_rebuild: same as \'rebuild\', also includes debugging symbols to \'$(ELF_IMAGE)\'.
  301.     @echo - clean_obj: deletes all object files, only keeps \'$(ELF_IMAGE)\' and \'$(IMAGE)\'.
  302.     @echo - clean_intermediate: deletes all intermediate binaries, only keeps the target image \'$(IMAGE)\'.
  303.     @echo - clean: deletes all intermediate binaries, incl. the target image \'$(IMAGE)\'.
  304.     @echo - help: displays these help instructions.
  305.     @echo
  306.  
  307.  
  308. .PHONY :  all rebuild clean clean_intermediate clean_obj debug debug_rebuild _debug_flags help
Advertisement
Add Comment
Please, Sign In to add comment