02.05.2013 Views

The Source Integrity Professional Edition User Guide - MKS

The Source Integrity Professional Edition User Guide - MKS

The Source Integrity Professional Edition User Guide - MKS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Here is another example, this time of a makefile employing<br />

metarules.<br />

Using Inference Rules<br />

FILES = main myFunc<br />

# notice the use of the $E macro representing<br />

# the executable file extension<br />

program$E : $(FILES:+$O)<br />

$(CC) $(CFLAGS) -e$@ $&<br />

%$O : %.c<br />

$(CC) -c $(CFLAGS) $<<br />

When <strong>MKS</strong> Make attempts to rebuild program$E (here the<br />

predefined E macro represents the executable file extension for your<br />

system), it checks the two specified object files to see if they, in turn,<br />

require rebuilding.<br />

<strong>MKS</strong> Make notes that these files end in the object file extension for<br />

your system, by expanding the O macro. Since these files lack a<br />

particular rule that names them as targets, <strong>MKS</strong> Make subsequently<br />

checks for any matching metarule. <strong>The</strong> metarule (the second rule in<br />

the makefile) does match the object file names, so it is used to rebuild<br />

the object files.<br />

Employing the metarule, <strong>MKS</strong> Make looks for the object files’<br />

matching source files (which end in a .c extension), and runs them<br />

through the compiler.<br />

Note the lack of specific reference to any object file in this makefile.<br />

<strong>MKS</strong> Make infers the appropriate object files by expanding<br />

$(FILES:+$O), and uses the metarule to match object files with their<br />

associated source.<br />

Here is another example, one that demonstrates the use of another<br />

common metarule.<br />

% .PRECIOUS : rcs/%$V<br />

-co -q $<<br />

<strong>The</strong> metarule states that any target (file) depends upon a prerequisite<br />

(an associated archive file) located in an rcs subdirectory. <strong>MKS</strong> Make<br />

matches any archive file to its associated working file. <strong>The</strong> recipe line<br />

uses the $< runtime macro to represent the prerequisite matching the<br />

target. Notice that it uses the dash command prefix. <strong>MKS</strong> Make<br />

ignores the failure of the check out (co) command (as it should, for<br />

example, if a revision of the file has already been checked out).<br />

Also, notice that it uses a macro called V to represent the possible<br />

archive file extension for the archive file. On UNIX-based systems,<br />

archive files usually end with a ,v extension. On PC-based systems,<br />

<strong>User</strong> <strong>Guide</strong> 283

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!