Browse Source

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.
dev/timer
René Kijewski 9 years ago
parent
commit
35e74ad725
  1. 30
      Makefile
  2. 13
      Makefile.application
  3. 20
      Makefile.base
  4. 30
      Makefile.include

30
Makefile

@ -1,30 +1,10 @@
ifeq (, $(__RIOTBUILD_FLAG))
all: welcome
@echo ""
@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
.all:
ifneq (,$(filter embunit_textui,$(USEMODULE)))
DIRS += tests/unittests/embunit/textui
endif
.PHONY: all doc docclean welcome
.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
all: welcome
@echo ""
@exit 1
doc:
"$(MAKE)" -BC doc/doxygen

13
Makefile.application

@ -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

20
Makefile.base

@ -4,11 +4,20 @@ endif
MODULE ?= $(shell basename $(CURDIR))
all: $(BINDIR)$(MODULE).a
@for i in $(DIRS); do $(MAKE) -C $$i || exit 1; done;
.PHONY: all ${DIRS:%=ALL--%} ${DIRS:%=CLEAN--%}
clean::
@for i in $(DIRS); do $(MAKE) -C $$i clean; done;
all: $(BINDIR)$(MODULE).a ..nothing
..nothing:
@:
clean:: ${DIRS:%=CLEAN--%}
${DIRS:%=ALL--%}:
"$(MAKE)" -C ${@:ALL--%=%}
${DIRS:%=CLEAN--%}:
"$(MAKE)" -C ${@:CLEAN--%=%} clean
ASMSRC = $(wildcard *.s)
ASSMSRC = $(wildcard *.S)
@ -21,7 +30,8 @@ endif
OBJ = $(SRC:%.c=$(BINDIR)$(MODULE)/%.o)
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)
# pull in dependency info for *existing* .o files

30
Makefile.include

@ -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
# set undefined variables
@ -33,12 +33,14 @@ CPUDEF = $(shell echo $(CPU)|tr 'a-z' 'A-Z'|tr '-' '_')
CFLAGS += -DBOARD_$(BB) -DCPU_$(CPUDEF)
export CFLAGS
export APPLICATION
export BINDIRBASE ?= $(CURDIR)/bin
export BINDIR ?= $(abspath $(BINDIRBASE)/$(BOARD))/
ifeq ($(QUIET),1)
AD=@
MAKEFLAGS += --no-print-directory
else
AD=
endif
@ -84,10 +86,8 @@ export ELFFILE ?= $(BINDIR)$(APPLICATION).elf
export HEXFILE ?= $(ELFFILE:.elf=.hex)
## make script for your application. Build RIOT-base here!
all: $(BINDIR)$(APPLICATION).a
@echo "Building application $(APPLICATION) for $(BOARD) w/ MCU $(MCU)."
"$(MAKE)" -C $(RIOTBOARD)/$(BOARD)
"$(MAKE)" -C $(RIOTBASE)
all: ..build-message $(USEPKG:%=${BINDIR}%.a) $(APPDEPS)
"$(MAKE)" -C $(CURDIR) -f $(RIOTBASE)/Makefile.application
ifeq (,$(RIOTNOLINK))
ifeq ($(BUILDOSXNATIVE),1)
$(AD)$(LINK) $(UNDEF) -o $(ELFFILE) $(BASELIBS) $(LINKFLAGS) -Wl,-no_pie
@ -98,14 +98,8 @@ endif
$(AD)$(OBJCOPY) $(OFLAGS) $(ELFFILE) $(HEXFILE)
endif
# string array of all names of c files in dir
SRC = $(wildcard *.c)
# 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)
..build-message:
@echo "Building application $(APPLICATION) for $(BOARD) w/ MCU $(MCU)."
# add extra include paths for packages in $(USEMODULE)
export USEMODULE_INCLUDES =
@ -119,7 +113,7 @@ INCLUDES += $(USEMODULE_INCLUDES_:%=-I%)
# The `clean` needs to be serialized before everything else.
ifneq (, $(filter clean, $(MAKECMDGOALS)))
$(OBJ) $(BASELIBS) $(USEPKG:%=$(RIOTBASE)/pkg/%/Makefile.include): clean
all $(BASELIBS) $(USEPKG:%=$(RIOTBASE)/pkg/%/Makefile.include): clean
endif
# include Makefile.includes for packages in $(USEPKG)
@ -130,14 +124,6 @@ $(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):
@mkdir -p ${BINDIR}
"$(MAKE)" -C $(RIOTBASE)/pkg/$(patsubst ${BINDIR}%.a,%,$@)

Loading…
Cancel
Save