string: factorize skip_spaces and export it to be generally available
[safe/jmp/linux-2.6] / scripts / mod / sumversion.c
index 43271a1..ecf9c7d 100644 (file)
@@ -7,6 +7,7 @@
 #include <ctype.h>
 #include <errno.h>
 #include <string.h>
+#include <limits.h>
 #include "modpost.h"
 
 /*
@@ -289,6 +290,15 @@ static int parse_file(const char *fname, struct md4_ctx *md)
        release_file(file, len);
        return 1;
 }
+/* Check whether the file is a static library or not */
+static int is_static_library(const char *objfile)
+{
+       int len = strlen(objfile);
+       if (objfile[len - 2] == '.' && objfile[len - 1] == 'a')
+               return 1;
+       else
+               return 0;
+}
 
 /* We have dir/file.o.  Open dir/.file.o.cmd, look for deps_ line to
  * figure out source file. */
@@ -316,8 +326,7 @@ static int parse_source_files(const char *objfile, struct md4_ctx *md)
 
        file = grab_file(cmd, &flen);
        if (!file) {
-               fprintf(stderr, "Warning: could not find %s for %s\n",
-                       cmd, objfile);
+               warn("could not find %s for %s\n", cmd, objfile);
                goto out;
        }
 
@@ -325,8 +334,6 @@ static int parse_source_files(const char *objfile, struct md4_ctx *md)
                deps_drivers/net/dummy.o := \
                  drivers/net/dummy.c \
                    $(wildcard include/config/net/fastroute.h) \
-                 include/linux/config.h \
-                   $(wildcard include/config/h.h) \
                  include/linux/module.h \
 
           Sum all files in the same dir or subdirs.
@@ -355,9 +362,8 @@ static int parse_source_files(const char *objfile, struct md4_ctx *md)
                /* Check if this file is in same dir as objfile */
                if ((strstr(line, dir)+strlen(dir)-1) == strrchr(line, '/')) {
                        if (!parse_file(line, md)) {
-                               fprintf(stderr,
-                                       "Warning: could not open %s: %s\n",
-                                       line, strerror(errno));
+                               warn("could not open %s: %s\n",
+                                    line, strerror(errno));
                                goto out_file;
                        }
 
@@ -383,8 +389,11 @@ void get_src_version(const char *modname, char sum[], unsigned sumlen)
        struct md4_ctx md;
        char *sources, *end, *fname;
        const char *basename;
-       char filelist[strlen(getenv("MODVERDIR")) + strlen("/") +
-                     strlen(modname) - strlen(".o") + strlen(".mod") + 1 ];
+       char filelist[PATH_MAX + 1];
+       char *modverdir = getenv("MODVERDIR");
+
+       if (!modverdir)
+               modverdir = ".";
 
        /* Source files for module are in .tmp_versions/modname.mod,
           after the first line. */
@@ -392,28 +401,24 @@ void get_src_version(const char *modname, char sum[], unsigned sumlen)
                basename = strrchr(modname, '/') + 1;
        else
                basename = modname;
-       sprintf(filelist, "%s/%.*s.mod", getenv("MODVERDIR"),
+       sprintf(filelist, "%s/%.*s.mod", modverdir,
                (int) strlen(basename) - 2, basename);
 
        file = grab_file(filelist, &len);
-       if (!file) {
-               fprintf(stderr, "Warning: could not find versions for %s\n",
-                       filelist);
+       if (!file)
+               /* not a module or .mod file missing - ignore */
                return;
-       }
 
        sources = strchr(file, '\n');
        if (!sources) {
-               fprintf(stderr, "Warning: malformed versions file for %s\n",
-                       modname);
+               warn("malformed versions file for %s\n", modname);
                goto release;
        }
 
        sources++;
        end = strchr(sources, '\n');
        if (!end) {
-               fprintf(stderr, "Warning: bad ending versions file for %s\n",
-                       modname);
+               warn("bad ending versions file for %s\n", modname);
                goto release;
        }
        *end = '\0';
@@ -422,7 +427,8 @@ void get_src_version(const char *modname, char sum[], unsigned sumlen)
        while ((fname = strsep(&sources, " ")) != NULL) {
                if (!*fname)
                        continue;
-               if (!parse_source_files(fname, &md))
+               if (!(is_static_library(fname)) &&
+                               !parse_source_files(fname, &md))
                        goto release;
        }
 
@@ -438,19 +444,19 @@ static void write_version(const char *filename, const char *sum,
 
        fd = open(filename, O_RDWR);
        if (fd < 0) {
-               fprintf(stderr, "Warning: changing sum in %s failed: %s\n",
+               warn("changing sum in %s failed: %s\n",
                        filename, strerror(errno));
                return;
        }
 
        if (lseek(fd, offset, SEEK_SET) == (off_t)-1) {
-               fprintf(stderr, "Warning: changing sum in %s:%lu failed: %s\n",
+               warn("changing sum in %s:%lu failed: %s\n",
                        filename, offset, strerror(errno));
                goto out;
        }
 
        if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
-               fprintf(stderr, "Warning: writing sum in %s failed: %s\n",
+               warn("writing sum in %s failed: %s\n",
                        filename, strerror(errno));
                goto out;
        }