#include <mk/defs.h>
#include <mksh/misc.h>
void print_dependencies(Name target, Property line);
static void print_deps(Name target, Property line);
static void print_more_deps(Name target, Name name);
static void print_filename(Name name);
static Boolean should_print_dep(Property line);
static void print_forest(Name target);
static void print_deplist(Dependency head);
void print_value(Name value, Daemon daemon);
static void print_rule(Name target);
static void print_rec_info(Name target);
static Boolean is_out_of_date(Property line);
extern void depvar_print_results (void);
void
print_dependencies(Name target, Property line)
{
Dependency dp;
static Boolean makefiles_printed = false;
if (target_variants) {
depvar_print_results();
}
if (!makefiles_printed) {
for (dp = makefiles_used; dp != NULL; dp = dp->next) {
if (dp->name == primary_makefile) {
break;
}
}
if (dp) {
print_deplist(dp);
for (dp = makefiles_used; dp != NULL; dp = dp->next) {
if (dp->name == primary_makefile) {
break;
}
(void)printf(" %s", dp->name->string_mb);
}
}
(void) printf("\n");
makefiles_printed = true;
}
print_deps(target, line);
if (target_variants) {
print_forest(target);
}
}
static void
print_more_deps(Name target, Name name)
{
Property line;
Dependency dependencies;
line = get_prop(name->prop, line_prop);
if (line != NULL && line->body.line.dependencies != NULL) {
(void) printf("%s:\t", target->string_mb);
print_deplist(line->body.line.dependencies);
(void) printf("\n");
for (dependencies= line->body.line.dependencies;
dependencies != NULL;
dependencies= dependencies->next) {
print_deps(dependencies->name,
get_prop(dependencies->name->prop, line_prop));
}
}
}
static void
print_deps(Name target, Property line)
{
Dependency dep;
if ((target->dependency_printed) ||
(target == force)) {
return;
}
target->dependency_printed = true;
if (should_print_dep(line)) {
if ((report_dependencies_level == 2) ||
(report_dependencies_level == 4)) {
if (is_out_of_date(line)) {
(void) printf("1 ");
} else {
(void) printf("0 ");
}
}
print_filename(target);
(void) printf(":\t");
print_deplist(line->body.line.dependencies);
print_rec_info(target);
(void) printf("\n");
for (dep = line->body.line.dependencies;
dep != NULL;
dep = dep->next) {
print_deps(dep->name,
get_prop(dep->name->prop, line_prop));
}
}
}
static Boolean
is_out_of_date(Property line)
{
Dependency dep;
Property line2;
if (line == NULL) {
return false;
}
if (line->body.line.is_out_of_date) {
return true;
}
for (dep = line->body.line.dependencies;
dep != NULL;
dep = dep->next) {
line2 = get_prop(dep->name->prop, line_prop);
if (is_out_of_date(line2)) {
line->body.line.is_out_of_date = true;
return true;
}
}
return false;
}
static void
print_deplist(Dependency head)
{
Dependency dp;
for (dp = head; dp != NULL; dp = dp->next) {
if ((report_dependencies_level != 2) ||
((!dp->automatic) ||
(dp->name->is_double_colon))) {
if (dp->name != force) {
putwchar(' ');
print_filename(dp->name);
}
}
}
}
static void
print_filename(Name name)
{
(void) printf("%s", name->string_mb);
}
static Boolean
should_print_dep(Property line)
{
if (line == NULL) {
return false;
}
if (line->body.line.dependencies != NULL) {
return true;
}
if (line->body.line.sccs_command) {
return false;
}
return true;
}
static void
print_forest(Name target)
{
Name_set::iterator np, e;
Property line;
for (np = hashtab.begin(), e = hashtab.end(); np != e; np++) {
if (np->is_target && !np->has_parent && np != target) {
(void) doname_check(np, true, false, false);
line = get_prop(np->prop, line_prop);
printf("-\n");
print_deps(np, line);
}
}
}
void
print_value(Name value, Daemon daemon)
{
Chain cp;
if (value == NULL)
(void)printf("=\n");
else
switch (daemon) {
case no_daemon:
(void)printf("= %s\n", value->string_mb);
break;
case chain_daemon:
for (cp= (Chain) value; cp != NULL; cp= cp->next)
(void)printf(cp->next == NULL ? "%s" : "%s ",
cp->name->string_mb);
(void)printf("\n");
break;
};
}
static void
print_rule(Name target)
{
Cmd_line rule;
Property line;
if (((line= get_prop(target->prop, line_prop)) == NULL) ||
((line->body.line.command_template == NULL) &&
(line->body.line.dependencies == NULL)))
return;
print_dependencies(target, line);
for (rule= line->body.line.command_template; rule != NULL; rule= rule->next)
(void)printf("\t%s\n", rule->command_line->string_mb);
}
static void
print_rec_info(Name target)
{
Recursive_make rp;
wchar_t *colon;
report_recursive_init();
rp = find_recursive_target(target);
if (rp) {
colon = (wchar_t *) wcschr(rp->oldline, (int) colon_char);
(void) printf("%s", colon + 1);
}
}