mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
make: refactor make system (parallelism, deduplication)
Almost everything was build sequentially in RIOT, because we employed explicit for-loops to build directories (DIRS). This PR makes our make system use normal dependencies to build directories. All our compiling rules were duplicated, once for the application, once for modules. This PR makes the application a normal module, removing this duplication.
This commit is contained in:
parent
c9c1f0d7fe
commit
35e74ad725
30
Makefile
30
Makefile
@ -1,30 +1,10 @@
|
|||||||
ifeq (, $(__RIOTBUILD_FLAG))
|
.all:
|
||||||
all: welcome
|
|
||||||
|
.PHONY: all doc docclean welcome
|
||||||
|
|
||||||
|
all: welcome
|
||||||
@echo ""
|
@echo ""
|
||||||
@exit 1
|
@exit 1
|
||||||
else
|
|
||||||
all:
|
|
||||||
mkdir -p $(BINDIR)
|
|
||||||
@for i in $(DIRS) ; do "$(MAKE)" -C $$i || exit 1; done ;
|
|
||||||
endif
|
|
||||||
|
|
||||||
DIRS = $(RIOTCPU)/$(CPU) core drivers sys
|
|
||||||
|
|
||||||
ifneq (,$(filter embunit,$(USEMODULE)))
|
|
||||||
DIRS += tests/unittests/embunit/embUnit
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifneq (,$(filter embunit_textui,$(USEMODULE)))
|
|
||||||
DIRS += tests/unittests/embunit/textui
|
|
||||||
endif
|
|
||||||
|
|
||||||
.PHONY: all clean doc docclean welcome
|
|
||||||
|
|
||||||
clean:
|
|
||||||
@for i in $(DIRS) ; do "$(MAKE)" -C $$i clean || exit 1; done ;
|
|
||||||
-@if [ -d $(BINDIR) ] ; \
|
|
||||||
then rm -rf $(BINDIR) ; \
|
|
||||||
fi
|
|
||||||
|
|
||||||
doc:
|
doc:
|
||||||
"$(MAKE)" -BC doc/doxygen
|
"$(MAKE)" -BC doc/doxygen
|
||||||
|
13
Makefile.application
Normal file
13
Makefile.application
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
MODULE = $(APPLICATION)
|
||||||
|
|
||||||
|
DIRS += $(RIOTCPU)/$(CPU) $(RIOTBOARD)/$(BOARD)
|
||||||
|
DIRS += $(RIOTBASE)/core $(RIOTBASE)/drivers $(RIOTBASE)/sys
|
||||||
|
|
||||||
|
ifneq (,$(filter embunit,$(USEMODULE)))
|
||||||
|
DIRS += $(RIOTBASE)/tests/unittests/embunit/embUnit
|
||||||
|
endif
|
||||||
|
ifneq (,$(filter embunit_textui,$(USEMODULE)))
|
||||||
|
DIRS += $(RIOTBASE)/tests/unittests/embunit/textui
|
||||||
|
endif
|
||||||
|
|
||||||
|
include $(RIOTBASE)/Makefile.base
|
@ -4,11 +4,20 @@ endif
|
|||||||
|
|
||||||
MODULE ?= $(shell basename $(CURDIR))
|
MODULE ?= $(shell basename $(CURDIR))
|
||||||
|
|
||||||
all: $(BINDIR)$(MODULE).a
|
.PHONY: all ${DIRS:%=ALL--%} ${DIRS:%=CLEAN--%}
|
||||||
@for i in $(DIRS); do $(MAKE) -C $$i || exit 1; done;
|
|
||||||
|
|
||||||
clean::
|
all: $(BINDIR)$(MODULE).a ..nothing
|
||||||
@for i in $(DIRS); do $(MAKE) -C $$i clean; done;
|
|
||||||
|
..nothing:
|
||||||
|
@:
|
||||||
|
|
||||||
|
clean:: ${DIRS:%=CLEAN--%}
|
||||||
|
|
||||||
|
${DIRS:%=ALL--%}:
|
||||||
|
"$(MAKE)" -C ${@:ALL--%=%}
|
||||||
|
|
||||||
|
${DIRS:%=CLEAN--%}:
|
||||||
|
"$(MAKE)" -C ${@:CLEAN--%=%} clean
|
||||||
|
|
||||||
ASMSRC = $(wildcard *.s)
|
ASMSRC = $(wildcard *.s)
|
||||||
ASSMSRC = $(wildcard *.S)
|
ASSMSRC = $(wildcard *.S)
|
||||||
@ -21,7 +30,8 @@ endif
|
|||||||
OBJ = $(SRC:%.c=$(BINDIR)$(MODULE)/%.o)
|
OBJ = $(SRC:%.c=$(BINDIR)$(MODULE)/%.o)
|
||||||
DEP = $(SRC:%.c=$(BINDIR)$(MODULE)/%.d)
|
DEP = $(SRC:%.c=$(BINDIR)$(MODULE)/%.d)
|
||||||
|
|
||||||
$(BINDIR)$(MODULE).a: $(OBJ) $(ASMOBJ)
|
$(BINDIR)$(MODULE).a: $(OBJ) $(ASMOBJ) ${DIRS:%=ALL--%}
|
||||||
|
@mkdir -p $(BINDIR)$(MODULE)
|
||||||
$(AD)$(AR) -rc $(BINDIR)$(MODULE).a $(OBJ) $(ASMOBJ)
|
$(AD)$(AR) -rc $(BINDIR)$(MODULE).a $(OBJ) $(ASMOBJ)
|
||||||
|
|
||||||
# pull in dependency info for *existing* .o files
|
# pull in dependency info for *existing* .o files
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# Provide a shallow sanity check. You cannot call `make` in the root directory.
|
# Provide a shallow sanity check. You cannot call `make` in a module directory.
|
||||||
export __RIOTBUILD_FLAG := RIOT
|
export __RIOTBUILD_FLAG := RIOT
|
||||||
|
|
||||||
# set undefined variables
|
# set undefined variables
|
||||||
@ -33,12 +33,14 @@ CPUDEF = $(shell echo $(CPU)|tr 'a-z' 'A-Z'|tr '-' '_')
|
|||||||
CFLAGS += -DBOARD_$(BB) -DCPU_$(CPUDEF)
|
CFLAGS += -DBOARD_$(BB) -DCPU_$(CPUDEF)
|
||||||
|
|
||||||
export CFLAGS
|
export CFLAGS
|
||||||
|
export APPLICATION
|
||||||
|
|
||||||
export BINDIRBASE ?= $(CURDIR)/bin
|
export BINDIRBASE ?= $(CURDIR)/bin
|
||||||
export BINDIR ?= $(abspath $(BINDIRBASE)/$(BOARD))/
|
export BINDIR ?= $(abspath $(BINDIRBASE)/$(BOARD))/
|
||||||
|
|
||||||
ifeq ($(QUIET),1)
|
ifeq ($(QUIET),1)
|
||||||
AD=@
|
AD=@
|
||||||
|
MAKEFLAGS += --no-print-directory
|
||||||
else
|
else
|
||||||
AD=
|
AD=
|
||||||
endif
|
endif
|
||||||
@ -84,10 +86,8 @@ export ELFFILE ?= $(BINDIR)$(APPLICATION).elf
|
|||||||
export HEXFILE ?= $(ELFFILE:.elf=.hex)
|
export HEXFILE ?= $(ELFFILE:.elf=.hex)
|
||||||
|
|
||||||
## make script for your application. Build RIOT-base here!
|
## make script for your application. Build RIOT-base here!
|
||||||
all: $(BINDIR)$(APPLICATION).a
|
all: ..build-message $(USEPKG:%=${BINDIR}%.a) $(APPDEPS)
|
||||||
@echo "Building application $(APPLICATION) for $(BOARD) w/ MCU $(MCU)."
|
"$(MAKE)" -C $(CURDIR) -f $(RIOTBASE)/Makefile.application
|
||||||
"$(MAKE)" -C $(RIOTBOARD)/$(BOARD)
|
|
||||||
"$(MAKE)" -C $(RIOTBASE)
|
|
||||||
ifeq (,$(RIOTNOLINK))
|
ifeq (,$(RIOTNOLINK))
|
||||||
ifeq ($(BUILDOSXNATIVE),1)
|
ifeq ($(BUILDOSXNATIVE),1)
|
||||||
$(AD)$(LINK) $(UNDEF) -o $(ELFFILE) $(BASELIBS) $(LINKFLAGS) -Wl,-no_pie
|
$(AD)$(LINK) $(UNDEF) -o $(ELFFILE) $(BASELIBS) $(LINKFLAGS) -Wl,-no_pie
|
||||||
@ -98,14 +98,8 @@ endif
|
|||||||
$(AD)$(OBJCOPY) $(OFLAGS) $(ELFFILE) $(HEXFILE)
|
$(AD)$(OBJCOPY) $(OFLAGS) $(ELFFILE) $(HEXFILE)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# string array of all names of c files in dir
|
..build-message:
|
||||||
SRC = $(wildcard *.c)
|
@echo "Building application $(APPLICATION) for $(BOARD) w/ MCU $(MCU)."
|
||||||
|
|
||||||
# string array of all names replaced .c with .o
|
|
||||||
OBJ = $(SRC:%.c=${BINDIR}${APPLICATION}/%.o)
|
|
||||||
|
|
||||||
$(BINDIR)$(APPLICATION).a: $(OBJ)
|
|
||||||
$(AD)$(AR) -rc $(BINDIR)$(APPLICATION).a $(OBJ)
|
|
||||||
|
|
||||||
# add extra include paths for packages in $(USEMODULE)
|
# add extra include paths for packages in $(USEMODULE)
|
||||||
export USEMODULE_INCLUDES =
|
export USEMODULE_INCLUDES =
|
||||||
@ -119,7 +113,7 @@ INCLUDES += $(USEMODULE_INCLUDES_:%=-I%)
|
|||||||
|
|
||||||
# The `clean` needs to be serialized before everything else.
|
# The `clean` needs to be serialized before everything else.
|
||||||
ifneq (, $(filter clean, $(MAKECMDGOALS)))
|
ifneq (, $(filter clean, $(MAKECMDGOALS)))
|
||||||
$(OBJ) $(BASELIBS) $(USEPKG:%=$(RIOTBASE)/pkg/%/Makefile.include): clean
|
all $(BASELIBS) $(USEPKG:%=$(RIOTBASE)/pkg/%/Makefile.include): clean
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# include Makefile.includes for packages in $(USEPKG)
|
# include Makefile.includes for packages in $(USEPKG)
|
||||||
@ -130,14 +124,6 @@ $(RIOTBASE)/pkg/%/Makefile.include::
|
|||||||
|
|
||||||
-include $(USEPKG:%=$(RIOTBASE)/pkg/%/Makefile.include)
|
-include $(USEPKG:%=$(RIOTBASE)/pkg/%/Makefile.include)
|
||||||
|
|
||||||
# pull in dependency info for *existing* .o files
|
|
||||||
-include $(OBJ:.o=.d)
|
|
||||||
|
|
||||||
$(BINDIR)$(APPLICATION)/%.o: %.c $(APPDEPS) $(USEPKG:%=${BINDIR}%.a)
|
|
||||||
@echo; echo "Compiling.... $*.c"; echo
|
|
||||||
$(AD)mkdir -p "$(dir $@)"
|
|
||||||
$(AD)$(CC) $(CFLAGS) $(INCLUDES) -c "$<" -o "$@"
|
|
||||||
|
|
||||||
$(USEPKG:%=${BINDIR}%.a):
|
$(USEPKG:%=${BINDIR}%.a):
|
||||||
@mkdir -p ${BINDIR}
|
@mkdir -p ${BINDIR}
|
||||||
"$(MAKE)" -C $(RIOTBASE)/pkg/$(patsubst ${BINDIR}%.a,%,$@)
|
"$(MAKE)" -C $(RIOTBASE)/pkg/$(patsubst ${BINDIR}%.a,%,$@)
|
||||||
|
Loading…
Reference in New Issue
Block a user