4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
30 #include <mksh/misc.h> /* get_prop() */
33 * File table of contents
35 void print_dependencies(register Name target
, register Property line
);
36 static void print_deps(register Name target
, register Property line
);
37 static void print_more_deps(Name target
, Name name
);
38 static void print_filename(Name name
);
39 static Boolean
should_print_dep(Property line
);
40 static void print_forest(Name target
);
41 static void print_deplist(Dependency head
);
42 void print_value(register Name value
, Daemon daemon
);
43 static void print_rule(register Name target
);
44 static void print_rec_info(Name target
);
45 static Boolean
is_out_of_date(Property line
);
46 extern void depvar_print_results (void);
49 * print_dependencies(target, line)
51 * Print all the dependencies of a target. First print all the Makefiles.
52 * Then print all the dependencies. Finally, print all the .INIT
56 * target The target we print dependencies for
57 * line We get the dependency list from here
59 * Global variables used:
60 * done The Name ".DONE"
61 * init The Name ".INIT"
62 * makefiles_used List of all makefiles read
65 print_dependencies(register Name target
, register Property line
)
68 static Boolean makefiles_printed
= false;
70 if (target_variants
) {
71 depvar_print_results();
74 if (!makefiles_printed
) {
76 * Search the makefile list for the primary makefile,
77 * then print it and its inclusions. After that go back
78 * and print the default.mk file and its inclusions.
80 for (dp
= makefiles_used
; dp
!= NULL
; dp
= dp
->next
) {
81 if (dp
->name
== primary_makefile
) {
87 for (dp
= makefiles_used
; dp
!= NULL
; dp
= dp
->next
) {
88 if (dp
->name
== primary_makefile
) {
91 (void)printf(" %s", dp
->name
->string_mb
);
95 makefiles_printed
= true;
97 print_deps(target
, line
);
99 print_more_deps(target, init);
100 print_more_deps(target, done);
102 if (target_variants
) {
103 print_forest(target
);
108 * print_more_deps(target, name)
110 * Print some special dependencies.
111 * These are the dependencies for the .INIT and .DONE targets.
114 * target Target built during make run
115 * name Special target to print dependencies for
117 * Global variables used:
120 print_more_deps(Name target
, Name name
)
123 register Dependency dependencies
;
125 line
= get_prop(name
->prop
, line_prop
);
126 if (line
!= NULL
&& line
->body
.line
.dependencies
!= NULL
) {
127 (void) printf("%s:\t", target
->string_mb
);
128 print_deplist(line
->body
.line
.dependencies
);
130 for (dependencies
= line
->body
.line
.dependencies
;
131 dependencies
!= NULL
;
132 dependencies
= dependencies
->next
) {
133 print_deps(dependencies
->name
,
134 get_prop(dependencies
->name
->prop
, line_prop
));
140 * print_deps(target, line, go_recursive)
142 * Print a regular dependency list. Append to this information which
143 * indicates whether or not the target is recursive.
146 * target target to print dependencies for
147 * line We get the dependency list from here
148 * go_recursive Should we show all dependencies recursively?
150 * Global variables used:
151 * recursive_name The Name ".RECURSIVE", printed
154 print_deps(register Name target
, register Property line
)
156 register Dependency dep
;
158 if ((target
->dependency_printed
) ||
162 target
->dependency_printed
= true;
164 /* only print entries that are actually derived and are not leaf
165 * files and are not the result of sccs get.
167 if (should_print_dep(line
)) {
168 if ((report_dependencies_level
== 2) ||
169 (report_dependencies_level
== 4)) {
170 if (is_out_of_date(line
)) {
176 print_filename(target
);
177 (void) printf(":\t");
178 print_deplist(line
->body
.line
.dependencies
);
179 print_rec_info(target
);
181 for (dep
= line
->body
.line
.dependencies
;
184 print_deps(dep
->name
,
185 get_prop(dep
->name
->prop
, line_prop
));
191 is_out_of_date(Property line
)
199 if (line
->body
.line
.is_out_of_date
) {
202 for (dep
= line
->body
.line
.dependencies
;
205 line2
= get_prop(dep
->name
->prop
, line_prop
);
206 if (is_out_of_date(line2
)) {
207 line
->body
.line
.is_out_of_date
= true;
215 * Given a dependency print it and all its siblings.
218 print_deplist(Dependency head
)
222 for (dp
= head
; dp
!= NULL
; dp
= dp
->next
) {
223 if ((report_dependencies_level
!= 2) ||
225 (dp
->name
->is_double_colon
))) {
226 if (dp
->name
!= force
) {
228 print_filename(dp
->name
);
235 * Print the name of a file for the -P option.
236 * If the file is a directory put on a trailing slash.
239 print_filename(Name name
)
241 (void) printf("%s", name
->string_mb
);
243 if (name->stat.is_dir) {
250 * should_print_dep(line)
252 * Test if we should print the dependencies of this target.
253 * The line must exist and either have children dependencies
254 * or have a command that is not an SCCS command.
257 * true if the dependencies should be printed
260 * line We get the dependency list from here
262 * Global variables used:
265 should_print_dep(Property line
)
270 if (line
->body
.line
.dependencies
!= NULL
) {
273 if (line
->body
.line
.sccs_command
) {
280 * Print out the root nodes of all the dependency trees
284 print_forest(Name target
)
286 Name_set::iterator np
, e
;
289 for (np
= hashtab
.begin(), e
= hashtab
.end(); np
!= e
; np
++) {
290 if (np
->is_target
&& !np
->has_parent
&& np
!= target
) {
291 (void) doname_check(np
, true, false, false);
292 line
= get_prop(np
->prop
, line_prop
);
294 print_deps(np
, line
);
301 * This is a set of routines for dumping the internal make state
302 * Used for the -p option
305 print_value(register Name value
, Daemon daemon
)
316 (void)printf("= %s\n", value
->string_mb
);
319 for (cp
= (Chain
) value
; cp
!= NULL
; cp
= cp
->next
)
320 (void)printf(cp
->next
== NULL
? "%s" : "%s ",
321 cp
->name
->string_mb
);
328 print_rule(register Name target
)
330 register Cmd_line rule
;
331 register Property line
;
333 if (((line
= get_prop(target
->prop
, line_prop
)) == NULL
) ||
334 ((line
->body
.line
.command_template
== NULL
) &&
335 (line
->body
.line
.dependencies
== NULL
)))
337 print_dependencies(target
, line
);
338 for (rule
= line
->body
.line
.command_template
; rule
!= NULL
; rule
= rule
->next
)
339 (void)printf("\t%s\n", rule
->command_line
->string_mb
);
344 * If target is recursive, print the following to standard out:
345 * .RECURSIVE subdir targ Makefile
348 print_rec_info(Name target
)
353 report_recursive_init();
355 rp
= find_recursive_target(target
);
359 * if found, print starting with the space after the ':'
361 colon
= (wchar_t *) wcschr(rp
->oldline
, (int) colon_char
);
362 (void) printf("%s", colon
+ 1);