Take the 2-minute tour ×

My first question (yay!) is about gnumake and parallel builds. Here's a quick example file:

.PHONY: tool_1 tool_2 tool_3 tool_4 all tools

all: | tools

tools: | tool_2 tool_3 tool_4

    # commands for tool 1

tool_2: | tool_1
    # commands for tool 2

tool_3: | tool_1
    # commands for tool 3

tool_4: | tool_1
    # commands for tool 4

If I do make -j on this guy, is what I have here correct to ensure that the commands for tool_1 are executed exactly once, and before make tries to build any of tool_[234]?

What I'm looking for is to have make -j cause tool_1 to be built first, then tool_[234] to be built in parallel, but without executing the commands for tool_1 three times. I hope that makes sense. Thanks for any suggestions or ideas!

share|improve this question
It does seem to be working like I want it to, but this parallel build stuff has a way of changing behaviour based on system load or from machine to machine, etc. –  Carl Norum Jan 23 '10 at 1:22

1 Answer 1

up vote 5 down vote accepted

make -j behaves exactly as you expect in your question. It does not make dependencies multiple times.

What does that pipe (|) character do in your dependency list?

share|improve this answer
order-only prerequisites: gnu.org/software/make/manual/make.html#Prerequisite-Types –  Amro Jan 23 '10 at 1:38
That's great, thanks @Alex. I couldn't find anything in the documentation that came right out and said that. –  Carl Norum Jan 23 '10 at 2:14
I thought I knew GNU make pretty well, but this was a feature I missed. –  JesperE Jan 23 '10 at 8:54

Your Answer


