xref: /linux-6.15/scripts/basic/fixdep.c (revision 87d660f0)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * "Optimize" a list of dependencies as spit out by gcc -MD
31da177e4SLinus Torvalds  * for the kernel build
41da177e4SLinus Torvalds  * ===========================================================================
51da177e4SLinus Torvalds  *
61da177e4SLinus Torvalds  * Author       Kai Germaschewski
71da177e4SLinus Torvalds  * Copyright    2002 by Kai Germaschewski  <[email protected]>
81da177e4SLinus Torvalds  *
91da177e4SLinus Torvalds  * This software may be used and distributed according to the terms
101da177e4SLinus Torvalds  * of the GNU General Public License, incorporated herein by reference.
111da177e4SLinus Torvalds  *
121da177e4SLinus Torvalds  *
131da177e4SLinus Torvalds  * Introduction:
141da177e4SLinus Torvalds  *
151da177e4SLinus Torvalds  * gcc produces a very nice and correct list of dependencies which
161da177e4SLinus Torvalds  * tells make when to remake a file.
171da177e4SLinus Torvalds  *
181da177e4SLinus Torvalds  * To use this list as-is however has the drawback that virtually
19264a2683SSam Ravnborg  * every file in the kernel includes autoconf.h.
201da177e4SLinus Torvalds  *
21264a2683SSam Ravnborg  * If the user re-runs make *config, autoconf.h will be
221da177e4SLinus Torvalds  * regenerated.  make notices that and will rebuild every file which
231da177e4SLinus Torvalds  * includes autoconf.h, i.e. basically all files. This is extremely
241da177e4SLinus Torvalds  * annoying if the user just changed CONFIG_HIS_DRIVER from n to m.
251da177e4SLinus Torvalds  *
261da177e4SLinus Torvalds  * So we play the same trick that "mkdep" played before. We replace
27264a2683SSam Ravnborg  * the dependency on autoconf.h by a dependency on every config
284e433fc4SCao jin  * option which is mentioned in any of the listed prerequisites.
291da177e4SLinus Torvalds  *
30c21b1e4dSJan Beulich  * kconfig populates a tree in include/config/ with an empty file
31c21b1e4dSJan Beulich  * for each config symbol and when the configuration is updated
32c21b1e4dSJan Beulich  * the files representing changed config options are touched
33c21b1e4dSJan Beulich  * which then let make pick up the changes and the files that use
34c21b1e4dSJan Beulich  * the config symbols are rebuilt.
351da177e4SLinus Torvalds  *
361da177e4SLinus Torvalds  * So if the user changes his CONFIG_HIS_DRIVER option, only the objects
374e433fc4SCao jin  * which depend on "include/config/his/driver.h" will be rebuilt,
381da177e4SLinus Torvalds  * so most likely only his driver ;-)
391da177e4SLinus Torvalds  *
401da177e4SLinus Torvalds  * The idea above dates, by the way, back to Michael E Chastain, AFAIK.
411da177e4SLinus Torvalds  *
421da177e4SLinus Torvalds  * So to get dependencies right, there are two issues:
431da177e4SLinus Torvalds  * o if any of the files the compiler read changed, we need to rebuild
441da177e4SLinus Torvalds  * o if the command line given to the compile the file changed, we
451da177e4SLinus Torvalds  *   better rebuild as well.
461da177e4SLinus Torvalds  *
471da177e4SLinus Torvalds  * The former is handled by using the -MD output, the later by saving
481da177e4SLinus Torvalds  * the command line used to compile the old object and comparing it
491da177e4SLinus Torvalds  * to the one we would now use.
501da177e4SLinus Torvalds  *
511da177e4SLinus Torvalds  * Again, also this idea is pretty old and has been discussed on
521da177e4SLinus Torvalds  * kbuild-devel a long time ago. I don't have a sensibly working
531da177e4SLinus Torvalds  * internet connection right now, so I rather don't mention names
541da177e4SLinus Torvalds  * without double checking.
551da177e4SLinus Torvalds  *
561da177e4SLinus Torvalds  * This code here has been based partially based on mkdep.c, which
571da177e4SLinus Torvalds  * says the following about its history:
581da177e4SLinus Torvalds  *
591da177e4SLinus Torvalds  *   Copyright abandoned, Michael Chastain, <mailto:[email protected]>.
601da177e4SLinus Torvalds  *   This is a C version of syncdep.pl by Werner Almesberger.
611da177e4SLinus Torvalds  *
621da177e4SLinus Torvalds  *
631da177e4SLinus Torvalds  * It is invoked as
641da177e4SLinus Torvalds  *
651da177e4SLinus Torvalds  *   fixdep <depfile> <target> <cmdline>
661da177e4SLinus Torvalds  *
671da177e4SLinus Torvalds  * and will read the dependency file <depfile>
681da177e4SLinus Torvalds  *
691da177e4SLinus Torvalds  * The transformed dependency snipped is written to stdout.
701da177e4SLinus Torvalds  *
711da177e4SLinus Torvalds  * It first generates a line
721da177e4SLinus Torvalds  *
731da177e4SLinus Torvalds  *   cmd_<target> = <cmdline>
741da177e4SLinus Torvalds  *
751da177e4SLinus Torvalds  * and then basically copies the .<target>.d file to stdout, in the
76264a2683SSam Ravnborg  * process filtering out the dependency on autoconf.h and adding
771da177e4SLinus Torvalds  * dependencies on include/config/my/option.h for every
784e433fc4SCao jin  * CONFIG_MY_OPTION encountered in any of the prerequisites.
791da177e4SLinus Torvalds  *
80dee81e98SAlexey Dobriyan  * We don't even try to really parse the header files, but
811da177e4SLinus Torvalds  * merely grep, i.e. if CONFIG_FOO is mentioned in a comment, it will
821da177e4SLinus Torvalds  * be picked up as well. It's not a problem with respect to
831da177e4SLinus Torvalds  * correctness, since that can only give too many dependencies, thus
841da177e4SLinus Torvalds  * we cannot miss a rebuild. Since people tend to not mention totally
851da177e4SLinus Torvalds  * unrelated CONFIG_ options all over the place, it's not an
861da177e4SLinus Torvalds  * efficiency problem either.
871da177e4SLinus Torvalds  *
881da177e4SLinus Torvalds  * (Note: it'd be easy to port over the complete mkdep state machine,
891da177e4SLinus Torvalds  *  but I don't think the added complexity is worth it)
901da177e4SLinus Torvalds  */
911da177e4SLinus Torvalds 
921da177e4SLinus Torvalds #include <sys/types.h>
931da177e4SLinus Torvalds #include <sys/stat.h>
941da177e4SLinus Torvalds #include <unistd.h>
951da177e4SLinus Torvalds #include <fcntl.h>
961da177e4SLinus Torvalds #include <string.h>
976f9ac9f4SMasahiro Yamada #include <stdarg.h>
981da177e4SLinus Torvalds #include <stdlib.h>
991da177e4SLinus Torvalds #include <stdio.h>
1001da177e4SLinus Torvalds #include <ctype.h>
1011da177e4SLinus Torvalds 
1024356f489STrevor Keith static void usage(void)
1031da177e4SLinus Torvalds {
104bbda5ec6SMasahiro Yamada 	fprintf(stderr, "Usage: fixdep <depfile> <target> <cmdline>\n");
1051da177e4SLinus Torvalds 	exit(1);
1061da177e4SLinus Torvalds }
1071da177e4SLinus Torvalds 
1084d99f93bSSam Ravnborg /*
1096f9ac9f4SMasahiro Yamada  * In the intended usage of this program, the stdout is redirected to .*.cmd
1106f9ac9f4SMasahiro Yamada  * files. The return value of printf() and putchar() must be checked to catch
1116f9ac9f4SMasahiro Yamada  * any error, e.g. "No space left on device".
1126f9ac9f4SMasahiro Yamada  */
1136f9ac9f4SMasahiro Yamada static void xprintf(const char *format, ...)
1146f9ac9f4SMasahiro Yamada {
1156f9ac9f4SMasahiro Yamada 	va_list ap;
1166f9ac9f4SMasahiro Yamada 	int ret;
1176f9ac9f4SMasahiro Yamada 
1186f9ac9f4SMasahiro Yamada 	va_start(ap, format);
1196f9ac9f4SMasahiro Yamada 	ret = vprintf(format, ap);
1206f9ac9f4SMasahiro Yamada 	if (ret < 0) {
1216f9ac9f4SMasahiro Yamada 		perror("fixdep");
1226f9ac9f4SMasahiro Yamada 		exit(1);
1236f9ac9f4SMasahiro Yamada 	}
1246f9ac9f4SMasahiro Yamada 	va_end(ap);
1256f9ac9f4SMasahiro Yamada }
1266f9ac9f4SMasahiro Yamada 
1276f9ac9f4SMasahiro Yamada static void xputchar(int c)
1286f9ac9f4SMasahiro Yamada {
1296f9ac9f4SMasahiro Yamada 	int ret;
1306f9ac9f4SMasahiro Yamada 
1316f9ac9f4SMasahiro Yamada 	ret = putchar(c);
1326f9ac9f4SMasahiro Yamada 	if (ret == EOF) {
1336f9ac9f4SMasahiro Yamada 		perror("fixdep");
1346f9ac9f4SMasahiro Yamada 		exit(1);
1356f9ac9f4SMasahiro Yamada 	}
1366f9ac9f4SMasahiro Yamada }
1376f9ac9f4SMasahiro Yamada 
1386f9ac9f4SMasahiro Yamada /*
139d8329e35SNicolas Pitre  * Print out a dependency path from a symbol name
140d8329e35SNicolas Pitre  */
141fbfa9be9SMasahiro Yamada static void print_dep(const char *m, int slen, const char *dir)
142d8329e35SNicolas Pitre {
143b3aa58d2SNicolas Pitre 	int c, prev_c = '/', i;
144d8329e35SNicolas Pitre 
1456f9ac9f4SMasahiro Yamada 	xprintf("    $(wildcard %s/", dir);
146d8329e35SNicolas Pitre 	for (i = 0; i < slen; i++) {
147d8329e35SNicolas Pitre 		c = m[i];
148d8329e35SNicolas Pitre 		if (c == '_')
149d8329e35SNicolas Pitre 			c = '/';
150d8329e35SNicolas Pitre 		else
151d8329e35SNicolas Pitre 			c = tolower(c);
152b3aa58d2SNicolas Pitre 		if (c != '/' || prev_c != '/')
1536f9ac9f4SMasahiro Yamada 			xputchar(c);
154b3aa58d2SNicolas Pitre 		prev_c = c;
155d8329e35SNicolas Pitre 	}
1566f9ac9f4SMasahiro Yamada 	xprintf(".h) \\\n");
157d8329e35SNicolas Pitre }
158d8329e35SNicolas Pitre 
1598af27e1dSEric Dumazet struct item {
1608af27e1dSEric Dumazet 	struct item	*next;
1618af27e1dSEric Dumazet 	unsigned int	len;
1628af27e1dSEric Dumazet 	unsigned int	hash;
1638af27e1dSEric Dumazet 	char		name[0];
1648af27e1dSEric Dumazet };
1651da177e4SLinus Torvalds 
1668af27e1dSEric Dumazet #define HASHSZ 256
1678af27e1dSEric Dumazet static struct item *hashtab[HASHSZ];
1688af27e1dSEric Dumazet 
1698af27e1dSEric Dumazet static unsigned int strhash(const char *str, unsigned int sz)
1701da177e4SLinus Torvalds {
1718af27e1dSEric Dumazet 	/* fnv32 hash */
1728af27e1dSEric Dumazet 	unsigned int i, hash = 2166136261U;
1731da177e4SLinus Torvalds 
1748af27e1dSEric Dumazet 	for (i = 0; i < sz; i++)
1758af27e1dSEric Dumazet 		hash = (hash ^ str[i]) * 0x01000193;
1768af27e1dSEric Dumazet 	return hash;
1778af27e1dSEric Dumazet }
1781da177e4SLinus Torvalds 
1791da177e4SLinus Torvalds /*
1801da177e4SLinus Torvalds  * Lookup a value in the configuration string.
1811da177e4SLinus Torvalds  */
1828af27e1dSEric Dumazet static int is_defined_config(const char *name, int len, unsigned int hash)
1831da177e4SLinus Torvalds {
1848af27e1dSEric Dumazet 	struct item *aux;
1858af27e1dSEric Dumazet 
1868af27e1dSEric Dumazet 	for (aux = hashtab[hash % HASHSZ]; aux; aux = aux->next) {
1878af27e1dSEric Dumazet 		if (aux->hash == hash && aux->len == len &&
1888af27e1dSEric Dumazet 		    memcmp(aux->name, name, len) == 0)
1891da177e4SLinus Torvalds 			return 1;
1901da177e4SLinus Torvalds 	}
1911da177e4SLinus Torvalds 	return 0;
1921da177e4SLinus Torvalds }
1931da177e4SLinus Torvalds 
1941da177e4SLinus Torvalds /*
1951da177e4SLinus Torvalds  * Add a new value to the configuration string.
1961da177e4SLinus Torvalds  */
1978af27e1dSEric Dumazet static void define_config(const char *name, int len, unsigned int hash)
1981da177e4SLinus Torvalds {
1998af27e1dSEric Dumazet 	struct item *aux = malloc(sizeof(*aux) + len);
2001da177e4SLinus Torvalds 
2018af27e1dSEric Dumazet 	if (!aux) {
2028af27e1dSEric Dumazet 		perror("fixdep:malloc");
2038af27e1dSEric Dumazet 		exit(1);
2048af27e1dSEric Dumazet 	}
2058af27e1dSEric Dumazet 	memcpy(aux->name, name, len);
2068af27e1dSEric Dumazet 	aux->len = len;
2078af27e1dSEric Dumazet 	aux->hash = hash;
2088af27e1dSEric Dumazet 	aux->next = hashtab[hash % HASHSZ];
2098af27e1dSEric Dumazet 	hashtab[hash % HASHSZ] = aux;
2101da177e4SLinus Torvalds }
2111da177e4SLinus Torvalds 
2121da177e4SLinus Torvalds /*
2131da177e4SLinus Torvalds  * Record the use of a CONFIG_* word.
2141da177e4SLinus Torvalds  */
2158af27e1dSEric Dumazet static void use_config(const char *m, int slen)
2161da177e4SLinus Torvalds {
2178af27e1dSEric Dumazet 	unsigned int hash = strhash(m, slen);
2181da177e4SLinus Torvalds 
2198af27e1dSEric Dumazet 	if (is_defined_config(m, slen, hash))
2201da177e4SLinus Torvalds 	    return;
2211da177e4SLinus Torvalds 
2228af27e1dSEric Dumazet 	define_config(m, slen, hash);
223fbfa9be9SMasahiro Yamada 	print_dep(m, slen, "include/config");
2241da177e4SLinus Torvalds }
2251da177e4SLinus Torvalds 
226d8329e35SNicolas Pitre /* test if s ends in sub */
22787b95a81SMasahiro Yamada static int str_ends_with(const char *s, int slen, const char *sub)
2281da177e4SLinus Torvalds {
2291da177e4SLinus Torvalds 	int sublen = strlen(sub);
2301da177e4SLinus Torvalds 
2311da177e4SLinus Torvalds 	if (sublen > slen)
23287b95a81SMasahiro Yamada 		return 0;
2331da177e4SLinus Torvalds 
23487b95a81SMasahiro Yamada 	return !memcmp(s + slen - sublen, sub, sublen);
2351da177e4SLinus Torvalds }
2361da177e4SLinus Torvalds 
237ab9ce9feSMasahiro Yamada static void parse_config_file(const char *p)
238ab9ce9feSMasahiro Yamada {
239ab9ce9feSMasahiro Yamada 	const char *q, *r;
2405b8ad96dSRasmus Villemoes 	const char *start = p;
241ab9ce9feSMasahiro Yamada 
242ab9ce9feSMasahiro Yamada 	while ((p = strstr(p, "CONFIG_"))) {
2435b8ad96dSRasmus Villemoes 		if (p > start && (isalnum(p[-1]) || p[-1] == '_')) {
2445b8ad96dSRasmus Villemoes 			p += 7;
2455b8ad96dSRasmus Villemoes 			continue;
2465b8ad96dSRasmus Villemoes 		}
247ab9ce9feSMasahiro Yamada 		p += 7;
248ab9ce9feSMasahiro Yamada 		q = p;
249ab9ce9feSMasahiro Yamada 		while (*q && (isalnum(*q) || *q == '_'))
250ab9ce9feSMasahiro Yamada 			q++;
251ab9ce9feSMasahiro Yamada 		if (str_ends_with(p, q - p, "_MODULE"))
252ab9ce9feSMasahiro Yamada 			r = q - 7;
253ab9ce9feSMasahiro Yamada 		else
254ab9ce9feSMasahiro Yamada 			r = q;
255ab9ce9feSMasahiro Yamada 		if (r > p)
256ab9ce9feSMasahiro Yamada 			use_config(p, r - p);
257ab9ce9feSMasahiro Yamada 		p = q;
258ab9ce9feSMasahiro Yamada 	}
259ab9ce9feSMasahiro Yamada }
260ab9ce9feSMasahiro Yamada 
2614003fd80SMasahiro Yamada static void *read_file(const char *filename)
2621da177e4SLinus Torvalds {
2631da177e4SLinus Torvalds 	struct stat st;
2641da177e4SLinus Torvalds 	int fd;
2654003fd80SMasahiro Yamada 	char *buf;
2661da177e4SLinus Torvalds 
2671da177e4SLinus Torvalds 	fd = open(filename, O_RDONLY);
2681da177e4SLinus Torvalds 	if (fd < 0) {
2694003fd80SMasahiro Yamada 		fprintf(stderr, "fixdep: error opening file: ");
2701da177e4SLinus Torvalds 		perror(filename);
2711da177e4SLinus Torvalds 		exit(2);
2721da177e4SLinus Torvalds 	}
27346fe94adSTom Rini 	if (fstat(fd, &st) < 0) {
2744003fd80SMasahiro Yamada 		fprintf(stderr, "fixdep: error fstat'ing file: ");
27546fe94adSTom Rini 		perror(filename);
27646fe94adSTom Rini 		exit(2);
27746fe94adSTom Rini 	}
2784003fd80SMasahiro Yamada 	buf = malloc(st.st_size + 1);
2794003fd80SMasahiro Yamada 	if (!buf) {
280dee81e98SAlexey Dobriyan 		perror("fixdep: malloc");
2817c2ec43aSLukas Bulwahn 		exit(2);
2821da177e4SLinus Torvalds 	}
2834003fd80SMasahiro Yamada 	if (read(fd, buf, st.st_size) != st.st_size) {
284dee81e98SAlexey Dobriyan 		perror("fixdep: read");
2857c2ec43aSLukas Bulwahn 		exit(2);
286dee81e98SAlexey Dobriyan 	}
2874003fd80SMasahiro Yamada 	buf[st.st_size] = '\0';
288dee81e98SAlexey Dobriyan 	close(fd);
289dee81e98SAlexey Dobriyan 
2904003fd80SMasahiro Yamada 	return buf;
2911da177e4SLinus Torvalds }
2921da177e4SLinus Torvalds 
29387b95a81SMasahiro Yamada /* Ignore certain dependencies */
29487b95a81SMasahiro Yamada static int is_ignored_file(const char *s, int len)
29587b95a81SMasahiro Yamada {
29687b95a81SMasahiro Yamada 	return str_ends_with(s, len, "include/generated/autoconf.h") ||
297*87d660f0SMasahiro Yamada 	       str_ends_with(s, len, "include/generated/autoksyms.h");
29887b95a81SMasahiro Yamada }
29987b95a81SMasahiro Yamada 
3007840fea2SMichal Marek /*
3017840fea2SMichal Marek  * Important: The below generated source_foo.o and deps_foo.o variable
3027840fea2SMichal Marek  * assignments are parsed not only by make, but also by the rather simple
3037840fea2SMichal Marek  * parser in scripts/mod/sumversion.c.
3047840fea2SMichal Marek  */
305bbda5ec6SMasahiro Yamada static void parse_dep_file(char *m, const char *target)
3061da177e4SLinus Torvalds {
30748b9d03cSJ.A. Magallon 	char *p;
30801b5cbe7SMasahiro Yamada 	int is_last, is_target;
3092ab8a996SStephen Warren 	int saw_any_target = 0;
3102ab8a996SStephen Warren 	int is_first_dep = 0;
3114003fd80SMasahiro Yamada 	void *buf;
3121da177e4SLinus Torvalds 
31301b5cbe7SMasahiro Yamada 	while (1) {
3142ab8a996SStephen Warren 		/* Skip any "white space" */
31501b5cbe7SMasahiro Yamada 		while (*m == ' ' || *m == '\\' || *m == '\n')
3161da177e4SLinus Torvalds 			m++;
31701b5cbe7SMasahiro Yamada 
31801b5cbe7SMasahiro Yamada 		if (!*m)
31901b5cbe7SMasahiro Yamada 			break;
32001b5cbe7SMasahiro Yamada 
3212ab8a996SStephen Warren 		/* Find next "white space" */
3221da177e4SLinus Torvalds 		p = m;
32301b5cbe7SMasahiro Yamada 		while (*p && *p != ' ' && *p != '\\' && *p != '\n')
3241da177e4SLinus Torvalds 			p++;
32501b5cbe7SMasahiro Yamada 		is_last = (*p == '\0');
3262ab8a996SStephen Warren 		/* Is the token we found a target name? */
3272ab8a996SStephen Warren 		is_target = (*(p-1) == ':');
3282ab8a996SStephen Warren 		/* Don't write any target names into the dependency file */
3292ab8a996SStephen Warren 		if (is_target) {
3302ab8a996SStephen Warren 			/* The /next/ file is the first dependency */
3312ab8a996SStephen Warren 			is_first_dep = 1;
33287b95a81SMasahiro Yamada 		} else if (!is_ignored_file(m, p - m)) {
333ccfe7887SMasahiro Yamada 			*p = '\0';
3342ab8a996SStephen Warren 
335b7bd1821SMichal Marek 			/*
33687b95a81SMasahiro Yamada 			 * Do not list the source file as dependency, so that
33787b95a81SMasahiro Yamada 			 * kbuild is not confused if a .c file is rewritten
33887b95a81SMasahiro Yamada 			 * into .S or vice versa. Storing it in source_* is
33987b95a81SMasahiro Yamada 			 * needed for modpost to compute srcversions.
340b7bd1821SMichal Marek 			 */
3412ab8a996SStephen Warren 			if (is_first_dep) {
3422ab8a996SStephen Warren 				/*
34387b95a81SMasahiro Yamada 				 * If processing the concatenation of multiple
34487b95a81SMasahiro Yamada 				 * dependency files, only process the first
34587b95a81SMasahiro Yamada 				 * target name, which will be the original
34687b95a81SMasahiro Yamada 				 * source name, and ignore any other target
34787b95a81SMasahiro Yamada 				 * names, which will be intermediate temporary
3482ab8a996SStephen Warren 				 * files.
3492ab8a996SStephen Warren 				 */
3502ab8a996SStephen Warren 				if (!saw_any_target) {
3512ab8a996SStephen Warren 					saw_any_target = 1;
3526f9ac9f4SMasahiro Yamada 					xprintf("source_%s := %s\n\n",
353ccfe7887SMasahiro Yamada 						target, m);
3546f9ac9f4SMasahiro Yamada 					xprintf("deps_%s := \\\n", target);
3552ab8a996SStephen Warren 				}
3562ab8a996SStephen Warren 				is_first_dep = 0;
35787b95a81SMasahiro Yamada 			} else {
3586f9ac9f4SMasahiro Yamada 				xprintf("  %s \\\n", m);
35987b95a81SMasahiro Yamada 			}
3604003fd80SMasahiro Yamada 
361ccfe7887SMasahiro Yamada 			buf = read_file(m);
3624003fd80SMasahiro Yamada 			parse_config_file(buf);
3634003fd80SMasahiro Yamada 			free(buf);
3641da177e4SLinus Torvalds 		}
36501b5cbe7SMasahiro Yamada 
36601b5cbe7SMasahiro Yamada 		if (is_last)
36701b5cbe7SMasahiro Yamada 			break;
36801b5cbe7SMasahiro Yamada 
3692ab8a996SStephen Warren 		/*
3702ab8a996SStephen Warren 		 * Start searching for next token immediately after the first
3712ab8a996SStephen Warren 		 * "whitespace" character that follows this token.
3722ab8a996SStephen Warren 		 */
3731da177e4SLinus Torvalds 		m = p + 1;
3741da177e4SLinus Torvalds 	}
3752ab8a996SStephen Warren 
3762ab8a996SStephen Warren 	if (!saw_any_target) {
3772ab8a996SStephen Warren 		fprintf(stderr, "fixdep: parse error; no targets found\n");
3782ab8a996SStephen Warren 		exit(1);
3792ab8a996SStephen Warren 	}
3802ab8a996SStephen Warren 
3816f9ac9f4SMasahiro Yamada 	xprintf("\n%s: $(deps_%s)\n\n", target, target);
3826f9ac9f4SMasahiro Yamada 	xprintf("$(deps_%s):\n", target);
3831da177e4SLinus Torvalds }
3841da177e4SLinus Torvalds 
3851da177e4SLinus Torvalds int main(int argc, char *argv[])
3861da177e4SLinus Torvalds {
3875d1ef76fSMasahiro Yamada 	const char *depfile, *target, *cmdline;
3884003fd80SMasahiro Yamada 	void *buf;
3894003fd80SMasahiro Yamada 
390bbda5ec6SMasahiro Yamada 	if (argc != 4)
3911da177e4SLinus Torvalds 		usage();
3921da177e4SLinus Torvalds 
3931da177e4SLinus Torvalds 	depfile = argv[1];
3941da177e4SLinus Torvalds 	target = argv[2];
3951da177e4SLinus Torvalds 	cmdline = argv[3];
3961da177e4SLinus Torvalds 
3976f9ac9f4SMasahiro Yamada 	xprintf("cmd_%s := %s\n\n", target, cmdline);
3984003fd80SMasahiro Yamada 
3994003fd80SMasahiro Yamada 	buf = read_file(depfile);
400bbda5ec6SMasahiro Yamada 	parse_dep_file(buf, target);
4014003fd80SMasahiro Yamada 	free(buf);
4021da177e4SLinus Torvalds 
4031da177e4SLinus Torvalds 	return 0;
4041da177e4SLinus Torvalds }
405