next up previous
Next: Special $ commands Up: A sample makefile and Previous: Comments

Macro definitions

In a makefile, it is very easy to define a macro, or text-substitution:

BASEDIR = /afs/acpub.duke.edu/users8/ola/courses/lib

Whenever you type $(BASEDIR) in the makefile, make will substitute in the text contained in the macro BASEDIR. One really useful thing about macros is that they can reference other macros:

TLIB = $(BASEDIR)/libtapestry.a

The trick is that make doesn't substitute for BASEDIR immediately when you define TLIB. Instead, when you reference TLIB, it expands into $(BASEDIR)/libtapestry.a which, since it still has a $ in it, expands into /afs/acpub.duke.edu/users8/ola/courses/lib/libtapestry.a. Therefore, you can define macros in any order, as long as they are defined before they are actually expanded.



Garrett
Fri Jan 24 17:04:25 EST 1997