scripts: fixdep: update from v3.10-rc1
This brings us the following which we need for dtb file generation. commit 2ab8a99661f4ce052bbad064237c441371df8751 Author: Stephen Warren <swarren@nvidia.com> Date: Wed Mar 6 10:27:45 2013 -0700 kbuild: fixdep: support concatenated dep files Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
a56472209f
commit
c478aa16b1
|
@ -138,38 +138,36 @@ static void print_cmdline(void)
|
||||||
printf("cmd_%s := %s\n\n", target, cmdline);
|
printf("cmd_%s := %s\n\n", target, cmdline);
|
||||||
}
|
}
|
||||||
|
|
||||||
char * str_config = NULL;
|
struct item {
|
||||||
int size_config = 0;
|
struct item *next;
|
||||||
int len_config = 0;
|
unsigned int len;
|
||||||
|
unsigned int hash;
|
||||||
|
char name[0];
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
#define HASHSZ 256
|
||||||
* Grow the configuration string to a desired length.
|
static struct item *hashtab[HASHSZ];
|
||||||
* Usually the first growth is plenty.
|
|
||||||
*/
|
static unsigned int strhash(const char *str, unsigned int sz)
|
||||||
static void grow_config(int len)
|
|
||||||
{
|
{
|
||||||
while (len_config + len > size_config) {
|
/* fnv32 hash */
|
||||||
if (size_config == 0)
|
unsigned int i, hash = 2166136261U;
|
||||||
size_config = 2048;
|
|
||||||
str_config = realloc(str_config, size_config *= 2);
|
for (i = 0; i < sz; i++)
|
||||||
if (str_config == NULL)
|
hash = (hash ^ str[i]) * 0x01000193;
|
||||||
{ perror("fixdep:malloc"); exit(1); }
|
return hash;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Lookup a value in the configuration string.
|
* Lookup a value in the configuration string.
|
||||||
*/
|
*/
|
||||||
static int is_defined_config(const char * name, int len)
|
static int is_defined_config(const char *name, int len, unsigned int hash)
|
||||||
{
|
{
|
||||||
const char * pconfig;
|
struct item *aux;
|
||||||
const char * plast = str_config + len_config - len;
|
|
||||||
for ( pconfig = str_config + 1; pconfig < plast; pconfig++ ) {
|
for (aux = hashtab[hash % HASHSZ]; aux; aux = aux->next) {
|
||||||
if (pconfig[ -1] == '\n'
|
if (aux->hash == hash && aux->len == len &&
|
||||||
&& pconfig[len] == '\n'
|
memcmp(aux->name, name, len) == 0)
|
||||||
&& !memcmp(pconfig, name, len))
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -178,13 +176,19 @@ static int is_defined_config(const char * name, int len)
|
||||||
/*
|
/*
|
||||||
* Add a new value to the configuration string.
|
* Add a new value to the configuration string.
|
||||||
*/
|
*/
|
||||||
static void define_config(const char * name, int len)
|
static void define_config(const char *name, int len, unsigned int hash)
|
||||||
{
|
{
|
||||||
grow_config(len + 1);
|
struct item *aux = malloc(sizeof(*aux) + len);
|
||||||
|
|
||||||
memcpy(str_config+len_config, name, len);
|
if (!aux) {
|
||||||
len_config += len;
|
perror("fixdep:malloc");
|
||||||
str_config[len_config++] = '\n';
|
exit(1);
|
||||||
|
}
|
||||||
|
memcpy(aux->name, name, len);
|
||||||
|
aux->len = len;
|
||||||
|
aux->hash = hash;
|
||||||
|
aux->next = hashtab[hash % HASHSZ];
|
||||||
|
hashtab[hash % HASHSZ] = aux;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -192,40 +196,49 @@ static void define_config(const char * name, int len)
|
||||||
*/
|
*/
|
||||||
static void clear_config(void)
|
static void clear_config(void)
|
||||||
{
|
{
|
||||||
len_config = 0;
|
struct item *aux, *next;
|
||||||
define_config("", 0);
|
unsigned int i;
|
||||||
|
|
||||||
|
for (i = 0; i < HASHSZ; i++) {
|
||||||
|
for (aux = hashtab[i]; aux; aux = next) {
|
||||||
|
next = aux->next;
|
||||||
|
free(aux);
|
||||||
|
}
|
||||||
|
hashtab[i] = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Record the use of a CONFIG_* word.
|
* Record the use of a CONFIG_* word.
|
||||||
*/
|
*/
|
||||||
static void use_config(char *m, int slen)
|
static void use_config(const char *m, int slen)
|
||||||
{
|
{
|
||||||
char s[PATH_MAX];
|
unsigned int hash = strhash(m, slen);
|
||||||
char *p;
|
int c, i;
|
||||||
|
|
||||||
if (is_defined_config(m, slen))
|
if (is_defined_config(m, slen, hash))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
define_config(m, slen);
|
define_config(m, slen, hash);
|
||||||
|
|
||||||
memcpy(s, m, slen); s[slen] = 0;
|
printf(" $(wildcard include/config/");
|
||||||
|
for (i = 0; i < slen; i++) {
|
||||||
for (p = s; p < s + slen; p++) {
|
c = m[i];
|
||||||
if (*p == '_')
|
if (c == '_')
|
||||||
*p = '/';
|
c = '/';
|
||||||
else
|
else
|
||||||
*p = tolower((int)*p);
|
c = tolower(c);
|
||||||
|
putchar(c);
|
||||||
}
|
}
|
||||||
printf(" $(wildcard include/config/%s.h) \\\n", s);
|
printf(".h) \\\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parse_config_file(char *map, size_t len)
|
static void parse_config_file(const char *map, size_t len)
|
||||||
{
|
{
|
||||||
int *end = (int *) (map + len);
|
const int *end = (const int *) (map + len);
|
||||||
/* start at +1, so that p can never be < map */
|
/* start at +1, so that p can never be < map */
|
||||||
int *m = (int *) map + 1;
|
const int *m = (const int *) map + 1;
|
||||||
char *p, *q;
|
const char *p, *q;
|
||||||
|
|
||||||
for (; m < end; m++) {
|
for (; m < end; m++) {
|
||||||
if (*m == INT_CONF) { p = (char *) m ; goto conf; }
|
if (*m == INT_CONF) { p = (char *) m ; goto conf; }
|
||||||
|
@ -265,7 +278,7 @@ static int strrcmp(char *s, char *sub)
|
||||||
return memcmp(s + slen - sublen, sub, sublen);
|
return memcmp(s + slen - sublen, sub, sublen);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void do_config_file(char *filename)
|
static void do_config_file(const char *filename)
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
int fd;
|
int fd;
|
||||||
|
@ -273,7 +286,7 @@ static void do_config_file(char *filename)
|
||||||
|
|
||||||
fd = open(filename, O_RDONLY);
|
fd = open(filename, O_RDONLY);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
fprintf(stderr, "fixdep: ");
|
fprintf(stderr, "fixdep: error opening config file: ");
|
||||||
perror(filename);
|
perror(filename);
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
|
@ -296,42 +309,89 @@ static void do_config_file(char *filename)
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Important: The below generated source_foo.o and deps_foo.o variable
|
||||||
|
* 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(void *map, size_t len)
|
||||||
{
|
{
|
||||||
char *m = map;
|
char *m = map;
|
||||||
char *end = m + len;
|
char *end = m + len;
|
||||||
char *p;
|
char *p;
|
||||||
char s[PATH_MAX];
|
char s[PATH_MAX];
|
||||||
|
int is_target;
|
||||||
p = strchr(m, ':');
|
int saw_any_target = 0;
|
||||||
if (!p) {
|
int is_first_dep = 0;
|
||||||
fprintf(stderr, "fixdep: parse error\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
memcpy(s, m, p-m); s[p-m] = 0;
|
|
||||||
printf("deps_%s := \\\n", target);
|
|
||||||
m = p+1;
|
|
||||||
|
|
||||||
clear_config();
|
clear_config();
|
||||||
|
|
||||||
while (m < end) {
|
while (m < end) {
|
||||||
|
/* Skip any "white space" */
|
||||||
while (m < end && (*m == ' ' || *m == '\\' || *m == '\n'))
|
while (m < end && (*m == ' ' || *m == '\\' || *m == '\n'))
|
||||||
m++;
|
m++;
|
||||||
|
/* Find next "white space" */
|
||||||
p = m;
|
p = m;
|
||||||
while (p < end && *p != ' ') p++;
|
while (p < end && *p != ' ' && *p != '\\' && *p != '\n')
|
||||||
if (p == end) {
|
|
||||||
do p--; while (!isalnum(*p));
|
|
||||||
p++;
|
p++;
|
||||||
|
/* 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, "arch/um/include/uml-config.h") &&
|
||||||
|
strrcmp(s, "include/linux/kconfig.h") &&
|
||||||
|
strrcmp(s, ".ver")) {
|
||||||
|
/*
|
||||||
|
* 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) {
|
||||||
|
/*
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
memcpy(s, m, p-m); s[p-m] = 0;
|
/*
|
||||||
if (strrcmp(s, "include/generated/autoconf.h") &&
|
* Start searching for next token immediately after the first
|
||||||
strrcmp(s, "arch/um/include/uml-config.h") &&
|
* "whitespace" character that follows this token.
|
||||||
strrcmp(s, ".ver")) {
|
*/
|
||||||
printf(" %s \\\n", s);
|
|
||||||
do_config_file(s);
|
|
||||||
}
|
|
||||||
m = p + 1;
|
m = p + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!saw_any_target) {
|
||||||
|
fprintf(stderr, "fixdep: parse error; no targets found\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
printf("\n%s: $(deps_%s)\n\n", target, target);
|
printf("\n%s: $(deps_%s)\n\n", target, target);
|
||||||
printf("$(deps_%s):\n", target);
|
printf("$(deps_%s):\n", target);
|
||||||
}
|
}
|
||||||
|
@ -344,11 +404,15 @@ static void print_deps(void)
|
||||||
|
|
||||||
fd = open(depfile, O_RDONLY);
|
fd = open(depfile, O_RDONLY);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
fprintf(stderr, "fixdep: ");
|
fprintf(stderr, "fixdep: error opening depfile: ");
|
||||||
perror(depfile);
|
perror(depfile);
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
fstat(fd, &st);
|
if (fstat(fd, &st) < 0) {
|
||||||
|
fprintf(stderr, "fixdep: error fstat'ing depfile: ");
|
||||||
|
perror(depfile);
|
||||||
|
exit(2);
|
||||||
|
}
|
||||||
if (st.st_size == 0) {
|
if (st.st_size == 0) {
|
||||||
fprintf(stderr,"fixdep: %s is empty\n",depfile);
|
fprintf(stderr,"fixdep: %s is empty\n",depfile);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
@ -374,7 +438,7 @@ static void traps(void)
|
||||||
int *p = (int *)test;
|
int *p = (int *)test;
|
||||||
|
|
||||||
if (*p != INT_CONF) {
|
if (*p != INT_CONF) {
|
||||||
fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
|
fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianness? %#x\n",
|
||||||
*p);
|
*p);
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue