kconfig: rename file_write_dep and move it to confdata.c
[carl9170fw.git] / config / confdata.c
index 481b07b10eb9191fe4dde158e9feb43770b246fb..45c462c9312c1176898dccc3e6c9e0c14d63e4e2 100644 (file)
@@ -43,16 +43,16 @@ static void conf_warning(const char *fmt, ...)
        conf_warnings++;
 }
 
-static void conf_default_message_callback(const char *fmt, va_list ap)
+static void conf_default_message_callback(const char *s)
 {
        printf("#\n# ");
-       vprintf(fmt, ap);
+       printf("%s", s);
        printf("\n#\n");
 }
 
-static void (*conf_message_callback) (const char *fmt, va_list ap) =
+static void (*conf_message_callback)(const char *s) =
        conf_default_message_callback;
-void conf_set_message_callback(void (*fn) (const char *fmt, va_list ap))
+void conf_set_message_callback(void (*fn)(const char *s))
 {
        conf_message_callback = fn;
 }
@@ -60,10 +60,15 @@ void conf_set_message_callback(void (*fn) (const char *fmt, va_list ap))
 static void conf_message(const char *fmt, ...)
 {
        va_list ap;
+       char buf[4096];
+
+       if (!conf_message_callback)
+               return;
 
        va_start(ap, fmt);
-       if (conf_message_callback)
-               conf_message_callback(fmt, ap);
+
+       vsnprintf(buf, sizeof(buf), fmt, ap);
+       conf_message_callback(buf);
        va_end(ap);
 }
 
@@ -859,6 +864,35 @@ next:
        return 0;
 }
 
+/* write a dependency file as used by kbuild to track dependencies */
+static int conf_write_dep(const char *name)
+{
+       struct file *file;
+       FILE *out;
+
+       if (!name)
+               name = ".kconfig.d";
+       out = fopen("..config.tmp", "w");
+       if (!out)
+               return 1;
+       fprintf(out, "deps_config := \\\n");
+       for (file = file_list; file; file = file->next) {
+               if (file->next)
+                       fprintf(out, "\t%s \\\n", file->name);
+               else
+                       fprintf(out, "\t%s\n", file->name);
+       }
+       fprintf(out, "\n%s: \\\n"
+                    "\t$(deps_config)\n\n", conf_get_autoconfig_name());
+
+       env_write_dep(out, conf_get_autoconfig_name());
+
+       fprintf(out, "\n$(deps_config): ;\n");
+       fclose(out);
+       rename("..config.tmp", name);
+       return 0;
+}
+
 static int conf_split_config(void)
 {
        const char *name;
@@ -981,7 +1015,7 @@ int conf_write_autoconf(void)
 
        sym_clear_all_valid();
 
-       file_write_dep("include/generated/auto.conf.cmd");
+       conf_write_dep("include/generated/auto.conf.cmd");
 
        if (conf_split_config())
                return 1;