pkgmaker.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092
  1. /*
  2. * pkgmaker - create package meta-data for OpenADK buildsystem
  3. *
  4. * Copyright (C) 2010-2013 Waldemar Brodkorb <wbx@openadk.org>
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <ctype.h>
  20. #include <dirent.h>
  21. #include <fcntl.h>
  22. #include <stdlib.h>
  23. #include <stdio.h>
  24. #include <string.h>
  25. #include <unistd.h>
  26. #include <sys/stat.h>
  27. #include <sys/types.h>
  28. #include "sortfile.h"
  29. #include "strmap.h"
  30. #define MAXLINE 4096
  31. #define MAXVALUE 168
  32. #define MAXVAR 64
  33. #define MAXPATH 320
  34. #define HASHSZ 32
  35. static int nobinpkgs;
  36. #define fatal_error(...) { \
  37. fprintf(stderr, "Fatal error. "); \
  38. fprintf(stderr, __VA_ARGS__); \
  39. fprintf(stderr, "\n"); \
  40. exit(1); \
  41. }
  42. static int parse_var_hash(char *buf, const char *varname, StrMap *strmap) {
  43. char *key, *value, *string;
  44. string = strstr(buf, varname);
  45. if (string != NULL) {
  46. string[strlen(string)-1] = '\0';
  47. key = strtok(string, ":=");
  48. value = strtok(NULL, "=\t");
  49. if (value != NULL)
  50. strmap_put(strmap, key, value);
  51. return(0);
  52. }
  53. return(1);
  54. }
  55. static int parse_var(char *buf, const char *varname, char *pvalue, char **result) {
  56. char *pkg_var;
  57. char *key, *value, *string;
  58. char pkg_str[MAXVAR];
  59. if ((pkg_var = malloc(MAXLINE)) != NULL)
  60. memset(pkg_var, 0, MAXLINE);
  61. else {
  62. perror("Can not allocate memory");
  63. exit(EXIT_FAILURE);
  64. }
  65. if (snprintf(pkg_str, MAXVAR, "%s:=", varname) < 0)
  66. perror("can not create path variable.");
  67. string = strstr(buf, pkg_str);
  68. if (string != NULL) {
  69. string[strlen(string)-1] = '\0';
  70. key = strtok(string, ":=");
  71. value = strtok(NULL, "=\t");
  72. if (value != NULL) {
  73. strncat(pkg_var, value, strlen(value));
  74. *result = strdup(pkg_var);
  75. } else {
  76. nobinpkgs = 1;
  77. *result = NULL;
  78. }
  79. free(pkg_var);
  80. return(0);
  81. } else {
  82. if (snprintf(pkg_str, MAXVAR, "%s+=", varname) < 0)
  83. perror("can not create path variable.");
  84. string = strstr(buf, pkg_str);
  85. if (string != NULL) {
  86. string[strlen(string)-1] = '\0';
  87. key = strtok(string, "+=");
  88. value = strtok(NULL, "=\t");
  89. if (pvalue != NULL)
  90. strncat(pkg_var, pvalue, strlen(pvalue));
  91. strncat(pkg_var, " ", 1);
  92. if (value != NULL)
  93. strncat(pkg_var, value, strlen(value));
  94. *result = strdup(pkg_var);
  95. free(pkg_var);
  96. return(0);
  97. }
  98. }
  99. free(pkg_var);
  100. return(1);
  101. }
  102. static int parse_var_with_pkg(char *buf, const char *varname, char *pvalue, char **result, char **pkgname, int varlen) {
  103. char *pkg_var, *check;
  104. char *key, *value, *string;
  105. if ((pkg_var = malloc(MAXLINE)) != NULL)
  106. memset(pkg_var, 0, MAXLINE);
  107. else {
  108. perror("Can not allocate memory");
  109. exit(EXIT_FAILURE);
  110. }
  111. check = strstr(buf, ":=");
  112. if (check != NULL) {
  113. string = strstr(buf, varname);
  114. if (string != NULL) {
  115. string[strlen(string)-1] = '\0';
  116. key = strtok(string, ":=");
  117. *pkgname = strdup(key+varlen);
  118. value = strtok(NULL, "=\t");
  119. if (value != NULL) {
  120. strncat(pkg_var, value, strlen(value));
  121. *result = strdup(pkg_var);
  122. }
  123. free(pkg_var);
  124. return(0);
  125. }
  126. } else {
  127. string = strstr(buf, varname);
  128. if (string != NULL) {
  129. string[strlen(string)-1] = '\0';
  130. key = strtok(string, "+=");
  131. value = strtok(NULL, "=\t");
  132. if (pvalue != NULL)
  133. strncat(pkg_var, pvalue, strlen(pvalue));
  134. strncat(pkg_var, " ", 1);
  135. if (value != NULL)
  136. strncat(pkg_var, value, strlen(value));
  137. *result = strdup(pkg_var);
  138. free(pkg_var);
  139. return(0);
  140. }
  141. }
  142. free(pkg_var);
  143. return(1);
  144. }
  145. #if 0
  146. static void iter_debug(const char *key, const char *value, const void *obj) {
  147. fprintf(stderr, "HASHMAP key: %s value: %s\n", key, value);
  148. }
  149. #endif
  150. static int hash_str(char *string) {
  151. int i;
  152. int hash;
  153. hash = 0;
  154. for (i=0; i<(int)strlen(string); i++) {
  155. hash += string[i];
  156. }
  157. return(hash);
  158. }
  159. static void iter(const char *key, const char *value, const void *obj) {
  160. FILE *config, *section;
  161. int hash;
  162. char *valuestr, *pkg, *subpkg;
  163. char buf[MAXPATH];
  164. char infile[MAXPATH];
  165. char outfile[MAXPATH];
  166. valuestr = strdup(value);
  167. config = fopen("package/Config.in.auto", "a");
  168. if (config == NULL)
  169. fatal_error("Can not open file package/Config.in.auto");
  170. hash = hash_str(valuestr);
  171. snprintf(infile, MAXPATH, "package/pkglist.d/sectionlst.%d", hash);
  172. snprintf(outfile, MAXPATH, "package/pkglist.d/sectionlst.%d.sorted", hash);
  173. if (access(infile, F_OK) == 0) {
  174. valuestr[strlen(valuestr)-1] = '\0';
  175. fprintf(config, "menu \"%s\"\n", valuestr);
  176. sortfile(infile, outfile);
  177. /* avoid duplicate section entries */
  178. unlink(infile);
  179. section = fopen(outfile, "r");
  180. while (fgets(buf, MAXPATH, section) != NULL) {
  181. buf[strlen(buf)-1] = '\0';
  182. if (buf[strlen(buf)-1] == '@') {
  183. buf[strlen(buf)-1] = '\0';
  184. fprintf(config, "source \"package/%s/Config.in.manual\"\n", buf);
  185. } else {
  186. subpkg = strtok(buf, "|");
  187. subpkg[strlen(subpkg)-1] = '\0';
  188. pkg = strtok(NULL, "|");
  189. fprintf(config, "source \"package/pkgconfigs.d/%s/Config.in.%s\"\n", pkg, subpkg);
  190. }
  191. }
  192. fprintf(config, "endmenu\n\n");
  193. fclose(section);
  194. }
  195. fclose(config);
  196. }
  197. static char *tolowerstr(char *string) {
  198. int i;
  199. char *str;
  200. /* transform to lowercase variable name */
  201. str = strdup(string);
  202. for (i=0; i<(int)strlen(str); i++) {
  203. if (str[i] == '_')
  204. str[i] = '-';
  205. str[i] = tolower(str[i]);
  206. }
  207. return(str);
  208. }
  209. static char *toupperstr(char *string) {
  210. int i;
  211. char *str;
  212. /* transform to uppercase variable name */
  213. str = strdup(string);
  214. for (i=0; i<(int)strlen(str); i++) {
  215. if (str[i] == '+')
  216. str[i] = 'X';
  217. if (str[i] == '-')
  218. str[i] = '_';
  219. /* remove negation here, useful for package host depends */
  220. if (str[i] == '!')
  221. str[i] = '_';
  222. str[i] = toupper(str[i]);
  223. }
  224. return(str);
  225. }
  226. int main() {
  227. DIR *pkgdir, *pkglistdir;
  228. struct dirent *pkgdirp;
  229. FILE *pkg, *cfg, *menuglobal, *section;
  230. char hvalue[MAXVALUE];
  231. char buf[MAXPATH];
  232. char tbuf[MAXPATH];
  233. char path[MAXPATH];
  234. char spath[MAXPATH];
  235. char dir[MAXPATH];
  236. char variable[2*MAXVAR];
  237. char *key, *value, *token, *cftoken, *sp, *hkey, *val, *pkg_fd;
  238. char *pkg_name, *pkg_depends, *pkg_section, *pkg_descr, *pkg_url;
  239. char *pkg_cxx, *pkg_subpkgs, *pkg_cfline, *pkg_dflt, *pkg_multi;
  240. char *pkg_need_cxx, *pkg_need_java, *pkgname;
  241. char *pkg_libc_depends, *pkg_host_depends, *pkg_system_depends, *pkg_arch_depends, *pkg_flavours, *pkg_flavours_string, *pkg_choices, *pseudo_name;
  242. char *packages, *pkg_name_u, *pkgs, *pkg_opts, *pkg_libname;
  243. char *saveptr, *p_ptr, *s_ptr, *pkg_helper;
  244. int result;
  245. StrMap *pkgmap, *sectionmap;
  246. pkg_name = NULL;
  247. pkg_descr = NULL;
  248. pkg_section = NULL;
  249. pkg_url = NULL;
  250. pkg_depends = NULL;
  251. pkg_opts = NULL;
  252. pkg_libname = NULL;
  253. pkg_flavours = NULL;
  254. pkg_flavours_string = NULL;
  255. pkg_choices = NULL;
  256. pkg_subpkgs = NULL;
  257. pkg_arch_depends = NULL;
  258. pkg_system_depends = NULL;
  259. pkg_host_depends = NULL;
  260. pkg_libc_depends = NULL;
  261. pkg_cxx = NULL;
  262. pkg_dflt = NULL;
  263. pkg_cfline = NULL;
  264. pkg_multi = NULL;
  265. pkg_need_cxx = NULL;
  266. pkg_need_java = NULL;
  267. pkgname = NULL;
  268. pkg_helper = NULL;
  269. p_ptr = NULL;
  270. s_ptr = NULL;
  271. unlink("package/Config.in.auto");
  272. /* open global sectionfile */
  273. menuglobal = fopen("package/Config.in.auto.global", "w");
  274. if (menuglobal == NULL)
  275. fatal_error("global section file not writable.");
  276. /* read section list and create a hash table */
  277. section = fopen("package/section.lst", "r");
  278. if (section == NULL)
  279. fatal_error("section listfile is missing");
  280. sectionmap = strmap_new(HASHSZ);
  281. while (fgets(tbuf, MAXPATH, section) != NULL) {
  282. key = strtok(tbuf, "\t");
  283. value = strtok(NULL, "\t");
  284. strmap_put(sectionmap, key, value);
  285. }
  286. fclose(section);
  287. if (mkdir("package/pkgconfigs.d", S_IRWXU) > 0)
  288. fatal_error("creation of package/pkgconfigs.d failed.");
  289. if (mkdir("package/pkgconfigs.d/gcc", S_IRWXU) > 0)
  290. fatal_error("creation of package/pkgconfigs.d/gcc failed.");
  291. if (mkdir("package/pkglist.d", S_IRWXU) > 0)
  292. fatal_error("creation of package/pkglist.d failed.");
  293. /* delete Config.in.dev */
  294. if (snprintf(path, MAXPATH, "package/pkgconfigs.d/gcc/Config.in.dev") < 0)
  295. fatal_error("failed to create path variable.");
  296. unlink(path);
  297. cfg = fopen(path, "w");
  298. if (cfg == NULL)
  299. fatal_error("Config.in.dev can not be opened");
  300. fprintf(cfg, "config ADK_PACKAGE_GLIBC_DEV\n");
  301. fprintf(cfg, "\tprompt \"glibc-dev............ development files for glibc\"\n");
  302. fprintf(cfg, "\ttristate\n");
  303. fprintf(cfg, "\tdefault n\n");
  304. fprintf(cfg, "\tdepends on ADK_TARGET_LIB_GLIBC\n");
  305. fprintf(cfg, "\thelp\n");
  306. fprintf(cfg, "\t GNU C library header files.\n\n");
  307. fprintf(cfg, "config ADK_PACKAGE_EGLIBC_DEV\n");
  308. fprintf(cfg, "\tprompt \"eglibc-dev........... development files for eglibc\"\n");
  309. fprintf(cfg, "\ttristate\n");
  310. fprintf(cfg, "\tdefault n\n");
  311. fprintf(cfg, "\tdepends on ADK_TARGET_LIB_EGLIBC\n");
  312. fprintf(cfg, "\thelp\n");
  313. fprintf(cfg, "\t GNU C library header files.\n\n");
  314. fprintf(cfg, "config ADK_PACKAGE_UCLIBC_DEV\n");
  315. fprintf(cfg, "\tprompt \"uclibc-dev........... development files for uclibc\"\n");
  316. fprintf(cfg, "\ttristate\n");
  317. fprintf(cfg, "\tdefault n\n");
  318. fprintf(cfg, "\tdepends on ADK_TARGET_LIB_UCLIBC\n");
  319. fprintf(cfg, "\thelp\n");
  320. fprintf(cfg, "\t C library header files.\n\n");
  321. fprintf(cfg, "config ADK_PACKAGE_MUSL_DEV\n");
  322. fprintf(cfg, "\tprompt \"musl-dev............. development files for musl\"\n");
  323. fprintf(cfg, "\ttristate\n");
  324. fprintf(cfg, "\tdefault n\n");
  325. fprintf(cfg, "\tdepends on ADK_TARGET_LIB_MUSL\n");
  326. fprintf(cfg, "\thelp\n");
  327. fprintf(cfg, "\t C library header files.\n\n");
  328. fclose(cfg);
  329. /* read Makefile's for all packages */
  330. pkgdir = opendir("package");
  331. while ((pkgdirp = readdir(pkgdir)) != NULL) {
  332. /* skip dotfiles */
  333. if (strncmp(pkgdirp->d_name, ".", 1) > 0) {
  334. if (snprintf(path, MAXPATH, "package/%s/Makefile", pkgdirp->d_name) < 0)
  335. fatal_error("can not create path variable.");
  336. pkg = fopen(path, "r");
  337. if (pkg == NULL)
  338. continue;
  339. /* skip manually maintained packages */
  340. if (snprintf(path, MAXPATH, "package/%s/Config.in.manual", pkgdirp->d_name) < 0)
  341. fatal_error("can not create path variable.");
  342. if (!access(path, F_OK)) {
  343. while (fgets(buf, MAXPATH, pkg) != NULL) {
  344. if ((parse_var(buf, "PKG_SECTION", NULL, &pkg_section)) == 0)
  345. continue;
  346. }
  347. memset(hvalue, 0 , MAXVALUE);
  348. result = strmap_get(sectionmap, pkg_section, hvalue, sizeof(hvalue));
  349. if (result == 1) {
  350. if (snprintf(spath, MAXPATH, "package/pkglist.d/sectionlst.%d", hash_str(hvalue)) < 0)
  351. fatal_error("can not create path variable.");
  352. section = fopen(spath, "a");
  353. if (section != NULL) {
  354. fprintf(section, "%s@\n", pkgdirp->d_name);
  355. fclose(section);
  356. }
  357. } else
  358. fatal_error("Can not find section description for package %s.",
  359. pkgdirp->d_name);
  360. fclose(pkg);
  361. continue;
  362. }
  363. nobinpkgs = 0;
  364. /* create output directories */
  365. if (snprintf(dir, MAXPATH, "package/pkgconfigs.d/%s", pkgdirp->d_name) < 0)
  366. fatal_error("can not create dir variable.");
  367. if (mkdir(dir, S_IRWXU) > 0)
  368. fatal_error("can not create directory.");
  369. /* allocate memory */
  370. hkey = malloc(MAXVAR);
  371. memset(hkey, 0, MAXVAR);
  372. memset(variable, 0, 2*MAXVAR);
  373. pkgmap = strmap_new(HASHSZ);
  374. /* parse package Makefile */
  375. while (fgets(buf, MAXPATH, pkg) != NULL) {
  376. /* just read variables prefixed with PKG */
  377. if (strncmp(buf, "PKG", 3) == 0) {
  378. if ((parse_var(buf, "PKG_NAME", NULL, &pkg_name)) == 0)
  379. continue;
  380. if (pkg_name != NULL)
  381. pkg_name_u = toupperstr(pkg_name);
  382. else
  383. pkg_name_u = toupperstr(pkgdirp->d_name);
  384. snprintf(variable, MAXVAR, "PKG_CFLINE_%s", pkg_name_u);
  385. if ((parse_var(buf, variable, pkg_cfline, &pkg_cfline)) == 0)
  386. continue;
  387. snprintf(variable, MAXVAR, "PKG_DFLT_%s", pkg_name_u);
  388. if ((parse_var(buf, variable, NULL, &pkg_dflt)) == 0)
  389. continue;
  390. if ((parse_var(buf, "PKG_LIBC_DEPENDS", NULL, &pkg_libc_depends)) == 0)
  391. continue;
  392. if ((parse_var(buf, "PKG_HOST_DEPENDS", NULL, &pkg_host_depends)) == 0)
  393. continue;
  394. if ((parse_var(buf, "PKG_ARCH_DEPENDS", NULL, &pkg_arch_depends)) == 0)
  395. continue;
  396. if ((parse_var(buf, "PKG_SYSTEM_DEPENDS", NULL, &pkg_system_depends)) == 0)
  397. continue;
  398. if ((parse_var(buf, "PKG_DESCR", NULL, &pkg_descr)) == 0)
  399. continue;
  400. if ((parse_var(buf, "PKG_SECTION", NULL, &pkg_section)) == 0)
  401. continue;
  402. if ((parse_var(buf, "PKG_URL", NULL, &pkg_url)) == 0)
  403. continue;
  404. if ((parse_var(buf, "PKG_CXX", NULL, &pkg_cxx)) == 0)
  405. continue;
  406. if ((parse_var(buf, "PKG_NEED_CXX", NULL, &pkg_need_cxx)) == 0)
  407. continue;
  408. if ((parse_var(buf, "PKG_NEED_JAVA", NULL, &pkg_need_java)) == 0)
  409. continue;
  410. if ((parse_var(buf, "PKG_MULTI", NULL, &pkg_multi)) == 0)
  411. continue;
  412. if ((parse_var(buf, "PKG_DEPENDS", pkg_depends, &pkg_depends)) == 0)
  413. continue;
  414. if ((parse_var(buf, "PKG_LIBNAME", pkg_libname, &pkg_libname)) == 0)
  415. continue;
  416. if ((parse_var(buf, "PKG_OPTS", pkg_opts, &pkg_opts)) == 0)
  417. continue;
  418. if ((parse_var_with_pkg(buf, "PKG_FLAVOURS_STRING_", pkg_flavours_string, &pkg_flavours_string, &pkgname, 20)) == 0)
  419. continue;
  420. if ((parse_var_with_pkg(buf, "PKG_FLAVOURS_", pkg_flavours, &pkg_flavours, &pkgname, 13)) == 0)
  421. continue;
  422. if ((parse_var_hash(buf, "PKGFD_", pkgmap)) == 0)
  423. continue;
  424. if ((parse_var_hash(buf, "PKGFX_", pkgmap)) == 0)
  425. continue;
  426. if ((parse_var_hash(buf, "PKGFS_", pkgmap)) == 0)
  427. continue;
  428. if ((parse_var_hash(buf, "PKGFC_", pkgmap)) == 0)
  429. continue;
  430. if ((parse_var_with_pkg(buf, "PKG_CHOICES_", pkg_choices, &pkg_choices, &pkgname, 12)) == 0)
  431. continue;
  432. if ((parse_var_hash(buf, "PKGCD_", pkgmap)) == 0)
  433. continue;
  434. if ((parse_var_hash(buf, "PKGCS_", pkgmap)) == 0)
  435. continue;
  436. if ((parse_var(buf, "PKG_SUBPKGS", pkg_subpkgs, &pkg_subpkgs)) == 0)
  437. continue;
  438. if ((parse_var_hash(buf, "PKGSD_", pkgmap)) == 0)
  439. continue;
  440. if ((parse_var_hash(buf, "PKGSS_", pkgmap)) == 0)
  441. continue;
  442. if ((parse_var_hash(buf, "PKGSC_", pkgmap)) == 0)
  443. continue;
  444. }
  445. }
  446. /* end of package Makefile parsing */
  447. if (fclose(pkg) != 0)
  448. perror("Failed to close file stream for Makefile");
  449. #if 0
  450. if (pkg_name != NULL)
  451. fprintf(stderr, "Package name is %s\n", pkg_name);
  452. if (pkg_section != NULL)
  453. fprintf(stderr, "Package section is %s\n", pkg_section);
  454. if (pkg_descr != NULL)
  455. fprintf(stderr, "Package description is %s\n", pkg_descr);
  456. if (pkg_depends != NULL)
  457. fprintf(stderr, "Package dependencies are %s\n", pkg_depends);
  458. if (pkg_subpkgs != NULL)
  459. fprintf(stderr, "Package subpackages are %s\n", pkg_subpkgs);
  460. if (pkg_flavours != NULL && pkgname != NULL)
  461. fprintf(stderr, "Package flavours for %s are %s\n", pkgname, pkg_flavours);
  462. if (pkg_flavours_string != NULL && pkgname != NULL)
  463. fprintf(stderr, "Package string flavours for %s are %s\n", pkgname, pkg_flavours_string);
  464. if (pkg_choices != NULL && pkgname != NULL)
  465. fprintf(stderr, "Package choices for %s are %s\n", pkgname, pkg_choices);
  466. if (pkg_url != NULL)
  467. fprintf(stderr, "Package homepage is %s\n", pkg_url);
  468. if (pkg_cfline != NULL)
  469. fprintf(stderr, "Package cfline is %s\n", pkg_cfline);
  470. if (pkg_multi != NULL)
  471. fprintf(stderr, "Package multi is %s\n", pkg_multi);
  472. if (pkg_opts != NULL)
  473. fprintf(stderr, "Package options are %s\n", pkg_opts);
  474. strmap_enum(pkgmap, iter_debug, NULL);
  475. #endif
  476. /* generate master source Config.in file */
  477. if (snprintf(path, MAXPATH, "package/pkgconfigs.d/%s/Config.in", pkgdirp->d_name) < 0)
  478. fatal_error("path variable creation failed.");
  479. fprintf(menuglobal, "source \"%s\"\n", path);
  480. /* recreating file is faster than truncating with w+ */
  481. unlink(path);
  482. cfg = fopen(path, "w");
  483. if (cfg == NULL)
  484. continue;
  485. pkgs = NULL;
  486. if (pkg_subpkgs != NULL)
  487. pkgs = strdup(pkg_subpkgs);
  488. fprintf(cfg, "config ADK_COMPILE_%s\n", toupperstr(pkgdirp->d_name));
  489. fprintf(cfg, "\ttristate\n");
  490. if (nobinpkgs == 0) {
  491. fprintf(cfg, "\tdepends on ");
  492. if (pkgs != NULL) {
  493. if (pkg_multi != NULL)
  494. if (strncmp(pkg_multi, "1", 1) == 0)
  495. fprintf(cfg, "ADK_HAVE_DOT_CONFIG || ");
  496. token = strtok(pkgs, " ");
  497. fprintf(cfg, "ADK_PACKAGE_%s", token);
  498. token = strtok(NULL, " ");
  499. while (token != NULL) {
  500. fprintf(cfg, " || ADK_PACKAGE_%s", token);
  501. token = strtok(NULL, " ");
  502. }
  503. fprintf(cfg, "\n");
  504. } else {
  505. fprintf(cfg, "ADK_PACKAGE_%s\n", toupperstr(pkgdirp->d_name));
  506. }
  507. }
  508. fprintf(cfg, "\tdefault n\n");
  509. fclose(cfg);
  510. free(pkgs);
  511. /* skip packages without binary package output */
  512. if (nobinpkgs == 1)
  513. continue;
  514. /* generate binary package specific Config.in files */
  515. if (pkg_subpkgs != NULL)
  516. packages = tolowerstr(pkg_subpkgs);
  517. else
  518. packages = strdup(pkgdirp->d_name);
  519. token = strtok_r(packages, " ", &p_ptr);
  520. while (token != NULL) {
  521. strncat(hkey, "PKGSC_", 6);
  522. strncat(hkey, toupperstr(token), strlen(token));
  523. memset(hvalue, 0 , MAXVALUE);
  524. result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  525. memset(hkey, 0 , MAXVAR);
  526. if (result == 1)
  527. pkg_section = strdup(hvalue);
  528. strncat(hkey, "PKGSD_", 6);
  529. strncat(hkey, toupperstr(token), strlen(token));
  530. memset(hvalue, 0 , MAXVALUE);
  531. result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  532. memset(hkey, 0 , MAXVAR);
  533. if (result == 1)
  534. pkg_descr = strdup(hvalue);
  535. pseudo_name = malloc(MAXLINE);
  536. memset(pseudo_name, 0, MAXLINE);
  537. strncat(pseudo_name, token, strlen(token));
  538. while (strlen(pseudo_name) < 20)
  539. strncat(pseudo_name, ".", 1);
  540. if (snprintf(path, MAXPATH, "package/pkgconfigs.d/%s/Config.in.%s", pkgdirp->d_name, token) < 0)
  541. fatal_error("failed to create path variable.");
  542. /* create temporary section files */
  543. memset(hvalue, 0 , MAXVALUE);
  544. result = strmap_get(sectionmap, pkg_section, hvalue, sizeof(hvalue));
  545. if (result == 1) {
  546. if (snprintf(spath, MAXPATH, "package/pkglist.d/sectionlst.%d", hash_str(hvalue)) < 0)
  547. fatal_error("failed to create path variable.");
  548. section = fopen(spath, "a");
  549. if (section != NULL) {
  550. fprintf(section, "%s |%s\n", token, pkgdirp->d_name);
  551. fclose(section);
  552. }
  553. } else
  554. fatal_error("Can not find section description for package %s.", pkgdirp->d_name);
  555. unlink(path);
  556. cfg = fopen(path, "w");
  557. if (cfg == NULL)
  558. perror("Can not open Config.in file");
  559. if (pkg_need_cxx != NULL) {
  560. fprintf(cfg, "comment \"%s... %s (disabled, c++ missing)\"\n", token, pkg_descr);
  561. fprintf(cfg, "depends on !ADK_TOOLCHAIN_GCC_CXX\n\n");
  562. }
  563. fprintf(cfg, "config ADK_PACKAGE_%s\n", toupperstr(token));
  564. /* no prompt for devonly packages */
  565. if (pkg_opts != NULL) {
  566. if (strstr(pkg_opts, "devonly") != NULL) {
  567. fprintf(cfg, "\t#prompt \"%s. %s\"\n", pseudo_name, pkg_descr);
  568. } else {
  569. fprintf(cfg, "\tprompt \"%s. %s\"\n", pseudo_name, pkg_descr);
  570. }
  571. } else {
  572. fprintf(cfg, "\tprompt \"%s. %s\"\n", pseudo_name, pkg_descr);
  573. }
  574. fprintf(cfg, "\ttristate\n");
  575. if (pkg_multi != NULL)
  576. if (strncmp(pkg_multi, "1", 1) == 0)
  577. if (strncmp(toupperstr(token), toupperstr(pkgdirp->d_name), strlen(token)) != 0)
  578. fprintf(cfg, "\tdepends on ADK_PACKAGE_%s\n", toupperstr(pkgdirp->d_name));
  579. free(pseudo_name);
  580. /* print custom cf line */
  581. if (pkg_cfline != NULL) {
  582. cftoken = strtok_r(pkg_cfline, "@", &saveptr);
  583. while (cftoken != NULL) {
  584. fprintf(cfg, "\t%s\n", cftoken);
  585. cftoken = strtok_r(NULL, "@", &saveptr);
  586. }
  587. free(pkg_cfline);
  588. pkg_cfline = NULL;
  589. }
  590. /* add sub package dependencies */
  591. strncat(hkey, "PKGSS_", 6);
  592. strncat(hkey, toupperstr(token), strlen(token));
  593. memset(hvalue, 0, MAXVALUE);
  594. result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  595. if (result == 1) {
  596. val = strtok_r(hvalue, " ", &saveptr);
  597. while (val != NULL) {
  598. if (strncmp(val, "kmod", 4) == 0)
  599. fprintf(cfg, "\tselect ADK_KPACKAGE_%s\n", toupperstr(val));
  600. else
  601. fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(val));
  602. val = strtok_r(NULL, " ", &saveptr);
  603. }
  604. }
  605. memset(hkey, 0, MAXVAR);
  606. /* create package target system dependency information */
  607. if (pkg_system_depends != NULL) {
  608. pkg_helper = strdup(pkg_system_depends);
  609. token = strtok(pkg_helper, " ");
  610. fprintf(cfg, "\tdepends on ");
  611. sp = "";
  612. while (token != NULL) {
  613. if(strncmp(token, "!", 1) == 0) {
  614. fprintf(cfg, "%s!ADK_TARGET_SYSTEM%s", sp, toupperstr(token));
  615. sp = " && ";
  616. } else {
  617. fprintf(cfg, "%sADK_TARGET_SYSTEM_%s", sp, toupperstr(token));
  618. sp = " || ";
  619. }
  620. token = strtok(NULL, " ");
  621. }
  622. fprintf(cfg, "\n");
  623. free(pkg_helper);
  624. pkg_helper = NULL;
  625. }
  626. /* create package host dependency information */
  627. if (pkg_host_depends != NULL) {
  628. pkg_helper = strdup(pkg_host_depends);
  629. token = strtok(pkg_helper, " ");
  630. fprintf(cfg, "\tdepends on ");
  631. sp = "";
  632. while (token != NULL) {
  633. if(strncmp(token, "!", 1) == 0) {
  634. fprintf(cfg, "%s!ADK_HOST%s", sp, toupperstr(token));
  635. sp = " && ";
  636. } else {
  637. fprintf(cfg, "%sADK_HOST_%s", sp, toupperstr(token));
  638. sp = " || ";
  639. }
  640. token = strtok(NULL, " ");
  641. }
  642. fprintf(cfg, "\n");
  643. free(pkg_helper);
  644. pkg_helper = NULL;
  645. }
  646. /* create package libc dependency information */
  647. if (pkg_libc_depends != NULL) {
  648. pkg_helper = strdup(pkg_libc_depends);
  649. token = strtok(pkg_helper, " ");
  650. fprintf(cfg, "\tdepends on ");
  651. sp = "";
  652. while (token != NULL) {
  653. if(strncmp(token, "!", 1) == 0) {
  654. fprintf(cfg, "%s!ADK_TARGET_LIB_%s", sp, toupperstr(token));
  655. sp = " && ";
  656. } else {
  657. fprintf(cfg, "%sADK_TARGET_LIB_%s", sp, toupperstr(token));
  658. sp = " || ";
  659. }
  660. token = strtok(NULL, " ");
  661. }
  662. fprintf(cfg, "\n");
  663. free(pkg_helper);
  664. pkg_helper = NULL;
  665. }
  666. /* create package target architecture dependency information */
  667. if (pkg_arch_depends != NULL) {
  668. pkg_helper = strdup(pkg_arch_depends);
  669. token = strtok(pkg_helper, " ");
  670. fprintf(cfg, "\tdepends on ");
  671. sp = "";
  672. while (token != NULL) {
  673. if(strncmp(token, "!", 1) == 0) {
  674. fprintf(cfg, "%s!ADK_LINUX%s", sp, toupperstr(token));
  675. sp = " && ";
  676. } else {
  677. fprintf(cfg, "%sADK_LINUX_%s", sp, toupperstr(token));
  678. sp = " || ";
  679. }
  680. token = strtok(NULL, " ");
  681. }
  682. fprintf(cfg, "\n");
  683. free(pkg_helper);
  684. pkg_helper = NULL;
  685. }
  686. /* create package dependency information */
  687. if (pkg_depends != NULL) {
  688. token = strtok(pkg_depends, " ");
  689. while (token != NULL) {
  690. if (strncmp(token, "kmod", 4) == 0)
  691. fprintf(cfg, "\tselect ADK_KPACKAGE_%s\n", toupperstr(token));
  692. else
  693. fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(token));
  694. token = strtok(NULL, " ");
  695. }
  696. free(pkg_depends);
  697. pkg_depends = NULL;
  698. }
  699. if (pkg_need_cxx != NULL) {
  700. fprintf(cfg, "\tdepends on ADK_TOOLCHAIN_GCC_CXX\n");
  701. }
  702. if (pkg_need_java != NULL) {
  703. fprintf(cfg, "\tdepends on ADK_TOOLCHAIN_GCC_JAVA\n");
  704. pkg_need_java = NULL;
  705. }
  706. fprintf(cfg, "\tselect ADK_COMPILE_%s\n", toupperstr(pkgdirp->d_name));
  707. if (pkg_dflt != NULL) {
  708. fprintf(cfg, "\tdefault %s\n", pkg_dflt);
  709. pkg_dflt = NULL;
  710. } else {
  711. fprintf(cfg, "\tdefault n\n");
  712. }
  713. fprintf(cfg, "\thelp\n");
  714. fprintf(cfg, "\t %s\n\n", pkg_descr);
  715. if (pkg_url != NULL)
  716. fprintf(cfg, "\t WWW: %s\n", pkg_url);
  717. /* handle special C++ packages */
  718. if (pkg_cxx != NULL) {
  719. fprintf(cfg, "\nchoice\n");
  720. fprintf(cfg, "prompt \"C++ library to use\"\n");
  721. fprintf(cfg, "depends on ADK_COMPILE_%s\n\n", toupperstr(pkgdirp->d_name));
  722. fprintf(cfg, "default ADK_COMPILE_%s_WITH_STDCXX if ADK_TARGET_LIB_GLIBC || ADK_TARGET_LIB_EGLIBC\n", pkg_cxx);
  723. fprintf(cfg, "default ADK_COMPILE_%s_WITH_UCLIBCXX if ADK_TARGET_LIB_UCLIBC\n\n", pkg_cxx);
  724. fprintf(cfg, "config ADK_COMPILE_%s_WITH_STDCXX\n", pkg_cxx);
  725. fprintf(cfg, "\tbool \"GNU C++ library\"\n");
  726. fprintf(cfg, "\tselect ADK_PACKAGE_LIBSTDCXX\n\n");
  727. fprintf(cfg, "config ADK_COMPILE_%s_WITH_UCLIBCXX\n", pkg_cxx);
  728. fprintf(cfg, "\tbool \"uClibc++ library\"\n");
  729. fprintf(cfg, "\tselect ADK_PACKAGE_UCLIBCXX\n\n");
  730. fprintf(cfg, "endchoice\n");
  731. free(pkg_cxx);
  732. pkg_cxx = NULL;
  733. }
  734. /* package flavours */
  735. if (pkg_flavours != NULL) {
  736. token = strtok(pkg_flavours, " ");
  737. while (token != NULL) {
  738. fprintf(cfg, "\nconfig ADK_PACKAGE_%s_%s\n", pkgname, toupperstr(token));
  739. // process default value
  740. strncat(hkey, "PKGFX_", 6);
  741. strncat(hkey, token, strlen(token));
  742. memset(hvalue, 0 , MAXVALUE);
  743. strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  744. memset(hkey, 0 , MAXVAR);
  745. pkg_fd = strdup(hvalue);
  746. if (strlen(pkg_fd) > 0)
  747. fprintf(cfg, "\tdefault %s\n", pkg_fd);
  748. else
  749. fprintf(cfg, "\tdefault n\n");
  750. // process flavour cfline
  751. strncat(hkey, "PKGFC_", 6);
  752. strncat(hkey, token, strlen(token));
  753. memset(hvalue, 0 , MAXVALUE);
  754. strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  755. memset(hkey, 0 , MAXVAR);
  756. pkg_fd = strdup(hvalue);
  757. if (strlen(pkg_fd) > 0)
  758. fprintf(cfg, "\t%s\n", pkg_fd);
  759. fprintf(cfg, "\tboolean ");
  760. strncat(hkey, "PKGFD_", 6);
  761. strncat(hkey, token, strlen(token));
  762. memset(hvalue, 0 , MAXVALUE);
  763. strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  764. memset(hkey, 0 , MAXVAR);
  765. pkg_fd = strdup(hvalue);
  766. fprintf(cfg, "\"%s\"\n", pkg_fd);
  767. fprintf(cfg, "\tdepends on ADK_PACKAGE_%s\n", pkgname);
  768. strncat(hkey, "PKGFS_", 6);
  769. strncat(hkey, token, strlen(token));
  770. result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  771. if (result == 1) {
  772. val = strtok_r(hvalue, " ", &saveptr);
  773. while (val != NULL) {
  774. if (strncmp(val, "kmod", 4) == 0)
  775. fprintf(cfg, "\tselect ADK_KPACKAGE_%s\n", toupperstr(val));
  776. else
  777. fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(val));
  778. val = strtok_r(NULL, " ", &saveptr);
  779. }
  780. }
  781. memset(hkey, 0, MAXVAR);
  782. fprintf(cfg, "\thelp\n");
  783. fprintf(cfg, "\t %s\n", pkg_fd);
  784. token = strtok(NULL, " ");
  785. }
  786. free(pkg_flavours);
  787. pkg_flavours = NULL;
  788. }
  789. /* package flavours string */
  790. if (pkg_flavours_string != NULL) {
  791. token = strtok(pkg_flavours_string, " ");
  792. while (token != NULL) {
  793. fprintf(cfg, "\nconfig ADK_PACKAGE_%s_%s\n", pkgname, toupperstr(token));
  794. // process default value
  795. strncat(hkey, "PKGFX_", 6);
  796. strncat(hkey, token, strlen(token));
  797. memset(hvalue, 0 , MAXVALUE);
  798. strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  799. memset(hkey, 0 , MAXVAR);
  800. pkg_fd = strdup(hvalue);
  801. if (strlen(pkg_fd) > 0)
  802. fprintf(cfg, "\tdefault \"%s\"\n", pkg_fd);
  803. // process flavour cfline
  804. strncat(hkey, "PKGFC_", 6);
  805. strncat(hkey, token, strlen(token));
  806. memset(hvalue, 0 , MAXVALUE);
  807. strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  808. memset(hkey, 0 , MAXVAR);
  809. pkg_fd = strdup(hvalue);
  810. if (strlen(pkg_fd) > 0)
  811. fprintf(cfg, "\t%s\n", pkg_fd);
  812. fprintf(cfg, "\tstring ");
  813. strncat(hkey, "PKGFD_", 6);
  814. strncat(hkey, token, strlen(token));
  815. memset(hvalue, 0 , MAXVALUE);
  816. strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  817. memset(hkey, 0 , MAXVAR);
  818. pkg_fd = strdup(hvalue);
  819. fprintf(cfg, "\"%s\"\n", pkg_fd);
  820. fprintf(cfg, "\tdepends on ADK_PACKAGE_%s\n", pkgname);
  821. strncat(hkey, "PKGFS_", 6);
  822. strncat(hkey, token, strlen(token));
  823. result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  824. if (result == 1) {
  825. val = strtok_r(hvalue, " ", &saveptr);
  826. while (val != NULL) {
  827. if (strncmp(val, "kmod", 4) == 0)
  828. fprintf(cfg, "\tselect ADK_KPACKAGE_%s\n", toupperstr(val));
  829. else
  830. fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(val));
  831. val = strtok_r(NULL, " ", &saveptr);
  832. }
  833. }
  834. memset(hkey, 0, MAXVAR);
  835. fprintf(cfg, "\thelp\n");
  836. fprintf(cfg, "\t %s\n", pkg_fd);
  837. token = strtok(NULL, " ");
  838. }
  839. free(pkg_flavours_string);
  840. pkg_flavours_string = NULL;
  841. }
  842. /* package choices */
  843. if (pkg_choices != NULL) {
  844. fprintf(cfg, "\nchoice\n");
  845. fprintf(cfg, "prompt \"Package flavour choice\"\n");
  846. fprintf(cfg, "depends on ADK_PACKAGE_%s\n\n", pkgname);
  847. token = strtok(pkg_choices, " ");
  848. while (token != NULL) {
  849. fprintf(cfg, "config ADK_PACKAGE_%s_%s\n", pkgname, toupperstr(token));
  850. fprintf(cfg, "\tbool ");
  851. strncat(hkey, "PKGCD_", 6);
  852. strncat(hkey, token, strlen(token));
  853. memset(hvalue, 0 , MAXVALUE);
  854. strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  855. memset(hkey, 0 , MAXVAR);
  856. fprintf(cfg, "\"%s\"\n", hvalue);
  857. strncat(hkey, "PKGCS_", 6);
  858. strncat(hkey, token, strlen(token));
  859. memset(hvalue, 0, MAXVALUE);
  860. result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  861. if (result == 1) {
  862. val = strtok_r(hvalue, " ", &saveptr);
  863. while (val != NULL) {
  864. if (strncmp(val, "kmod", 4) == 0)
  865. fprintf(cfg, "\tselect ADK_KPACKAGE_%s\n", toupperstr(val));
  866. else
  867. fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(val));
  868. val = strtok_r(NULL, " ", &saveptr);
  869. }
  870. }
  871. memset(hkey, 0, MAXVAR);
  872. token = strtok(NULL, " ");
  873. }
  874. fprintf(cfg, "\nendchoice\n");
  875. free(pkg_choices);
  876. pkg_choices = NULL;
  877. }
  878. /* close file descriptor for Config.in file */
  879. fclose(cfg);
  880. /* create Config.in files for development packages */
  881. if (pkg_opts != NULL) {
  882. if (strstr(pkg_opts, "dev") != NULL) {
  883. if (snprintf(path, MAXPATH, "package/pkgconfigs.d/gcc/Config.in.dev") < 0)
  884. fatal_error("failed to create path variable.");
  885. cfg = fopen(path, "a");
  886. if (cfg == NULL)
  887. perror("Can not open Config.in.dev file");
  888. if (pkg_libname == NULL)
  889. pkg_libname = strdup(pkg_name);
  890. fprintf(cfg, "\n");
  891. fprintf(cfg, "config ADK_PACKAGE_%s_DEV\n", toupperstr(pkg_libname));
  892. pseudo_name = malloc(MAXLINE);
  893. memset(pseudo_name, 0, MAXLINE);
  894. strncat(pseudo_name, pkg_libname, strlen(pkg_libname));
  895. strncat(pseudo_name, "-dev", 4);
  896. while (strlen(pseudo_name) < 20)
  897. strncat(pseudo_name, ".", 1);
  898. fprintf(cfg, "\tprompt \"%s. development files for %s\"\n", pseudo_name, pkg_libname);
  899. fprintf(cfg, "\ttristate\n");
  900. fprintf(cfg, "\tdepends on ADK_PACKAGE_GCC\n");
  901. fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(pkg_libname));
  902. fprintf(cfg, "\tdefault n\n");
  903. fclose(cfg);
  904. free(pseudo_name);
  905. free(pkg_libname);
  906. pkg_libname = NULL;
  907. }
  908. pkg_opts = NULL;
  909. }
  910. /* parse next package */
  911. token = strtok_r(NULL, " ", &p_ptr);
  912. }
  913. /* end of package output generation */
  914. free(packages);
  915. packages = NULL;
  916. pkg_need_cxx = NULL;
  917. pkg_need_java = NULL;
  918. /* reset flags, free memory */
  919. free(pkg_name);
  920. free(pkg_descr);
  921. free(pkg_section);
  922. free(pkg_url);
  923. free(pkg_depends);
  924. free(pkg_flavours);
  925. free(pkg_flavours_string);
  926. free(pkg_choices);
  927. free(pkg_subpkgs);
  928. free(pkg_arch_depends);
  929. free(pkg_system_depends);
  930. free(pkg_host_depends);
  931. free(pkg_libc_depends);
  932. free(pkg_cxx);
  933. free(pkg_dflt);
  934. free(pkg_cfline);
  935. free(pkg_multi);
  936. pkg_name = NULL;
  937. pkg_descr = NULL;
  938. pkg_section = NULL;
  939. pkg_url = NULL;
  940. pkg_depends = NULL;
  941. pkg_flavours = NULL;
  942. pkg_flavours_string = NULL;
  943. pkg_choices = NULL;
  944. pkg_subpkgs = NULL;
  945. pkg_arch_depends = NULL;
  946. pkg_system_depends = NULL;
  947. pkg_host_depends = NULL;
  948. pkg_libc_depends = NULL;
  949. pkg_cxx = NULL;
  950. pkg_dflt = NULL;
  951. pkg_cfline = NULL;
  952. pkg_multi = NULL;
  953. strmap_delete(pkgmap);
  954. nobinpkgs = 0;
  955. free(hkey);
  956. }
  957. }
  958. /* add menu to gcc package */
  959. if (snprintf(path, MAXPATH, "package/pkgconfigs.d/gcc/Config.in.gcc") < 0)
  960. fatal_error("failed to create path variable.");
  961. cfg = fopen(path, "a");
  962. if (cfg == NULL)
  963. perror("Can not open Config.in.gcc file");
  964. fprintf(cfg, "menu \"Development packages\"\n");
  965. fprintf(cfg, "depends on ADK_PACKAGE_GCC\n");
  966. fprintf(cfg, "source \"package/pkgconfigs.d/gcc/Config.in.dev\"\n");
  967. fprintf(cfg, "endmenu\n");
  968. fclose(cfg);
  969. /* create Config.in.auto */
  970. strmap_enum(sectionmap, iter, NULL);
  971. strmap_delete(sectionmap);
  972. fclose(menuglobal);
  973. closedir(pkgdir);
  974. /* remove temporary section files */
  975. pkglistdir = opendir("package/pkglist.d");
  976. while ((pkgdirp = readdir(pkglistdir)) != NULL) {
  977. if (strncmp(pkgdirp->d_name, "sectionlst.", 11) == 0) {
  978. if (snprintf(path, MAXPATH, "package/pkglist.d/%s", pkgdirp->d_name) < 0)
  979. fatal_error("creating path variable failed.");
  980. if (unlink(path) < 0)
  981. fatal_error("removing file failed.");
  982. }
  983. }
  984. closedir(pkglistdir);
  985. return(0);
  986. }