Commit 33ec0479 authored by Kai Germaschewski's avatar Kai Germaschewski

kbuild: Pass <target> to fixdep

cpp -MD guesses the target name from the source file name, but not
always correctly, e.g. when compiling fixdep, it generates prequisites
for fixdep.o instead of fixdep.
 
fixdep now fixes up the -MD generated output to contain the right target,
which is the one we pass on the command line.
parent ea253a53
...@@ -415,7 +415,7 @@ if_changed_dep = $(if $(strip $? \ ...@@ -415,7 +415,7 @@ if_changed_dep = $(if $(strip $? \
@set -e; \ @set -e; \
$(if $($(quiet)cmd_$(1)),echo ' $($(quiet)cmd_$(1))';) \ $(if $($(quiet)cmd_$(1)),echo ' $($(quiet)cmd_$(1))';) \
$(cmd_$(1)); \ $(cmd_$(1)); \
$(TOPDIR)/scripts/fixdep $(subst /,_,$@) $(TOPDIR) '$(cmd_$(1))' > .$(subst /,_,$@).tmp; \ $(TOPDIR)/scripts/fixdep .$(subst /,_,$@).d $@ $(TOPDIR) '$(cmd_$(1))' > .$(subst /,_,$@).tmp; \
rm -f .$(subst /,_,$@).d; \ rm -f .$(subst /,_,$@).d; \
mv -f .$(subst /,_,$@).tmp .$(subst /,_,$@).cmd ) mv -f .$(subst /,_,$@).tmp .$(subst /,_,$@).cmd )
......
...@@ -61,9 +61,9 @@ ...@@ -61,9 +61,9 @@
* *
* It is invoked as * It is invoked as
* *
* fixdep <target> <topdir> <cmdline> * fixdep <depfile> <target> <topdir> <cmdline>
* *
* and will read the dependency file ".<target>.d". * and will read the dependency file <depfile>
* *
* The transformed dependency snipped is written to stdout. * The transformed dependency snipped is written to stdout.
* *
...@@ -112,29 +112,20 @@ ...@@ -112,29 +112,20 @@
#define INT_FIG_ ntohl(0x4649475f) #define INT_FIG_ ntohl(0x4649475f)
char *topdir; char *topdir;
char *target;
char *depfile;
char *cmdline;
void usage(void) void usage(void)
{ {
fprintf(stderr, "Usage: fixdep <target> <topdir> <cmdline>\n"); fprintf(stderr, "Usage: fixdep <depfile> <target> <topdir> <cmdline>\n");
exit(1); exit(1);
} }
void print_cmdline(char *target, char *cmdline) void print_cmdline(void)
{ {
char *s = strdup(target); printf("cmd_%s := %s\n\n", target, cmdline);
char *p = s;
if (!s) {
fprintf(stderr, "no mem!\n");
exit(2);
}
while ((p = strchr(p,'/')))
*p = '_';
printf("cmd_%s := %s\n\n", s, cmdline);
free(s);
} }
char * str_config = NULL; char * str_config = NULL;
...@@ -297,11 +288,11 @@ void parse_dep_file(void *map, size_t len) ...@@ -297,11 +288,11 @@ void parse_dep_file(void *map, size_t len)
p = strchr(m, ':'); p = strchr(m, ':');
if (!p) { if (!p) {
fprintf(stderr, "parse error at %d", __LINE__); fprintf(stderr, "fixdep: parse error\n");
exit(1); exit(1);
} }
memcpy(s, m, p-m); s[p-m] = 0; memcpy(s, m, p-m); s[p-m] = 0;
printf("%s: \\\n", s); printf("%s: \\\n", target);
m = p+1; m = p+1;
clear_config(); clear_config();
...@@ -326,22 +317,20 @@ void parse_dep_file(void *map, size_t len) ...@@ -326,22 +317,20 @@ void parse_dep_file(void *map, size_t len)
printf("\n"); printf("\n");
} }
void print_deps(char *target) void print_deps(void)
{ {
char filename[PATH_MAX];
struct stat st; struct stat st;
int fd; int fd;
void *map; void *map;
sprintf(filename, ".%s.d", target); fd = open(depfile, O_RDONLY);
fd = open(filename, O_RDONLY);
if (fd < 0) { if (fd < 0) {
perror(filename); perror(depfile);
exit(2); exit(2);
} }
fstat(fd, &st); fstat(fd, &st);
if (st.st_size == 0) { if (st.st_size == 0) {
fprintf(stderr,"%s is empty\n",filename); fprintf(stderr,"fixdep: %s is empty\n",depfile);
close(fd); close(fd);
return; return;
} }
...@@ -362,7 +351,7 @@ void traps(void) ...@@ -362,7 +351,7 @@ void traps(void)
char *test = "CONF"; char *test = "CONF";
if (*(int *)test != INT_CONF) { if (*(int *)test != INT_CONF) {
fprintf(stderr, "sizeof(int) != 4 or wrong endianess? %#x\n", fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
*(int *)test); *(int *)test);
exit(2); exit(2);
} }
...@@ -370,19 +359,18 @@ void traps(void) ...@@ -370,19 +359,18 @@ void traps(void)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
char *target, *cmdline;
traps(); traps();
if (argc != 4) if (argc != 5)
usage(); usage();
target = argv[1]; depfile = argv[1];
topdir = argv[2]; target = argv[2];
cmdline = argv[3]; topdir = argv[3];
cmdline = argv[4];
print_cmdline(target, cmdline); print_cmdline();
print_deps(target); print_deps();
return 0; return 0;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment