Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Trying to remove recursive makefiles #7670

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
db1c452
example/saul: rename application as their already is a 'saul' module
cladmi Oct 17, 2017
32ec1d0
cpu/native/Makefile: only build vfs is necessary
cladmi Oct 17, 2017
513d580
sys/random/Makefile: Fix 'DIRS' setting relative to tinymt32
cladmi Oct 17, 2017
83100d8
sys: Makefile.modules: Define MODULE_DIR_$(module) vars
cladmi Sep 5, 2017
a2e3d0a
sys: Use Makefile.modules in sys Makefile
cladmi Sep 5, 2017
9a4e6f6
Makefile.base: create a per module ..nothing target
cladmi Oct 12, 2017
aa1a5f8
Makefile.base: Group 'DIRS' management at the end
cladmi Oct 2, 2017
a7ee17a
Makefile.base: use current module directory in source path
cladmi Oct 2, 2017
3fd0583
Makefile.base: undefine 'local' variables
cladmi Oct 4, 2017
ed76b6a
Makefile.base: use defined XXXFLAGS_module_name
cladmi Oct 2, 2017
54f61d7
VERIFY ME IF MISSING OTHER FILES! Modules Makefile: set FLAGS specifi…
cladmi Oct 2, 2017
7a8ca42
MAGIC HERE SEE COMMENTS: Makefile.base: add support for non recursive…
cladmi Oct 2, 2017
fe32082
sys/Makefile: build all sys modules with nonrecursive makefiles
cladmi Oct 2, 2017
b096ee1
drivers: Makefile.modules: Define MODULE_DIR_$(module) vars
cladmi Oct 4, 2017
e54b05c
drivers: use all Makefile.modules in drivers Makefile
cladmi Oct 4, 2017
9f704b6
drivers/Makefile: build all drivers modules with nonrecursive makefiles
cladmi Oct 4, 2017
b42911b
boards/Makefile.modules: add MODULE_DIR for each boards module
cladmi Oct 12, 2017
544aeb1
makefiles/applications.inc.mk: build 'boards' directory
cladmi Oct 12, 2017
66358f1
boards: use Makefile.modules in Makefile
cladmi Oct 12, 2017
be0affe
boards/Makefile: build all board/common modules with nonrecursive mak…
cladmi Oct 12, 2017
911bfa2
cpu: prefix all common modules by CPUCOMMON_ name
cladmi Oct 12, 2017
d8ea116
cpu/Makefile.modules: Define MODULE_DIR_$(module) vars
cladmi Oct 17, 2017
bf4d8d8
makefiles/applications.inc.mk: build 'cpu' directory
cladmi Oct 12, 2017
f57cd36
cpu: use Makefile.modules in Makefile
cladmi Oct 12, 2017
4df093f
boards/Makefile: do not build empty module for nothing
cladmi Oct 12, 2017
0d8c6d8
Makefile.base: set MODULE as immediate variable
cladmi Oct 17, 2017
1788f86
core/Makefile.modules: add MODULE_DIR for core module
cladmi Oct 17, 2017
60e1647
FIXUP MAKEFILE.BASE: CFLAGS_$(MODULE) for LTO objects
cladmi Oct 23, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 89 additions & 34 deletions Makefile.base
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,30 @@ ifeq (, $(__RIOTBUILD_FLAG))
$(error You cannot build a module on its own. Use "make" in your application's directory instead.)
endif

unexport DIRS
DIRS := $(sort $(abspath ${DIRS}))

MODULE ?= $(shell basename $(CURDIR))
ifneq (,$(NONRECURSIVE))
# This makefile should be included before including other makefiles !
# Or you must define MODULE_DIR to the realpath of your module
# Including Makefile should be the penultimate included one
INCLUDING_MAKEFILE := $(shell echo $(MAKEFILE_LIST) | awk '{print $$(NF-1)}')
MODULE_DIR ?= $(realpath $(dir $(INCLUDING_MAKEFILE)))
endif

.PHONY: all ${DIRS:%=ALL--%} ${DIRS:%=CLEAN--%}
MODULE_DIR ?= $(CURDIR)
MODULE ?= $(shell basename $(MODULE_DIR))

all: $(BINDIR)/$(MODULE).a ..nothing
# Use immediate variables for D and MODULE as they are undefined at the end
MODULE := $(MODULE)
D := $(MODULE_DIR)
# D is for prepending the module directory to files path when importing

..nothing:
@:
.PHONY: all

clean:: ${DIRS:%=CLEAN--%}
all: $(BINDIR)/$(MODULE).a

${DIRS:%=ALL--%}:
$(QQ)"$(MAKE)" -C ${@:ALL--%=%}

${DIRS:%=CLEAN--%}:
$(QQ)"$(MAKE)" -C ${@:CLEAN--%=%} clean
# dir_wildcard: Same as 'wildcard' but for given directory
# call dir_wildcard,PATTERN,DIRECTORY
# The 'DIRECTORY' part is not included in returned paths
dir_wildcard = $(patsubst $(2)/%,%,$(wildcard $(2)/$(1)))

## submodules
ifeq (1, $(SUBMODULES))
Expand All @@ -35,21 +40,22 @@ ifeq (1, $(SUBMODULES))

# don't fail if a selected *.c file does not exist
ifeq (1, $(SUBMODULES_NOFORCE))
SRC := $(filter $(SRC), $(wildcard *.c))
SRC := $(filter $(SRC), $(call dir_wildcard,*.c,$(D)))
endif
endif

ifeq ($(strip $(SRC))$(NO_AUTO_SRC),)
SRC := $(filter-out $(SRC_NOLTO), $(wildcard *.c))
SRC := $(call dir_wildcard,*.c,$(D))
SRC := $(filter-out $(SRC_NOLTO), $(SRC))
endif
ifeq ($(strip $(SRCXX))$(NO_AUTO_SRC),)
SRCXX := $(wildcard *.cpp)
SRCXX := $(call dir_wildcard,*.cpp,$(D))
endif
ifeq ($(strip $(ASMSRC))$(NO_AUTO_SRC),)
ASMSRC := $(wildcard *.s)
ASMSRC := $(call dir_wildcard,*.s,$(D))
endif
ifeq ($(strip $(ASSMSRC))$(NO_AUTO_SRC),)
ASSMSRC := $(wildcard *.S)
ASSMSRC := $(call dir_wildcard,*.S,$(D))
endif

OBJC_LTO := $(SRC:%.c=$(BINDIR)/$(MODULE)/%.o)
Expand All @@ -62,39 +68,88 @@ ASSMOBJ := $(ASSMSRC:%.S=$(BINDIR)/$(MODULE)/%.o)
OBJ := $(OBJC) $(OBJCXX) $(ASMOBJ) $(ASSMOBJ)
DEP := $(OBJC:.o=.d) $(OBJCXX:.o=.d) $(ASSMOBJ:.o=.d)

$(BINDIR)/$(MODULE)/:
$(Q)mkdir -p $@
$(BINDIR)/$(MODULE).a: $(OBJ)
$(Q)$(AR) $(ARFLAGS) $@ $?

$(BINDIR)/$(MODULE).a $(OBJ): | $(BINDIR)/$(MODULE)/

$(BINDIR)/$(MODULE).a: $(OBJ) | ${DIRS:%=ALL--%}
$(Q)$(AR) $(ARFLAGS) $@ $?
$(BINDIR)/$(MODULE)/:
$(Q)mkdir -p $@

CXXFLAGS = $(filter-out $(CXXUWFLAGS), $(CFLAGS)) $(CXXEXFLAGS)
CCASFLAGS = $(filter-out $(CCASUWFLAGS), $(CFLAGS)) $(CCASEXFLAGS)
# Use MODULE specific FLAGS variables for non recursive makefiles
# In targets, they are only evaluated at execution time
CFLAGS_$(MODULE) := $(CFLAGS) $(CFLAGS_$(MODULE))
CXXFLAGS_$(MODULE) := $(filter-out $(CXXUWFLAGS), $(CFLAGS_$(MODULE))) $(CXXEXFLAGS) $(CXXFLAGS_$(MODULE))
ASFLAGS_$(MODULE) := $(ASFLAGS) $(ASFLAGS_$(MODULE))
CCASFLAGS_$(MODULE) := $(filter-out $(CCASUWFLAGS), $(CFLAGS_$(MODULE))) $(CCASEXFLAGS) $(CCASFLAGS_$(MODULE))

# compile and generate dependency info

$(OBJC_LTO): CFLAGS+=$(LTOFLAGS)
$(OBJC_LTO): CFLAGS_$(MODULE)+=$(LTOFLAGS)

$(OBJC): $(BINDIR)/$(MODULE)/%.o: %.c $(RIOTBUILD_CONFIG_HEADER_C)
# Return module name from object path
module_from_obj = $(notdir $(realpath $(dir $1)))

$(OBJC): $(BINDIR)/$(MODULE)/%.o: $(D)/%.c $(RIOTBUILD_CONFIG_HEADER_C)
$(eval MODULE = $(call module_from_obj,$@))
$(Q)$(CCACHE) $(CC) \
-DRIOT_FILE_RELATIVE=\"$(patsubst $(RIOTBASE)/%,%,$(abspath $<))\" \
-DRIOT_FILE_NOPATH=\"$(notdir $<)\" \
$(CFLAGS) $(INCLUDES) -MD -MP -c -o $@ $(abspath $<)
$(CFLAGS_$(MODULE)) $(INCLUDES) -MD -MP -c -o $@ $(abspath $<)

$(OBJCXX): $(BINDIR)/$(MODULE)/%.o: %.cpp $(RIOTBUILD_CONFIG_HEADER_C)
$(OBJCXX): $(BINDIR)/$(MODULE)/%.o: $(D)/%.cpp $(RIOTBUILD_CONFIG_HEADER_C)
$(eval MODULE = $(call module_from_obj,$@))
$(Q)$(CCACHE) $(CXX) \
-DRIOT_FILE_RELATIVE=\"$(patsubst $(RIOTBASE)/%,%,$(abspath $<))\" \
-DRIOT_FILE_NOPATH=\"$(notdir $<)\" \
$(CXXFLAGS) $(CXXINCLUDES) $(INCLUDES) -MD -MP -c -o $@ $(abspath $<)
$(CXXFLAGS_$(MODULE)) $(CXXINCLUDES) $(INCLUDES) -MD -MP -c -o $@ $(abspath $<)

$(ASMOBJ): $(BINDIR)/$(MODULE)/%.o: $(D)/%.s
$(eval MODULE = $(call module_from_obj,$@))
$(Q)$(AS) $(ASFLAGS_$(MODULE)) -o $@ $(abspath $<)

$(ASMOBJ): $(BINDIR)/$(MODULE)/%.o: %.s
$(Q)$(AS) $(ASFLAGS) -o $@ $(abspath $<)
$(ASSMOBJ): $(BINDIR)/$(MODULE)/%.o: $(D)/%.S $(RIOTBUILD_CONFIG_HEADER_C)
$(eval MODULE = $(call module_from_obj,$@))
$(Q)$(CCAS) $(CCASFLAGS_$(MODULE)) $(INCLUDES) -MD -MP -c -o $@ $(abspath $<)


# Building DIRS

unexport DIRS
DIRS := $(sort $(abspath ${DIRS}))
.PHONY: ${DIRS:%=ALL--%} ${DIRS:%=CLEAN--%}

clean:: ${DIRS:%=CLEAN--%}

${DIRS:%=ALL--%}:
$(QQ)"$(MAKE)" -C ${@:ALL--%=%}

${DIRS:%=CLEAN--%}:
$(QQ)"$(MAKE)" -C ${@:CLEAN--%=%} clean

$(BINDIR)/$(MODULE).a $(OBJ): | ${DIRS:%=ALL--%}

# No message when changing directory and nothing to do
all: ..nothing_$(MODULE)
..nothing_$(MODULE):
@:

$(ASSMOBJ): $(BINDIR)/$(MODULE)/%.o: %.S $(RIOTBUILD_CONFIG_HEADER_C)
$(Q)$(CCAS) $(CCASFLAGS) $(INCLUDES) -MD -MP -c -o $@ $(abspath $<)

# pull in dependency info for *existing* .o files
# deleted header files will be silently ignored
-include $(DEP)

# Undefine local variables as they would break if in non-recursive mode
undefine SRC
undefine SRC_NOLTO
undefine SRCXX
undefine ASMSRC
undefine ASSMSRC

undefine SUBMODULES
undefine NO_AUTO_SRC
undefine BASE_MODULE
undefine SUBMODULES_NOFORCE

undefine MODULE
undefine MODULE_DIR
8 changes: 8 additions & 0 deletions boards/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
OLD_NONRECURSIVE := $(NONRECURSIVE)
NONRECURSIVE = 1

include Makefile.modules

MAKEFILE_DIRS = $(sort $(foreach module, $(USEMODULE), $(MODULE_DIR_$(module))))
include $(MAKEFILE_DIRS:%=%/Makefile)
NONRECURSIVE := $(OLD_NONRECURSIVE)
21 changes: 21 additions & 0 deletions boards/Makefile.modules
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Current makefile directory
D := $(abspath $(dir $(word $(words $(MAKEFILE_LIST)), $(MAKEFILE_LIST))))

# $(BOARD) implements "board" module
MODULE_DIR_board := $(D)/$(BOARD)

MODULE_DIR_arduino-atmega-common := $(D)/arduino-atmega-common
MODULE_DIR_arduino-mkr-common := $(D)/arduino-mkr-common
MODULE_DIR_mini := $(D)/calliope-mini/mini
MODULE_DIR_chronos-drivers := $(D)/chronos/drivers
MODULE_DIR_iotlab-common := $(D)/iotlab-common
MODULE_DIR_microbit := $(D)/microbit/microbit
MODULE_DIR_msb-430-common := $(D)/msb-430-common
MODULE_DIR_msb-430-common-drivers := $(D)/msb-430-common/drivers
MODULE_DIR_msba2-common := $(D)/msba2-common
MODULE_DIR_msba2-common-drivers := $(D)/msba2-common/drivers
MODULE_DIR_native-drivers := $(D)/native/drivers
MODULE_DIR_remote-common := $(D)/remote-common
MODULE_DIR_wsn430-common := $(D)/wsn430-common
MODULE_DIR_wsn430-common-drivers := $(D)/wsn430-common/drivers
MODULE_DIR_x86-multiboot-common := $(D)/x86-multiboot-common
2 changes: 0 additions & 2 deletions boards/arduino-duemilanove/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
MODULE = board

DIRS = $(RIOTBOARD)/arduino-atmega-common

include $(RIOTBASE)/Makefile.base
2 changes: 0 additions & 2 deletions boards/arduino-mega2560/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
MODULE = board

DIRS = $(RIOTBOARD)/arduino-atmega-common

include $(RIOTBASE)/Makefile.base
2 changes: 0 additions & 2 deletions boards/arduino-mkr1000/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
MODULE = board

DIRS = $(RIOTBOARD)/arduino-mkr-common

include $(RIOTBASE)/Makefile.base
2 changes: 0 additions & 2 deletions boards/arduino-mkrzero/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
MODULE = board

DIRS = $(RIOTBOARD)/arduino-mkr-common

include $(RIOTBASE)/Makefile.base
2 changes: 0 additions & 2 deletions boards/arduino-uno/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
MODULE = board

DIRS = $(RIOTBOARD)/arduino-atmega-common

include $(RIOTBASE)/Makefile.base
2 changes: 0 additions & 2 deletions boards/avsextrem/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
MODULE = board

DIRS = $(RIOTBOARD)/msba2-common

include $(RIOTBASE)/Makefile.base
4 changes: 0 additions & 4 deletions boards/calliope-mini/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
MODULE = board

ifneq (,$(filter mini,$(USEMODULE)))
DIRS += mini
endif

include $(RIOTBASE)/Makefile.base
2 changes: 0 additions & 2 deletions boards/chronos/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
MODULE = board

DIRS = drivers

include $(RIOTBASE)/Makefile.base
2 changes: 0 additions & 2 deletions boards/iotlab-a8-m3/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
MODULE = board

DIRS = $(RIOTBOARD)/iotlab-common

include $(RIOTBASE)/Makefile.base
2 changes: 0 additions & 2 deletions boards/iotlab-m3/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
MODULE = board

DIRS = $(RIOTBOARD)/iotlab-common

include $(RIOTBASE)/Makefile.base
4 changes: 0 additions & 4 deletions boards/microbit/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
MODULE = board

ifneq (,$(filter microbit,$(USEMODULE)))
DIRS += microbit
endif

include $(RIOTBASE)/Makefile.base
2 changes: 0 additions & 2 deletions boards/msb-430-common/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
MODULE = msb-430-common

DIRS = drivers

include $(RIOTBASE)/Makefile.base
2 changes: 0 additions & 2 deletions boards/msb-430/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
MODULE = board

DIRS = $(RIOTBOARD)/msb-430-common

include $(RIOTBASE)/Makefile.base
2 changes: 0 additions & 2 deletions boards/msb-430h/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
MODULE = board

DIRS = $(RIOTBOARD)/msb-430-common

include $(RIOTBASE)/Makefile.base
2 changes: 0 additions & 2 deletions boards/msba2-common/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
MODULE = msba2-common

DIRS = drivers

include $(RIOTBASE)/Makefile.base
2 changes: 0 additions & 2 deletions boards/msba2/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
MODULE = board

DIRS = $(RIOTBOARD)/msba2-common

include $(RIOTBASE)/Makefile.base
3 changes: 1 addition & 2 deletions boards/native/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
MODULE = board

DIRS = drivers

include $(RIOTBASE)/Makefile.base

# TODO Why here ?
INCLUDES = $(NATIVEINCLUDES)
2 changes: 0 additions & 2 deletions boards/qemu-i386/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
MODULE = board

DIRS = $(RIOTBOARD)/x86-multiboot-common

include $(RIOTBASE)/Makefile.base
2 changes: 0 additions & 2 deletions boards/remote-pa/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
MODULE = board

DIRS = $(RIOTBOARD)/remote-common

include $(RIOTBASE)/Makefile.base
2 changes: 0 additions & 2 deletions boards/remote-reva/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
MODULE = board

DIRS = $(RIOTBOARD)/remote-common

include $(RIOTBASE)/Makefile.base
2 changes: 0 additions & 2 deletions boards/remote-revb/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
MODULE = board

DIRS = $(RIOTBOARD)/remote-common

include $(RIOTBASE)/Makefile.base
2 changes: 0 additions & 2 deletions boards/wsn430-v1_3b/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
MODULE = board

DIRS = $(RIOTBOARD)/wsn430-common

include $(RIOTBASE)/Makefile.base
2 changes: 0 additions & 2 deletions boards/wsn430-v1_4/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
MODULE = board

DIRS = $(RIOTBOARD)/wsn430-common

include $(RIOTBASE)/Makefile.base
4 changes: 4 additions & 0 deletions core/Makefile.modules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Current makefile directory
D := $(abspath $(dir $(word $(words $(MAKEFILE_LIST)), $(MAKEFILE_LIST))))

MODULE_DIR_core := $(D)
7 changes: 7 additions & 0 deletions cpu/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
MODULE = cpu_dir

include Makefile.modules
include $(wildcard */Makefile.modules)

DIRS = $(foreach module, $(USEMODULE), $(MODULE_DIR_$(module)))
include $(RIOTBASE)/Makefile.base
10 changes: 10 additions & 0 deletions cpu/Makefile.modules
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Current makefile directory
D := $(abspath $(dir $(word $(words $(MAKEFILE_LIST)), $(MAKEFILE_LIST))))

# $(CPU) implements "cpu" module
MODULE_DIR_cpu := $(D)/$(CPU)

# $(CPU)/periph implements "periph" module if it exists
ifneq (,$(wildcard $(D)/$(CPU)/periph/Makefile))
MODULE_DIR_periph := $(D)/$(CPU)/periph
endif
4 changes: 1 addition & 3 deletions cpu/arm7_common/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
CFLAGS += $(CFLAGS_BASIC)

DIRS = periph
CFLAGS_arm7_common += $(CFLAGS_BASIC)

include $(RIOTBASE)/Makefile.base
5 changes: 5 additions & 0 deletions cpu/arm7_common/Makefile.modules
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Current makefile directory
D := $(abspath $(dir $(word $(words $(MAKEFILE_LIST)), $(MAKEFILE_LIST))))

MODULE_DIR_arm7_common := $(D)
MODULE_DIR_arm7_common_periph := $(D)/periph
3 changes: 0 additions & 3 deletions cpu/atmega1281/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
# define the module that is build
MODULE = cpu
# add a list of subdirectories, that should also be build
DIRS = $(ATMEGA_COMMON)
include $(RIOTBASE)/Makefile.base
Loading