Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi-threaded make

I can multi-thread a make with make -jN

Can I dictate multi-threading within the Makefile so that just make from the command-line runs multiple threads. Here's my makefile:

BIN_OBJS = $(wildcard *.bin)
HEX_OBJS = $(subst .bin,.hex,$(BIN_OBJS))

all: $(HEX_OBJS)

$(HEX_OBJS): %.hex: %.bin
    python ../../tools/bin2h.py $< > $@
like image 272
eplictical Avatar asked May 22 '14 18:05

eplictical


1 Answers

First, to be clear, make is not multi-threaded. Using -j just tells make to run multiple commands at the same time (in the background, basically).

Second, no, it's not possible to enable multiple jobs from within the makefile. You don't want to do that, in general, anyway because other systems will have different numbers of cores and whatever value you choose won't work well on those systems.

You don't have to write multiple makefiles, though, you can just use:

BIN_OBJS = $(wildcard *.bin)
HEX_OBJS = $(subst .bin,.hex,$(BIN_OBJS))

.PHONY: all multi
multi:
        $(MAKE) -j8 all

all: $(HEX_OBJS)

$(HEX_OBJS): %.hex: %.bin
        python ../../tools/bin2h.py $< > $@
like image 79
MadScientist Avatar answered Oct 14 '22 17:10

MadScientist