Advertisement
Guest User

Makefile

a guest
Jun 29th, 2016
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Make 11.88 KB | None | 0 0
  1. PROJECT_NAME := ble_app_hrs_s130_custom_board
  2.  
  3. export OUTPUT_FILENAME
  4. #MAKEFILE_NAME := $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
  5. MAKEFILE_NAME := $(MAKEFILE_LIST)
  6. MAKEFILE_DIR := $(dir $(MAKEFILE_NAME) )
  7.  
  8. TEMPLATE_PATH = $(NRF_SDK_ROOT)/components/toolchain/gcc
  9. ifeq ($(OS),Windows_NT)
  10. include $(TEMPLATE_PATH)/Makefile.windows
  11. else
  12. include $(TEMPLATE_PATH)/Makefile.posix
  13. endif
  14.  
  15. MK := mkdir
  16. RM := rm -rf
  17.  
  18. #echo suspend
  19. ifeq ("$(VERBOSE)","1")
  20. NO_ECHO :=
  21. else
  22. NO_ECHO := @
  23. endif
  24.  
  25. # Toolchain commands
  26. CC              := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-gcc'
  27. XX              := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-g++'
  28. AS              := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-as'
  29. AR              := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-ar' -r
  30. LD              := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-ld'
  31. NM              := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-nm'
  32. OBJDUMP         := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-objdump'
  33. OBJCOPY         := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-objcopy'
  34. SIZE            := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-size'
  35.  
  36. #function for removing duplicates in a list
  37. remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-out $(firstword $1),$1))))
  38.  
  39. #source common to all targets
  40. C_SOURCE_FILES += \
  41. $(abspath $(NRF_SDK_ROOT)/components/libraries/util/app_error.c) \
  42. $(abspath $(NRF_SDK_ROOT)/components/libraries/util/app_error_weak.c) \
  43. $(abspath $(NRF_SDK_ROOT)/components/libraries/fifo/app_fifo.c) \
  44. $(abspath $(NRF_SDK_ROOT)/components/libraries/timer/app_timer.c) \
  45. $(abspath $(NRF_SDK_ROOT)/components/libraries/trace/app_trace.c) \
  46. $(abspath $(NRF_SDK_ROOT)/components/libraries/util/app_util_platform.c) \
  47. $(abspath $(NRF_SDK_ROOT)/components/libraries/fstorage/fstorage.c) \
  48. $(abspath $(NRF_SDK_ROOT)/components/libraries/util/nrf_assert.c) \
  49. $(abspath $(NRF_SDK_ROOT)/components/libraries/util/nrf_log.c) \
  50. $(abspath $(NRF_SDK_ROOT)/components/libraries/uart/retarget.c) \
  51. $(abspath $(NRF_SDK_ROOT)/components/libraries/sensorsim/sensorsim.c) \
  52. $(abspath $(NRF_SDK_ROOT)/components/libraries/uart/app_uart_fifo.c) \
  53. $(abspath $(NRF_SDK_ROOT)/components/drivers_nrf/delay/nrf_delay.c) \
  54. $(abspath $(NRF_SDK_ROOT)/components/drivers_nrf/common/nrf_drv_common.c) \
  55. $(abspath $(NRF_SDK_ROOT)/components/drivers_nrf/gpiote/nrf_drv_gpiote.c) \
  56. $(abspath $(NRF_SDK_ROOT)/components/drivers_nrf/uart/nrf_drv_uart.c) \
  57. $(abspath $(NRF_SDK_ROOT)/components/drivers_nrf/pstorage/pstorage.c) \
  58. $(abspath $(NRF_SDK_ROOT)/examples/bsp/bsp.c) \
  59. $(abspath $(NRF_SDK_ROOT)/examples/bsp/bsp_btn_ble.c) \
  60. $(abspath $(NRF_SDK_ROOT)/external/segger_rtt/RTT_Syscalls_GCC.c) \
  61. $(abspath $(NRF_SDK_ROOT)/external/segger_rtt/SEGGER_RTT.c) \
  62. $(abspath $(NRF_SDK_ROOT)/external/segger_rtt/SEGGER_RTT_printf.c) \
  63. $(abspath $(NRF_SDK_ROOT)/components/ble/common/ble_advdata.c) \
  64. $(abspath $(NRF_SDK_ROOT)/components/ble/ble_advertising/ble_advertising.c) \
  65. $(abspath $(NRF_SDK_ROOT)/components/ble/ble_services/ble_bas/ble_bas.c) \
  66. $(abspath $(NRF_SDK_ROOT)/components/ble/common/ble_conn_params.c) \
  67. $(abspath $(NRF_SDK_ROOT)/components/ble/ble_services/ble_dis/ble_dis.c) \
  68. $(abspath $(NRF_SDK_ROOT)/components/ble/ble_services/ble_hrs/ble_hrs.c) \
  69. $(abspath $(NRF_SDK_ROOT)/components/ble/common/ble_srv_common.c) \
  70. $(abspath $(NRF_SDK_ROOT)/components/ble/device_manager/device_manager_peripheral.c) \
  71. $(abspath $(NRF_SDK_ROOT)/components/toolchain/system_nrf51.c) \
  72. $(abspath $(NRF_SDK_ROOT)/components/softdevice/common/softdevice_handler/softdevice_handler.c) \
  73. $(abspath $(NRF_SDK_ROOT)/components/drivers_nrf/nrf_soc_nosd/nrf_soc.c) \
  74.  
  75. CXX_SOURCE_FILES += \
  76. $(abspath ../../../lib/i2c/i2c.cpp) \
  77. $(abspath ../../../main.cpp) \
  78.  
  79. #assembly files common to all targets
  80. ASM_SOURCE_FILES  = $(abspath $(NRF_SDK_ROOT)/components/toolchain/gcc/gcc_startup_nrf51.s)
  81.  
  82. #includes common to all targets
  83. INC_PATHS  = -I$(abspath ../../../config/genki_ble_test_s130_custom_board)
  84. INC_PATHS += -I$(abspath ../../../config)
  85. INC_PATHS += -I$(abspath $(NRF_SDK_ROOT)/components/drivers_nrf/config)
  86. INC_PATHS += -I$(abspath $(NRF_SDK_ROOT)/components/libraries/timer)
  87. INC_PATHS += -I$(abspath $(NRF_SDK_ROOT)/components/libraries/fifo)
  88. INC_PATHS += -I$(abspath $(NRF_SDK_ROOT)/components/libraries/fstorage/config)
  89. INC_PATHS += -I$(abspath $(NRF_SDK_ROOT)/components/softdevice/s130/headers)
  90. INC_PATHS += -I$(abspath $(NRF_SDK_ROOT)/components/drivers_nrf/delay)
  91. INC_PATHS += -I$(abspath $(NRF_SDK_ROOT)/components/libraries/util)
  92. INC_PATHS += -I$(abspath $(NRF_SDK_ROOT)/components/ble/device_manager)
  93. INC_PATHS += -I$(abspath $(NRF_SDK_ROOT)/components/drivers_nrf/uart)
  94. INC_PATHS += -I$(abspath $(NRF_SDK_ROOT)/components/ble/common)
  95. INC_PATHS += -I$(abspath $(NRF_SDK_ROOT)/components/libraries/sensorsim)
  96. INC_PATHS += -I$(abspath $(NRF_SDK_ROOT)/components/drivers_nrf/pstorage)
  97. INC_PATHS += -I$(abspath $(NRF_SDK_ROOT)/components/ble/ble_services/ble_dis)
  98. INC_PATHS += -I$(abspath $(NRF_SDK_ROOT)/components/device)
  99. INC_PATHS += -I$(abspath $(NRF_SDK_ROOT)/components/libraries/uart)
  100. INC_PATHS += -I$(abspath $(NRF_SDK_ROOT)/components/libraries/button)
  101. INC_PATHS += -I$(abspath $(NRF_SDK_ROOT)/components/libraries/fstorage)
  102. INC_PATHS += -I$(abspath $(NRF_SDK_ROOT)/components/libraries/experimental_section_vars)
  103. INC_PATHS += -I$(abspath $(NRF_SDK_ROOT)/components/drivers_nrf/gpiote)
  104. INC_PATHS += -I$(abspath $(NRF_SDK_ROOT)/external/segger_rtt)
  105. INC_PATHS += -I$(abspath $(NRF_SDK_ROOT)/examples/bsp)
  106. INC_PATHS += -I$(abspath $(NRF_SDK_ROOT)/components/toolchain/CMSIS/Include)
  107. INC_PATHS += -I$(abspath $(NRF_SDK_ROOT)/components/drivers_nrf/hal)
  108. INC_PATHS += -I$(abspath $(NRF_SDK_ROOT)/components/toolchain/gcc)
  109. INC_PATHS += -I$(abspath $(NRF_SDK_ROOT)/components/toolchain)
  110. INC_PATHS += -I$(abspath $(NRF_SDK_ROOT)/components/drivers_nrf/common)
  111. INC_PATHS += -I$(abspath $(NRF_SDK_ROOT)/components/ble/ble_advertising)
  112. INC_PATHS += -I$(abspath $(NRF_SDK_ROOT)/components/softdevice/s130/headers/nrf51)
  113. INC_PATHS += -I$(abspath $(NRF_SDK_ROOT)/components/libraries/trace)
  114. INC_PATHS += -I$(abspath $(NRF_SDK_ROOT)/components/ble/ble_services/ble_bas)
  115. INC_PATHS += -I$(abspath $(NRF_SDK_ROOT)/components/softdevice/common/softdevice_handler)
  116. INC_PATHS += -I$(abspath $(NRF_SDK_ROOT)/components/ble/ble_services/ble_hrs)
  117. INC_PATHS += -I$(abspath $(NRF_SDK_ROOT)/components/drivers_nrf/twi_master)
  118. INC_PATHS += -I$(abspath $(NRF_SDK_ROOT)/components/drivers_nrf/nrf_soc_nosd)
  119. INC_PATHS += -I$(abspath ../../../lib/i2c)
  120.  
  121. OBJECT_DIRECTORY = _build
  122. LISTING_DIRECTORY = $(OBJECT_DIRECTORY)
  123. OUTPUT_BINARY_DIRECTORY = $(OBJECT_DIRECTORY)
  124.  
  125. # Sorting removes duplicates
  126. BUILD_DIRECTORIES := $(sort $(OBJECT_DIRECTORY) $(OUTPUT_BINARY_DIRECTORY) $(LISTING_DIRECTORY) )
  127.  
  128. # C flags to all targets
  129. CFLAGS  = -DNRF_LOG_USES_UART=1
  130. CFLAGS += -DBOARD_CUSTOM
  131. CFLAGS += -DSOFTDEVICE_PRESENT
  132. CFLAGS += -DNRF51
  133. CFLAGS += -DS130
  134. CFLAGS += -DBLE_STACK_SUPPORT_REQD
  135. CFLAGS += -DSWI_DISABLE0
  136. CFLAGS += -mcpu=cortex-m0
  137. CFLAGS += -mthumb -mabi=aapcs
  138. CFLAGS += -Wall -O3 -g3
  139. CFLAGS += -mfloat-abi=soft
  140. # keep every function in separate section. This will allow linker to dump unused functions
  141. CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing
  142. CFLAGS += -fno-builtin --short-enums
  143. # keep every function in separate section. This will allow linker to dump unused functions
  144. LDFLAGS += -Xlinker -Map=$(LISTING_DIRECTORY)/$(OUTPUT_FILENAME).map
  145. LDFLAGS += -mthumb -mabi=aapcs -L $(TEMPLATE_PATH) -T$(LINKER_SCRIPT)
  146. LDFLAGS += -mcpu=cortex-m0
  147. # let linker to dump unused sections
  148. LDFLAGS += -Wl,--gc-sections
  149. # use newlib in nano version
  150. LDFLAGS += --specs=nano.specs -lc -lnosys
  151.  
  152. # Assembler flags
  153. ASMFLAGS += -x assembler-with-cpp
  154. ASMFLAGS += -DNRF_LOG_USES_UART=1
  155. ASMFLAGS += -DBOARD_CUSTOM
  156. ASMFLAGS += -DSOFTDEVICE_PRESENT
  157. ASMFLAGS += -DSWI_DISABLE0
  158. ASMFLAGS += -DNRF51
  159. ASMFLAGS += -DS130
  160. ASMFLAGS += -DBLE_STACK_SUPPORT_REQD
  161.  
  162. CXXFLAGS = -fno-exceptions -fno-rtti
  163.  
  164. #default target - first one defined
  165. default: clean nrf51822_xxac_s130
  166.  
  167. #building all targets
  168. all: clean
  169.     $(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e cleanobj
  170.     $(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e nrf51822_xxac_s130
  171.  
  172. #target for printing all targets
  173. help:
  174.     @echo following targets are available:
  175.     @echo   nrf51822_xxac_s130
  176.     @echo   flash_softdevice
  177.  
  178. C_SOURCE_FILE_NAMES = $(notdir $(C_SOURCE_FILES))
  179. C_PATHS = $(call remduplicates, $(dir $(C_SOURCE_FILES) ) )
  180. C_OBJECTS = $(addprefix $(OBJECT_DIRECTORY)/, $(C_SOURCE_FILE_NAMES:.c=.o) )
  181.  
  182. ASM_SOURCE_FILE_NAMES = $(notdir $(ASM_SOURCE_FILES))
  183. ASM_PATHS = $(call remduplicates, $(dir $(ASM_SOURCE_FILES) ))
  184. ASM_OBJECTS = $(addprefix $(OBJECT_DIRECTORY)/, $(ASM_SOURCE_FILE_NAMES:.s=.o) )
  185.  
  186. CXX_SOURCE_FILE_NAMES = $(notdir $(CXX_SOURCE_FILES))
  187. CXX_PATHS = $(call remduplicates, $(dir $(CXX_SOURCE_FILES) ) )
  188. CXX_OBJECTS = $(addprefix $(OBJECT_DIRECTORY)/, $(CXX_SOURCE_FILE_NAMES:.cpp=.o) )
  189.  
  190. vpath %.c $(C_PATHS)
  191. vpath %.s $(ASM_PATHS)
  192. vpath %.cpp $(CXX_PATHS)
  193.  
  194. OBJECTS = $(C_OBJECTS) $(ASM_OBJECTS) $(CXX_OBJECTS)
  195.  
  196. nrf51822_xxac_s130: OUTPUT_FILENAME := nrf51822_xxac_s130
  197. nrf51822_xxac_s130: LINKER_SCRIPT=ble_app_hrs_gcc_nrf51.ld
  198.  
  199. nrf51822_xxac_s130: $(BUILD_DIRECTORIES) $(OBJECTS)
  200.     @echo Linking target: $(OUTPUT_FILENAME).out
  201.     $(NO_ECHO)$(XX) $(LDFLAGS) $(OBJECTS) $(LIBS) -lm -o $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
  202.     $(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e finalize
  203.  
  204. ## Create build directories
  205. $(BUILD_DIRECTORIES):
  206.     echo $(MAKEFILE_NAME)
  207.     $(MK) $@
  208.  
  209. # Create objects from C SRC files
  210. $(OBJECT_DIRECTORY)/%.o: %.c
  211.     @echo Compiling file: $(notdir $<)
  212.     $(NO_ECHO)$(CC) -std=gnu99 $(CFLAGS) $(INC_PATHS) -c -o $@ $<
  213.  
  214. # Create objects from Cpp SRC files
  215. $(OBJECT_DIRECTORY)/%.o: %.cpp
  216.     @echo Compiling file: $(notdir $<)
  217.     $(NO_ECHO)$(XX) $(CFLAGS) -fpermissive $(CXXFLAGS) $(INC_PATHS) -c -o $@ $<
  218.  
  219. # Assemble files
  220. $(OBJECT_DIRECTORY)/%.o: %.s
  221.     @echo Compiling file: $(notdir $<)
  222.     $(NO_ECHO)$(CC) -std=c99 $(ASMFLAGS) $(INC_PATHS) -c -o $@ $<
  223.  
  224.  
  225. # Link
  226. $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out: $(BUILD_DIRECTORIES) $(OBJECTS)
  227.     @echo Linking target: $(OUTPUT_FILENAME).out
  228.     $(NO_ECHO)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
  229.  
  230.  
  231. ## Create binary .bin file from the .out file
  232. $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin: $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
  233.     @echo Preparing: $(OUTPUT_FILENAME).bin
  234.     $(NO_ECHO)$(OBJCOPY) -O binary $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin
  235.  
  236. ## Create binary .hex file from the .out file
  237. $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex: $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
  238.     @echo Preparing: $(OUTPUT_FILENAME).hex
  239.     $(NO_ECHO)$(OBJCOPY) -O ihex $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex
  240.  
  241. finalize: genbin genhex echosize
  242.  
  243. genbin:
  244.     @echo Preparing: $(OUTPUT_FILENAME).bin
  245.     $(NO_ECHO)$(OBJCOPY) -O binary $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin
  246.  
  247. ## Create binary .hex file from the .out file
  248. genhex:
  249.     @echo Preparing: $(OUTPUT_FILENAME).hex
  250.     $(NO_ECHO)$(OBJCOPY) -O ihex $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex
  251.  
  252. echosize:
  253.     -@echo ''
  254.     $(NO_ECHO)$(SIZE) $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
  255.     -@echo ''
  256.  
  257. clean:
  258.     $(RM) $(BUILD_DIRECTORIES)
  259.  
  260. cleanobj:
  261.     $(RM) $(BUILD_DIRECTORIES)/*.o
  262.  
  263. flash: $(MAKECMDGOALS)
  264.     @echo Flashing: $(OUTPUT_BINARY_DIRECTORY)/$<.hex
  265.     nrfjprog --program $(OUTPUT_BINARY_DIRECTORY)/$<.hex -f nrf51  --sectorerase
  266.     nrfjprog --reset
  267.  
  268. ## Flash softdevice
  269. flash_softdevice:
  270.     @echo Flashing: s130_nrf51_2.0.0_softdevice.hex
  271.     nrfjprog --program ../../../../../../components/softdevice/s130/hex/s130_nrf51_2.0.0_softdevice.hex -f nrf51 --chiperase
  272.     nrfjprog --reset
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement