Merge pull request #1938 from hathach/update-build

Fix build on windows and macos
This commit is contained in:
Ha Thach 2023-03-06 15:10:21 +07:00 committed by GitHub
commit 66da95a0ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
46 changed files with 171 additions and 118 deletions

56
.github/workflows/build_win_mac.yml vendored Normal file
View File

@ -0,0 +1,56 @@
name: Build Windows/MacOS
on:
push:
paths:
- 'src/**'
- 'examples/**'
- 'lib/**'
- 'hw/**'
- '.github/workflows/build_win_mac.yml'
pull_request:
branches: [ master ]
paths:
- 'src/**'
- 'examples/**'
- 'lib/**'
- 'hw/**'
- '.github/workflows/build_win_mac.yml'
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
# ---------------------------------------
# Build ARM family
# ---------------------------------------
build-arm:
strategy:
fail-fast: false
matrix:
os: [windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install ARM GCC
uses: carlosperate/arm-none-eabi-gcc-action@v1
with:
release: '10.3-2021.10'
- name: Checkout TinyUSB
uses: actions/checkout@v3
- name: Checkout common submodules in lib
run: git submodule update --init lib/FreeRTOS-Kernel lib/lwip
- name: Get Dependencies
run: python3 tools/get_dependencies.py stm32f4
- name: Build
run: python3 tools/build_family.py stm32f4 stm32f411disco

View File

@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk
INC += \

View File

@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk
INC += \

View File

@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk
INC += \

View File

@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk
INC += \

View File

@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk
INC += \

View File

@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk
INC += \

View File

@ -1,6 +1,5 @@
DEPS_SUBMODULES += lib/FreeRTOS-Kernel
include ../../../tools/top.mk
include ../../make.mk
FREERTOS_SRC = lib/FreeRTOS-Kernel

View File

@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk
INC += \

View File

@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk
INC += \

View File

@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk
INC += \

View File

@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk
INC += \

View File

@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk
INC += \

View File

@ -1,6 +1,5 @@
DEPS_SUBMODULES += lib/FreeRTOS-Kernel
include ../../../tools/top.mk
include ../../make.mk
FREERTOS_SRC = lib/FreeRTOS-Kernel

View File

@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk
INC += \

View File

@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk
INC += \

View File

@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk
INC += \

View File

@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk
INC += \

View File

@ -1,6 +1,5 @@
DEPS_SUBMODULES += lib/lwip
include ../../../tools/top.mk
include ../../make.mk
# suppress warning caused by lwip

View File

@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk
INC += \

View File

@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk
INC += \

View File

@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk
ifeq ($(DISABLE_MJPEG),1)

View File

@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk
INC += \

View File

@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk
INC += \

View File

@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk
INC += \

View File

@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk
INC += \

View File

@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk
INC += \

View File

@ -1,4 +1,3 @@
include ../../../tools/top.mk
include ../../make.mk
FATFS_PATH = lib/fatfs/source

View File

@ -2,6 +2,35 @@
# Common make definition for all examples
# ---------------------------------------
#-------------- TOP and CURRENT_PATH ------------
# Set TOP to be the path to get from the current directory (where make was
# invoked) to the top of the tree. $(lastword $(MAKEFILE_LIST)) returns
# the name of this makefile relative to where make was invoked.
THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST))
# strip off /tools/top.mk to get for example ../../..
# and Set TOP to an absolute path
TOP = $(abspath $(subst make.mk,..,$(THIS_MAKEFILE)))
# Set CURRENT_PATH to the relative path from TOP to the current directory, ie examples/device/cdc_msc_freertos
CURRENT_PATH = $(subst $(TOP)/,,$(abspath .))
# Detect whether shell style is windows or not
# https://stackoverflow.com/questions/714100/os-detecting-makefile/52062069#52062069
ifeq '$(findstring ;,$(PATH))' ';'
# PATH contains semicolon - so we're definitely on Windows.
CMDEXE := 1
# makefile shell commands should use syntax for DOS CMD, not unix sh
# Unfortunately, SHELL may point to sh or bash, which can't accept DOS syntax.
# We can't just use sh, because while sh and/or bash shell may be available,
# many Windows environments won't have utilities like realpath used below, so...
# Force DOS command shell on Windows.
SHELL := cmd.exe
endif
# Build directory
BUILD := _build/$(BOARD)
@ -45,14 +74,10 @@ else
SRC_C += $(subst $(TOP)/,,$(wildcard $(TOP)/$(FAMILY_PATH)/*.c))
endif
#-------------- Cross Compiler ------------
# Can be set by board, default to ARM GCC
CROSS_COMPILE ?= arm-none-eabi-
# Allow for -Os to be changed by board makefiles in case -Os is not allowed
CFLAGS_OPTIMIZED ?= -Os
ifeq ($(CC),iccarm)
USE_IAR = 1
endif
@ -61,29 +86,28 @@ ifdef USE_IAR
AS = iasmarm
LD = ilinkarm
OBJCOPY = ielftool
SIZE = echo "size not available for IAR"
SIZE = size
else
CC = $(CROSS_COMPILE)gcc
CXX = $(CROSS_COMPILE)g++
AS = $(CC) -x assembler-with-cpp
LD = $(CC)
GDB = $(CROSS_COMPILE)gdb
OBJCOPY = $(CROSS_COMPILE)objcopy
SIZE = $(CROSS_COMPILE)size
endif
MKDIR = mkdir
ifeq ($(CMDEXE),1)
CP = copy
RM = del
MKDIR = mkdir
PYTHON = python
else
SED = sed
CP = cp
RM = rm
MKDIR = mkdir
PYTHON = python3
endif
@ -95,6 +119,9 @@ SRC_C += $(subst $(TOP)/,,$(wildcard $(TOP)/$(BOARD_PATH)/*.c))
INC += $(TOP)/$(FAMILY_PATH)
# Allow for -Os to be changed by board makefiles in case -Os is not allowed
CFLAGS_OPTIMIZED ?= -Os
# GCC Compiler Flags
GCC_CFLAGS += \
-ggdb \

View File

@ -112,7 +112,7 @@ OBJ_DIRS = $(sort $(dir $(OBJ)))
$(OBJ): | $(OBJ_DIRS)
$(OBJ_DIRS):
ifeq ($(CMDEXE),1)
@$(MKDIR) $(subst /,\,$@)
-@$(MKDIR) $(subst /,\,$@)
else
@$(MKDIR) -p $@
endif
@ -139,7 +139,21 @@ $(BUILD)/obj/%_asm.o: %.S
@echo AS $(notdir $@)
@$(AS) $(ASFLAGS) -c -o $@ $<
ifndef USE_IAR
ifdef USE_IAR
# IAR Compiler
$(BUILD)/$(PROJECT).bin: $(BUILD)/$(PROJECT).elf
@echo CREATE $@
@$(OBJCOPY) --silent --bin $^ $@
$(BUILD)/$(PROJECT).hex: $(BUILD)/$(PROJECT).elf
@echo CREATE $@
@$(OBJCOPY) --silent --ihex $^ $@
$(BUILD)/$(PROJECT).elf: $(OBJ)
@echo LINK $@
@$(LD) -o $@ $(IAR_LDFLAGS) $^
else
# GCC based compiler
$(BUILD)/$(PROJECT).bin: $(BUILD)/$(PROJECT).elf
@echo CREATE $@
@ -153,20 +167,6 @@ $(BUILD)/$(PROJECT).elf: $(OBJ)
@echo LINK $@
@$(LD) -o $@ $(LDFLAGS) $^ -Wl,--start-group $(LIBS) -Wl,--end-group
else
# IAR Compiler
$(BUILD)/$(PROJECT).bin: $(BUILD)/$(PROJECT).elf
@echo CREATE $@
@$(OBJCOPY) --silent --bin $^ $@
$(BUILD)/$(PROJECT).hex: $(BUILD)/$(PROJECT).elf
@echo CREATE $@
@$(OBJCOPY) --silent --ihex $^ $@
$(BUILD)/$(PROJECT).elf: $(OBJ)
@echo LINK $@
@$(LD) -o $@ $(IAR_LDFLAGS) $^
endif
# UF2 generation, iMXRT need to strip to text only before conversion
@ -265,7 +265,11 @@ debug-bmp: $(BUILD)/$(PROJECT).elf
# Create binary directory
$(BIN):
ifeq ($(CMDEXE),1)
@$(MKDIR) $(subst /,\,$@)
else
@$(MKDIR) -p $@
endif
# Copy binaries .elf, .bin, .hex, .uf2 to BIN for upload
# due to large size of combined artifacts, only uf2 is uploaded for now

View File

@ -165,7 +165,7 @@ void HardFault_Handler (void)
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
void assert_failed(const char* file, uint32_t line)
{
(void) file; (void) line;
/* USER CODE BEGIN 6 */

View File

@ -24,7 +24,7 @@ GCC_CFLAGS += \
-nostdlib -nostartfiles \
# suppress warning caused by vendor mcu driver
GCC_CFLAGS += -Wno-error=unused-parameter -Wno-error=cast-align -Wno-error=cast-qual
GCC_CFLAGS += -Wno-error=unused-parameter -Wno-error=cast-align
# IAR Flags
IAR_CFLAGS += --cpu cortex-m0
@ -42,7 +42,9 @@ SRC_C += \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_rcc.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_rcc_ex.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_gpio.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_uart.c
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_dma.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_uart.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_uart_ex.c
INC += \
$(TOP)/$(BOARD_PATH) \

View File

@ -303,9 +303,9 @@
* If expr is true, it returns no value.
* @retval None
*/
#define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__))
#define assert_param(expr) ((expr) ? (void)0U : assert_failed(__FILE__, __LINE__))
/* Exported functions ------------------------------------------------------- */
void assert_failed(uint8_t* file, uint32_t line);
void assert_failed(const char* file, uint32_t line);
#else
#define assert_param(expr) ((void)0U)
#endif /* USE_FULL_ASSERT */

View File

@ -151,7 +151,7 @@ void HardFault_Handler (void)
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(char *file, uint32_t line)
void assert_failed(const char *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,

View File

@ -362,9 +362,9 @@
* If expr is true, it returns no value.
* @retval None
*/
#define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__))
#define assert_param(expr) ((expr) ? (void)0U : assert_failed(__FILE__, __LINE__))
/* Exported functions ------------------------------------------------------- */
void assert_failed(uint8_t* file, uint32_t line);
void assert_failed(const char* file, uint32_t line);
#else
#define assert_param(expr) ((void)0U)
#endif /* USE_FULL_ASSERT */

View File

@ -42,6 +42,7 @@ SRC_C += \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_rcc.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_rcc_ex.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_uart.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_dma.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_gpio.c
INC += \

View File

@ -52,6 +52,7 @@ SRC_C += \
$(ST_CMSIS)/Source/Templates/system_stm32$(ST_FAMILY)xx.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_cortex.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_dma.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_rcc.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_rcc_ex.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_gpio.c \

View File

@ -43,6 +43,7 @@ SRC_C += \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_rcc.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_rcc_ex.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_uart.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_uart_ex.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_gpio.c
INC += \

View File

@ -37,7 +37,7 @@ GCC_CFLAGS += \
-nostdlib -nostartfiles
# suppress warning caused by vendor mcu driver
GCC_CFLAGS += -Wno-error=maybe-uninitialized -Wno-error=cast-align
GCC_CFLAGS += -Wno-error=maybe-uninitialized -Wno-error=cast-align -Wno-error=unused-parameter
# IAR Flags
IAR_CFLAGS += --cpu cortex-m7 --fpu VFPv5_D16
@ -52,10 +52,13 @@ SRC_C += \
$(ST_CMSIS)/Source/Templates/system_stm32$(ST_FAMILY)xx.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_cortex.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_dma.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_rcc.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_rcc_ex.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_gpio.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_uart.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_uart_ex.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_pwr.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_pwr_ex.c
INC += \

View File

@ -39,12 +39,14 @@ SRC_C += \
$(ST_CMSIS)/Source/Templates/system_stm32$(ST_FAMILY)xx.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_cortex.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_dma.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_rcc.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_rcc_ex.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_pwr.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_pwr_ex.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_gpio.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_uart.c
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_uart.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_uart_ex.c
INC += \
$(TOP)/lib/CMSIS_5/CMSIS/Core/Include \

View File

@ -1,4 +1,3 @@
include ../../../../tools/top.mk
include ../../make.mk
INC += \

View File

@ -1,4 +1,3 @@
include ../../../../tools/top.mk
include ../../make.mk
INC += \

View File

@ -1,6 +1,5 @@
DEPS_SUBMODULES += lib/lwip
include ../../../../tools/top.mk
include ../../make.mk
# suppress warning caused by lwip

View File

@ -2,6 +2,34 @@
# Common make definition for all examples
# ---------------------------------------
#-------------- TOP and CURRENT_PATH ------------
# Set TOP to be the path to get from the current directory (where make was
# invoked) to the top of the tree. $(lastword $(MAKEFILE_LIST)) returns
# the name of this makefile relative to where make was invoked.
THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST))
# strip off /tools/top.mk to get for example ../../..
# and Set TOP to an absolute path
TOP = $(abspath $(subst make.mk,../..,$(THIS_MAKEFILE)))
# Set CURRENT_PATH to the relative path from TOP to the current directory, ie examples/device/cdc_msc_freertos
CURRENT_PATH = $(subst $(TOP)/,,$(abspath .))
# Detect whether shell style is windows or not
# https://stackoverflow.com/questions/714100/os-detecting-makefile/52062069#52062069
ifeq '$(findstring ;,$(PATH))' ';'
# PATH contains semicolon - so we're definitely on Windows.
CMDEXE := 1
# makefile shell commands should use syntax for DOS CMD, not unix sh
# Unfortunately, SHELL may point to sh or bash, which can't accept DOS syntax.
# We can't just use sh, because while sh and/or bash shell may be available,
# many Windows environments won't have utilities like realpath used below, so...
# Force DOS command shell on Windows.
SHELL := cmd.exe
endif
# Build directory
BUILD := _build
PROJECT := $(notdir $(CURDIR))
@ -42,8 +70,6 @@ SANITIZER_FLAGS ?= -fsanitize=fuzzer \
CFLAGS += $(COVERAGE_FLAGS) $(SANITIZER_FLAGS)
#-------------- Source files and compiler flags --------------
INC += $(TOP)/test
# Compiler Flags

View File

@ -114,9 +114,14 @@ def build_example(example, board, make_option):
def build_size(example, board):
elf_file = 'examples/{}/_build/{}/*.elf'.format(example, board)
size_output = subprocess.run('size {}'.format(elf_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])
return (flash_size, sram_size)
size_cmd = 'make -j -C examples/{} BOARD={} size'.format(example, board)
size_output = subprocess.run(size_cmd, shell=True, stdout=subprocess.PIPE).stdout.decode("utf-8").splitlines()
for i, l in enumerate(size_output):
text_title = 'text data bss dec'
if text_title in l:
size_list = size_output[i+1].split('\t')
flash_size = int(size_list[0])
sram_size = int(size_list[1]) + int(size_list[2])
return (flash_size, sram_size)
return (0, 0)

View File

@ -1,45 +0,0 @@
ifneq ($(lastword a b),b)
$(error This Makefile requires make 3.81 or newer)
endif
# Detect whether shell style is windows or not
# https://stackoverflow.com/questions/714100/os-detecting-makefile/52062069#52062069
ifeq '$(findstring ;,$(PATH))' ';'
# PATH contains semicolon - so we're definitely on Windows.
CMDEXE := 1
# makefile shell commands should use syntax for DOS CMD, not unix sh
# Unfortunately, SHELL may point to sh or bash, which can't accept DOS syntax.
# We can't just use sh, because while sh and/or bash shell may be available,
# many Windows environments won't have utilities like realpath used below, so...
# Force DOS command shell on Windows.
SHELL := cmd.exe
endif
#$(info top.mk: SHELL=$(SHELL))
#$(info top.mk: CMDEXE=$(CMDEXE))
# Set TOP to be the path to get from the current directory (where make was
# invoked) to the top of the tree. $(lastword $(MAKEFILE_LIST)) returns
# the name of this makefile relative to where make was invoked.
THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST))
# strip off /tools/top.mk to get for example ../../..
TOP := $(patsubst %/tools/top.mk,%,$(THIS_MAKEFILE))
#$(info top.mk: Initial TOP=$(TOP))
# Set TOP to an absolute path, for example /tinyUSB (from ../../..)
ifeq ($(CMDEXE),1)
TOP := $(subst \,/,$(shell for %%i in ( $(TOP) ) do echo %%~fi))
else
TOP := $(shell realpath $(TOP))
endif
#$(info top.mk: Top directory is $(TOP))
# Set CURRENT_PATH to the relative path from TOP to the current directory, ie examples/device/cdc_msc_freertos
ifeq ($(CMDEXE),1)
CURRENT_PATH := $(subst $(TOP)/,,$(subst \,/,$(shell echo %CD%)))
else
CURRENT_PATH := $(shell realpath --relative-to=$(TOP) `pwd`)
endif
#$(info top.mk: Path from top is $(CURRENT_PATH))