1 /* RCS $Id: dmdump.c,v 1.4 2007-06-12 06:05:11 obo Exp $
4 -- Dump the internal dag to stdout.
7 -- This file contains the routine that is called to dump a version of
8 -- the digested makefile to the standard output. May be useful perhaps
9 -- to the ordinary user, and invaluable for debugging make.
12 -- Dennis Vadura, dvadura@dmake.wticorp.com
15 -- http://dmake.wticorp.com/
18 -- Copyright (c) 1996,1997 by WTI Corp. All rights reserved.
20 -- This program is NOT free software; you can redistribute it and/or
21 -- modify it under the terms of the Software License Agreement Provided
22 -- in the file <distribution-root>/readme/license.txt.
25 -- Use cvs log to obtain detailed change logs.
30 #define M_TEST (M_PRECIOUS | M_VAR_MASK)
32 static void dump_name
ANSI((CELLPTR
, int, int));
33 static void dump_normal_target
ANSI((CELLPTR
, CELLPTR
, int));
34 static void dump_prerequisites
ANSI((LINKPTR
, CELLPTR
, int, int, int));
35 static void dump_conditionals
ANSI((CELLPTR
,STRINGPTR
,int,int));
36 static void dump_macro
ANSI((HASHPTR
, int));
41 ======== Dump onto standard output the digested makefile. Note that
42 the form of the dump is not representative of the contents
43 of the original makefile contents at all */
50 puts( "# Dump of dmake macro variables:" );
51 for( i
=0; i
<HASH_TABLE_SIZE
; i
++)
52 for( hp
=Macs
[i
]; hp
!= NIL(HASH
); hp
= hp
->ht_next
) {
53 int flag
= hp
->ht_flag
;
57 puts( "\n#====================================" );
58 puts( "# Dump of targets:\n" );
60 for( i
=0; i
<HASH_TABLE_SIZE
; i
++ )
61 for( hp
= Defs
[i
]; hp
!= NIL(HASH
); hp
= hp
->ht_next
)
62 if( !(hp
->CP_OWNR
->ce_flag
& F_PERCENT
) ) {
63 if( hp
->CP_OWNR
== Root
)
64 puts( "# ******* ROOT TARGET ********" );
65 if (Targets
->ce_prq
&& hp
->CP_OWNR
== Targets
->ce_prq
->cl_prq
)
66 puts( "# ******* FIRST USER DEFINED TARGET ******" );
67 dump_normal_target( hp
->CP_OWNR
,NIL(CELL
),hp
->CP_OWNR
->ce_flag
);
70 puts( "\n#====================================" );
71 puts( "# Dump of inference graph\n" );
73 for( i
=0; i
<HASH_TABLE_SIZE
; i
++ )
74 for( hp
= Defs
[i
]; hp
!= NIL(HASH
); hp
= hp
->ht_next
)
75 if( (hp
->CP_OWNR
->ce_flag
& F_PERCENT
) &&
76 !(hp
->CP_OWNR
->ce_flag
& F_MAGIC
) )
77 dump_normal_target(hp
->CP_OWNR
,NIL(CELL
),hp
->CP_OWNR
->ce_flag
);
87 Given a string pointer print the recipe line out */
93 if( sp
== NIL(STRING
) ) return;
96 if( sp
->st_attr
& A_SILENT
) putchar( '@' );
97 if( sp
->st_attr
& A_IGNORE
) putchar( '-' );
98 if( sp
->st_attr
& A_SHELL
) putchar( '+' );
99 if( sp
->st_attr
& A_SWAP
) putchar( '%' );
102 for( nl
=strchr(st
,'\n'); nl
!= NIL( char); nl
=strchr(st
,'\n') ) {
104 printf( "%s\\\n", st
);
108 printf( "%s\n", st
);
112 static char *_attrs
[] = { ".PRECIOUS", ".SILENT", ".LIBRARY",
113 ".EPILOG", ".PROLOG", ".IGNORE", ".SYMBOL", ".NOINFER",
114 ".UPDATEALL", ".SEQUENTIAL", ".SETDIR=", ".USESHELL",
118 # if defined(__CYGWIN__)
125 ".PHONY", ".NOSTATE", ".IGNOREGROUP", ".EXECUTE", ".ERRREMOVE" };
128 dump_normal_target( cp
, namecp
, flag
)/*
129 ========================================
130 Dump in makefile like format the dag information */
135 register STRINGPTR sp
;
139 DB_ENTER( "dump_normal_target" );
141 if(!(cp
->ce_flag
& F_TARGET
) && !cp
->ce_attr
&& !cp
->ce_prq
) {
145 if(cp
->ce_set
&& cp
->ce_set
!= cp
) {
149 if( cp
->ce_flag
& F_MULTI
) {
150 /* recursively print multi or %-targets. */
151 int tflag
= cp
->ce_prq
->cl_prq
->ce_flag
;
152 if( !(cp
->ce_flag
& F_PERCENT
) ) tflag
|= F_MULTI
;
153 dump_conditionals(cp
, cp
->ce_cond
, TRUE
, TRUE
);
157 /* Output also master targtet. (Only in debug builds) */
158 printf("Master name(s) (DBUG build): ");
159 dump_name(cp
, FALSE
, TRUE
);
163 /* %-targets set namecp (3rd parameter) to NULL so that the next
164 * recursive dump_normal_target() prints the name of cp->ce_prq->cl_prq
165 * instead of cp. This should be the same unless CeMeToo(cp) points
166 * to a cell that is the head of an .UPDATEALL list. */
167 dump_prerequisites(cp
->ce_prq
,(cp
->ce_flag
&F_PERCENT
)?NIL(CELL
):cp
,
171 dump_name(namecp
?namecp
:cp
, FALSE
, TRUE
);
173 for( k
=0, attr
=1; attr
<= MAX_ATTR
; attr
<<= 1, k
++ )
174 if( cp
->ce_attr
& attr
) {
175 printf( "%s%s ", _attrs
[k
],
176 (attr
!= A_SETDIR
) ? "" : (cp
->ce_dir
?cp
->ce_dir
:"") );
181 if( flag
& F_MULTI
) putchar( ':' );
182 if( flag
& F_SINGLE
) putchar( '!' );
185 dump_prerequisites( cp
->ce_prq
, NIL(CELL
), FALSE
, FALSE
, F_DEFAULT
);
186 dump_prerequisites( cp
->ce_indprq
, NIL(CELL
),TRUE
, FALSE
, F_DEFAULT
);
189 if( cp
->ce_flag
& F_GROUP
) puts( "[" );
190 for( sp
= cp
->ce_recipe
; sp
!= NIL(STRING
); sp
= sp
->st_next
)
192 if( cp
->ce_flag
& F_GROUP
) {
196 dump_conditionals(cp
, cp
->ce_cond
, flag
&F_MULTI
, FALSE
);
205 dump_conditionals( cp
, sp
, multi
, global
)
212 dump_name(cp
, FALSE
, TRUE
);
213 printf(".%sCONDITIONALS %s\n", global
?"GLOBAL":"",multi
?"::":":");
216 printf("\t%s\n",sp
->st_string
);
228 printf( "%s ", hp
->ht_name
);
229 if(flag
& M_EXPANDED
)
233 if(hp
->ht_value
!= NIL(char))
234 printf( "%s",hp
->ht_value
);
236 if(flag
& M_PRECIOUS
)
237 printf( "\t # PRECIOUS " );
244 dump_prerequisites( lp
, namecp
, quote
, recurse
, flag
)/*
245 ========================================================
246 Dump as prerequisites if recurse is FALSE or as targets
247 if recurse is TRUE. (For F_MULTI/F_PERCENT targets.) */
254 for( ; lp
; lp
=lp
->cl_next
)
256 dump_normal_target(lp
->cl_prq
, namecp
, flag
);
257 else if( lp
->cl_prq
)
258 dump_name(lp
->cl_prq
, quote
, FALSE
);
263 dump_name( cp
, quote
, all
)/*
264 =============================
265 Prints out the first or all (if all is TRUE) names of an lcell list.
266 If quote is true enclose in ' quotes, if quote
267 is FALSE and the name includes a space enclose in " quotes. */
275 for(lp
=CeMeToo(cp
);lp
;lp
=lp
->cl_next
) {
276 if( !quote
&& strchr(lp
->cl_prq
->CE_NAME
,' ') != NIL(char)) {
281 if (quote
) putchar(qc
);
282 printf( "%s", lp
->cl_prq
->CE_NAME
);
283 if (quote
) putchar(qc
);