What are automatic variables (dollar variables) in a Makefile?

Suppose in your Makefile you wrote:

prog: main.c
	clang -o prog main.c

There are a couple of repetitions: you mention main.c twice, and prog twice. You can eliminate the repetition with automatic variables:

prog: main.c
  clang -o $@ $^

$@ (“dollar at”) is part of the Makefile language. In your recipe, it refers to the thing it is going to build (above, that’s prog). Mnemonic: it’s the target you’re aiming at.

$^ (“dollar caret”) refers to the dependencies/inputs (above, that’s main.c). If it contains multiple dependencies, they are separated by spaces.

I just released Vidrio, a free app for macOS and Windows to make your screen-sharing awesomely holographic. Vidrio shows your webcam video on your screen, just like a mirror. Then you just share or record your screen with Zoom, QuickTime, or any other app. Vidrio makes your presentations effortlessly engaging, showing your gestures, gazes, and expressions. #1 on Product Hunt. Available for macOS and Windows.

With Vidrio

With generic competitor

More by Jim

Tagged . All content copyright James Fisher 2016. This post is not associated with my employer. Found an error? Edit this page.