Skip to content

Buildsystem: Migrate Boards and CPU using Common Code to USEMODULE #21331

@crasbe

Description

@crasbe

As discussed in #21298 and #21299, boards and cpus use a rather convoluted way of using common code in the boards/common and cpu/xxx_common folders:

The Makefile usually includes a statement to include the directories:

ifneq (,$(filter boards_common_adafruit-nrf52-bootloader,$(USEMODULE)))
# add the adafruit-nrf52-bootloader directory to the build
DIRS += $(RIOTBOARD)/common/adafruit-nrf52-bootloader
endif

The Makefile.{include, dep, features} has to have dedicated include commands:

# Include the common definitions for the Adafruit nRF52 Bootloader
include $(RIOTBOARD)/common/adafruit-nrf52-bootloader/Makefile.include

The USEMODULE for the common board is not defined in the boards/xxx/Makefile.dep as you would expect but in the boards/common/yyy/Makefile.dep:

# make sure the bootloader module is used for reset to work
USEMODULE += boards_common_adafruit-nrf52-bootloader




Since this is rather ugly, PR #21327 introduced Makefiles in the boards/ folder that work similar to the way the sys/Makefile*s work: It checks if the common code USEMODULE is set and automagically includes the necessary folders and directories.

Instead of setting all the things discussed previously, a board now only has to set the USEMODULE in the boards/xxx/Makefile.dep and no additional incldues or DIR += commands.

USEMODULE += boards_common_adafruit-nrf52-bootloader

The first common code that got adapted to the new style was the adafruit-nrf52-bootloader in #21327, but there is still a lot of potential:

RIOT$ grep -Rwh . -e "DIRS =" | grep -i common | sort -u
DIRS = $(ATMEGA_COMMON)
DIRS = $(RIOTBOARD)/common/arduino-atmega
DIRS = $(RIOTBOARD)/common/arduino-due
DIRS = $(RIOTBOARD)/common/arduino-mkr
DIRS = $(RIOTBOARD)/common/arduino-zero
DIRS = $(RIOTBOARD)/common/atmega
DIRS = $(RIOTBOARD)/common/atxmega
DIRS = $(RIOTBOARD)/common/blxxxpill
DIRS = $(RIOTBOARD)/common/e104-bt50xxa-tb
DIRS = $(RIOTBOARD)/common/esp32
DIRS = $(RIOTBOARD)/common/esp32c3
DIRS = $(RIOTBOARD)/common/esp32s2
DIRS = $(RIOTBOARD)/common/esp32s3
DIRS = $(RIOTBOARD)/common/esp32x
DIRS = $(RIOTBOARD)/common/esp8266
DIRS = $(RIOTBOARD)/common/iotlab
DIRS = $(RIOTBOARD)/common/kw41z
DIRS = $(RIOTBOARD)/common/msb-430
DIRS = $(RIOTBOARD)/common/nrf51
DIRS = $(RIOTBOARD)/common/nrf52xxxdk
DIRS = $(RIOTBOARD)/common/nucleo
DIRS = $(RIOTBOARD)/common/particle-mesh
DIRS = $(RIOTBOARD)/common/remote
DIRS = $(RIOTBOARD)/common/samdx1-arduino-bootloader
DIRS = $(RIOTBOARD)/common/saml1x
DIRS = $(RIOTBOARD)/common/silabs
DIRS = $(RIOTBOARD)/common/weact-f4x1cx
DIRS = $(RIOTCPU)/arm7_common
DIRS = $(RIOTCPU)/arm7_common periph
DIRS = $(RIOTCPU)/atmega_common/
DIRS = $(RIOTCPU)/cortexm_common periph
DIRS = $(RIOTCPU)/cortexm_common periph stmclk vectors
DIRS = $(RIOTCPU)/riscv_common periph vendor
DIRS = periph $(RIOTCPU)/avr8_common/
DIRS = periph $(RIOTCPU)/cortexm_common
DIRS = periph $(RIOTCPU)/cortexm_common $(RIOTCPU)/cc26xx_cc13xx
DIRS = periph $(RIOTCPU)/cortexm_common $(RIOTCPU)/nrf5x_common
DIRS = periph $(RIOTCPU)/cortexm_common $(RIOTCPU)/nrf5x_common vectors
DIRS = periph $(RIOTCPU)/cortexm_common $(RIOTCPU)/sam0_common
DIRS = periph $(RIOTCPU)/cortexm_common $(RIOTCPU)/sam0_common vectors
DIRS = periph $(RIOTCPU)/cortexm_common $(RIOTCPU)/sam_common
DIRS = periph $(RIOTCPU)/cortexm_common vendor
RIOT$ grep -Rwh . -e "DIRS +=" | grep -i common | sort -u
  DIRS += $(RIOTBOARD)/common/adafruit-nrf52-bootloader
  DIRS += $(RIOTBOARD)/common/microbit
  DIRS += $(RIOTBOARD)/common/samdx1-arduino-bootloader
  DIRS += common
  DIRS += net/application_layer/cord/common
<div class="line">DIRS += $(RIOTBOARD)/common/myCommonFolder</div>
DIRS += $(RIOTBOARD)/common/arduino-zero
DIRS += $(RIOTBOARD)/common/init
DIRS += $(RIOTBOARD)/common/myCommonFolder
DIRS += $(RIOTBOARD)/common/qn908x
DIRS += $(RIOTBOARD)/common/remote
DIRS += $(RIOTBOARD)/common/samdx1-arduino-bootloader
DIRS += $(RIOTBOARD)/common/slwstk6000b
DIRS += $(RIOTBOARD)/common/sodaq
DIRS += $(RIOTCPU)/cortexm_common
DIRS += $(RIOTCPU)/esp_common
DIRS += periph $(RIOTCPU)/riscv_common
DIRS += src/common

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: boardsArea: Board portsArea: build systemArea: Build systemArea: cpuArea: CPU/MCU portsCommunity: help wantedThe contributors require help from other members of the communityType: cleanupThe issue proposes a clean-up / The PR cleans-up parts of the codebase / documentationType: trackingThe issue tracks and organizes the sub-tasks of a larger effort

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions