65 lines
2.4 KiB
Text
65 lines
2.4 KiB
Text
<!--
|
|
$FreeBSD$
|
|
-->
|
|
|
|
<chapter id="answers">
|
|
<title>Answers to Exercises</title>
|
|
|
|
<bridgehead>Exercise 3.1</bridgehead>
|
|
|
|
<para>This is something of a trick question, for which I apologize.
|
|
The trick comes from the &unix; definition of a suffix, which
|
|
<application>PMake</application> does not necessarily share.
|
|
You will have noticed that all the suffixes used in this tutorial
|
|
(and in &unix; in general) begin with a period
|
|
(<filename>.ms</filename>, <filename>.c</filename>, etc.).
|
|
Now, <application>PMake</application>'s idea of a suffix is more
|
|
like English's: it is the characters at the end of a word. With
|
|
this in mind, one possible solution to this problem goes as
|
|
follows:</para>
|
|
|
|
<programlisting>.SUFFIXES : ec.exe .exe ec.obj .obj .asm
|
|
ec.objec.exe .obj.exe :
|
|
link -o $(.TARGET) $(.IMPSRC)
|
|
.asmec.obj :
|
|
asm -o $(.TARGET) -DDO_ERROR_CHECKING $(.IMPSRC)
|
|
.asm.obj :
|
|
asm -o $(.TARGET) $(.IMPSRC)</programlisting>
|
|
|
|
<bridgehead>Excercise 3.2</bridgehead>
|
|
|
|
<para>The trick to this one lies in the <literal>:=</literal>
|
|
variable-assignment operator and the <literal>:S</literal>
|
|
variable-expansion modifier. Basically what you want is to take
|
|
the pointer variable, so to speak, and transform it into an
|
|
invocation of the variable at which it points. You might try
|
|
something like:</para>
|
|
|
|
<programlisting>$(PTR:S/^/\$(/:S/$/))</programlisting>
|
|
|
|
<para>which places <literal>$(</literal> at the front of the
|
|
variable name and <literal>)</literal> at the end, thus
|
|
transforming <literal>VAR,</literal> for example, into
|
|
<literal>$(VAR)</literal>, which is just what we want.
|
|
Unfortunately (as you know if you have tried it), since, as it
|
|
says in the hint, <application>PMake</application> does no further
|
|
substitution on the result of a modified expansion, that is all
|
|
you get. The solution is to make use of <literal>:=</literal> to
|
|
place that string into yet another variable, then invoke the other
|
|
variable directly:</para>
|
|
|
|
<programlisting>*PTR := $(PTR:S/^/\$(/:S/$/)/)</programlisting>
|
|
|
|
<para>You can then use <literal>$(*PTR)</literal> to your heart's
|
|
content.</para>
|
|
</chapter>
|
|
|
|
<!--
|
|
Local Variables:
|
|
mode: sgml
|
|
sgml-indent-data: t
|
|
sgml-omittag: nil
|
|
sgml-always-quote-attributes: t
|
|
sgml-parent-document: ("../book.sgml" "chapter")
|
|
End:
|
|
-->
|