diff options
| author | hathach <[email protected]> | 2023-03-06 13:25:56 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2023-03-06 13:25:56 +0700 |
| commit | e62d1a03acfa2a3b8afa0568690fdcad5495c260 (patch) | |
| tree | fbd26e5f87db05cf88e9790ab6cb5d3cb898bd81 | |
| parent | b6404d143ed218ad13dce62bd16b9a21de3bba79 (diff) | |
integrate top.mk into make.mk
33 files changed, 97 insertions, 102 deletions
diff --git a/examples/device/audio_4_channel_mic/Makefile b/examples/device/audio_4_channel_mic/Makefile index 5a455078e..2a3d854fb 100644 --- a/examples/device/audio_4_channel_mic/Makefile +++ b/examples/device/audio_4_channel_mic/Makefile @@ -1,4 +1,3 @@ -include ../../../tools/top.mk include ../../make.mk INC += \ diff --git a/examples/device/audio_test/Makefile b/examples/device/audio_test/Makefile index 5a455078e..2a3d854fb 100644 --- a/examples/device/audio_test/Makefile +++ b/examples/device/audio_test/Makefile @@ -1,4 +1,3 @@ -include ../../../tools/top.mk include ../../make.mk INC += \ diff --git a/examples/device/audio_test_multi_rate/Makefile b/examples/device/audio_test_multi_rate/Makefile index 5a455078e..2a3d854fb 100644 --- a/examples/device/audio_test_multi_rate/Makefile +++ b/examples/device/audio_test_multi_rate/Makefile @@ -1,4 +1,3 @@ -include ../../../tools/top.mk include ../../make.mk INC += \ diff --git a/examples/device/board_test/Makefile b/examples/device/board_test/Makefile index 5a455078e..2a3d854fb 100644 --- a/examples/device/board_test/Makefile +++ b/examples/device/board_test/Makefile @@ -1,4 +1,3 @@ -include ../../../tools/top.mk include ../../make.mk INC += \ diff --git a/examples/device/cdc_dual_ports/Makefile b/examples/device/cdc_dual_ports/Makefile index 5a455078e..2a3d854fb 100644 --- a/examples/device/cdc_dual_ports/Makefile +++ b/examples/device/cdc_dual_ports/Makefile @@ -1,4 +1,3 @@ -include ../../../tools/top.mk include ../../make.mk INC += \ diff --git a/examples/device/cdc_msc/Makefile b/examples/device/cdc_msc/Makefile index 69b633fea..da088ea6b 100644 --- a/examples/device/cdc_msc/Makefile +++ b/examples/device/cdc_msc/Makefile @@ -1,4 +1,3 @@ -include ../../../tools/top.mk include ../../make.mk INC += \ diff --git a/examples/device/cdc_msc_freertos/Makefile b/examples/device/cdc_msc_freertos/Makefile index 4ee816880..e2bbc2268 100644 --- a/examples/device/cdc_msc_freertos/Makefile +++ b/examples/device/cdc_msc_freertos/Makefile @@ -1,6 +1,5 @@ DEPS_SUBMODULES += lib/FreeRTOS-Kernel -include ../../../tools/top.mk include ../../make.mk FREERTOS_SRC = lib/FreeRTOS-Kernel diff --git a/examples/device/dfu/Makefile b/examples/device/dfu/Makefile index 5148ed55a..b3f2cc588 100644 --- a/examples/device/dfu/Makefile +++ b/examples/device/dfu/Makefile @@ -1,4 +1,3 @@ -include ../../../tools/top.mk include ../../make.mk INC += \ diff --git a/examples/device/dfu_runtime/Makefile b/examples/device/dfu_runtime/Makefile index 69b633fea..da088ea6b 100644 --- a/examples/device/dfu_runtime/Makefile +++ b/examples/device/dfu_runtime/Makefile @@ -1,4 +1,3 @@ -include ../../../tools/top.mk include ../../make.mk INC += \ diff --git a/examples/device/dynamic_configuration/Makefile b/examples/device/dynamic_configuration/Makefile index 69b633fea..da088ea6b 100644 --- a/examples/device/dynamic_configuration/Makefile +++ b/examples/device/dynamic_configuration/Makefile @@ -1,4 +1,3 @@ -include ../../../tools/top.mk include ../../make.mk INC += \ diff --git a/examples/device/hid_boot_interface/Makefile b/examples/device/hid_boot_interface/Makefile index c6a9c5b21..d58a539e8 100644 --- a/examples/device/hid_boot_interface/Makefile +++ b/examples/device/hid_boot_interface/Makefile @@ -1,4 +1,3 @@ -include ../../../tools/top.mk include ../../make.mk INC += \ diff --git a/examples/device/hid_composite/Makefile b/examples/device/hid_composite/Makefile index 69b633fea..da088ea6b 100644 --- a/examples/device/hid_composite/Makefile +++ b/examples/device/hid_composite/Makefile @@ -1,4 +1,3 @@ -include ../../../tools/top.mk include ../../make.mk INC += \ diff --git a/examples/device/hid_composite_freertos/Makefile b/examples/device/hid_composite_freertos/Makefile index a354a90b6..099a43893 100644 --- a/examples/device/hid_composite_freertos/Makefile +++ b/examples/device/hid_composite_freertos/Makefile @@ -1,6 +1,5 @@ DEPS_SUBMODULES += lib/FreeRTOS-Kernel -include ../../../tools/top.mk include ../../make.mk FREERTOS_SRC = lib/FreeRTOS-Kernel diff --git a/examples/device/hid_generic_inout/Makefile b/examples/device/hid_generic_inout/Makefile index 69b633fea..da088ea6b 100644 --- a/examples/device/hid_generic_inout/Makefile +++ b/examples/device/hid_generic_inout/Makefile @@ -1,4 +1,3 @@ -include ../../../tools/top.mk include ../../make.mk INC += \ diff --git a/examples/device/hid_multiple_interface/Makefile b/examples/device/hid_multiple_interface/Makefile index 69b633fea..da088ea6b 100644 --- a/examples/device/hid_multiple_interface/Makefile +++ b/examples/device/hid_multiple_interface/Makefile @@ -1,4 +1,3 @@ -include ../../../tools/top.mk include ../../make.mk INC += \ diff --git a/examples/device/midi_test/Makefile b/examples/device/midi_test/Makefile index 5a455078e..2a3d854fb 100644 --- a/examples/device/midi_test/Makefile +++ b/examples/device/midi_test/Makefile @@ -1,4 +1,3 @@ -include ../../../tools/top.mk include ../../make.mk INC += \ diff --git a/examples/device/msc_dual_lun/Makefile b/examples/device/msc_dual_lun/Makefile index 5a455078e..2a3d854fb 100644 --- a/examples/device/msc_dual_lun/Makefile +++ b/examples/device/msc_dual_lun/Makefile @@ -1,4 +1,3 @@ -include ../../../tools/top.mk include ../../make.mk INC += \ diff --git a/examples/device/net_lwip_webserver/Makefile b/examples/device/net_lwip_webserver/Makefile index 55bd820bd..bc2914b36 100644 --- a/examples/device/net_lwip_webserver/Makefile +++ b/examples/device/net_lwip_webserver/Makefile @@ -1,6 +1,5 @@ DEPS_SUBMODULES += lib/lwip -include ../../../tools/top.mk include ../../make.mk # suppress warning caused by lwip diff --git a/examples/device/uac2_headset/Makefile b/examples/device/uac2_headset/Makefile index 5a455078e..2a3d854fb 100644 --- a/examples/device/uac2_headset/Makefile +++ b/examples/device/uac2_headset/Makefile @@ -1,4 +1,3 @@ -include ../../../tools/top.mk include ../../make.mk INC += \ diff --git a/examples/device/usbtmc/Makefile b/examples/device/usbtmc/Makefile index 69b633fea..da088ea6b 100644 --- a/examples/device/usbtmc/Makefile +++ b/examples/device/usbtmc/Makefile @@ -1,4 +1,3 @@ -include ../../../tools/top.mk include ../../make.mk INC += \ diff --git a/examples/device/video_capture/Makefile b/examples/device/video_capture/Makefile index fda66bcc1..90d174c32 100644 --- a/examples/device/video_capture/Makefile +++ b/examples/device/video_capture/Makefile @@ -1,4 +1,3 @@ -include ../../../tools/top.mk include ../../make.mk ifeq ($(DISABLE_MJPEG),1) diff --git a/examples/device/webusb_serial/Makefile b/examples/device/webusb_serial/Makefile index 5a455078e..2a3d854fb 100644 --- a/examples/device/webusb_serial/Makefile +++ b/examples/device/webusb_serial/Makefile @@ -1,4 +1,3 @@ -include ../../../tools/top.mk include ../../make.mk INC += \ diff --git a/examples/dual/host_hid_to_device_cdc/Makefile b/examples/dual/host_hid_to_device_cdc/Makefile index 3fe9b0888..95c88e7e8 100644 --- a/examples/dual/host_hid_to_device_cdc/Makefile +++ b/examples/dual/host_hid_to_device_cdc/Makefile @@ -1,4 +1,3 @@ -include ../../../tools/top.mk include ../../make.mk INC += \ diff --git a/examples/host/bare_api/Makefile b/examples/host/bare_api/Makefile index 84555a889..058307c40 100644 --- a/examples/host/bare_api/Makefile +++ b/examples/host/bare_api/Makefile @@ -1,4 +1,3 @@ -include ../../../tools/top.mk include ../../make.mk INC += \ diff --git a/examples/host/cdc_msc_hid/Makefile b/examples/host/cdc_msc_hid/Makefile index 9adccfa3a..7c16b39d3 100644 --- a/examples/host/cdc_msc_hid/Makefile +++ b/examples/host/cdc_msc_hid/Makefile @@ -1,4 +1,3 @@ -include ../../../tools/top.mk include ../../make.mk INC += \ diff --git a/examples/host/hid_controller/Makefile b/examples/host/hid_controller/Makefile index e7fbd741f..cda2977bc 100644 --- a/examples/host/hid_controller/Makefile +++ b/examples/host/hid_controller/Makefile @@ -1,4 +1,3 @@ -include ../../../tools/top.mk include ../../make.mk INC += \ diff --git a/examples/host/msc_file_explorer/Makefile b/examples/host/msc_file_explorer/Makefile index de2f9c01c..1fda72b18 100644 --- a/examples/host/msc_file_explorer/Makefile +++ b/examples/host/msc_file_explorer/Makefile @@ -1,4 +1,3 @@ -include ../../../tools/top.mk include ../../make.mk FATFS_PATH = lib/fatfs/source diff --git a/examples/make.mk b/examples/make.mk index e02d226b6..d91263db9 100644 --- a/examples/make.mk +++ b/examples/make.mk @@ -2,57 +2,38 @@ # Common make definition for all examples # --------------------------------------- -# Build directory -BUILD := _build/$(BOARD) - -PROJECT := $(notdir $(CURDIR)) -BIN := $(TOP)/_bin/$(BOARD)/$(notdir $(CURDIR)) - -# Handy check parameter function -check_defined = \ - $(strip $(foreach 1,$1, \ - $(call __check_defined,$1,$(strip $(value 2))))) -__check_defined = \ - $(if $(value $1),, \ - $(error Undefined make flag: $1$(if $2, ($2)))) +#-------------- TOP and CURRENT_PATH ------------ -#-------------- Select the board to build for. ------------ +# 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)) -# Board without family -ifneq ($(wildcard $(TOP)/hw/bsp/$(BOARD)/board.mk),) -BOARD_PATH := hw/bsp/$(BOARD) -FAMILY := -endif - -# Board within family -ifeq ($(BOARD_PATH),) - BOARD_PATH := $(subst $(TOP)/,,$(wildcard $(TOP)/hw/bsp/*/boards/$(BOARD))) - FAMILY := $(word 3, $(subst /, ,$(BOARD_PATH))) - FAMILY_PATH = hw/bsp/$(FAMILY) -endif +# strip off /tools/top.mk to get for example ../../.. +# and Set TOP to an absolute path +TOP = $(abspath $(subst make.mk,..,$(THIS_MAKEFILE))) -ifeq ($(BOARD_PATH),) - $(info You must provide a BOARD parameter with 'BOARD=') - $(error Invalid BOARD specified) -endif +# Set CURRENT_PATH to the relative path from TOP to the current directory, ie examples/device/cdc_msc_freertos +CURRENT_PATH = $(subst $(TOP)/,,$(abspath .)) -ifeq ($(FAMILY),) - include $(TOP)/hw/bsp/$(BOARD)/board.mk -else - # Include Family and Board specific defs - include $(TOP)/$(FAMILY_PATH)/family.mk +# 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 - SRC_C += $(subst $(TOP)/,,$(wildcard $(TOP)/$(FAMILY_PATH)/*.c)) +# 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 - #-------------- 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 @@ -68,7 +49,7 @@ else CXX = $(CROSS_COMPILE)g++ AS = $(CC) -x assembler-with-cpp LD = $(CC) - + GDB = $(CROSS_COMPILE)gdb OBJCOPY = $(CROSS_COMPILE)objcopy SIZE = $(CROSS_COMPILE)size @@ -86,6 +67,50 @@ else PYTHON = python3 endif + +# Build directory +BUILD := _build/$(BOARD) + +PROJECT := $(notdir $(CURDIR)) +BIN := $(TOP)/_bin/$(BOARD)/$(notdir $(CURDIR)) + +# Handy check parameter function +check_defined = \ + $(strip $(foreach 1,$1, \ + $(call __check_defined,$1,$(strip $(value 2))))) +__check_defined = \ + $(if $(value $1),, \ + $(error Undefined make flag: $1$(if $2, ($2)))) + +#-------------- Select the board to build for. ------------ + +# Board without family +ifneq ($(wildcard $(TOP)/hw/bsp/$(BOARD)/board.mk),) +BOARD_PATH := hw/bsp/$(BOARD) +FAMILY := +endif + +# Board within family +ifeq ($(BOARD_PATH),) + BOARD_PATH := $(subst $(TOP)/,,$(wildcard $(TOP)/hw/bsp/*/boards/$(BOARD))) + FAMILY := $(word 3, $(subst /, ,$(BOARD_PATH))) + FAMILY_PATH = hw/bsp/$(FAMILY) +endif + +ifeq ($(BOARD_PATH),) + $(info You must provide a BOARD parameter with 'BOARD=') + $(error Invalid BOARD specified) +endif + +ifeq ($(FAMILY),) + include $(TOP)/hw/bsp/$(BOARD)/board.mk +else + # Include Family and Board specific defs + include $(TOP)/$(FAMILY_PATH)/family.mk + + SRC_C += $(subst $(TOP)/,,$(wildcard $(TOP)/$(FAMILY_PATH)/*.c)) +endif + #-------------- Source files and compiler flags -------------- # Include all source C in family & board folder @@ -94,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 \ diff --git a/test/fuzz/device/cdc/Makefile b/test/fuzz/device/cdc/Makefile index ee51936b5..7071df057 100644 --- a/test/fuzz/device/cdc/Makefile +++ b/test/fuzz/device/cdc/Makefile @@ -1,4 +1,3 @@ -include ../../../../tools/top.mk include ../../make.mk INC += \ diff --git a/test/fuzz/device/msc/Makefile b/test/fuzz/device/msc/Makefile index ee51936b5..7071df057 100644 --- a/test/fuzz/device/msc/Makefile +++ b/test/fuzz/device/msc/Makefile @@ -1,4 +1,3 @@ -include ../../../../tools/top.mk include ../../make.mk INC += \ diff --git a/test/fuzz/device/net/Makefile b/test/fuzz/device/net/Makefile index 22241fcdc..4e99604ad 100644 --- a/test/fuzz/device/net/Makefile +++ b/test/fuzz/device/net/Makefile @@ -1,6 +1,5 @@ DEPS_SUBMODULES += lib/lwip -include ../../../../tools/top.mk include ../../make.mk # suppress warning caused by lwip diff --git a/test/fuzz/make.mk b/test/fuzz/make.mk index e7c5518e7..934819665 100644 --- a/test/fuzz/make.mk +++ b/test/fuzz/make.mk @@ -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 diff --git a/tools/top.mk b/tools/top.mk deleted file mode 100644 index fdae6337c..000000000 --- a/tools/top.mk +++ /dev/null @@ -1,29 +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 - -# 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 /tools/top.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 .)) |
