mk doesn't work the way I expect

Andrew Hume andrew at alice.UUCP
Sun Apr 2 14:15:46 AEST 1989


In article <24726 at watmath.waterloo.edu>, gamiddleton at watmath.waterloo.edu (Guy Middleton) writes:
> We just got mk, and I tried running this mkfile:
> 
> 	PROGS	= host addr hostaddr
> 
> 	all:V:	$PROGS
> 
> 	$PROGS:
> 		$CC -o $target $target.c
> 
> I expected this to happen:
> 
> 	cc -o host host.c
> 	cc -o addr addr.c
> 	cc -o hostaddr hostaddr.c
> 
> Instead, I got this:
> 
> 	cc -o host addr hostaddr host addr hostaddr.c
> 
> I got what I expected when the "all:V:  $PROGS" line was removed.
> 
> Why does it work this way?  Am I missing something obvious?


well, what you said was that host addr hostaddr can all be made from
no prerequisites from one recipe. i suspect you wanted to say

all:V:	$PROGS

%:	%.c
	$CC -o $stem $stem.c
or more pedantically,
	$CC $CFLAGS -o $stem $stem.c


the reason it worked the way you expected when the all line was removed was
that each of $PROGS was made individually (by default mk makes
targets of first nonmetarule), and the $CC recipe got a single
value for target.
	when the all line was there, mk said AHA! i can make all three things
at once with just one invocation of the recipe and set $target='host addr hostaddr'.

feel free to mail me at research!andrew or andrew at research.att.com.



More information about the Comp.unix.wizards mailing list