Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am seeing a makefile and it has the symbols $@ and $< in it. I have never seen them, and Google does not show any results about them. Do you know what these commands do?

share|improve this question
up vote 7 down vote accepted

From make manpage:

$@ is:

The file name of the target of the rule. If the target is an archive member, then ‘$@’ is the name of the archive file. In a pattern rule that has multiple targets (see Introduction to Pattern Rules), ‘$@’ is the name of whichever target caused the rule's recipe to be run.

$< is:

The name of the first prerequisite. If the target got its recipe from an implicit rule, this will be the first prerequisite added by the implicit rule.

You can see complete manual here.

share|improve this answer
Thanks a lot Gnouc. Upvoted and chosen as best answer:) – John Smith Feb 23 '14 at 15:49
Note that this only applies to GNU make. POSIX defines $< only for inference rules and the .DEFAULT rule. – nwellnhof Feb 23 '14 at 20:31
You should also consider $^, which is all prerequisites. This is useful in rules for prog: a.o b.o c.o as $(CC) -o $@ $^ – vonbrand Feb 24 '14 at 1:53

To give an example: say you have a bunch of .c files that you want to compile to individual programs. You could write one make rule for each of them, or you could write one rule for all of them:

    %: %.c
            gcc -o "$@" "$<"

This rule means: if you have a make target (say program) and a .c file with the same basename (program.c), you can compile the .c file using gcc, giving the -o option with the name of the target (gcc -o program program.c).

share|improve this answer
Thanks a lot Daniel. You were very helpful. Upvoted :) – John Smith Feb 23 '14 at 15:49
Are you sure that the " are allowed here? – vonbrand Feb 24 '14 at 1:47
@vonbrand yes, pretty sure. – daniel kullmann Feb 24 '14 at 5:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.