Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do $< and $@ represent in a Makefile?

Tags:

makefile

Can anybody please explain the meaning of $< and $@ in a Makefile?

like image 633
Renjith G Avatar asked May 29 '09 06:05

Renjith G


1 Answers

$< evaluates to the first "prerequisite" in the make rule, and $@ evaluates to the "target" in the make rule.

Here's an example:

file.o : file.c
        $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@

In this case, $< will be replaced with file.c and $@ will be file.o.

These are more useful in generic rules like this:

%.o : %.c
        $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@

See this manual for more info.

like image 178
Andy White Avatar answered Oct 31 '22 03:10

Andy White