14-support-out-of-tree-config.patch 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. ---
  2. conf.c | 1
  3. confdata.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++---------------
  4. util.c | 16 +++++++++++++--
  5. 3 files changed, 61 insertions(+), 18 deletions(-)
  6. Index: kconfig/conf.c
  7. ===================================================================
  8. --- kconfig.orig/conf.c
  9. +++ kconfig/conf.c
  10. @@ -565,7 +565,6 @@ int main(int ac, char **av)
  11. }
  12. name = av[optind];
  13. conf_parse(name);
  14. - //zconfdump(stdout);
  15. if (sync_kconfig) {
  16. name = conf_get_configname();
  17. if (stat(name, &tmpstat)) {
  18. Index: kconfig/confdata.c
  19. ===================================================================
  20. --- kconfig.orig/confdata.c
  21. +++ kconfig/confdata.c
  22. @@ -13,6 +13,7 @@
  23. #include <string.h>
  24. #include <time.h>
  25. #include <unistd.h>
  26. +#include <libgen.h>
  27. #include "lkc.h"
  28. @@ -76,9 +77,7 @@ const char *conf_get_configname(void)
  29. const char *conf_get_autoconfig_name(void)
  30. {
  31. - char *name = getenv("KCONFIG_AUTOCONFIG");
  32. -
  33. - return name ? name : "include/config/auto.conf";
  34. + return getenv("KCONFIG_AUTOCONFIG");
  35. }
  36. static char *conf_expand_value(const char *in)
  37. @@ -748,6 +747,9 @@ int conf_write(const char *name)
  38. char dirname[PATH_MAX+1], tmpname[PATH_MAX+1], newname[PATH_MAX+1];
  39. char *env;
  40. + if (!name)
  41. + name = conf_get_configname();
  42. +
  43. dirname[0] = 0;
  44. if (name && name[0]) {
  45. struct stat st;
  46. @@ -842,6 +844,7 @@ static int conf_split_config(void)
  47. {
  48. const char *name;
  49. char path[PATH_MAX+1];
  50. + char *opwd, *dir, *_name;
  51. char *s, *d, c;
  52. struct symbol *sym;
  53. struct stat sb;
  54. @@ -851,8 +854,20 @@ static int conf_split_config(void)
  55. conf_read_simple(name, S_DEF_AUTO);
  56. sym_calc_value(modules_sym);
  57. - if (chdir("include/config"))
  58. - return 1;
  59. + opwd = malloc(256);
  60. + _name = strdup(name);
  61. + if (opwd == NULL || _name == NULL)
  62. + return 1;
  63. + opwd = getcwd(opwd, 256);
  64. + dir = dirname(_name);
  65. + if (dir == NULL) {
  66. + res = 1;
  67. + goto err;
  68. + }
  69. + if (chdir(dir)) {
  70. + res = 1;
  71. + goto err;
  72. + }
  73. res = 0;
  74. for_all_symbols(i, sym) {
  75. @@ -945,9 +960,11 @@ static int conf_split_config(void)
  76. close(fd);
  77. }
  78. out:
  79. - if (chdir("../.."))
  80. - return 1;
  81. -
  82. + if (chdir(opwd))
  83. + res = 1;
  84. +err:
  85. + free(opwd);
  86. + free(_name);
  87. return res;
  88. }
  89. @@ -957,25 +974,38 @@ int conf_write_autoconf(void)
  90. const char *name;
  91. FILE *out, *tristate, *out_h;
  92. int i;
  93. + char dir[PATH_MAX+1], buf[PATH_MAX+1];
  94. + char *s;
  95. +
  96. + strcpy(dir, conf_get_configname());
  97. + s = strrchr(dir, '/');
  98. + if (s)
  99. + s[1] = 0;
  100. + else
  101. + dir[0] = 0;
  102. sym_clear_all_valid();
  103. - file_write_dep("include/config/auto.conf.cmd");
  104. + sprintf(buf, "%s.config.cmd", dir);
  105. + file_write_dep(buf);
  106. if (conf_split_config())
  107. return 1;
  108. - out = fopen(".tmpconfig", "w");
  109. + sprintf(buf, "%s.tmpconfig", dir);
  110. + out = fopen(buf, "w");
  111. if (!out)
  112. return 1;
  113. - tristate = fopen(".tmpconfig_tristate", "w");
  114. + sprintf(buf, "%s.tmpconfig_tristate", dir);
  115. + tristate = fopen(buf, "w");
  116. if (!tristate) {
  117. fclose(out);
  118. return 1;
  119. }
  120. - out_h = fopen(".tmpconfig.h", "w");
  121. + sprintf(buf, "%s.tmpconfig.h", dir);
  122. + out_h = fopen(buf, "w");
  123. if (!out_h) {
  124. fclose(out);
  125. fclose(tristate);
  126. @@ -1007,19 +1037,22 @@ int conf_write_autoconf(void)
  127. name = getenv("KCONFIG_AUTOHEADER");
  128. if (!name)
  129. name = "include/generated/autoconf.h";
  130. - if (rename(".tmpconfig.h", name))
  131. + sprintf(buf, "%s.tmpconfig.h", dir);
  132. + if (rename(buf, name))
  133. return 1;
  134. name = getenv("KCONFIG_TRISTATE");
  135. if (!name)
  136. name = "include/config/tristate.conf";
  137. - if (rename(".tmpconfig_tristate", name))
  138. + sprintf(buf, "%s.tmpconfig_tristate", dir);
  139. + if (rename(buf, name))
  140. return 1;
  141. name = conf_get_autoconfig_name();
  142. /*
  143. * This must be the last step, kbuild has a dependency on auto.conf
  144. * and this marks the successful completion of the previous steps.
  145. */
  146. - if (rename(".tmpconfig", name))
  147. + sprintf(buf, "%s.tmpconfig", dir);
  148. + if (rename(buf, name))
  149. return 1;
  150. return 0;
  151. Index: kconfig/util.c
  152. ===================================================================
  153. --- kconfig.orig/util.c
  154. +++ kconfig/util.c
  155. @@ -34,6 +34,8 @@ struct file *file_lookup(const char *nam
  156. /* write a dependency file as used by kbuild to track dependencies */
  157. int file_write_dep(const char *name)
  158. {
  159. + char *str;
  160. + char buf[PATH_MAX+1], buf2[PATH_MAX+1], dir[PATH_MAX+1];
  161. struct symbol *sym, *env_sym;
  162. struct expr *e;
  163. struct file *file;
  164. @@ -41,7 +43,16 @@ int file_write_dep(const char *name)
  165. if (!name)
  166. name = ".kconfig.d";
  167. - out = fopen("..config.tmp", "w");
  168. +
  169. + strcpy(dir, conf_get_configname());
  170. + str = strrchr(dir, '/');
  171. + if (str)
  172. + str[1] = 0;
  173. + else
  174. + dir[0] = 0;
  175. +
  176. + sprintf(buf, "%s..config.tmp", dir);
  177. + out = fopen(buf, "w");
  178. if (!out)
  179. return 1;
  180. fprintf(out, "deps_config := \\\n");
  181. @@ -72,7 +83,8 @@ int file_write_dep(const char *name)
  182. fprintf(out, "\n$(deps_config): ;\n");
  183. fclose(out);
  184. - rename("..config.tmp", name);
  185. + sprintf(buf2, "%s%s", dir, name);
  186. + rename(buf, buf2);
  187. return 0;
  188. }