Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the symbol pipe '|' means in a Makefile

From target/linux/ar71xx/image/Makefile

KERNEL := kernel-bin | patch-cmdline | lzma | uImage lzma

Could you please help me understand what does this line means and provide an example on how to use the symbol pipe | in a Makefile

like image 916
Mouin Avatar asked Mar 08 '23 19:03

Mouin


2 Answers

This line is simply setting the make variable KERNEL to the string kernel-bin | patch-cmdline | lzma | uImage lzma. The pipe symbol (|) has no special meaning to make here.

You'll have to see how the variable is being used. Most likely it appears in a recipe somewhere, like this:

foo:
       $(KERNEL)

In that case the variable is expanded and the results are sent to the shell. In the shell, the pipe symbol causes the stdout from the command on the lefto be hooked up to the stdin of the command on the righ: it's called a pipeline or piping data.

Here you have a pipeline of 4 comands: kernel-bin's output is sent to 'patch-cmdline's input, patch-cmdline's output is sent to lzma's input, lzma's output is sent to uImage lzma's input.

like image 106
MadScientist Avatar answered Apr 03 '23 20:04

MadScientist


There is another use of '|' pipe symbol - to define order only prerequisites that simply provider target ordering and not build dependency:

For example:

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

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

all: $(OBJS)

$(OBJS): | $(OBJDIR)

$(OBJDIR):
        mkdir $(OBJDIR)

Ref: https://www.gnu.org/software/make/manual/html_node/Prerequisite-Types.html

like image 38
shalz Avatar answered Apr 03 '23 19:04

shalz