diff --git a/Makefile.ac b/Makefile.ac index b2f40075c6..0b61ff8c95 100644 --- a/Makefile.ac +++ b/Makefile.ac @@ -56,6 +56,20 @@ else MKTEMP = mktemp endif +# detection of number of processors for parallel compilation +# can be overridden by calling toplevel make with e.g. J=2 +NPROCS := 1 +ifeq ($J,) +ifeq ($(UNAME),Linux) + NPROCS := $(shell grep -c ^processor /proc/cpuinfo) +else ifeq ($(UNAME),Darwin) + NPROCS := $(shell sysctl hw.ncpu | awk '{print $$2}') +endif # $(UNAME) +else + NPROCS := $J +endif # $J + + # "make Q=''" to get full echo Q=@ @@ -176,8 +190,8 @@ $(SETTINGS_TELEMETRY) : $(PERIODIC_H) @echo BUILD $(AIRCRAFT), TARGET $* $(Q)PAPARAZZI_SRC=$(PAPARAZZI_SRC) PAPARAZZI_HOME=$(PAPARAZZI_HOME) TARGET=$* Q=$(Q) $(GENERATORS)/gen_aircraft.out $(AIRCRAFT) -%.compile: %.ac_h print_version - cd $(AIRBORNE); $(MAKE) TARGET=$* all +%.compile: %.ac_h | print_version + cd $(AIRBORNE); $(MAKE) -j$(NPROCS) TARGET=$* all %.upload: %.compile cd $(AIRBORNE); $(MAKE) TARGET=$* upload diff --git a/conf/Makefile.lpc21 b/conf/Makefile.lpc21 index 7313b7c2c9..64205059b6 100644 --- a/conf/Makefile.lpc21 +++ b/conf/Makefile.lpc21 @@ -173,6 +173,11 @@ include $(PAPARAZZI_SRC)/conf/Makefile.arm-embedded-common # Default target. all: printcommands sizebefore build sizeafter +# depend order only for parallel make +sizebefore: | printcommands +build: | printcommands sizebefore +sizeafter: | build + build: $(OBJDIR) elf hex lss sym $(OBJDIR): diff --git a/conf/Makefile.omap b/conf/Makefile.omap index da5e15c86d..4e5fedcc8c 100644 --- a/conf/Makefile.omap +++ b/conf/Makefile.omap @@ -79,6 +79,9 @@ printcommands: all: printcommands build +# depend order only for parallel make +build: | printcommands + build: $(OBJDIR) elf $(OBJDIR): diff --git a/conf/Makefile.stm32 b/conf/Makefile.stm32 index 4e8176523d..857d31941e 100644 --- a/conf/Makefile.stm32 +++ b/conf/Makefile.stm32 @@ -152,6 +152,11 @@ include $(PAPARAZZI_SRC)/conf/Makefile.arm-embedded-common # Default target. all: printcommands sizebefore build sizeafter +# depend order only for parallel make +sizebefore: | printcommands +build: | printcommands sizebefore +sizeafter: | build + build: $(OBJDIR) elf bin hex # lss sym @@ -189,7 +194,7 @@ sym: $(OBJDIR)/$(TARGET).sym # Link: create ELF output file from object files. .SECONDARY : $(OBJDIR)/$(TARGET).elf .PRECIOUS : $(COBJ) $(AOBJ) -%.elf: $(COBJ) $(AOBJ) +%.elf: $(COBJ) $(AOBJ) | $(OBJDIR) @echo LD $@ $(Q)$(LD) $(LDFLAGS) $($(TARGET).LDFLAGS) -o $@ $(COBJ) $(AOBJ) $(LDLIBS) @@ -209,14 +214,12 @@ $(AOBJ) : $(OBJDIR)/%.o : %.S include $(PAPARAZZI_SRC)/conf/Makefile.stm32-upload # Listing of phony targets. -.PHONY : all build elf bin lss sym start_gdb start_telnet +.PHONY : all build elf bin lss sym # # Dependencies # - -DEPS = $(addprefix $(OBJDIR)/,$($(TARGET).srcs:.c=.d)) - ifneq ($(MAKECMDGOALS),clean) +DEPS = $(addprefix $(OBJDIR)/,$($(TARGET).srcs:.c=.d)) -include $(DEPS) endif