'gnu make: rule execution order

I am reading https://www.gnu.org/software/make/manual/make.pdf. On page 24 it says

OBJDIR := objdir
OBJS := $(addprefix $(OBJDIR)/,foo.o bar.o baz.o)

$(OBJDIR)/%.o : %.c                    #first rule
   $(COMPILE.c) $(OUTPUT_OPTION) $<

all: $(OBJS)

$(OBJS): | $(OBJDIR)                   #third rule

$(OBJDIR):
   mkdir $(OBJDIR)

Now the rule to create the objdir directory will be run, if needed, before any ‘.o’ is built

I do not understand why the directory will be created first?? When target all is created, it looks at the prerequisite $(OBJDIR)/foo.o... and for this prerequisite both rules apply: the first and the third rule. Why is the third rule executed before the first rule? How does make decide in general which rule to apply first if two or more rules apply?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source