[Cook] [PATCH] order of implicit recipe use
Lev S Bishop
lev.bishop at yale.edu
Tue May 3 04:55:51 EST 2005
>From section 11.8 of the user's guide, paragraph 4:
"If the target was not in the target list of any explicit recipe, cook
then scans the instantiated implicit recipes in the order they were
defined, in two passes. Implicit recipes which not not have pattern
elements in the basename of the targets are scanned before implicit
recipes which do have patterns in the basename."
To me, this states that patterns such as %0file.o: %0file.c should come
before %0%.o: %0%.c. However, this is not how the code actually works.
What the code actually does is give priority to patterns of the form
"xxxx/file.o: yyyy/file.c", where the xxxx and yyyy may contain wildcards,
but the final '/' before the filename is important. Eg,
"%1/file.o: %1/file.c" gets priority.
I made a patch so that the "%0file.o: %0file.c" type patterns also get
priority, in line with the user's guide, but now I am not so sure whether
this is a good idea. The user's guide goes on to say:
"Usually this has no significant effect, however in heavily heterogeneous
builds this method is often used in constructing the dependency files, so
that all architectures may use the one implicit dependency recipe, rather
than stating every architecture explicitly."
Maybe the point is that the patterns are supposed to match in a directory
tree like:
i386-linux/file.o
sparc-solaris/file.o
...etc
so we write patterns like "%/file.o: file.c". So maybe it's a
documentation bug not a C bug. Anybody got any comments?
Anyway, here is my patch, in case anybody thinks this is a better
behaviour.
--- cook/cook.c 2005-04-24 14:35:15.944819200 -0400
+++ cook/cook.c 2005-04-24 16:22:44.913224000 -0400
@@ -80,6 +80,7 @@
#include <ac/stddef.h>
#include <ac/stdio.h>
+#include <ac/string.h>
#include <ac/time.h>
#include <cascade.h>
@@ -1299,6 +1300,47 @@
trace((/*{*/"}\n"));
}
+/*
+ * NAME
+ * pattern_entryname - take path pattern apart
+ *
+ * SYNOPSIS
+ * string_ty *pattern_entryname(string_ty *path);
+ *
+ * DESCRIPTION
+ * Pattern_entryname is used to extract the entry part
+ * from a pattern (ie removes up to the last "/" or "%0").
+ *
+ * RETURNS
+ * pointer to dynamically allocated string.
+ *
+ * CAVEAT
+ * Use str_free() when you are done with the return value.
+ */
+
+static string_ty * pattern_entryname _((string_ty *));
+
+static string_ty *
+pattern_entryname(path)
+ string_ty *path;
+{
+ char *cp;
+
+ trace(("pattern_entryname(path = %08lX)\n{\n", path));
+ trace_string(path->str_text);
+ cp = strrchr(path->str_text, '/');
+ if (!cp) cp = path->str_text; else ++cp;
+ if (strspn(cp, "%0") == 2) cp += 2;
+ if (cp != path->str_text)
+ path = str_from_c(cp);
+ else
+ path = str_copy(path);
+ trace_string(path->str_text);
+ trace(("return %08lX;\n", path));
+ trace((/*{*/"}\n"));
+ return path;
+}
+
/*
* NAME
@@ -1332,7 +1374,7 @@
string_list_constructor(&base_list);
for (j = 0; j < rp->target->nstrings; ++j)
{
- base = os_entryname(rp->target->string[j]);
+ base = pattern_entryname(rp->target->string[j]);
if (match_usage_mask(mp, base, &rp->pos) != 0)
{
match_delete(mp);
More information about the Cook-users
mailing list