2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* "Optimize" a list of dependencies as spit out by gcc -MD
|
|
|
|
* for the kernel build
|
|
|
|
* ===========================================================================
|
|
|
|
*
|
|
|
|
* Author Kai Germaschewski
|
|
|
|
* Copyright 2002 by Kai Germaschewski <kai.germaschewski@gmx.de>
|
|
|
|
*
|
|
|
|
* This software may be used and distributed according to the terms
|
|
|
|
* of the GNU General Public License, incorporated herein by reference.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Introduction:
|
|
|
|
*
|
|
|
|
* gcc produces a very nice and correct list of dependencies which
|
|
|
|
* tells make when to remake a file.
|
|
|
|
*
|
|
|
|
* To use this list as-is however has the drawback that virtually
|
2009-10-18 05:49:24 +07:00
|
|
|
* every file in the kernel includes autoconf.h.
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
2009-10-18 05:49:24 +07:00
|
|
|
* If the user re-runs make *config, autoconf.h will be
|
2005-04-17 05:20:36 +07:00
|
|
|
* regenerated. make notices that and will rebuild every file which
|
|
|
|
* includes autoconf.h, i.e. basically all files. This is extremely
|
|
|
|
* annoying if the user just changed CONFIG_HIS_DRIVER from n to m.
|
|
|
|
*
|
|
|
|
* So we play the same trick that "mkdep" played before. We replace
|
2009-10-18 05:49:24 +07:00
|
|
|
* the dependency on autoconf.h by a dependency on every config
|
2017-08-08 20:20:50 +07:00
|
|
|
* option which is mentioned in any of the listed prerequisites.
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
2007-03-29 16:27:14 +07:00
|
|
|
* kconfig populates a tree in include/config/ with an empty file
|
|
|
|
* for each config symbol and when the configuration is updated
|
|
|
|
* the files representing changed config options are touched
|
|
|
|
* which then let make pick up the changes and the files that use
|
|
|
|
* the config symbols are rebuilt.
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
|
|
|
* So if the user changes his CONFIG_HIS_DRIVER option, only the objects
|
2017-08-08 20:20:50 +07:00
|
|
|
* which depend on "include/config/his/driver.h" will be rebuilt,
|
2005-04-17 05:20:36 +07:00
|
|
|
* so most likely only his driver ;-)
|
|
|
|
*
|
|
|
|
* The idea above dates, by the way, back to Michael E Chastain, AFAIK.
|
|
|
|
*
|
|
|
|
* So to get dependencies right, there are two issues:
|
|
|
|
* o if any of the files the compiler read changed, we need to rebuild
|
|
|
|
* o if the command line given to the compile the file changed, we
|
|
|
|
* better rebuild as well.
|
|
|
|
*
|
|
|
|
* The former is handled by using the -MD output, the later by saving
|
|
|
|
* the command line used to compile the old object and comparing it
|
|
|
|
* to the one we would now use.
|
|
|
|
*
|
|
|
|
* Again, also this idea is pretty old and has been discussed on
|
|
|
|
* kbuild-devel a long time ago. I don't have a sensibly working
|
|
|
|
* internet connection right now, so I rather don't mention names
|
|
|
|
* without double checking.
|
|
|
|
*
|
|
|
|
* This code here has been based partially based on mkdep.c, which
|
|
|
|
* says the following about its history:
|
|
|
|
*
|
|
|
|
* Copyright abandoned, Michael Chastain, <mailto:mec@shout.net>.
|
|
|
|
* This is a C version of syncdep.pl by Werner Almesberger.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* It is invoked as
|
|
|
|
*
|
|
|
|
* fixdep <depfile> <target> <cmdline>
|
|
|
|
*
|
|
|
|
* and will read the dependency file <depfile>
|
|
|
|
*
|
|
|
|
* The transformed dependency snipped is written to stdout.
|
|
|
|
*
|
|
|
|
* It first generates a line
|
|
|
|
*
|
|
|
|
* cmd_<target> = <cmdline>
|
|
|
|
*
|
|
|
|
* and then basically copies the .<target>.d file to stdout, in the
|
2009-10-18 05:49:24 +07:00
|
|
|
* process filtering out the dependency on autoconf.h and adding
|
2005-04-17 05:20:36 +07:00
|
|
|
* dependencies on include/config/my/option.h for every
|
2017-08-08 20:20:50 +07:00
|
|
|
* CONFIG_MY_OPTION encountered in any of the prerequisites.
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
|
|
|
* It will also filter out all the dependencies on *.ver. We need
|
|
|
|
* to make sure that the generated version checksum are globally up
|
|
|
|
* to date before even starting the recursive build, so it's too late
|
|
|
|
* at this point anyway.
|
|
|
|
*
|
2016-08-25 01:03:05 +07:00
|
|
|
* We don't even try to really parse the header files, but
|
2005-04-17 05:20:36 +07:00
|
|
|
* merely grep, i.e. if CONFIG_FOO is mentioned in a comment, it will
|
|
|
|
* be picked up as well. It's not a problem with respect to
|
|
|
|
* correctness, since that can only give too many dependencies, thus
|
|
|
|
* we cannot miss a rebuild. Since people tend to not mention totally
|
|
|
|
* unrelated CONFIG_ options all over the place, it's not an
|
|
|
|
* efficiency problem either.
|
|
|
|
*
|
|
|
|
* (Note: it'd be easy to port over the complete mkdep state machine,
|
|
|
|
* but I don't think the added complexity is worth it)
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Note 2: if somebody writes HELLO_CONFIG_BOOM in a file, it will depend onto
|
|
|
|
* CONFIG_BOOM. This could seem a bug (not too hard to fix), but please do not
|
|
|
|
* fix it! Some UserModeLinux files (look at arch/um/) call CONFIG_BOOM as
|
|
|
|
* UML_CONFIG_BOOM, to avoid conflicts with /usr/include/linux/autoconf.h,
|
|
|
|
* through arch/um/include/uml-config.h; this fixdep "bug" makes sure that
|
|
|
|
* those files will have correct dependencies.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
2016-02-13 03:00:50 +07:00
|
|
|
int insert_extra_deps;
|
2005-04-17 05:20:36 +07:00
|
|
|
char *target;
|
|
|
|
char *depfile;
|
|
|
|
char *cmdline;
|
|
|
|
|
2009-09-19 02:49:23 +07:00
|
|
|
static void usage(void)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2016-02-13 03:00:50 +07:00
|
|
|
fprintf(stderr, "Usage: fixdep [-e] <depfile> <target> <cmdline>\n");
|
|
|
|
fprintf(stderr, " -e insert extra dependencies given on stdin\n");
|
2005-04-17 05:20:36 +07:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2005-12-26 05:21:14 +07:00
|
|
|
/*
|
|
|
|
* Print out the commandline prefixed with cmd_<target filename> :=
|
2006-01-30 16:04:27 +07:00
|
|
|
*/
|
2009-09-19 02:49:23 +07:00
|
|
|
static void print_cmdline(void)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2006-01-30 16:04:27 +07:00
|
|
|
printf("cmd_%s := %s\n\n", target, cmdline);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2016-02-13 03:00:50 +07:00
|
|
|
/*
|
|
|
|
* Print out a dependency path from a symbol name
|
|
|
|
*/
|
|
|
|
static void print_config(const char *m, int slen)
|
|
|
|
{
|
|
|
|
int c, i;
|
|
|
|
|
|
|
|
printf(" $(wildcard include/config/");
|
|
|
|
for (i = 0; i < slen; i++) {
|
|
|
|
c = m[i];
|
|
|
|
if (c == '_')
|
|
|
|
c = '/';
|
|
|
|
else
|
|
|
|
c = tolower(c);
|
|
|
|
putchar(c);
|
|
|
|
}
|
|
|
|
printf(".h) \\\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-09 22:29:27 +07:00
|
|
|
struct item {
|
|
|
|
struct item *next;
|
|
|
|
unsigned int len;
|
|
|
|
unsigned int hash;
|
|
|
|
char name[0];
|
|
|
|
};
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2010-11-09 22:29:27 +07:00
|
|
|
#define HASHSZ 256
|
|
|
|
static struct item *hashtab[HASHSZ];
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2010-11-09 22:29:27 +07:00
|
|
|
static unsigned int strhash(const char *str, unsigned int sz)
|
|
|
|
{
|
|
|
|
/* fnv32 hash */
|
|
|
|
unsigned int i, hash = 2166136261U;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2010-11-09 22:29:27 +07:00
|
|
|
for (i = 0; i < sz; i++)
|
|
|
|
hash = (hash ^ str[i]) * 0x01000193;
|
|
|
|
return hash;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Lookup a value in the configuration string.
|
|
|
|
*/
|
2010-11-09 22:29:27 +07:00
|
|
|
static int is_defined_config(const char *name, int len, unsigned int hash)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2010-11-09 22:29:27 +07:00
|
|
|
struct item *aux;
|
|
|
|
|
|
|
|
for (aux = hashtab[hash % HASHSZ]; aux; aux = aux->next) {
|
|
|
|
if (aux->hash == hash && aux->len == len &&
|
|
|
|
memcmp(aux->name, name, len) == 0)
|
2005-04-17 05:20:36 +07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a new value to the configuration string.
|
|
|
|
*/
|
2010-11-09 22:29:27 +07:00
|
|
|
static void define_config(const char *name, int len, unsigned int hash)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2010-11-09 22:29:27 +07:00
|
|
|
struct item *aux = malloc(sizeof(*aux) + len);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2010-11-09 22:29:27 +07:00
|
|
|
if (!aux) {
|
|
|
|
perror("fixdep:malloc");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
memcpy(aux->name, name, len);
|
|
|
|
aux->len = len;
|
|
|
|
aux->hash = hash;
|
|
|
|
aux->next = hashtab[hash % HASHSZ];
|
|
|
|
hashtab[hash % HASHSZ] = aux;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Record the use of a CONFIG_* word.
|
|
|
|
*/
|
2010-11-09 22:29:27 +07:00
|
|
|
static void use_config(const char *m, int slen)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2010-11-09 22:29:27 +07:00
|
|
|
unsigned int hash = strhash(m, slen);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2010-11-09 22:29:27 +07:00
|
|
|
if (is_defined_config(m, slen, hash))
|
2005-04-17 05:20:36 +07:00
|
|
|
return;
|
|
|
|
|
2010-11-09 22:29:27 +07:00
|
|
|
define_config(m, slen, hash);
|
2016-02-13 03:00:50 +07:00
|
|
|
print_config(m, slen);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2016-08-25 01:03:05 +07:00
|
|
|
static void parse_config_file(const char *p)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2016-08-25 01:03:05 +07:00
|
|
|
const char *q, *r;
|
|
|
|
|
|
|
|
while ((p = strstr(p, "CONFIG_"))) {
|
2015-07-24 12:18:45 +07:00
|
|
|
p += 7;
|
2016-08-25 01:03:05 +07:00
|
|
|
q = p;
|
|
|
|
while (*q && (isalnum(*q) || *q == '_'))
|
|
|
|
q++;
|
|
|
|
if (memcmp(q - 7, "_MODULE", 7) == 0)
|
|
|
|
r = q - 7;
|
|
|
|
else
|
|
|
|
r = q;
|
|
|
|
if (r > p)
|
|
|
|
use_config(p, r - p);
|
|
|
|
p = q;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-13 03:00:50 +07:00
|
|
|
/* test if s ends in sub */
|
2015-11-19 01:07:15 +07:00
|
|
|
static int strrcmp(const char *s, const char *sub)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
int slen = strlen(s);
|
|
|
|
int sublen = strlen(sub);
|
|
|
|
|
|
|
|
if (sublen > slen)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return memcmp(s + slen - sublen, sub, sublen);
|
|
|
|
}
|
|
|
|
|
2010-11-09 22:29:27 +07:00
|
|
|
static void do_config_file(const char *filename)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
int fd;
|
2016-08-25 01:03:05 +07:00
|
|
|
char *map;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
fd = open(filename, O_RDONLY);
|
|
|
|
if (fd < 0) {
|
2010-12-23 01:30:14 +07:00
|
|
|
fprintf(stderr, "fixdep: error opening config file: ");
|
2005-04-17 05:20:36 +07:00
|
|
|
perror(filename);
|
|
|
|
exit(2);
|
|
|
|
}
|
2015-12-08 04:26:08 +07:00
|
|
|
if (fstat(fd, &st) < 0) {
|
|
|
|
fprintf(stderr, "fixdep: error fstat'ing config file: ");
|
|
|
|
perror(filename);
|
|
|
|
exit(2);
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
if (st.st_size == 0) {
|
|
|
|
close(fd);
|
|
|
|
return;
|
|
|
|
}
|
2016-08-25 01:03:05 +07:00
|
|
|
map = malloc(st.st_size + 1);
|
|
|
|
if (!map) {
|
|
|
|
perror("fixdep: malloc");
|
2018-01-08 17:04:01 +07:00
|
|
|
exit(2);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2016-08-25 01:03:05 +07:00
|
|
|
if (read(fd, map, st.st_size) != st.st_size) {
|
|
|
|
perror("fixdep: read");
|
2018-01-08 17:04:01 +07:00
|
|
|
exit(2);
|
2016-08-25 01:03:05 +07:00
|
|
|
}
|
|
|
|
map[st.st_size] = '\0';
|
|
|
|
close(fd);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2016-08-25 01:03:05 +07:00
|
|
|
parse_config_file(map);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2016-08-25 01:03:05 +07:00
|
|
|
free(map);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2011-03-12 04:34:47 +07:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2018-01-11 20:05:41 +07:00
|
|
|
static void parse_dep_file(char *m)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2005-06-26 04:59:22 +07:00
|
|
|
char *p;
|
2005-04-17 05:20:36 +07:00
|
|
|
char s[PATH_MAX];
|
2018-01-11 20:05:41 +07:00
|
|
|
int is_last, is_target;
|
kbuild: fixdep: support concatenated dep files
The current use-case for fixdep is: a source file is run through a single
processing step, which creates a single dependency file as a side-effect,
which fixdep transforms into the file used by the kernel build process.
In order to transparently run the C pre-processor on device-tree files,
we wish to run both gcc -E and dtc on a source file in a single rule.
This generates two dependency files, which must be transformed together
into the file used by the kernel build process. This change modifies
fixdep so it can process the concatenation of multiple separate input
dependency files, and produce a correct unified output.
The code changes have the slight benefit of transforming the loop in
parse_dep_file() into more of a lexer/tokenizer, with the loop body being
more of a parser. Previously, some of this logic was mixed together
before the loop. I also added some comments, which I hope are useful.
Benchmarking shows that on a cross-compiled ARM tegra_defconfig build,
there is less than 0.5 seconds speed decrease with this change, on top
of a build time of ~2m24s. This is probably within the noise.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Rob Herring <rob.herring@calxeda.com>
2013-03-07 00:27:45 +07:00
|
|
|
int saw_any_target = 0;
|
|
|
|
int is_first_dep = 0;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2018-01-11 20:05:41 +07:00
|
|
|
while (1) {
|
kbuild: fixdep: support concatenated dep files
The current use-case for fixdep is: a source file is run through a single
processing step, which creates a single dependency file as a side-effect,
which fixdep transforms into the file used by the kernel build process.
In order to transparently run the C pre-processor on device-tree files,
we wish to run both gcc -E and dtc on a source file in a single rule.
This generates two dependency files, which must be transformed together
into the file used by the kernel build process. This change modifies
fixdep so it can process the concatenation of multiple separate input
dependency files, and produce a correct unified output.
The code changes have the slight benefit of transforming the loop in
parse_dep_file() into more of a lexer/tokenizer, with the loop body being
more of a parser. Previously, some of this logic was mixed together
before the loop. I also added some comments, which I hope are useful.
Benchmarking shows that on a cross-compiled ARM tegra_defconfig build,
there is less than 0.5 seconds speed decrease with this change, on top
of a build time of ~2m24s. This is probably within the noise.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Rob Herring <rob.herring@calxeda.com>
2013-03-07 00:27:45 +07:00
|
|
|
/* Skip any "white space" */
|
2018-01-11 20:05:41 +07:00
|
|
|
while (*m == ' ' || *m == '\\' || *m == '\n')
|
2005-04-17 05:20:36 +07:00
|
|
|
m++;
|
2018-01-11 20:05:41 +07:00
|
|
|
|
|
|
|
if (!*m)
|
|
|
|
break;
|
|
|
|
|
kbuild: fixdep: support concatenated dep files
The current use-case for fixdep is: a source file is run through a single
processing step, which creates a single dependency file as a side-effect,
which fixdep transforms into the file used by the kernel build process.
In order to transparently run the C pre-processor on device-tree files,
we wish to run both gcc -E and dtc on a source file in a single rule.
This generates two dependency files, which must be transformed together
into the file used by the kernel build process. This change modifies
fixdep so it can process the concatenation of multiple separate input
dependency files, and produce a correct unified output.
The code changes have the slight benefit of transforming the loop in
parse_dep_file() into more of a lexer/tokenizer, with the loop body being
more of a parser. Previously, some of this logic was mixed together
before the loop. I also added some comments, which I hope are useful.
Benchmarking shows that on a cross-compiled ARM tegra_defconfig build,
there is less than 0.5 seconds speed decrease with this change, on top
of a build time of ~2m24s. This is probably within the noise.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Rob Herring <rob.herring@calxeda.com>
2013-03-07 00:27:45 +07:00
|
|
|
/* Find next "white space" */
|
2005-04-17 05:20:36 +07:00
|
|
|
p = m;
|
2018-01-11 20:05:41 +07:00
|
|
|
while (*p && *p != ' ' && *p != '\\' && *p != '\n')
|
2005-04-17 05:20:36 +07:00
|
|
|
p++;
|
2018-01-11 20:05:41 +07:00
|
|
|
is_last = (*p == '\0');
|
kbuild: fixdep: support concatenated dep files
The current use-case for fixdep is: a source file is run through a single
processing step, which creates a single dependency file as a side-effect,
which fixdep transforms into the file used by the kernel build process.
In order to transparently run the C pre-processor on device-tree files,
we wish to run both gcc -E and dtc on a source file in a single rule.
This generates two dependency files, which must be transformed together
into the file used by the kernel build process. This change modifies
fixdep so it can process the concatenation of multiple separate input
dependency files, and produce a correct unified output.
The code changes have the slight benefit of transforming the loop in
parse_dep_file() into more of a lexer/tokenizer, with the loop body being
more of a parser. Previously, some of this logic was mixed together
before the loop. I also added some comments, which I hope are useful.
Benchmarking shows that on a cross-compiled ARM tegra_defconfig build,
there is less than 0.5 seconds speed decrease with this change, on top
of a build time of ~2m24s. This is probably within the noise.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Rob Herring <rob.herring@calxeda.com>
2013-03-07 00:27:45 +07:00
|
|
|
/* 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") &&
|
kbuild: add fine grained build dependencies for exported symbols
Like with kconfig options, we now have the ability to compile in and
out individual EXPORT_SYMBOL() declarations based on the content of
include/generated/autoksyms.h. However we don't want the entire
world to be rebuilt whenever that file is touched.
Let's apply the same build dependency trick used for CONFIG_* symbols
where the time stamp of empty files whose paths matching those symbols
is used to trigger fine grained rebuilds. In our case the key is the
symbol name passed to EXPORT_SYMBOL().
However, unlike config options, we cannot just use fixdep to parse
the source code for EXPORT_SYMBOL(ksym) because several variants exist
and parsing them all in a separate tool, and keeping it in synch, is
not trivially maintainable. Furthermore, there are variants such as
EXPORT_SYMBOL_GPL(pci_user_read_config_##size);
that are instanciated via a macro for which we can't easily determine
the actual exported symbol name(s) short of actually running the
preprocessor on them.
Storing the symbol name string in a special ELF section doesn't work
for targets that output assembly or preprocessed source.
So the best way is really to leverage the preprocessor by having it
output actual symbol names anchored by a special sequence that can be
easily filtered out. Then the list of symbols is simply fed to fixdep
to be merged with the other dependencies.
That implies the preprocessor is executed twice for each source file.
A previous attempt relied on a warning pragma for each EXPORT_SYMBOL()
instance that was filtered apart from stderr by the build system with
a sed script during the actual compilation pass. Unfortunately the
preprocessor/compiler diagnostic output isn't stable between versions
and this solution, although more efficient, was deemed too fragile.
Because of the lowercasing performed by fixdep, there might be name
collisions triggering spurious rebuilds for similar symbols. But this
shouldn't be a big issue in practice. (This is the case for CONFIG_*
symbols and I didn't want to be different here, whatever the original
reason for doing so.)
To avoid needless build overhead, the exported symbol name gathering is
performed only when CONFIG_TRIM_UNUSED_KSYMS is selected.
Signed-off-by: Nicolas Pitre <nico@linaro.org>
Acked-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-23 01:41:57 +07:00
|
|
|
strrcmp(s, "include/generated/autoksyms.h") &&
|
kbuild: fixdep: support concatenated dep files
The current use-case for fixdep is: a source file is run through a single
processing step, which creates a single dependency file as a side-effect,
which fixdep transforms into the file used by the kernel build process.
In order to transparently run the C pre-processor on device-tree files,
we wish to run both gcc -E and dtc on a source file in a single rule.
This generates two dependency files, which must be transformed together
into the file used by the kernel build process. This change modifies
fixdep so it can process the concatenation of multiple separate input
dependency files, and produce a correct unified output.
The code changes have the slight benefit of transforming the loop in
parse_dep_file() into more of a lexer/tokenizer, with the loop body being
more of a parser. Previously, some of this logic was mixed together
before the loop. I also added some comments, which I hope are useful.
Benchmarking shows that on a cross-compiled ARM tegra_defconfig build,
there is less than 0.5 seconds speed decrease with this change, on top
of a build time of ~2m24s. This is probably within the noise.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Rob Herring <rob.herring@calxeda.com>
2013-03-07 00:27:45 +07:00
|
|
|
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);
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2018-01-11 20:05:41 +07:00
|
|
|
|
|
|
|
if (is_last)
|
|
|
|
break;
|
|
|
|
|
kbuild: fixdep: support concatenated dep files
The current use-case for fixdep is: a source file is run through a single
processing step, which creates a single dependency file as a side-effect,
which fixdep transforms into the file used by the kernel build process.
In order to transparently run the C pre-processor on device-tree files,
we wish to run both gcc -E and dtc on a source file in a single rule.
This generates two dependency files, which must be transformed together
into the file used by the kernel build process. This change modifies
fixdep so it can process the concatenation of multiple separate input
dependency files, and produce a correct unified output.
The code changes have the slight benefit of transforming the loop in
parse_dep_file() into more of a lexer/tokenizer, with the loop body being
more of a parser. Previously, some of this logic was mixed together
before the loop. I also added some comments, which I hope are useful.
Benchmarking shows that on a cross-compiled ARM tegra_defconfig build,
there is less than 0.5 seconds speed decrease with this change, on top
of a build time of ~2m24s. This is probably within the noise.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Rob Herring <rob.herring@calxeda.com>
2013-03-07 00:27:45 +07:00
|
|
|
/*
|
|
|
|
* Start searching for next token immediately after the first
|
|
|
|
* "whitespace" character that follows this token.
|
|
|
|
*/
|
2005-04-17 05:20:36 +07:00
|
|
|
m = p + 1;
|
|
|
|
}
|
kbuild: fixdep: support concatenated dep files
The current use-case for fixdep is: a source file is run through a single
processing step, which creates a single dependency file as a side-effect,
which fixdep transforms into the file used by the kernel build process.
In order to transparently run the C pre-processor on device-tree files,
we wish to run both gcc -E and dtc on a source file in a single rule.
This generates two dependency files, which must be transformed together
into the file used by the kernel build process. This change modifies
fixdep so it can process the concatenation of multiple separate input
dependency files, and produce a correct unified output.
The code changes have the slight benefit of transforming the loop in
parse_dep_file() into more of a lexer/tokenizer, with the loop body being
more of a parser. Previously, some of this logic was mixed together
before the loop. I also added some comments, which I hope are useful.
Benchmarking shows that on a cross-compiled ARM tegra_defconfig build,
there is less than 0.5 seconds speed decrease with this change, on top
of a build time of ~2m24s. This is probably within the noise.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Rob Herring <rob.herring@calxeda.com>
2013-03-07 00:27:45 +07:00
|
|
|
|
|
|
|
if (!saw_any_target) {
|
|
|
|
fprintf(stderr, "fixdep: parse error; no targets found\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2016-02-13 03:00:50 +07:00
|
|
|
do_extra_deps();
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
printf("\n%s: $(deps_%s)\n\n", target, target);
|
|
|
|
printf("$(deps_%s):\n", target);
|
|
|
|
}
|
|
|
|
|
2018-01-11 20:05:41 +07:00
|
|
|
static void print_deps(const char *filename)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
int fd;
|
2018-01-11 20:05:41 +07:00
|
|
|
char *buf;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2018-01-11 20:05:41 +07:00
|
|
|
fd = open(filename, O_RDONLY);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (fd < 0) {
|
2010-12-23 01:30:14 +07:00
|
|
|
fprintf(stderr, "fixdep: error opening depfile: ");
|
2018-01-11 20:05:41 +07:00
|
|
|
perror(filename);
|
2005-04-17 05:20:36 +07:00
|
|
|
exit(2);
|
|
|
|
}
|
2010-12-23 01:30:14 +07:00
|
|
|
if (fstat(fd, &st) < 0) {
|
2014-06-10 17:08:13 +07:00
|
|
|
fprintf(stderr, "fixdep: error fstat'ing depfile: ");
|
2018-01-11 20:05:41 +07:00
|
|
|
perror(filename);
|
2014-06-10 17:08:13 +07:00
|
|
|
exit(2);
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
if (st.st_size == 0) {
|
|
|
|
close(fd);
|
|
|
|
return;
|
|
|
|
}
|
2018-01-11 20:05:41 +07:00
|
|
|
buf = malloc(st.st_size + 1);
|
|
|
|
if (!buf) {
|
|
|
|
perror("fixdep: malloc");
|
|
|
|
exit(2);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2018-01-11 20:05:41 +07:00
|
|
|
if (read(fd, buf, st.st_size) != st.st_size) {
|
|
|
|
perror("fixdep: read");
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
buf[st.st_size] = '\0';
|
|
|
|
close(fd);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2018-01-11 20:05:41 +07:00
|
|
|
parse_dep_file(buf);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2018-01-11 20:05:41 +07:00
|
|
|
free(buf);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2016-02-13 03:00:50 +07:00
|
|
|
if (argc == 5 && !strcmp(argv[1], "-e")) {
|
|
|
|
insert_extra_deps = 1;
|
|
|
|
argv++;
|
|
|
|
} else if (argc != 4)
|
2005-04-17 05:20:36 +07:00
|
|
|
usage();
|
|
|
|
|
|
|
|
depfile = argv[1];
|
|
|
|
target = argv[2];
|
|
|
|
cmdline = argv[3];
|
|
|
|
|
|
|
|
print_cmdline();
|
2018-01-11 20:05:41 +07:00
|
|
|
print_deps(depfile);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|