|
@@ -104,20 +104,12 @@
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
#include <sys/stat.h>
|
|
|
-#include <sys/mman.h>
|
|
|
#include <unistd.h>
|
|
|
#include <fcntl.h>
|
|
|
#include <string.h>
|
|
|
#include <stdlib.h>
|
|
|
#include <stdio.h>
|
|
|
-#include <limits.h>
|
|
|
#include <ctype.h>
|
|
|
-#include <arpa/inet.h>
|
|
|
-
|
|
|
-int insert_extra_deps;
|
|
|
-char *target;
|
|
|
-char *depfile;
|
|
|
-char *cmdline;
|
|
|
|
|
|
static void usage(void)
|
|
|
{
|
|
@@ -126,14 +118,6 @@ static void usage(void)
|
|
|
exit(1);
|
|
|
}
|
|
|
|
|
|
-/*
|
|
|
- * Print out the commandline prefixed with cmd_<target filename> :=
|
|
|
- */
|
|
|
-static void print_cmdline(void)
|
|
|
-{
|
|
|
- printf("cmd_%s := %s\n\n", target, cmdline);
|
|
|
-}
|
|
|
-
|
|
|
/*
|
|
|
* Print out a dependency path from a symbol name
|
|
|
*/
|
|
@@ -155,16 +139,16 @@ static void print_config(const char *m, int slen)
|
|
|
|
|
|
static void do_extra_deps(void)
|
|
|
{
|
|
|
- if (insert_extra_deps) {
|
|
|
- char buf[80];
|
|
|
- while(fgets(buf, sizeof(buf), stdin)) {
|
|
|
- int len = strlen(buf);
|
|
|
- if (len < 2 || buf[len-1] != '\n') {
|
|
|
- fprintf(stderr, "fixdep: bad data on stdin\n");
|
|
|
- exit(1);
|
|
|
- }
|
|
|
- print_config(buf, len-1);
|
|
|
+ char buf[80];
|
|
|
+
|
|
|
+ while (fgets(buf, sizeof(buf), stdin)) {
|
|
|
+ int len = strlen(buf);
|
|
|
+
|
|
|
+ if (len < 2 || buf[len - 1] != '\n') {
|
|
|
+ fprintf(stderr, "fixdep: bad data on stdin\n");
|
|
|
+ exit(1);
|
|
|
}
|
|
|
+ print_config(buf, len - 1);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -235,6 +219,17 @@ static void use_config(const char *m, int slen)
|
|
|
print_config(m, slen);
|
|
|
}
|
|
|
|
|
|
+/* test if s ends in sub */
|
|
|
+static int str_ends_with(const char *s, int slen, const char *sub)
|
|
|
+{
|
|
|
+ int sublen = strlen(sub);
|
|
|
+
|
|
|
+ if (sublen > slen)
|
|
|
+ return 0;
|
|
|
+
|
|
|
+ return !memcmp(s + slen - sublen, sub, sublen);
|
|
|
+}
|
|
|
+
|
|
|
static void parse_config_file(const char *p)
|
|
|
{
|
|
|
const char *q, *r;
|
|
@@ -244,7 +239,7 @@ static void parse_config_file(const char *p)
|
|
|
q = p;
|
|
|
while (*q && (isalnum(*q) || *q == '_'))
|
|
|
q++;
|
|
|
- if (memcmp(q - 7, "_MODULE", 7) == 0)
|
|
|
+ if (str_ends_with(p, q - p, "_MODULE"))
|
|
|
r = q - 7;
|
|
|
else
|
|
|
r = q;
|
|
@@ -254,56 +249,46 @@ static void parse_config_file(const char *p)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-/* test if s ends in sub */
|
|
|
-static int strrcmp(const char *s, const char *sub)
|
|
|
-{
|
|
|
- int slen = strlen(s);
|
|
|
- int sublen = strlen(sub);
|
|
|
-
|
|
|
- if (sublen > slen)
|
|
|
- return 1;
|
|
|
-
|
|
|
- return memcmp(s + slen - sublen, sub, sublen);
|
|
|
-}
|
|
|
-
|
|
|
-static void do_config_file(const char *filename)
|
|
|
+static void *read_file(const char *filename)
|
|
|
{
|
|
|
struct stat st;
|
|
|
int fd;
|
|
|
- char *map;
|
|
|
+ char *buf;
|
|
|
|
|
|
fd = open(filename, O_RDONLY);
|
|
|
if (fd < 0) {
|
|
|
- fprintf(stderr, "fixdep: error opening config file: ");
|
|
|
+ fprintf(stderr, "fixdep: error opening file: ");
|
|
|
perror(filename);
|
|
|
exit(2);
|
|
|
}
|
|
|
if (fstat(fd, &st) < 0) {
|
|
|
- fprintf(stderr, "fixdep: error fstat'ing config file: ");
|
|
|
+ fprintf(stderr, "fixdep: error fstat'ing file: ");
|
|
|
perror(filename);
|
|
|
exit(2);
|
|
|
}
|
|
|
- if (st.st_size == 0) {
|
|
|
- close(fd);
|
|
|
- return;
|
|
|
- }
|
|
|
- map = malloc(st.st_size + 1);
|
|
|
- if (!map) {
|
|
|
+ buf = malloc(st.st_size + 1);
|
|
|
+ if (!buf) {
|
|
|
perror("fixdep: malloc");
|
|
|
- close(fd);
|
|
|
- return;
|
|
|
+ exit(2);
|
|
|
}
|
|
|
- if (read(fd, map, st.st_size) != st.st_size) {
|
|
|
+ if (read(fd, buf, st.st_size) != st.st_size) {
|
|
|
perror("fixdep: read");
|
|
|
- close(fd);
|
|
|
- return;
|
|
|
+ exit(2);
|
|
|
}
|
|
|
- map[st.st_size] = '\0';
|
|
|
+ buf[st.st_size] = '\0';
|
|
|
close(fd);
|
|
|
|
|
|
- parse_config_file(map);
|
|
|
+ return buf;
|
|
|
+}
|
|
|
|
|
|
- free(map);
|
|
|
+/* Ignore certain dependencies */
|
|
|
+static int is_ignored_file(const char *s, int len)
|
|
|
+{
|
|
|
+ return str_ends_with(s, len, "include/generated/autoconf.h") ||
|
|
|
+ str_ends_with(s, len, "include/generated/autoksyms.h") ||
|
|
|
+ str_ends_with(s, len, "arch/um/include/uml-config.h") ||
|
|
|
+ str_ends_with(s, len, "include/linux/kconfig.h") ||
|
|
|
+ str_ends_with(s, len, ".ver");
|
|
|
}
|
|
|
|
|
|
/*
|
|
@@ -311,71 +296,70 @@ static void do_config_file(const char *filename)
|
|
|
* assignments are parsed not only by make, but also by the rather simple
|
|
|
* parser in scripts/mod/sumversion.c.
|
|
|
*/
|
|
|
-static void parse_dep_file(void *map, size_t len)
|
|
|
+static void parse_dep_file(char *m, const char *target, int insert_extra_deps)
|
|
|
{
|
|
|
- char *m = map;
|
|
|
- char *end = m + len;
|
|
|
char *p;
|
|
|
- char s[PATH_MAX];
|
|
|
- int is_target;
|
|
|
+ int is_last, is_target;
|
|
|
int saw_any_target = 0;
|
|
|
int is_first_dep = 0;
|
|
|
+ void *buf;
|
|
|
|
|
|
- while (m < end) {
|
|
|
+ while (1) {
|
|
|
/* Skip any "white space" */
|
|
|
- while (m < end && (*m == ' ' || *m == '\\' || *m == '\n'))
|
|
|
+ while (*m == ' ' || *m == '\\' || *m == '\n')
|
|
|
m++;
|
|
|
+
|
|
|
+ if (!*m)
|
|
|
+ break;
|
|
|
+
|
|
|
/* Find next "white space" */
|
|
|
p = m;
|
|
|
- while (p < end && *p != ' ' && *p != '\\' && *p != '\n')
|
|
|
+ while (*p && *p != ' ' && *p != '\\' && *p != '\n')
|
|
|
p++;
|
|
|
+ is_last = (*p == '\0');
|
|
|
/* Is the token we found a target name? */
|
|
|
is_target = (*(p-1) == ':');
|
|
|
/* Don't write any target names into the dependency file */
|
|
|
if (is_target) {
|
|
|
/* The /next/ file is the first dependency */
|
|
|
is_first_dep = 1;
|
|
|
- } else {
|
|
|
- /* Save this token/filename */
|
|
|
- memcpy(s, m, p-m);
|
|
|
- s[p - m] = 0;
|
|
|
-
|
|
|
- /* Ignore certain dependencies */
|
|
|
- if (strrcmp(s, "include/generated/autoconf.h") &&
|
|
|
- strrcmp(s, "include/generated/autoksyms.h") &&
|
|
|
- strrcmp(s, "arch/um/include/uml-config.h") &&
|
|
|
- strrcmp(s, "include/linux/kconfig.h") &&
|
|
|
- strrcmp(s, ".ver")) {
|
|
|
+ } else if (!is_ignored_file(m, p - m)) {
|
|
|
+ *p = '\0';
|
|
|
+
|
|
|
+ /*
|
|
|
+ * Do not list the source file as dependency, so that
|
|
|
+ * kbuild is not confused if a .c file is rewritten
|
|
|
+ * into .S or vice versa. Storing it in source_* is
|
|
|
+ * needed for modpost to compute srcversions.
|
|
|
+ */
|
|
|
+ if (is_first_dep) {
|
|
|
/*
|
|
|
- * Do not list the source file as dependency,
|
|
|
- * so that kbuild is not confused if a .c file
|
|
|
- * is rewritten into .S or vice versa. Storing
|
|
|
- * it in source_* is needed for modpost to
|
|
|
- * compute srcversions.
|
|
|
+ * If processing the concatenation of multiple
|
|
|
+ * dependency files, only process the first
|
|
|
+ * target name, which will be the original
|
|
|
+ * source name, and ignore any other target
|
|
|
+ * names, which will be intermediate temporary
|
|
|
+ * files.
|
|
|
*/
|
|
|
- if (is_first_dep) {
|
|
|
- /*
|
|
|
- * If processing the concatenation of
|
|
|
- * multiple dependency files, only
|
|
|
- * process the first target name, which
|
|
|
- * will be the original source name,
|
|
|
- * and ignore any other target names,
|
|
|
- * which will be intermediate temporary
|
|
|
- * files.
|
|
|
- */
|
|
|
- if (!saw_any_target) {
|
|
|
- saw_any_target = 1;
|
|
|
- printf("source_%s := %s\n\n",
|
|
|
- target, s);
|
|
|
- printf("deps_%s := \\\n",
|
|
|
- target);
|
|
|
- }
|
|
|
- is_first_dep = 0;
|
|
|
- } else
|
|
|
- printf(" %s \\\n", s);
|
|
|
- do_config_file(s);
|
|
|
+ if (!saw_any_target) {
|
|
|
+ saw_any_target = 1;
|
|
|
+ printf("source_%s := %s\n\n",
|
|
|
+ target, m);
|
|
|
+ printf("deps_%s := \\\n", target);
|
|
|
+ }
|
|
|
+ is_first_dep = 0;
|
|
|
+ } else {
|
|
|
+ printf(" %s \\\n", m);
|
|
|
}
|
|
|
+
|
|
|
+ buf = read_file(m);
|
|
|
+ parse_config_file(buf);
|
|
|
+ free(buf);
|
|
|
}
|
|
|
+
|
|
|
+ if (is_last)
|
|
|
+ break;
|
|
|
+
|
|
|
/*
|
|
|
* Start searching for next token immediately after the first
|
|
|
* "whitespace" character that follows this token.
|
|
@@ -388,50 +372,19 @@ static void parse_dep_file(void *map, size_t len)
|
|
|
exit(1);
|
|
|
}
|
|
|
|
|
|
- do_extra_deps();
|
|
|
+ if (insert_extra_deps)
|
|
|
+ do_extra_deps();
|
|
|
|
|
|
printf("\n%s: $(deps_%s)\n\n", target, target);
|
|
|
printf("$(deps_%s):\n", target);
|
|
|
}
|
|
|
|
|
|
-static void print_deps(void)
|
|
|
-{
|
|
|
- struct stat st;
|
|
|
- int fd;
|
|
|
- void *map;
|
|
|
-
|
|
|
- fd = open(depfile, O_RDONLY);
|
|
|
- if (fd < 0) {
|
|
|
- fprintf(stderr, "fixdep: error opening depfile: ");
|
|
|
- perror(depfile);
|
|
|
- exit(2);
|
|
|
- }
|
|
|
- if (fstat(fd, &st) < 0) {
|
|
|
- fprintf(stderr, "fixdep: error fstat'ing depfile: ");
|
|
|
- perror(depfile);
|
|
|
- exit(2);
|
|
|
- }
|
|
|
- if (st.st_size == 0) {
|
|
|
- fprintf(stderr,"fixdep: %s is empty\n",depfile);
|
|
|
- close(fd);
|
|
|
- return;
|
|
|
- }
|
|
|
- map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
|
|
|
- if ((long) map == -1) {
|
|
|
- perror("fixdep: mmap");
|
|
|
- close(fd);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- parse_dep_file(map, st.st_size);
|
|
|
-
|
|
|
- munmap(map, st.st_size);
|
|
|
-
|
|
|
- close(fd);
|
|
|
-}
|
|
|
-
|
|
|
int main(int argc, char *argv[])
|
|
|
{
|
|
|
+ const char *depfile, *target, *cmdline;
|
|
|
+ int insert_extra_deps = 0;
|
|
|
+ void *buf;
|
|
|
+
|
|
|
if (argc == 5 && !strcmp(argv[1], "-e")) {
|
|
|
insert_extra_deps = 1;
|
|
|
argv++;
|
|
@@ -442,8 +395,11 @@ int main(int argc, char *argv[])
|
|
|
target = argv[2];
|
|
|
cmdline = argv[3];
|
|
|
|
|
|
- print_cmdline();
|
|
|
- print_deps();
|
|
|
+ printf("cmd_%s := %s\n\n", target, cmdline);
|
|
|
+
|
|
|
+ buf = read_file(depfile);
|
|
|
+ parse_dep_file(buf, target, insert_extra_deps);
|
|
|
+ free(buf);
|
|
|
|
|
|
return 0;
|
|
|
}
|