106 #include <sys/types.h>
107 #include <sys/stat.h>
108 #include <sys/mman.h>
116 #include <arpa/inet.h>
118 #define INT_CONF ntohl(0x434f4e46)
119 #define INT_ONFI ntohl(0x4f4e4649)
120 #define INT_NFIG ntohl(0x4e464947)
121 #define INT_FIG_ ntohl(0x4649475f)
127 static void usage(
void)
129 fprintf(stderr,
"Usage: fixdep <depfile> <target> <cmdline>\n");
136 static void print_cmdline(
void)
151 static unsigned int strhash(
const char *
str,
unsigned int sz)
154 unsigned int i,
hash = 2166136261
U;
156 for (i = 0; i < sz; i++)
157 hash = (hash ^ str[i]) * 0x01000193;
164 static int is_defined_config(
const char *
name,
int len,
unsigned int hash)
169 if (aux->
hash == hash && aux->
len == len &&
179 static void define_config(
const char *name,
int len,
unsigned int hash)
181 struct item *aux =
malloc(
sizeof(*aux) + len);
184 perror(
"fixdep:malloc");
197 static void clear_config(
void)
202 for (i = 0; i <
HASHSZ; i++) {
203 for (aux = hashtab[i];
aux; aux =
next) {
214 static void use_config(
const char *
m,
int slen)
216 unsigned int hash = strhash(m, slen);
219 if (is_defined_config(m, slen, hash))
222 define_config(m, slen, hash);
224 printf(
" $(wildcard include/config/");
225 for (i = 0; i < slen; i++) {
236 static void parse_config_file(
const char *
map,
size_t len)
238 const int *
end = (
const int *) (map + len);
240 const int *m = (
const int *) map + 1;
243 for (; m <
end; m++) {
244 if (*m ==
INT_CONF) { p = (
char *) m ;
goto conf; }
245 if (*m ==
INT_ONFI) { p = (
char *) m-1;
goto conf; }
246 if (*m ==
INT_NFIG) { p = (
char *) m-2;
goto conf; }
247 if (*m ==
INT_FIG_) { p = (
char *) m-3;
goto conf; }
250 if (p > map + len - 7)
252 if (
memcmp(p,
"CONFIG_", 7))
254 for (q = p + 7; q < map +
len; q++) {
255 if (!(
isalnum(*q) || *q ==
'_'))
261 if (!
memcmp(q - 7,
"_MODULE", 7))
265 use_config(p+7, q-p-7);
270 static int strrcmp(
char *
s,
char *sub)
278 return memcmp(s + slen - sublen, sub, sublen);
281 static void do_config_file(
const char *
filename)
289 fprintf(stderr,
"fixdep: error opening config file: ");
294 if (
st.st_size == 0) {
299 if ((
long) map == -1) {
300 perror(
"fixdep: mmap");
305 parse_config_file(map,
st.st_size);
307 munmap(map,
st.st_size);
317 static void parse_dep_file(
void *map,
size_t len)
327 fprintf(stderr,
"fixdep: parse error\n");
337 while (m < end && (*m ==
' ' || *m ==
'\\' || *m ==
'\n'))
340 while (p < end && *p !=
' ') p++;
346 if (strrcmp(s,
"include/generated/autoconf.h") &&
347 strrcmp(s,
"arch/um/include/uml-config.h") &&
348 strrcmp(s,
"include/linux/kconfig.h") &&
349 strrcmp(s,
".ver")) {
370 static void print_deps(
void)
378 fprintf(stderr,
"fixdep: error opening depfile: ");
382 if (fstat(fd, &
st) < 0) {
383 fprintf(stderr,
"fixdep: error fstat'ing depfile: ");
387 if (
st.st_size == 0) {
393 if ((
long) map == -1) {
394 perror(
"fixdep: mmap");
399 parse_dep_file(map,
st.st_size);
401 munmap(map,
st.st_size);
406 static void traps(
void)
409 int *p = (
int *)
test;
412 fprintf(stderr,
"fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",