Browse Source

Merge pull request #1326 from Kijewski/make-parallel-dirs

make: refactor make system (parallelism, deduplication)
dev/timer
René Kijewski 8 years ago
parent
commit
6ed3cf182b
  1. 30
      Makefile
  2. 13
      Makefile.application
  3. 33
      Makefile.base
  4. 30
      Makefile.include
  5. 2
      Makefile.modules
  6. 4
      boards/native/Makefile
  7. 4
      boards/native/drivers/Makefile
  8. 4
      cpu/native/Makefile
  9. 4
      cpu/native/net/Makefile
  10. 4
      cpu/native/rtc/Makefile
  11. 17
      tests/unittests/Makefile

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

33
Makefile.base

@ -2,13 +2,25 @@ ifeq (, $(__RIOTBUILD_FLAG))
$(error You cannot build a module on its own. Use "make" in your application's directory instead.)
endif
unexport DIRS
DIRS := $(abspath ${DIRS})
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--%}
all: $(BINDIR)$(MODULE).a ..nothing
..nothing:
@:
clean::
@for i in $(DIRS); do $(MAKE) -C $$i clean; done;
clean:: ${DIRS:%=CLEAN--%}
${DIRS:%=ALL--%}:
"$(MAKE)" -C ${@:ALL--%=%}
${DIRS:%=CLEAN--%}:
"$(MAKE)" -C ${@:CLEAN--%=%} clean
ASMSRC = $(wildcard *.s)
ASSMSRC = $(wildcard *.S)
@ -21,19 +33,18 @@ 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
# deleted header files will be silently ignored
-include $(OBJ:.o=.d)
# compile and generate dependency info,
# prepend path to dependency info file
# compile and generate dependency info
$(BINDIR)$(MODULE)/%.o: %.c
@mkdir -p $(BINDIR)$(MODULE)
$(AD)$(CC) $(CFLAGS) $(INCLUDES) -c $*.c -o $(BINDIR)$(MODULE)/$*.o
$(AD)$(CC) $(CFLAGS) $(INCLUDES) -MM $*.c |\
sed -e "1s|^|$(BINDIR)$(MODULE)/|" > $(BINDIR)$(MODULE)/$*.d
$(AD)$(CC) $(CFLAGS) $(INCLUDES) -MD -MP -c -o $(BINDIR)$(MODULE)/$*.o $(abspath $*.c)
$(BINDIR)$(MODULE)/%.o: %.s
@mkdir -p $(BINDIR)$(MODULE)
@ -41,4 +52,4 @@ $(BINDIR)$(MODULE)/%.o: %.s
$(BINDIR)$(MODULE)/%.o: %.S
@mkdir -p $(BINDIR)$(MODULE)
$(AD)$(CC) -c $(CFLAGS) $*.S -o $(BINDIR)$(MODULE)/$*.o
$(AD)$(CC) $(CFLAGS) $(INCLUDES) -MD -MP -c -o $(BINDIR)$(MODULE)/$*.o $(abspath $*.S)

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)
$(AD)DIRS="$(DIRS)" "$(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,%,$@)

2
Makefile.modules

@ -8,7 +8,7 @@ ED = $(USEMODULE:%=-DMODULE_%)
ED += $(USEPKG:%=-DMODULE_%)
EXTDEFINES = $(shell echo $(sort $(ED))|tr 'a-z' 'A-Z')
REALMODULES = $(filter-out $(PSEUDOMODULES), $(sort $(USEMODULE)))
export BASELIBS = $(REALMODULES:%=$(BINDIR)%.a)
export BASELIBS += $(REALMODULES:%=$(BINDIR)%.a)
CFLAGS += $(EXTDEFINES)

4
boards/native/Makefile

@ -6,6 +6,4 @@ include $(RIOTBASE)/Makefile.base
$(BINDIR)$(MODULE)/%.o: %.c
@mkdir -p $(BINDIR)$(MODULE)
$(AD)$(CC) $(CFLAGS) $(NATIVEINCLUDES) -c $*.c -o $(BINDIR)$(MODULE)/$*.o
$(AD)$(CC) $(CFLAGS) $(NATIVEINCLUDES) -MM $*.c |\
sed -e "1s|^|$(BINDIR)$(MODULE)/|" > $(BINDIR)$(MODULE)/$*.d
$(AD)$(CC) $(CFLAGS) $(NATIVEINCLUDES) -MD -MP -c -o $(BINDIR)$(MODULE)/$*.o $(abspath $*.c)

4
boards/native/drivers/Makefile

