Using Sun WorkShop

Macros

The make utility's macro facility allows simple parameterless string substitutions. For example, the list of relocatable files that make up the target program pattern can be expressed as a single macro string, making it easier to change.

A macro string definition has the form:

NAME = string

Use of a macro string is indicated by

$(NAME)

which is replaced by make with the actual value of the macro string named.

This example adds a macro definition naming all the object files to the beginning of makefile:

 OBJ = pattern.o computepts.o startupcore.o

Now the macro can be used in both the list of dependencies as well as on the f77 link command for target pattern in makefile:


pattern: $(OBJ)
   f77 $(OBJ) -lcore77 -lcore -lsunwindow
\
   -lpixrect -o pattern 

For macro strings with single-letter names, the parentheses may be omitted.

Creating Macros With the Make Macros Dialog Box

You can use the Make Macros dialog box in Sun WorkShop to add macros to or delete macros from the Macros list in your WorkShop target, and reassign values for makefile macros in the list. For detailed information on using the dialog box, see "Using Makefile Macros".

Overriding of Macro Values

The initial values of makefile macros can be overridden with command-line options to make. For example, suppose you have the following line at the top of makefile:

FFLAGS=-u

and the compile-line of computepts.f:

f77 $(FFLAGS) -c computepts.f

and the final link:

f77 $(FFLAGS) $(OBJ) -lcore77 -lcore -lsunwindow \ lpixrect -o pattern

Now a simple make command without arguments uses the value of FFLAGS set above. However, this can be overridden from the command line:


demo% make "FFLAGS=-u -O"

Here, the definition of the FFLAGS macro on the make command line overrides the makefile initialization, and both the -O flag and the -u flag are passed to f77. Note that "FFLAGS=" can also be used on the command line to reset the macro so that it has no effect.


Note -

You can use the Make Macros dialog box in Sun WorkShop to override the value of a macro (see "Using Makefile Macros").