fixdep.c (fc8e1ead9314cf0e0f1922e661428b93d3a50d88) | fixdep.c (4356f4890792a678936c93c9196e8f7742e04535) |
---|---|
1/* 2 * "Optimize" a list of dependencies as spit out by gcc -MD 3 * for the kernel build 4 * =========================================================================== 5 * 6 * Author Kai Germaschewski 7 * Copyright 2002 by Kai Germaschewski <kai.germaschewski@gmx.de> 8 * --- 111 unchanged lines hidden (view full) --- 120#define INT_ONFI ntohl(0x4f4e4649) 121#define INT_NFIG ntohl(0x4e464947) 122#define INT_FIG_ ntohl(0x4649475f) 123 124char *target; 125char *depfile; 126char *cmdline; 127 | 1/* 2 * "Optimize" a list of dependencies as spit out by gcc -MD 3 * for the kernel build 4 * =========================================================================== 5 * 6 * Author Kai Germaschewski 7 * Copyright 2002 by Kai Germaschewski <kai.germaschewski@gmx.de> 8 * --- 111 unchanged lines hidden (view full) --- 120#define INT_ONFI ntohl(0x4f4e4649) 121#define INT_NFIG ntohl(0x4e464947) 122#define INT_FIG_ ntohl(0x4649475f) 123 124char *target; 125char *depfile; 126char *cmdline; 127 |
128void usage(void) | 128static void usage(void) |
129 130{ 131 fprintf(stderr, "Usage: fixdep <depfile> <target> <cmdline>\n"); 132 exit(1); 133} 134 135/* 136 * Print out the commandline prefixed with cmd_<target filename> := 137 */ | 129 130{ 131 fprintf(stderr, "Usage: fixdep <depfile> <target> <cmdline>\n"); 132 exit(1); 133} 134 135/* 136 * Print out the commandline prefixed with cmd_<target filename> := 137 */ |
138void print_cmdline(void) | 138static void print_cmdline(void) |
139{ 140 printf("cmd_%s := %s\n\n", target, cmdline); 141} 142 143char * str_config = NULL; 144int size_config = 0; 145int len_config = 0; 146 147/* 148 * Grow the configuration string to a desired length. 149 * Usually the first growth is plenty. 150 */ | 139{ 140 printf("cmd_%s := %s\n\n", target, cmdline); 141} 142 143char * str_config = NULL; 144int size_config = 0; 145int len_config = 0; 146 147/* 148 * Grow the configuration string to a desired length. 149 * Usually the first growth is plenty. 150 */ |
151void grow_config(int len) | 151static void grow_config(int len) |
152{ 153 while (len_config + len > size_config) { 154 if (size_config == 0) 155 size_config = 2048; 156 str_config = realloc(str_config, size_config *= 2); 157 if (str_config == NULL) 158 { perror("fixdep:malloc"); exit(1); } 159 } 160} 161 162 163 164/* 165 * Lookup a value in the configuration string. 166 */ | 152{ 153 while (len_config + len > size_config) { 154 if (size_config == 0) 155 size_config = 2048; 156 str_config = realloc(str_config, size_config *= 2); 157 if (str_config == NULL) 158 { perror("fixdep:malloc"); exit(1); } 159 } 160} 161 162 163 164/* 165 * Lookup a value in the configuration string. 166 */ |
167int is_defined_config(const char * name, int len) | 167static int is_defined_config(const char * name, int len) |
168{ 169 const char * pconfig; 170 const char * plast = str_config + len_config - len; 171 for ( pconfig = str_config + 1; pconfig < plast; pconfig++ ) { 172 if (pconfig[ -1] == '\n' 173 && pconfig[len] == '\n' 174 && !memcmp(pconfig, name, len)) 175 return 1; 176 } 177 return 0; 178} 179 180/* 181 * Add a new value to the configuration string. 182 */ | 168{ 169 const char * pconfig; 170 const char * plast = str_config + len_config - len; 171 for ( pconfig = str_config + 1; pconfig < plast; pconfig++ ) { 172 if (pconfig[ -1] == '\n' 173 && pconfig[len] == '\n' 174 && !memcmp(pconfig, name, len)) 175 return 1; 176 } 177 return 0; 178} 179 180/* 181 * Add a new value to the configuration string. 182 */ |
183void define_config(const char * name, int len) | 183static void define_config(const char * name, int len) |
184{ 185 grow_config(len + 1); 186 187 memcpy(str_config+len_config, name, len); 188 len_config += len; 189 str_config[len_config++] = '\n'; 190} 191 192/* 193 * Clear the set of configuration strings. 194 */ | 184{ 185 grow_config(len + 1); 186 187 memcpy(str_config+len_config, name, len); 188 len_config += len; 189 str_config[len_config++] = '\n'; 190} 191 192/* 193 * Clear the set of configuration strings. 194 */ |
195void clear_config(void) | 195static void clear_config(void) |
196{ 197 len_config = 0; 198 define_config("", 0); 199} 200 201/* 202 * Record the use of a CONFIG_* word. 203 */ | 196{ 197 len_config = 0; 198 define_config("", 0); 199} 200 201/* 202 * Record the use of a CONFIG_* word. 203 */ |
204void use_config(char *m, int slen) | 204static void use_config(char *m, int slen) |
205{ 206 char s[PATH_MAX]; 207 char *p; 208 209 if (is_defined_config(m, slen)) 210 return; 211 212 define_config(m, slen); --- 4 unchanged lines hidden (view full) --- 217 if (*p == '_') 218 *p = '/'; 219 else 220 *p = tolower((int)*p); 221 } 222 printf(" $(wildcard include/config/%s.h) \\\n", s); 223} 224 | 205{ 206 char s[PATH_MAX]; 207 char *p; 208 209 if (is_defined_config(m, slen)) 210 return; 211 212 define_config(m, slen); --- 4 unchanged lines hidden (view full) --- 217 if (*p == '_') 218 *p = '/'; 219 else 220 *p = tolower((int)*p); 221 } 222 printf(" $(wildcard include/config/%s.h) \\\n", s); 223} 224 |
225void parse_config_file(char *map, size_t len) | 225static void parse_config_file(char *map, size_t len) |
226{ 227 int *end = (int *) (map + len); 228 /* start at +1, so that p can never be < map */ 229 int *m = (int *) map + 1; 230 char *p, *q; 231 232 for (; m < end; m++) { 233 if (*m == INT_CONF) { p = (char *) m ; goto conf; } --- 17 unchanged lines hidden (view full) --- 251 q -= 7; 252 if( (q-p-7) < 0 ) 253 continue; 254 use_config(p+7, q-p-7); 255 } 256} 257 258/* test is s ends in sub */ | 226{ 227 int *end = (int *) (map + len); 228 /* start at +1, so that p can never be < map */ 229 int *m = (int *) map + 1; 230 char *p, *q; 231 232 for (; m < end; m++) { 233 if (*m == INT_CONF) { p = (char *) m ; goto conf; } --- 17 unchanged lines hidden (view full) --- 251 q -= 7; 252 if( (q-p-7) < 0 ) 253 continue; 254 use_config(p+7, q-p-7); 255 } 256} 257 258/* test is s ends in sub */ |
259int strrcmp(char *s, char *sub) | 259static int strrcmp(char *s, char *sub) |
260{ 261 int slen = strlen(s); 262 int sublen = strlen(sub); 263 264 if (sublen > slen) 265 return 1; 266 267 return memcmp(s + slen - sublen, sub, sublen); 268} 269 | 260{ 261 int slen = strlen(s); 262 int sublen = strlen(sub); 263 264 if (sublen > slen) 265 return 1; 266 267 return memcmp(s + slen - sublen, sub, sublen); 268} 269 |
270void do_config_file(char *filename) | 270static void do_config_file(char *filename) |
271{ 272 struct stat st; 273 int fd; 274 void *map; 275 276 fd = open(filename, O_RDONLY); 277 if (fd < 0) { 278 fprintf(stderr, "fixdep: "); --- 14 unchanged lines hidden (view full) --- 293 294 parse_config_file(map, st.st_size); 295 296 munmap(map, st.st_size); 297 298 close(fd); 299} 300 | 271{ 272 struct stat st; 273 int fd; 274 void *map; 275 276 fd = open(filename, O_RDONLY); 277 if (fd < 0) { 278 fprintf(stderr, "fixdep: "); --- 14 unchanged lines hidden (view full) --- 293 294 parse_config_file(map, st.st_size); 295 296 munmap(map, st.st_size); 297 298 close(fd); 299} 300 |
301void parse_dep_file(void *map, size_t len) | 301static void parse_dep_file(void *map, size_t len) |
302{ 303 char *m = map; 304 char *end = m + len; 305 char *p; 306 char s[PATH_MAX]; 307 308 p = strchr(m, ':'); 309 if (!p) { --- 23 unchanged lines hidden (view full) --- 333 do_config_file(s); 334 } 335 m = p + 1; 336 } 337 printf("\n%s: $(deps_%s)\n\n", target, target); 338 printf("$(deps_%s):\n", target); 339} 340 | 302{ 303 char *m = map; 304 char *end = m + len; 305 char *p; 306 char s[PATH_MAX]; 307 308 p = strchr(m, ':'); 309 if (!p) { --- 23 unchanged lines hidden (view full) --- 333 do_config_file(s); 334 } 335 m = p + 1; 336 } 337 printf("\n%s: $(deps_%s)\n\n", target, target); 338 printf("$(deps_%s):\n", target); 339} 340 |
341void print_deps(void) | 341static void print_deps(void) |
342{ 343 struct stat st; 344 int fd; 345 void *map; 346 347 fd = open(depfile, O_RDONLY); 348 if (fd < 0) { 349 fprintf(stderr, "fixdep: "); --- 15 unchanged lines hidden (view full) --- 365 366 parse_dep_file(map, st.st_size); 367 368 munmap(map, st.st_size); 369 370 close(fd); 371} 372 | 342{ 343 struct stat st; 344 int fd; 345 void *map; 346 347 fd = open(depfile, O_RDONLY); 348 if (fd < 0) { 349 fprintf(stderr, "fixdep: "); --- 15 unchanged lines hidden (view full) --- 365 366 parse_dep_file(map, st.st_size); 367 368 munmap(map, st.st_size); 369 370 close(fd); 371} 372 |
373void traps(void) | 373static void traps(void) |
374{ 375 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF"; 376 int *p = (int *)test; 377 378 if (*p != INT_CONF) { 379 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n", 380 *p); 381 exit(2); --- 19 unchanged lines hidden --- | 374{ 375 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF"; 376 int *p = (int *)test; 377 378 if (*p != INT_CONF) { 379 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n", 380 *p); 381 exit(2); --- 19 unchanged lines hidden --- |