@ -4,6 +4,4 @@ include $(RIOTBASE)/Makefile.base
$(BINDIR)$(MODULE)/%.o: %.c
@mkdir -p $(BINDIR)$(MODULE)
$(AD)$(CC) $(CFLAGS) $(NATIVEINCLUDES) -c $*.c -o $(BINDIR)$(MODULE)/$*.o
$(AD)$(CC) $(CFLAGS) $(NATIVEINCLUDES) -MM $*.c |\
sed -e "1s|^|$(BINDIR)$(MODULE)/|" > $(BINDIR)$(MODULE)/$*.d
$(AD)$(CC) $(CFLAGS) $(NATIVEINCLUDES) -MD -MP -c -o $(BINDIR)$(MODULE)/$*.o $(abspath $*.c)

4
cpu/native/Makefile

@ -11,6 +11,4 @@ include $(RIOTBASE)/Makefile.base
$(BINDIR)$(MODULE)/%.o: %.c
@mkdir -p $(BINDIR)$(MODULE)
$(AD)$(CC) $(CFLAGS) $(NATIVEINCLUDES) -c $*.c -o $(BINDIR)$(MODULE)/$*.o
$(AD)$(CC) $(CFLAGS) $(NATIVEINCLUDES) -MM $*.c |\
sed -e "1s|^|$(BINDIR)$(MODULE)/|" > $(BINDIR)$(MODULE)/$*.d
$(AD)$(CC) $(CFLAGS) $(NATIVEINCLUDES) -MD -MP -c -o $(BINDIR)$(MODULE)/$*.o $(abspath $*.c)

4
cpu/native/net/Makefile

@ -4,6 +4,4 @@ include $(RIOTBASE)/Makefile.base
$(BINDIR)$(MODULE)/%.o: %.c
@mkdir -p $(BINDIR)$(MODULE)
$(AD)$(CC) $(CFLAGS) $(NATIVEINCLUDES) -c $*.c -o $(BINDIR)$(MODULE)/$*.o
$(AD)$(CC) $(CFLAGS) $(NATIVEINCLUDES) -MM $*.c |\
sed -e "1s|^|$(BINDIR)$(MODULE)/|" > $(BINDIR)$(MODULE)/$*.d
$(AD)$(CC) $(CFLAGS) $(NATIVEINCLUDES) -MD -MP -c -o $(BINDIR)$(MODULE)/$*.o $(abspath $*.c)

4
cpu/native/rtc/Makefile

@ -2,6 +2,4 @@ include $(RIOTBASE)/Makefile.base
$(BINDIR)$(MODULE)/%.o: %.c
@mkdir -p $(BINDIR)$(MODULE)
$(AD)$(CC) $(CFLAGS) $(NATIVEINCLUDES) -c $*.c -o $(BINDIR)$(MODULE)/$*.o
$(AD)$(CC) $(CFLAGS) $(NATIVEINCLUDES) -MM $*.c |\
sed -e "1s|^|$(BINDIR)$(MODULE)/|" > $(BINDIR)$(MODULE)/$*.d
$(AD)$(CC) $(CFLAGS) $(NATIVEINCLUDES) -MD -MP -c -o $(BINDIR)$(MODULE)/$*.o $(abspath $*.c)

17
tests/unittests/Makefile

@ -25,27 +25,18 @@ endif
# Pull in `Makefile.include`s from the test suites:
-include $(UNIT_TESTS:%=$(RIOTBASE)/tests/unittests/%/Makefile.include)
include $(RIOTBASE)/Makefile.include
DIRS += $(UNIT_TESTS)
BASELIBS += $(UNIT_TESTS:%=$(BINDIR)%.a)
UNITTEST_LIBS := $(UNIT_TESTS:%=$(BINDIR)%.a)
include $(RIOTBASE)/Makefile.include
all: $(UNITTEST_LIBS)
$(UNIT_TESTS): all
.FORCE:
$(UNITTEST_LIBS): $(BINDIR)%.a: .FORCE
"$(MAKE)" -C $(CURDIR)/$*
charEMPTY :=
charSPACE := $(charEMPTY) $(charEMPTY)
charCOMMA := ,
ifeq (, $(UNIT_TESTS))
CFLAGS += -DNO_TEST_SUITES
$(warning There was no test suite specified!)
else
CFLAGS += -DTEST_SUITES='$(subst $(charSPACE),$(charCOMMA),$(UNIT_TESTS:tests-%=%))'
CFLAGS += -DTEST_SUITES='$(subst $() $(),$(charCOMMA),$(UNIT_TESTS:tests-%=%))'
endif
BASELIBS += $(UNITTEST_LIBS)

Loading…
Cancel
Save