makefile and build clean up

This commit is contained in:
hathach 2020-03-24 16:04:21 +07:00
parent 74d5dac7a8
commit bfa269c55f
2 changed files with 82 additions and 91 deletions

145
Makefile
View File

@ -33,21 +33,22 @@ OUTPUT_FILENAME = $(BOARD)_bootloader-$(GIT_VERSION)
#****************************************************************************** #******************************************************************************
# Tool configure # Tool configure
#****************************************************************************** #******************************************************************************
# Toolchain commands
# Should be added to your PATH
CROSS_COMPILE = arm-none-eabi-
CC := $(CROSS_COMPILE)gcc
AS := $(CROSS_COMPILE)as
AR := $(CROSS_COMPILE)ar -r
LD := $(CROSS_COMPILE)ld
NM := $(CROSS_COMPILE)nm
OBJDUMP := $(CROSS_COMPILE)objdump
OBJCOPY := $(CROSS_COMPILE)objcopy
SIZE := $(CROSS_COMPILE)size
GDB := $(CROSS_COMPILE)gdb
NRFUTIL = adafruit-nrfutil NRFUTIL = adafruit-nrfutil
ifneq ($(JLINK),)
NRFJPROG = nrfjprog -s $(JLINK)
else
NRFJPROG = nrfjprog NRFJPROG = nrfjprog
endif
# auto-detect BMP on macOS, otherwise have to specify
BMP_PORT ?= $(shell ls -1 /dev/cu.usbmodem????????1 | head -1)
ifeq ($(OS),Windows_NT)
PROGFILES = C:/Program Files (x86)
GNU_INSTALL_ROOT = $(PROGFILES)/GNU Tools ARM Embedded/7 2018-q2-update/bin/
endif
MK := mkdir MK := mkdir
RM := rm -rf RM := rm -rf
@ -59,28 +60,14 @@ else
QUIET = @ QUIET = @
endif endif
GNU_PREFIX = arm-none-eabi # auto-detect BMP on macOS, otherwise have to specify
BMP_PORT ?= $(shell ls -1 /dev/cu.usbmodem????????1 | head -1)
# Toolchain commands GDB_BMP = $(GDB) -ex 'target extended-remote $(BMP_PORT)' -ex 'monitor swdp_scan' -ex 'attach 1'
CC := '$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-gcc'
AS := '$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-as'
AR := '$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-ar' -r
LD := '$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-ld'
NM := '$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-nm'
OBJDUMP := '$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-objdump'
OBJCOPY := '$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-objcopy'
SIZE := '$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-size'
GDB := '$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-gdb'
GDB_BMP = arm-none-eabi-gdb -ex 'target extended-remote $(BMP_PORT)' -ex 'monitor swdp_scan' -ex 'attach 1'
#function for removing duplicates in a list
remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-out $(firstword $1),$1))))
#********************************* #*********************************
# Select the board to build # Select the board to build
#********************************* #*********************************
BOARD_LIST = $(sort $(subst .h,,$(subst src/boards/,,$(wildcard src/boards/*)))) BOARD_LIST = $(sort $(subst src/boards/,,$(wildcard src/boards/*)))
ifeq ($(filter $(BOARD),$(BOARD_LIST)),) ifeq ($(filter $(BOARD),$(BOARD_LIST)),)
$(info You must provide a BOARD parameter with 'BOARD='. Supported boards are:) $(info You must provide a BOARD parameter with 'BOARD='. Supported boards are:)
@ -116,49 +103,49 @@ endif
#****************************************************************************** #******************************************************************************
# src # src
C_SOURCE_FILES += $(SRC_PATH)/main.c C_SRC += $(SRC_PATH)/boards.c
C_SOURCE_FILES += $(SRC_PATH)/boards.c C_SRC += $(SRC_PATH)/dfu_ble_svc.c
C_SOURCE_FILES += $(SRC_PATH)/flash_nrf5x.c C_SRC += $(SRC_PATH)/dfu_init.c
C_SOURCE_FILES += $(SRC_PATH)/dfu_ble_svc.c C_SRC += $(SRC_PATH)/flash_nrf5x.c
C_SOURCE_FILES += $(SRC_PATH)/dfu_init.c C_SRC += $(SRC_PATH)/main.c
# all sources files in specific board # all sources files in specific board
C_SOURCE_FILES += $(wildcard $(SRC_PATH)/boards/$(BOARD)/*.c) C_SRC += $(wildcard $(SRC_PATH)/boards/$(BOARD)/*.c)
# nrfx # nrfx
C_SOURCE_FILES += $(NRFX_PATH)/drivers/src/nrfx_power.c C_SRC += $(NRFX_PATH)/drivers/src/nrfx_power.c
C_SOURCE_FILES += $(NRFX_PATH)/drivers/src/nrfx_nvmc.c C_SRC += $(NRFX_PATH)/drivers/src/nrfx_nvmc.c
C_SOURCE_FILES += $(NRFX_PATH)/mdk/system_$(MCU_SUB_VARIANT).c C_SRC += $(NRFX_PATH)/mdk/system_$(MCU_SUB_VARIANT).c
# SDK 11 files # SDK 11 files
C_SOURCE_FILES += $(SDK11_PATH)/libraries/bootloader_dfu/bootloader.c C_SRC += $(SDK11_PATH)/libraries/bootloader_dfu/bootloader.c
C_SOURCE_FILES += $(SDK11_PATH)/libraries/bootloader_dfu/bootloader_settings.c C_SRC += $(SDK11_PATH)/libraries/bootloader_dfu/bootloader_settings.c
C_SOURCE_FILES += $(SDK11_PATH)/libraries/bootloader_dfu/bootloader_util.c C_SRC += $(SDK11_PATH)/libraries/bootloader_dfu/bootloader_util.c
C_SOURCE_FILES += $(SDK11_PATH)/libraries/bootloader_dfu/dfu_transport_serial.c C_SRC += $(SDK11_PATH)/libraries/bootloader_dfu/dfu_transport_serial.c
C_SOURCE_FILES += $(SDK11_PATH)/libraries/bootloader_dfu/dfu_transport_ble.c C_SRC += $(SDK11_PATH)/libraries/bootloader_dfu/dfu_transport_ble.c
C_SOURCE_FILES += $(SDK11_PATH)/libraries/bootloader_dfu/dfu_single_bank.c C_SRC += $(SDK11_PATH)/libraries/bootloader_dfu/dfu_single_bank.c
C_SOURCE_FILES += $(SDK11_PATH)/drivers_nrf/pstorage/pstorage_raw.c C_SRC += $(SDK11_PATH)/drivers_nrf/pstorage/pstorage_raw.c
C_SOURCE_FILES += $(SDK11_PATH)/ble/ble_services/ble_dfu/ble_dfu.c C_SRC += $(SDK11_PATH)/ble/ble_services/ble_dfu/ble_dfu.c
C_SOURCE_FILES += $(SDK11_PATH)/ble/ble_services/ble_dis/ble_dis.c C_SRC += $(SDK11_PATH)/ble/ble_services/ble_dis/ble_dis.c
# Latest SDK files # Latest SDK files
C_SOURCE_FILES += $(SDK_PATH)/libraries/timer/app_timer.c C_SRC += $(SDK_PATH)/libraries/timer/app_timer.c
C_SOURCE_FILES += $(SDK_PATH)/libraries/scheduler/app_scheduler.c C_SRC += $(SDK_PATH)/libraries/scheduler/app_scheduler.c
C_SOURCE_FILES += $(SDK_PATH)/libraries/util/app_error.c C_SRC += $(SDK_PATH)/libraries/util/app_error.c
C_SOURCE_FILES += $(SDK_PATH)/libraries/util/app_util_platform.c C_SRC += $(SDK_PATH)/libraries/util/app_util_platform.c
C_SOURCE_FILES += $(SDK_PATH)/libraries/crc16/crc16.c C_SRC += $(SDK_PATH)/libraries/crc16/crc16.c
C_SOURCE_FILES += $(SDK_PATH)/libraries/hci/hci_mem_pool.c C_SRC += $(SDK_PATH)/libraries/hci/hci_mem_pool.c
C_SOURCE_FILES += $(SDK_PATH)/libraries/hci/hci_slip.c C_SRC += $(SDK_PATH)/libraries/hci/hci_slip.c
C_SOURCE_FILES += $(SDK_PATH)/libraries/hci/hci_transport.c C_SRC += $(SDK_PATH)/libraries/hci/hci_transport.c
C_SOURCE_FILES += $(SDK_PATH)/libraries/util/nrf_assert.c C_SRC += $(SDK_PATH)/libraries/util/nrf_assert.c
# UART or USB Serial # UART or USB Serial
ifeq ($(MCU_SUB_VARIANT),nrf52) ifeq ($(MCU_SUB_VARIANT),nrf52)
C_SOURCE_FILES += $(SDK_PATH)/libraries/uart/app_uart.c C_SRC += $(SDK_PATH)/libraries/uart/app_uart.c
C_SOURCE_FILES += $(SDK_PATH)/drivers_nrf/uart/nrf_drv_uart.c C_SRC += $(SDK_PATH)/drivers_nrf/uart/nrf_drv_uart.c
C_SOURCE_FILES += $(SDK_PATH)/drivers_nrf/common/nrf_drv_common.c C_SRC += $(SDK_PATH)/drivers_nrf/common/nrf_drv_common.c
IPATH += $(SDK11_PATH)/libraries/util IPATH += $(SDK11_PATH)/libraries/util
IPATH += $(SDK_PATH)/drivers_nrf/common IPATH += $(SDK_PATH)/drivers_nrf/common
@ -166,19 +153,19 @@ IPATH += $(SDK_PATH)/drivers_nrf/uart
else else
# src # src
C_SOURCE_FILES += $(SRC_PATH)/usb/usb_desc.c C_SRC += $(SRC_PATH)/usb/usb_desc.c
C_SOURCE_FILES += $(SRC_PATH)/usb/usb.c C_SRC += $(SRC_PATH)/usb/usb.c
C_SOURCE_FILES += $(SRC_PATH)/usb/msc_uf2.c C_SRC += $(SRC_PATH)/usb/msc_uf2.c
C_SOURCE_FILES += $(SRC_PATH)/usb/uf2/ghostfat.c C_SRC += $(SRC_PATH)/usb/uf2/ghostfat.c
# TinyUSB stack # TinyUSB stack
C_SOURCE_FILES += $(TUSB_PATH)/portable/nordic/nrf5x/dcd_nrf5x.c C_SRC += $(TUSB_PATH)/portable/nordic/nrf5x/dcd_nrf5x.c
C_SOURCE_FILES += $(TUSB_PATH)/common/tusb_fifo.c C_SRC += $(TUSB_PATH)/common/tusb_fifo.c
C_SOURCE_FILES += $(TUSB_PATH)/device/usbd.c C_SRC += $(TUSB_PATH)/device/usbd.c
C_SOURCE_FILES += $(TUSB_PATH)/device/usbd_control.c C_SRC += $(TUSB_PATH)/device/usbd_control.c
C_SOURCE_FILES += $(TUSB_PATH)/class/cdc/cdc_device.c C_SRC += $(TUSB_PATH)/class/cdc/cdc_device.c
C_SOURCE_FILES += $(TUSB_PATH)/class/msc/msc_device.c C_SRC += $(TUSB_PATH)/class/msc/msc_device.c
C_SOURCE_FILES += $(TUSB_PATH)/tusb.c C_SRC += $(TUSB_PATH)/tusb.c
endif endif
@ -186,7 +173,7 @@ endif
#****************************************************************************** #******************************************************************************
# Assembly Files # Assembly Files
#****************************************************************************** #******************************************************************************
ASM_SOURCE_FILES = $(NRFX_PATH)/mdk/gcc_startup_$(MCU_SUB_VARIANT).S ASM_SRC = $(NRFX_PATH)/mdk/gcc_startup_$(MCU_SUB_VARIANT).S
#****************************************************************************** #******************************************************************************
# INCLUDE PATH # INCLUDE PATH
@ -292,12 +279,16 @@ ASMFLAGS += -DSOFTDEVICE_PRESENT
ASMFLAGS += -DFLOAT_ABI_HARD ASMFLAGS += -DFLOAT_ABI_HARD
ASMFLAGS += $(MCU_FLAGS) ASMFLAGS += $(MCU_FLAGS)
C_SOURCE_FILE_NAMES = $(notdir $(C_SOURCE_FILES))
C_PATHS = $(call remduplicates, $(dir $(C_SOURCE_FILES) ) ) #function for removing duplicates in a list
remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-out $(firstword $1),$1))))
C_SOURCE_FILE_NAMES = $(notdir $(C_SRC))
C_PATHS = $(call remduplicates, $(dir $(C_SRC) ) )
C_OBJECTS = $(addprefix $(BUILD)/, $(C_SOURCE_FILE_NAMES:.c=.o) ) C_OBJECTS = $(addprefix $(BUILD)/, $(C_SOURCE_FILE_NAMES:.c=.o) )
ASM_SOURCE_FILE_NAMES = $(notdir $(ASM_SOURCE_FILES)) ASM_SOURCE_FILE_NAMES = $(notdir $(ASM_SRC))
ASM_PATHS = $(call remduplicates, $(dir $(ASM_SOURCE_FILES) )) ASM_PATHS = $(call remduplicates, $(dir $(ASM_SRC) ))
ASM_OBJECTS = $(addprefix $(BUILD)/, $(ASM_SOURCE_FILE_NAMES:.S=.o) ) ASM_OBJECTS = $(addprefix $(BUILD)/, $(ASM_SOURCE_FILE_NAMES:.S=.o) )
vpath %.c $(C_PATHS) vpath %.c $(C_PATHS)

View File

@ -1,5 +1,6 @@
import os import os
import shutil import shutil
import glob
import sys import sys
import subprocess import subprocess
import time import time
@ -7,27 +8,25 @@ import time
subprocess.run("rm -rf _build*", shell=True) subprocess.run("rm -rf _build*", shell=True)
subprocess.run("rm -rf bin/*", shell=True) subprocess.run("rm -rf bin/*", shell=True)
travis = False
if "TRAVIS" in os.environ and os.environ["TRAVIS"] == "true":
travis = True
success_count = 0 success_count = 0
fail_count = 0 fail_count = 0
exit_status = 0 exit_status = 0
build_format = '| {:30} | {:9} ' build_format = '| {:32} | {:9} | {:5} | {:6} | {:6} |'
build_separator = '-' * 54 build_separator = '-' * 74
# All supported boards
all_boards = [] all_boards = []
for entry in os.scandir("src/boards"): for entry in os.scandir("src/boards"):
all_boards.append(entry.name) all_boards.append(entry.name)
all_boards.sort()
#sha, version = build_info.get_version_info() #sha, version = build_info.get_version_info()
total_time = time.monotonic() total_time = time.monotonic()
print(build_separator) print(build_separator)
print((build_format + '| {:5} |').format('Board', 'Result', 'Time')) print(build_format.format('Board', 'Result', 'Time', 'Flash', 'SRAM'))
print(build_separator) print(build_separator)
for board in all_boards: for board in all_boards:
@ -51,15 +50,16 @@ for board in all_boards:
if entry.name.endswith(extension) and "nosd" not in entry.name: if entry.name.endswith(extension) and "nosd" not in entry.name:
shutil.copy(entry.path, bin_directory) shutil.copy(entry.path, bin_directory)
if travis: out_file = glob.glob('_build-{}/*.out'.format(board))[0]
print('travis_fold:start:build-{}\\r'.format(board)) size_output = subprocess.run('size {}'.format(out_file), shell=True, stdout=subprocess.PIPE).stdout.decode("utf-8")
size_list = size_output.split('\n')[1].split('\t')
flash_size = int(size_list[0])
sram_size = int(size_list[1]) + int(size_list[2])
print((build_format + '| {:.2f}s |').format(board, success, build_duration)) print(build_format.format(board, success, "{:.2f}s".format(build_duration), flash_size, sram_size))
if make_result.returncode != 0: if make_result.returncode != 0:
print(make_result.stdout.decode("utf-8")) print(make_result.stdout.decode("utf-8"))
if travis:
print('travis_fold:end:build-{}\\r'.format(board))
# Build Summary # Build Summary
total_time = time.monotonic() - total_time total_time = time.monotonic() - total_time