Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a semicolon in a makefile prerequisites list?

Tags:

makefile

In one of the early sections of the GNU make manual, Section 3.7, there is an outline of a makefile recipe

immediate : immediate ; deferred
        deferred

involving a semicolon in the prerequisites list. So a valid recipe could be

output.o : output.c header1.h header2.h; header3.h
        gcc output.c -o output.o

What is the point of the semicolon? Since the aforementioned section talks about immediate and deferred variable expansion, I am guessing that the part up to the semicolon is expanded immediately and the part of the semicolon is expanded only once the target is executed. Can anybody confirm?

I have found similar questions on SO but those present special cases and none of the their accepted answers seem to get the point.

like image 528
shuhalo Avatar asked Sep 02 '25 05:09

shuhalo


2 Answers

As explained in 4.2 Rule Syntax:

In general, a rule looks like this:

targets : prerequisites
        recipe
        …

or like this:

targets : prerequisites ; recipe
        recipe
        …

[...]

The recipe lines start with a tab character (or the first character in the value of the .RECIPEPREFIX variable; see Special Variables). The first recipe line may appear on the line after the prerequisites, with a tab character, or may appear on the same line, with a semicolon. Either way, the effect is the same.

(Emphasis mine.)

Your example is equivalent to

output.o : output.c header1.h header2.h
        header3.h
        gcc output.c -o output.o
like image 116
melpomene Avatar answered Sep 05 '25 01:09

melpomene


Semicolon simply allows to write the first line of the recipe on the same line as the prerequisites list.

This way (given that your recipes fit a single line) you can write a Makefile w/o any evil tabs. There's no much use in it otherwise.

like image 34
Matt Avatar answered Sep 04 '25 23:09

Matt