-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
Description
Some makefiles use variables with their immediate value before they get the final one.
It's not problematic for build flags but for variables containing files/path.
The root of the problem is that the makefiles do not follow a pattern of defining all variables first/including sub makefiles, and then only after define the rules using the variables as file target or file dependency.
This issue will be the central one to reference sub pull requests to fix this uses.
Debugging
The problem can be seen by using $(info debug VARIABLE $(VARIABLE)) before usage.
TODO list:
- USEMODULE USEPKG FEATURES_REQUIRED in board/cpu Makefile.include
- Use of
PKG_BUILDDIR- ccn-lite
- relic
- ... ?
- BASELIBS in Makefile.include
board/cpu Makefile.include
Some boards and cpus Makefile.include have different behaviors depending on the modules.
git grep -e USEPKG -e USEMODULE -e FEATURES boards/ cpu/ | grep Makefile.include | grep -e ifeq -e ifneq
boards/common/nrf52xxxdk/Makefile.include:ifneq (,$(filter nordic_softdevice_ble,$(USEPKG)))
boards/native/Makefile.include:ifneq (,$(filter netdev_default gnrc_netdev_default,$(USEMODULE)))
cpu/esp8266/Makefile.include:ifneq (, $(filter pthread, $(USEMODULE)))
cpu/esp8266/Makefile.include:ifneq (, $(filter esp_sw_timer, $(USEMODULE)))
cpu/esp8266/Makefile.include:ifneq (, $(filter esp_sdk, $(USEMODULE)))
cpu/esp8266/Makefile.include:ifneq (, $(filter esp_gdbstub, $(USEMODULE)))
cpu/esp8266/Makefile.include:ifneq (, $(filter esp_gdb, $(USEMODULE)))
cpu/esp8266/Makefile.include:ifneq (, $(filter esp_spiffs, $(USEMODULE)))
cpu/esp8266/Makefile.include:ifneq (, $(filter esp_sdk, $(USEMODULE)))
cpu/esp8266/Makefile.include: ifneq (, $(filter esp_now, $(USEMODULE)))
cpu/stm32_common/Makefile.include:ifneq (,$(filter periph_flashpage periph_eeprom,$(FEATURES_REQUIRED)))
However, modules dependencies are only resolved after including these files.
Some even include Makefile.dep to fix issues (other for no reason)
git grep Makefile.dep boards | grep 'Makefile.include:'
boards/common/arduino-atmega/Makefile.include:include $(RIOTBOARD)/common/arduino-atmega/Makefile.dep
boards/common/arduino-mkr/Makefile.include:include $(RIOTBOARD)/$(BOARD)/Makefile.dep
boards/common/nrf52xxxdk/Makefile.include:include $(RIOTBOARD)/$(BOARD)/Makefile.dep
boards/common/nrf52xxxdk/Makefile.include:include $(RIOTBOARD)/$(BOARD)/Makefile.dep
boards/feather-m0/Makefile.include:include $(RIOTBOARD)/$(BOARD)/Makefile.dep
boards/sensebox_samd21/Makefile.include:include $(RIOTBOARD)/$(BOARD)/Makefile.dep
boards/sodaq-explorer/Makefile.include:include $(RIOTBOARD)/$(BOARD)/Makefile.dep
boards/sodaq-one/Makefile.include:include $(RIOTBOARD)/$(BOARD)/Makefile.dep
Dependencies need to be processed before including any other Makefile.include.
Also referenced in #9811
pkg/ PKG_BUILDDIR
Some packages makefile use $(PKG_BUILDDIR) with its immediate value when defining targets before it is defined by including pkg/pkg.mk.
It is mitigated because then they are treated as non file targets, and because the command repeats the variable and does not use the automatic make variables like $@. #8509 (comment)
Done
Makefile.include
In
Makefile.include, all uses of$(BASELIBS), except when defining_LINK, are using the immediate > value of$(BASELIBS)which does not have its final value as this is done by includingmodules.inc.mk200 lines below.All the uses are currently solved by hidden "tricks"
$(ELFFILE): $(BASELIBS)which works because there is a$(ELFFILE): FORCErule, so it will be rebuilt anyway, and_LINKis using the deferred value ofBASELIBS.link: $(BASELIBS)when in theRIOTNOLINKcase, where BASELIBS is missing$(USEPKG:%=$(BINDIR)/%.a)files, but as$(BINDIR)/$(APPLICATION_MODULE).ahas a dependency to$(USEPKG:%=$(BINDIR)/%.a)they are still build anyway.- The
cleanbefore building trick for parallel execution is using$(BASELIBS)also without the$(USEPKG:%=$(BINDIR)/%.a)files. But as there is theRIOTPKG/%/Makefile.includetarget also depending onclean, the packages are built afterclean.