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

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