xref: /OK3568_Linux_fs/kernel/scripts/basic/fixdep.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * "Optimize" a list of dependencies as spit out by gcc -MD
3*4882a593Smuzhiyun  * for the kernel build
4*4882a593Smuzhiyun  * ===========================================================================
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * Author       Kai Germaschewski
7*4882a593Smuzhiyun  * Copyright    2002 by Kai Germaschewski  <kai.germaschewski@gmx.de>
8*4882a593Smuzhiyun  *
9*4882a593Smuzhiyun  * This software may be used and distributed according to the terms
10*4882a593Smuzhiyun  * of the GNU General Public License, incorporated herein by reference.
11*4882a593Smuzhiyun  *
12*4882a593Smuzhiyun  *
13*4882a593Smuzhiyun  * Introduction:
14*4882a593Smuzhiyun  *
15*4882a593Smuzhiyun  * gcc produces a very nice and correct list of dependencies which
16*4882a593Smuzhiyun  * tells make when to remake a file.
17*4882a593Smuzhiyun  *
18*4882a593Smuzhiyun  * To use this list as-is however has the drawback that virtually
19*4882a593Smuzhiyun  * every file in the kernel includes autoconf.h.
20*4882a593Smuzhiyun  *
21*4882a593Smuzhiyun  * If the user re-runs make *config, autoconf.h will be
22*4882a593Smuzhiyun  * regenerated.  make notices that and will rebuild every file which
23*4882a593Smuzhiyun  * includes autoconf.h, i.e. basically all files. This is extremely
24*4882a593Smuzhiyun  * annoying if the user just changed CONFIG_HIS_DRIVER from n to m.
25*4882a593Smuzhiyun  *
26*4882a593Smuzhiyun  * So we play the same trick that "mkdep" played before. We replace
27*4882a593Smuzhiyun  * the dependency on autoconf.h by a dependency on every config
28*4882a593Smuzhiyun  * option which is mentioned in any of the listed prerequisites.
29*4882a593Smuzhiyun  *
30*4882a593Smuzhiyun  * kconfig populates a tree in include/config/ with an empty file
31*4882a593Smuzhiyun  * for each config symbol and when the configuration is updated
32*4882a593Smuzhiyun  * the files representing changed config options are touched
33*4882a593Smuzhiyun  * which then let make pick up the changes and the files that use
34*4882a593Smuzhiyun  * the config symbols are rebuilt.
35*4882a593Smuzhiyun  *
36*4882a593Smuzhiyun  * So if the user changes his CONFIG_HIS_DRIVER option, only the objects
37*4882a593Smuzhiyun  * which depend on "include/config/his/driver.h" will be rebuilt,
38*4882a593Smuzhiyun  * so most likely only his driver ;-)
39*4882a593Smuzhiyun  *
40*4882a593Smuzhiyun  * The idea above dates, by the way, back to Michael E Chastain, AFAIK.
41*4882a593Smuzhiyun  *
42*4882a593Smuzhiyun  * So to get dependencies right, there are two issues:
43*4882a593Smuzhiyun  * o if any of the files the compiler read changed, we need to rebuild
44*4882a593Smuzhiyun  * o if the command line given to the compile the file changed, we
45*4882a593Smuzhiyun  *   better rebuild as well.
46*4882a593Smuzhiyun  *
47*4882a593Smuzhiyun  * The former is handled by using the -MD output, the later by saving
48*4882a593Smuzhiyun  * the command line used to compile the old object and comparing it
49*4882a593Smuzhiyun  * to the one we would now use.
50*4882a593Smuzhiyun  *
51*4882a593Smuzhiyun  * Again, also this idea is pretty old and has been discussed on
52*4882a593Smuzhiyun  * kbuild-devel a long time ago. I don't have a sensibly working
53*4882a593Smuzhiyun  * internet connection right now, so I rather don't mention names
54*4882a593Smuzhiyun  * without double checking.
55*4882a593Smuzhiyun  *
56*4882a593Smuzhiyun  * This code here has been based partially based on mkdep.c, which
57*4882a593Smuzhiyun  * says the following about its history:
58*4882a593Smuzhiyun  *
59*4882a593Smuzhiyun  *   Copyright abandoned, Michael Chastain, <mailto:mec@shout.net>.
60*4882a593Smuzhiyun  *   This is a C version of syncdep.pl by Werner Almesberger.
61*4882a593Smuzhiyun  *
62*4882a593Smuzhiyun  *
63*4882a593Smuzhiyun  * It is invoked as
64*4882a593Smuzhiyun  *
65*4882a593Smuzhiyun  *   fixdep <depfile> <target> <cmdline>
66*4882a593Smuzhiyun  *
67*4882a593Smuzhiyun  * and will read the dependency file <depfile>
68*4882a593Smuzhiyun  *
69*4882a593Smuzhiyun  * The transformed dependency snipped is written to stdout.
70*4882a593Smuzhiyun  *
71*4882a593Smuzhiyun  * It first generates a line
72*4882a593Smuzhiyun  *
73*4882a593Smuzhiyun  *   cmd_<target> = <cmdline>
74*4882a593Smuzhiyun  *
75*4882a593Smuzhiyun  * and then basically copies the .<target>.d file to stdout, in the
76*4882a593Smuzhiyun  * process filtering out the dependency on autoconf.h and adding
77*4882a593Smuzhiyun  * dependencies on include/config/my/option.h for every
78*4882a593Smuzhiyun  * CONFIG_MY_OPTION encountered in any of the prerequisites.
79*4882a593Smuzhiyun  *
80*4882a593Smuzhiyun  * We don't even try to really parse the header files, but
81*4882a593Smuzhiyun  * merely grep, i.e. if CONFIG_FOO is mentioned in a comment, it will
82*4882a593Smuzhiyun  * be picked up as well. It's not a problem with respect to
83*4882a593Smuzhiyun  * correctness, since that can only give too many dependencies, thus
84*4882a593Smuzhiyun  * we cannot miss a rebuild. Since people tend to not mention totally
85*4882a593Smuzhiyun  * unrelated CONFIG_ options all over the place, it's not an
86*4882a593Smuzhiyun  * efficiency problem either.
87*4882a593Smuzhiyun  *
88*4882a593Smuzhiyun  * (Note: it'd be easy to port over the complete mkdep state machine,
89*4882a593Smuzhiyun  *  but I don't think the added complexity is worth it)
90*4882a593Smuzhiyun  */
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun #include <sys/types.h>
93*4882a593Smuzhiyun #include <sys/stat.h>
94*4882a593Smuzhiyun #include <unistd.h>
95*4882a593Smuzhiyun #include <fcntl.h>
96*4882a593Smuzhiyun #include <string.h>
97*4882a593Smuzhiyun #include <stdarg.h>
98*4882a593Smuzhiyun #include <stdlib.h>
99*4882a593Smuzhiyun #include <stdio.h>
100*4882a593Smuzhiyun #include <ctype.h>
101*4882a593Smuzhiyun 
usage(void)102*4882a593Smuzhiyun static void usage(void)
103*4882a593Smuzhiyun {
104*4882a593Smuzhiyun 	fprintf(stderr, "Usage: fixdep <depfile> <target> <cmdline>\n");
105*4882a593Smuzhiyun 	exit(1);
106*4882a593Smuzhiyun }
107*4882a593Smuzhiyun 
108*4882a593Smuzhiyun /*
109*4882a593Smuzhiyun  * In the intended usage of this program, the stdout is redirected to .*.cmd
110*4882a593Smuzhiyun  * files. The return value of printf() and putchar() must be checked to catch
111*4882a593Smuzhiyun  * any error, e.g. "No space left on device".
112*4882a593Smuzhiyun  */
xprintf(const char * format,...)113*4882a593Smuzhiyun static void xprintf(const char *format, ...)
114*4882a593Smuzhiyun {
115*4882a593Smuzhiyun 	va_list ap;
116*4882a593Smuzhiyun 	int ret;
117*4882a593Smuzhiyun 
118*4882a593Smuzhiyun 	va_start(ap, format);
119*4882a593Smuzhiyun 	ret = vprintf(format, ap);
120*4882a593Smuzhiyun 	if (ret < 0) {
121*4882a593Smuzhiyun 		perror("fixdep");
122*4882a593Smuzhiyun 		exit(1);
123*4882a593Smuzhiyun 	}
124*4882a593Smuzhiyun 	va_end(ap);
125*4882a593Smuzhiyun }
126*4882a593Smuzhiyun 
xputchar(int c)127*4882a593Smuzhiyun static void xputchar(int c)
128*4882a593Smuzhiyun {
129*4882a593Smuzhiyun 	int ret;
130*4882a593Smuzhiyun 
131*4882a593Smuzhiyun 	ret = putchar(c);
132*4882a593Smuzhiyun 	if (ret == EOF) {
133*4882a593Smuzhiyun 		perror("fixdep");
134*4882a593Smuzhiyun 		exit(1);
135*4882a593Smuzhiyun 	}
136*4882a593Smuzhiyun }
137*4882a593Smuzhiyun 
138*4882a593Smuzhiyun /*
139*4882a593Smuzhiyun  * Print out a dependency path from a symbol name
140*4882a593Smuzhiyun  */
print_dep(const char * m,int slen,const char * dir)141*4882a593Smuzhiyun static void print_dep(const char *m, int slen, const char *dir)
142*4882a593Smuzhiyun {
143*4882a593Smuzhiyun 	int c, prev_c = '/', i;
144*4882a593Smuzhiyun 
145*4882a593Smuzhiyun 	xprintf("    $(wildcard %s/", dir);
146*4882a593Smuzhiyun 	for (i = 0; i < slen; i++) {
147*4882a593Smuzhiyun 		c = m[i];
148*4882a593Smuzhiyun 		if (c == '_')
149*4882a593Smuzhiyun 			c = '/';
150*4882a593Smuzhiyun 		else
151*4882a593Smuzhiyun 			c = tolower(c);
152*4882a593Smuzhiyun 		if (c != '/' || prev_c != '/')
153*4882a593Smuzhiyun 			xputchar(c);
154*4882a593Smuzhiyun 		prev_c = c;
155*4882a593Smuzhiyun 	}
156*4882a593Smuzhiyun 	xprintf(".h) \\\n");
157*4882a593Smuzhiyun }
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun struct item {
160*4882a593Smuzhiyun 	struct item	*next;
161*4882a593Smuzhiyun 	unsigned int	len;
162*4882a593Smuzhiyun 	unsigned int	hash;
163*4882a593Smuzhiyun 	char		name[];
164*4882a593Smuzhiyun };
165*4882a593Smuzhiyun 
166*4882a593Smuzhiyun #define HASHSZ 256
167*4882a593Smuzhiyun static struct item *hashtab[HASHSZ];
168*4882a593Smuzhiyun 
strhash(const char * str,unsigned int sz)169*4882a593Smuzhiyun static unsigned int strhash(const char *str, unsigned int sz)
170*4882a593Smuzhiyun {
171*4882a593Smuzhiyun 	/* fnv32 hash */
172*4882a593Smuzhiyun 	unsigned int i, hash = 2166136261U;
173*4882a593Smuzhiyun 
174*4882a593Smuzhiyun 	for (i = 0; i < sz; i++)
175*4882a593Smuzhiyun 		hash = (hash ^ str[i]) * 0x01000193;
176*4882a593Smuzhiyun 	return hash;
177*4882a593Smuzhiyun }
178*4882a593Smuzhiyun 
179*4882a593Smuzhiyun /*
180*4882a593Smuzhiyun  * Lookup a value in the configuration string.
181*4882a593Smuzhiyun  */
is_defined_config(const char * name,int len,unsigned int hash)182*4882a593Smuzhiyun static int is_defined_config(const char *name, int len, unsigned int hash)
183*4882a593Smuzhiyun {
184*4882a593Smuzhiyun 	struct item *aux;
185*4882a593Smuzhiyun 
186*4882a593Smuzhiyun 	for (aux = hashtab[hash % HASHSZ]; aux; aux = aux->next) {
187*4882a593Smuzhiyun 		if (aux->hash == hash && aux->len == len &&
188*4882a593Smuzhiyun 		    memcmp(aux->name, name, len) == 0)
189*4882a593Smuzhiyun 			return 1;
190*4882a593Smuzhiyun 	}
191*4882a593Smuzhiyun 	return 0;
192*4882a593Smuzhiyun }
193*4882a593Smuzhiyun 
194*4882a593Smuzhiyun /*
195*4882a593Smuzhiyun  * Add a new value to the configuration string.
196*4882a593Smuzhiyun  */
define_config(const char * name,int len,unsigned int hash)197*4882a593Smuzhiyun static void define_config(const char *name, int len, unsigned int hash)
198*4882a593Smuzhiyun {
199*4882a593Smuzhiyun 	struct item *aux = malloc(sizeof(*aux) + len);
200*4882a593Smuzhiyun 
201*4882a593Smuzhiyun 	if (!aux) {
202*4882a593Smuzhiyun 		perror("fixdep:malloc");
203*4882a593Smuzhiyun 		exit(1);
204*4882a593Smuzhiyun 	}
205*4882a593Smuzhiyun 	memcpy(aux->name, name, len);
206*4882a593Smuzhiyun 	aux->len = len;
207*4882a593Smuzhiyun 	aux->hash = hash;
208*4882a593Smuzhiyun 	aux->next = hashtab[hash % HASHSZ];
209*4882a593Smuzhiyun 	hashtab[hash % HASHSZ] = aux;
210*4882a593Smuzhiyun }
211*4882a593Smuzhiyun 
212*4882a593Smuzhiyun /*
213*4882a593Smuzhiyun  * Record the use of a CONFIG_* word.
214*4882a593Smuzhiyun  */
use_config(const char * m,int slen)215*4882a593Smuzhiyun static void use_config(const char *m, int slen)
216*4882a593Smuzhiyun {
217*4882a593Smuzhiyun 	unsigned int hash = strhash(m, slen);
218*4882a593Smuzhiyun 
219*4882a593Smuzhiyun 	if (is_defined_config(m, slen, hash))
220*4882a593Smuzhiyun 	    return;
221*4882a593Smuzhiyun 
222*4882a593Smuzhiyun 	define_config(m, slen, hash);
223*4882a593Smuzhiyun 	print_dep(m, slen, "include/config");
224*4882a593Smuzhiyun }
225*4882a593Smuzhiyun 
226*4882a593Smuzhiyun /* test if s ends in sub */
str_ends_with(const char * s,int slen,const char * sub)227*4882a593Smuzhiyun static int str_ends_with(const char *s, int slen, const char *sub)
228*4882a593Smuzhiyun {
229*4882a593Smuzhiyun 	int sublen = strlen(sub);
230*4882a593Smuzhiyun 
231*4882a593Smuzhiyun 	if (sublen > slen)
232*4882a593Smuzhiyun 		return 0;
233*4882a593Smuzhiyun 
234*4882a593Smuzhiyun 	return !memcmp(s + slen - sublen, sub, sublen);
235*4882a593Smuzhiyun }
236*4882a593Smuzhiyun 
parse_config_file(const char * p)237*4882a593Smuzhiyun static void parse_config_file(const char *p)
238*4882a593Smuzhiyun {
239*4882a593Smuzhiyun 	const char *q, *r;
240*4882a593Smuzhiyun 	const char *start = p;
241*4882a593Smuzhiyun 
242*4882a593Smuzhiyun 	while ((p = strstr(p, "CONFIG_"))) {
243*4882a593Smuzhiyun 		if (p > start && (isalnum(p[-1]) || p[-1] == '_')) {
244*4882a593Smuzhiyun 			p += 7;
245*4882a593Smuzhiyun 			continue;
246*4882a593Smuzhiyun 		}
247*4882a593Smuzhiyun 		p += 7;
248*4882a593Smuzhiyun 		q = p;
249*4882a593Smuzhiyun 		while (isalnum(*q) || *q == '_')
250*4882a593Smuzhiyun 			q++;
251*4882a593Smuzhiyun 		if (str_ends_with(p, q - p, "_MODULE"))
252*4882a593Smuzhiyun 			r = q - 7;
253*4882a593Smuzhiyun 		else
254*4882a593Smuzhiyun 			r = q;
255*4882a593Smuzhiyun 		if (r > p)
256*4882a593Smuzhiyun 			use_config(p, r - p);
257*4882a593Smuzhiyun 		p = q;
258*4882a593Smuzhiyun 	}
259*4882a593Smuzhiyun }
260*4882a593Smuzhiyun 
read_file(const char * filename)261*4882a593Smuzhiyun static void *read_file(const char *filename)
262*4882a593Smuzhiyun {
263*4882a593Smuzhiyun 	struct stat st;
264*4882a593Smuzhiyun 	int fd;
265*4882a593Smuzhiyun 	char *buf;
266*4882a593Smuzhiyun 
267*4882a593Smuzhiyun 	fd = open(filename, O_RDONLY);
268*4882a593Smuzhiyun 	if (fd < 0) {
269*4882a593Smuzhiyun 		fprintf(stderr, "fixdep: error opening file: ");
270*4882a593Smuzhiyun 		perror(filename);
271*4882a593Smuzhiyun 		exit(2);
272*4882a593Smuzhiyun 	}
273*4882a593Smuzhiyun 	if (fstat(fd, &st) < 0) {
274*4882a593Smuzhiyun 		fprintf(stderr, "fixdep: error fstat'ing file: ");
275*4882a593Smuzhiyun 		perror(filename);
276*4882a593Smuzhiyun 		exit(2);
277*4882a593Smuzhiyun 	}
278*4882a593Smuzhiyun 	buf = malloc(st.st_size + 1);
279*4882a593Smuzhiyun 	if (!buf) {
280*4882a593Smuzhiyun 		perror("fixdep: malloc");
281*4882a593Smuzhiyun 		exit(2);
282*4882a593Smuzhiyun 	}
283*4882a593Smuzhiyun 	if (read(fd, buf, st.st_size) != st.st_size) {
284*4882a593Smuzhiyun 		perror("fixdep: read");
285*4882a593Smuzhiyun 		exit(2);
286*4882a593Smuzhiyun 	}
287*4882a593Smuzhiyun 	buf[st.st_size] = '\0';
288*4882a593Smuzhiyun 	close(fd);
289*4882a593Smuzhiyun 
290*4882a593Smuzhiyun 	return buf;
291*4882a593Smuzhiyun }
292*4882a593Smuzhiyun 
293*4882a593Smuzhiyun /* Ignore certain dependencies */
is_ignored_file(const char * s,int len)294*4882a593Smuzhiyun static int is_ignored_file(const char *s, int len)
295*4882a593Smuzhiyun {
296*4882a593Smuzhiyun 	return str_ends_with(s, len, "include/generated/autoconf.h") ||
297*4882a593Smuzhiyun 	       str_ends_with(s, len, "include/generated/autoksyms.h");
298*4882a593Smuzhiyun }
299*4882a593Smuzhiyun 
300*4882a593Smuzhiyun /*
301*4882a593Smuzhiyun  * Important: The below generated source_foo.o and deps_foo.o variable
302*4882a593Smuzhiyun  * assignments are parsed not only by make, but also by the rather simple
303*4882a593Smuzhiyun  * parser in scripts/mod/sumversion.c.
304*4882a593Smuzhiyun  */
parse_dep_file(char * m,const char * target)305*4882a593Smuzhiyun static void parse_dep_file(char *m, const char *target)
306*4882a593Smuzhiyun {
307*4882a593Smuzhiyun 	char *p;
308*4882a593Smuzhiyun 	int is_last, is_target;
309*4882a593Smuzhiyun 	int saw_any_target = 0;
310*4882a593Smuzhiyun 	int is_first_dep = 0;
311*4882a593Smuzhiyun 	void *buf;
312*4882a593Smuzhiyun 
313*4882a593Smuzhiyun 	while (1) {
314*4882a593Smuzhiyun 		/* Skip any "white space" */
315*4882a593Smuzhiyun 		while (*m == ' ' || *m == '\\' || *m == '\n')
316*4882a593Smuzhiyun 			m++;
317*4882a593Smuzhiyun 
318*4882a593Smuzhiyun 		if (!*m)
319*4882a593Smuzhiyun 			break;
320*4882a593Smuzhiyun 
321*4882a593Smuzhiyun 		/* Find next "white space" */
322*4882a593Smuzhiyun 		p = m;
323*4882a593Smuzhiyun 		while (*p && *p != ' ' && *p != '\\' && *p != '\n')
324*4882a593Smuzhiyun 			p++;
325*4882a593Smuzhiyun 		is_last = (*p == '\0');
326*4882a593Smuzhiyun 		/* Is the token we found a target name? */
327*4882a593Smuzhiyun 		is_target = (*(p-1) == ':');
328*4882a593Smuzhiyun 		/* Don't write any target names into the dependency file */
329*4882a593Smuzhiyun 		if (is_target) {
330*4882a593Smuzhiyun 			/* The /next/ file is the first dependency */
331*4882a593Smuzhiyun 			is_first_dep = 1;
332*4882a593Smuzhiyun 		} else if (!is_ignored_file(m, p - m)) {
333*4882a593Smuzhiyun 			*p = '\0';
334*4882a593Smuzhiyun 
335*4882a593Smuzhiyun 			/*
336*4882a593Smuzhiyun 			 * Do not list the source file as dependency, so that
337*4882a593Smuzhiyun 			 * kbuild is not confused if a .c file is rewritten
338*4882a593Smuzhiyun 			 * into .S or vice versa. Storing it in source_* is
339*4882a593Smuzhiyun 			 * needed for modpost to compute srcversions.
340*4882a593Smuzhiyun 			 */
341*4882a593Smuzhiyun 			if (is_first_dep) {
342*4882a593Smuzhiyun 				/*
343*4882a593Smuzhiyun 				 * If processing the concatenation of multiple
344*4882a593Smuzhiyun 				 * dependency files, only process the first
345*4882a593Smuzhiyun 				 * target name, which will be the original
346*4882a593Smuzhiyun 				 * source name, and ignore any other target
347*4882a593Smuzhiyun 				 * names, which will be intermediate temporary
348*4882a593Smuzhiyun 				 * files.
349*4882a593Smuzhiyun 				 */
350*4882a593Smuzhiyun 				if (!saw_any_target) {
351*4882a593Smuzhiyun 					saw_any_target = 1;
352*4882a593Smuzhiyun 					xprintf("source_%s := %s\n\n",
353*4882a593Smuzhiyun 						target, m);
354*4882a593Smuzhiyun 					xprintf("deps_%s := \\\n", target);
355*4882a593Smuzhiyun 				}
356*4882a593Smuzhiyun 				is_first_dep = 0;
357*4882a593Smuzhiyun 			} else {
358*4882a593Smuzhiyun 				xprintf("  %s \\\n", m);
359*4882a593Smuzhiyun 			}
360*4882a593Smuzhiyun 
361*4882a593Smuzhiyun 			buf = read_file(m);
362*4882a593Smuzhiyun 			parse_config_file(buf);
363*4882a593Smuzhiyun 			free(buf);
364*4882a593Smuzhiyun 		}
365*4882a593Smuzhiyun 
366*4882a593Smuzhiyun 		if (is_last)
367*4882a593Smuzhiyun 			break;
368*4882a593Smuzhiyun 
369*4882a593Smuzhiyun 		/*
370*4882a593Smuzhiyun 		 * Start searching for next token immediately after the first
371*4882a593Smuzhiyun 		 * "whitespace" character that follows this token.
372*4882a593Smuzhiyun 		 */
373*4882a593Smuzhiyun 		m = p + 1;
374*4882a593Smuzhiyun 	}
375*4882a593Smuzhiyun 
376*4882a593Smuzhiyun 	if (!saw_any_target) {
377*4882a593Smuzhiyun 		fprintf(stderr, "fixdep: parse error; no targets found\n");
378*4882a593Smuzhiyun 		exit(1);
379*4882a593Smuzhiyun 	}
380*4882a593Smuzhiyun 
381*4882a593Smuzhiyun 	xprintf("\n%s: $(deps_%s)\n\n", target, target);
382*4882a593Smuzhiyun 	xprintf("$(deps_%s):\n", target);
383*4882a593Smuzhiyun }
384*4882a593Smuzhiyun 
main(int argc,char * argv[])385*4882a593Smuzhiyun int main(int argc, char *argv[])
386*4882a593Smuzhiyun {
387*4882a593Smuzhiyun 	const char *depfile, *target, *cmdline;
388*4882a593Smuzhiyun 	void *buf;
389*4882a593Smuzhiyun 
390*4882a593Smuzhiyun 	if (argc != 4)
391*4882a593Smuzhiyun 		usage();
392*4882a593Smuzhiyun 
393*4882a593Smuzhiyun 	depfile = argv[1];
394*4882a593Smuzhiyun 	target = argv[2];
395*4882a593Smuzhiyun 	cmdline = argv[3];
396*4882a593Smuzhiyun 
397*4882a593Smuzhiyun 	xprintf("cmd_%s := %s\n\n", target, cmdline);
398*4882a593Smuzhiyun 
399*4882a593Smuzhiyun 	buf = read_file(depfile);
400*4882a593Smuzhiyun 	parse_dep_file(buf, target);
401*4882a593Smuzhiyun 	free(buf);
402*4882a593Smuzhiyun 
403*4882a593Smuzhiyun 	return 0;
404*4882a593Smuzhiyun }
405