pkgmaker.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. /*
  2. * pkgmaker - create package meta-data for OpenADK buildsystem
  3. *
  4. * Copyright (C) 2010,2011 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. /*
  103. static void iter_debug(const char *key, const char *value, const void *obj) {
  104. fprintf(stderr, "HASHMAP key: %s value: %s\n", key, value);
  105. }
  106. */
  107. static int hash_str(char *string) {
  108. int i;
  109. int hash;
  110. hash = 0;
  111. for (i=0; i<(int)strlen(string); i++) {
  112. hash += string[i];
  113. }
  114. return(hash);
  115. }
  116. static void iter(const char *key, const char *value, const void *obj) {
  117. FILE *config, *section;
  118. int hash;
  119. char *valuestr, *pkg, *subpkg;
  120. char buf[MAXPATH];
  121. char infile[MAXPATH];
  122. char outfile[MAXPATH];
  123. valuestr = strdup(value);
  124. config = fopen("package/Config.in.auto", "a");
  125. if (config == NULL)
  126. fatal_error("Can not open file package/Config.in.auto");
  127. hash = hash_str(valuestr);
  128. snprintf(infile, MAXPATH, "package/pkglist.d/sectionlst.%d", hash);
  129. snprintf(outfile, MAXPATH, "package/pkglist.d/sectionlst.%d.sorted", hash);
  130. if (access(infile, F_OK) == 0) {
  131. valuestr[strlen(valuestr)-1] = '\0';
  132. fprintf(config, "menu \"%s\"\n", valuestr);
  133. sortfile(infile, outfile);
  134. /* avoid duplicate section entries */
  135. unlink(infile);
  136. section = fopen(outfile, "r");
  137. while (fgets(buf, MAXPATH, section) != NULL) {
  138. buf[strlen(buf)-1] = '\0';
  139. if (buf[strlen(buf)-1] == '@') {
  140. buf[strlen(buf)-1] = '\0';
  141. fprintf(config, "source \"package/%s/Config.in.manual\"\n", buf);
  142. } else {
  143. subpkg = strtok(buf, "|");
  144. subpkg[strlen(subpkg)-1] = '\0';
  145. pkg = strtok(NULL, "|");
  146. fprintf(config, "source \"package/pkgconfigs.d/%s/Config.in.%s\"\n", pkg, subpkg);
  147. }
  148. }
  149. fprintf(config, "endmenu\n\n");
  150. fclose(section);
  151. }
  152. fclose(config);
  153. }
  154. static char *tolowerstr(char *string) {
  155. int i;
  156. char *str;
  157. /* transform to lowercase variable name */
  158. str = strdup(string);
  159. for (i=0; i<(int)strlen(str); i++) {
  160. if (str[i] == '_')
  161. str[i] = '-';
  162. str[i] = tolower(str[i]);
  163. }
  164. return(str);
  165. }
  166. static char *toupperstr(char *string) {
  167. int i;
  168. char *str;
  169. /* transform to uppercase variable name */
  170. str = strdup(string);
  171. for (i=0; i<(int)strlen(str); i++) {
  172. if (str[i] == '+')
  173. str[i] = 'X';
  174. if (str[i] == '-')
  175. str[i] = '_';
  176. /* remove negation here, useful for package host depends */
  177. if (str[i] == '!')
  178. str[i] = '_';
  179. str[i] = toupper(str[i]);
  180. }
  181. return(str);
  182. }
  183. int main() {
  184. DIR *pkgdir, *pkglistdir;
  185. struct dirent *pkgdirp;
  186. FILE *pkg, *cfg, *menuglobal, *section;
  187. char hvalue[MAXVALUE];
  188. char buf[MAXPATH];
  189. char tbuf[MAXPATH];
  190. char path[MAXPATH];
  191. char spath[MAXPATH];
  192. char dir[MAXPATH];
  193. char variable[2*MAXVAR];
  194. char *key, *value, *token, *cftoken, *sp, *hkey, *val, *pkg_fd;
  195. char *pkg_name, *pkg_depends, *pkg_section, *pkg_descr, *pkg_url;
  196. char *pkg_cxx, *pkg_subpkgs, *pkg_cfline, *pkg_dflt, *pkg_multi;
  197. char *pkg_need_cxx, *pkg_need_java;
  198. char *pkg_host_depends, *pkg_arch_depends, *pkg_flavours, *pkg_choices, *pseudo_name;
  199. char *packages, *pkg_name_u, *pkgs;
  200. char *saveptr, *p_ptr, *s_ptr;
  201. int result;
  202. StrMap *pkgmap, *sectionmap;
  203. pkg_name = NULL;
  204. pkg_descr = NULL;
  205. pkg_section = NULL;
  206. pkg_url = NULL;
  207. pkg_depends = NULL;
  208. pkg_flavours = NULL;
  209. pkg_choices = NULL;
  210. pkg_subpkgs = NULL;
  211. pkg_arch_depends = NULL;
  212. pkg_host_depends = NULL;
  213. pkg_cxx = NULL;
  214. pkg_dflt = NULL;
  215. pkg_cfline = NULL;
  216. pkg_multi = NULL;
  217. pkg_need_cxx = NULL;
  218. pkg_need_java = NULL;
  219. p_ptr = NULL;
  220. s_ptr = NULL;
  221. unlink("package/Config.in.auto");
  222. /* open global sectionfile */
  223. menuglobal = fopen("package/Config.in.auto.global", "w");
  224. if (menuglobal == NULL)
  225. fatal_error("global section file not writable.");
  226. /* read section list and create a hash table */
  227. section = fopen("package/section.lst", "r");
  228. if (section == NULL)
  229. fatal_error("section listfile is missing");
  230. sectionmap = strmap_new(HASHSZ);
  231. while (fgets(tbuf, MAXPATH, section) != NULL) {
  232. key = strtok(tbuf, "\t");
  233. value = strtok(NULL, "\t");
  234. strmap_put(sectionmap, key, value);
  235. }
  236. fclose(section);
  237. if (mkdir("package/pkgconfigs.d", S_IRWXU) > 0)
  238. fatal_error("creation of package/pkgconfigs.d failed.");
  239. if (mkdir("package/pkglist.d", S_IRWXU) > 0)
  240. fatal_error("creation of package/pkglist.d failed.");
  241. /* read Makefile's for all packages */
  242. pkgdir = opendir("package");
  243. while ((pkgdirp = readdir(pkgdir)) != NULL) {
  244. /* skip dotfiles */
  245. if (strncmp(pkgdirp->d_name, ".", 1) > 0) {
  246. if (snprintf(path, MAXPATH, "package/%s/Makefile", pkgdirp->d_name) < 0)
  247. fatal_error("can not create path variable.");
  248. pkg = fopen(path, "r");
  249. if (pkg == NULL)
  250. continue;
  251. /* skip manually maintained packages */
  252. if (snprintf(path, MAXPATH, "package/%s/Config.in.manual", pkgdirp->d_name) < 0)
  253. fatal_error("can not create path variable.");
  254. if (!access(path, F_OK)) {
  255. while (fgets(buf, MAXPATH, pkg) != NULL) {
  256. if ((parse_var(buf, "PKG_SECTION", NULL, &pkg_section)) == 0)
  257. continue;
  258. }
  259. memset(hvalue, 0 , MAXVALUE);
  260. result = strmap_get(sectionmap, pkg_section, hvalue, sizeof(hvalue));
  261. if (result == 1) {
  262. if (snprintf(spath, MAXPATH, "package/pkglist.d/sectionlst.%d", hash_str(hvalue)) < 0)
  263. fatal_error("can not create path variable.");
  264. section = fopen(spath, "a");
  265. if (section != NULL) {
  266. fprintf(section, "%s@\n", pkgdirp->d_name);
  267. fclose(section);
  268. }
  269. } else
  270. fatal_error("Can not find section description for package %s.",
  271. pkgdirp->d_name);
  272. fclose(pkg);
  273. continue;
  274. }
  275. nobinpkgs = 0;
  276. /* create output directories */
  277. if (snprintf(dir, MAXPATH, "package/pkgconfigs.d/%s", pkgdirp->d_name) < 0)
  278. fatal_error("can not create dir variable.");
  279. if (mkdir(dir, S_IRWXU) > 0)
  280. fatal_error("can not create directory.");
  281. /* allocate memory */
  282. hkey = malloc(MAXVAR);
  283. memset(hkey, 0, MAXVAR);
  284. memset(variable, 0, 2*MAXVAR);
  285. pkgmap = strmap_new(HASHSZ);
  286. /* parse package Makefile */
  287. while (fgets(buf, MAXPATH, pkg) != NULL) {
  288. /* just read variables prefixed with PKG */
  289. if (strncmp(buf, "PKG", 3) == 0) {
  290. if ((parse_var(buf, "PKG_NAME", NULL, &pkg_name)) == 0)
  291. continue;
  292. if (pkg_name != NULL)
  293. pkg_name_u = toupperstr(pkg_name);
  294. else
  295. pkg_name_u = toupperstr(pkgdirp->d_name);
  296. snprintf(variable, MAXVAR, "PKG_CFLINE_%s", pkg_name_u);
  297. if ((parse_var(buf, variable, pkg_cfline, &pkg_cfline)) == 0)
  298. continue;
  299. snprintf(variable, MAXVAR, "PKG_DFLT_%s", pkg_name_u);
  300. if ((parse_var(buf, variable, NULL, &pkg_dflt)) == 0)
  301. continue;
  302. if ((parse_var(buf, "PKG_HOST_DEPENDS", NULL, &pkg_host_depends)) == 0)
  303. continue;
  304. if ((parse_var(buf, "PKG_ARCH_DEPENDS", NULL, &pkg_arch_depends)) == 0)
  305. continue;
  306. if ((parse_var(buf, "PKG_DESCR", NULL, &pkg_descr)) == 0)
  307. continue;
  308. if ((parse_var(buf, "PKG_SECTION", NULL, &pkg_section)) == 0)
  309. continue;
  310. if ((parse_var(buf, "PKG_URL", NULL, &pkg_url)) == 0)
  311. continue;
  312. if ((parse_var(buf, "PKG_CXX", NULL, &pkg_cxx)) == 0)
  313. continue;
  314. if ((parse_var(buf, "PKG_NEED_CXX", NULL, &pkg_need_cxx)) == 0)
  315. continue;
  316. if ((parse_var(buf, "PKG_NEED_JAVA", NULL, &pkg_need_java)) == 0)
  317. continue;
  318. if ((parse_var(buf, "PKG_MULTI", NULL, &pkg_multi)) == 0)
  319. continue;
  320. if ((parse_var(buf, "PKG_DEPENDS", pkg_depends, &pkg_depends)) == 0)
  321. continue;
  322. if ((parse_var(buf, "PKG_FLAVOURS", pkg_flavours, &pkg_flavours)) == 0)
  323. continue;
  324. if ((parse_var_hash(buf, "PKGFD_", pkgmap)) == 0)
  325. continue;
  326. if ((parse_var_hash(buf, "PKGFS_", pkgmap)) == 0)
  327. continue;
  328. if ((parse_var(buf, "PKG_CHOICES", pkg_choices, &pkg_choices)) == 0)
  329. continue;
  330. if ((parse_var_hash(buf, "PKGCD_", pkgmap)) == 0)
  331. continue;
  332. if ((parse_var_hash(buf, "PKGCS_", pkgmap)) == 0)
  333. continue;
  334. if ((parse_var(buf, "PKG_SUBPKGS", pkg_subpkgs, &pkg_subpkgs)) == 0)
  335. continue;
  336. if ((parse_var_hash(buf, "PKGSD_", pkgmap)) == 0)
  337. continue;
  338. if ((parse_var_hash(buf, "PKGSS_", pkgmap)) == 0)
  339. continue;
  340. if ((parse_var_hash(buf, "PKGSC_", pkgmap)) == 0)
  341. continue;
  342. }
  343. }
  344. /* end of package Makefile parsing */
  345. if (fclose(pkg) != 0)
  346. perror("Failed to close file stream for Makefile");
  347. /*
  348. if (pkg_name != NULL)
  349. fprintf(stderr, "Package name is %s\n", pkg_name);
  350. if (pkg_section != NULL)
  351. fprintf(stderr, "Package section is %s\n", pkg_section);
  352. if (pkg_descr != NULL)
  353. fprintf(stderr, "Package description is %s\n", pkg_descr);
  354. if (pkg_depends != NULL)
  355. fprintf(stderr, "Package dependencies are %s\n", pkg_depends);
  356. if (pkg_subpkgs != NULL)
  357. fprintf(stderr, "Package subpackages are %s\n", pkg_subpkgs);
  358. if (pkg_flavours != NULL)
  359. fprintf(stderr, "Package flavours are %s\n", pkg_flavours);
  360. if (pkg_choices != NULL)
  361. fprintf(stderr, "Package choices are %s\n", pkg_choices);
  362. if (pkg_url != NULL)
  363. fprintf(stderr, "Package homepage is %s\n", pkg_url);
  364. if (pkg_cfline != NULL)
  365. fprintf(stderr, "Package cfline is %s\n", pkg_cfline);
  366. if (pkg_multi != NULL)
  367. fprintf(stderr, "Package multi is %s\n", pkg_multi);
  368. strmap_enum(pkgmap, iter_debug, NULL);
  369. */
  370. /* generate master source Config.in file */
  371. if (snprintf(path, MAXPATH, "package/pkgconfigs.d/%s/Config.in", pkgdirp->d_name) < 0)
  372. fatal_error("path variable creation failed.");
  373. fprintf(menuglobal, "source \"%s\"\n", path);
  374. /* recreating file is faster than truncating with w+ */
  375. unlink(path);
  376. cfg = fopen(path, "w");
  377. if (cfg == NULL)
  378. continue;
  379. pkgs = NULL;
  380. if (pkg_subpkgs != NULL)
  381. pkgs = strdup(pkg_subpkgs);
  382. fprintf(cfg, "config ADK_COMPILE_%s\n", toupperstr(pkgdirp->d_name));
  383. fprintf(cfg, "\ttristate\n");
  384. if (nobinpkgs == 0) {
  385. fprintf(cfg, "\tdepends on ");
  386. if (pkgs != NULL) {
  387. if (pkg_multi != NULL)
  388. if (strncmp(pkg_multi, "1", 1) == 0)
  389. fprintf(cfg, "ADK_HAVE_DOT_CONFIG || ");
  390. token = strtok(pkgs, " ");
  391. fprintf(cfg, "ADK_PACKAGE_%s", token);
  392. token = strtok(NULL, " ");
  393. while (token != NULL) {
  394. fprintf(cfg, " || ADK_PACKAGE_%s", token);
  395. token = strtok(NULL, " ");
  396. }
  397. fprintf(cfg, "\n");
  398. } else {
  399. fprintf(cfg, "ADK_PACKAGE_%s\n", toupperstr(pkgdirp->d_name));
  400. }
  401. }
  402. fprintf(cfg, "\tdefault n\n");
  403. fclose(cfg);
  404. free(pkgs);
  405. /* skip packages without binary package output */
  406. if (nobinpkgs == 1)
  407. continue;
  408. /* generate binary package specific Config.in files */
  409. if (pkg_subpkgs != NULL)
  410. packages = tolowerstr(pkg_subpkgs);
  411. else
  412. packages = strdup(pkgdirp->d_name);
  413. token = strtok_r(packages, " ", &p_ptr);
  414. while (token != NULL) {
  415. strncat(hkey, "PKGSC_", 6);
  416. strncat(hkey, toupperstr(token), strlen(token));
  417. memset(hvalue, 0 , MAXVALUE);
  418. result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  419. memset(hkey, 0 , MAXVAR);
  420. if (result == 1)
  421. pkg_section = strdup(hvalue);
  422. strncat(hkey, "PKGSD_", 6);
  423. strncat(hkey, toupperstr(token), strlen(token));
  424. memset(hvalue, 0 , MAXVALUE);
  425. result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  426. memset(hkey, 0 , MAXVAR);
  427. if (result == 1)
  428. pkg_descr = strdup(hvalue);
  429. pseudo_name = malloc(MAXLINE);
  430. memset(pseudo_name, 0, MAXLINE);
  431. strncat(pseudo_name, token, strlen(token));
  432. while (strlen(pseudo_name) < 20)
  433. strncat(pseudo_name, ".", 1);
  434. if (snprintf(path, MAXPATH, "package/pkgconfigs.d/%s/Config.in.%s", pkgdirp->d_name, token) < 0)
  435. fatal_error("failed to create path variable.");
  436. /* create temporary section files */
  437. memset(hvalue, 0 , MAXVALUE);
  438. result = strmap_get(sectionmap, pkg_section, hvalue, sizeof(hvalue));
  439. if (result == 1) {
  440. if (snprintf(spath, MAXPATH, "package/pkglist.d/sectionlst.%d", hash_str(hvalue)) < 0)
  441. fatal_error("failed to create path variable.");
  442. section = fopen(spath, "a");
  443. if (section != NULL) {
  444. fprintf(section, "%s |%s\n", token, pkgdirp->d_name);
  445. fclose(section);
  446. }
  447. } else
  448. fatal_error("Can not find section description for package %s.", pkgdirp->d_name);
  449. unlink(path);
  450. cfg = fopen(path, "w");
  451. if (cfg == NULL)
  452. perror("Can not open Config.in file");
  453. if (pkg_need_cxx != NULL) {
  454. fprintf(cfg, "comment \"%s... %s (disabled, c++ missing)\"\n", token, pkg_descr);
  455. fprintf(cfg, "depends on !ADK_TOOLCHAIN_GCC_CXX\n\n");
  456. }
  457. fprintf(cfg, "config ADK_PACKAGE_%s\n", toupperstr(token));
  458. fprintf(cfg, "\tprompt \"%s. %s\"\n", pseudo_name, pkg_descr);
  459. fprintf(cfg, "\ttristate\n");
  460. if (pkg_multi != NULL)
  461. if (strncmp(pkg_multi, "1", 1) == 0)
  462. if (strncmp(toupperstr(token), toupperstr(pkgdirp->d_name), strlen(token)) != 0)
  463. fprintf(cfg, "\tdepends on ADK_PACKAGE_%s\n", toupperstr(pkgdirp->d_name));
  464. free(pseudo_name);
  465. /* print custom cf line */
  466. if (pkg_cfline != NULL) {
  467. cftoken = strtok_r(pkg_cfline, "@", &saveptr);
  468. while (cftoken != NULL) {
  469. fprintf(cfg, "\t%s\n", cftoken);
  470. cftoken = strtok_r(NULL, "@", &saveptr);
  471. }
  472. }
  473. /* add sub package dependencies */
  474. strncat(hkey, "PKGSS_", 6);
  475. strncat(hkey, toupperstr(token), strlen(token));
  476. memset(hvalue, 0, MAXVALUE);
  477. result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  478. if (result == 1) {
  479. val = strtok_r(hvalue, " ", &saveptr);
  480. while (val != NULL) {
  481. fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(val));
  482. val = strtok_r(NULL, " ", &saveptr);
  483. }
  484. }
  485. memset(hkey, 0, MAXVAR);
  486. /* create package host dependency information */
  487. if (pkg_host_depends != NULL) {
  488. token = strtok(pkg_host_depends, " ");
  489. fprintf(cfg, "\tdepends on ");
  490. sp = "";
  491. while (token != NULL) {
  492. if(strncmp(token, "!", 1) == 0) {
  493. fprintf(cfg, "%s!ADK_HOST%s", sp, toupperstr(token));
  494. sp = " && ";
  495. } else {
  496. fprintf(cfg, "%sADK_HOST_%s", sp, toupperstr(token));
  497. sp = " || ";
  498. }
  499. token = strtok(NULL, " ");
  500. }
  501. fprintf(cfg, "\n");
  502. }
  503. /* create package target architecture dependency information */
  504. if (pkg_arch_depends != NULL) {
  505. token = strtok(pkg_arch_depends, " ");
  506. fprintf(cfg, "\tdepends on ");
  507. sp = "";
  508. while (token != NULL) {
  509. if(strncmp(token, "!", 1) == 0) {
  510. fprintf(cfg, "%s!ADK_LINUX%s", sp, toupperstr(token));
  511. sp = " && ";
  512. } else {
  513. fprintf(cfg, "%sADK_LINUX_%s", sp, toupperstr(token));
  514. sp = " || ";
  515. }
  516. token = strtok(NULL, " ");
  517. }
  518. fprintf(cfg, "\n");
  519. }
  520. /* create package dependency information */
  521. if (pkg_depends != NULL) {
  522. token = strtok(pkg_depends, " ");
  523. while (token != NULL) {
  524. if (strncmp(token, "kmod", 4) == 0)
  525. fprintf(cfg, "\tselect ADK_KPACKAGE_%s\n", toupperstr(token));
  526. else
  527. fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(token));
  528. token = strtok(NULL, " ");
  529. }
  530. free(pkg_depends);
  531. pkg_depends = NULL;
  532. }
  533. if (pkg_need_cxx != NULL) {
  534. fprintf(cfg, "\tdepends on ADK_TOOLCHAIN_GCC_CXX\n");
  535. }
  536. if (pkg_need_java != NULL) {
  537. fprintf(cfg, "\tdepends on ADK_TOOLCHAIN_GCC_JAVA\n");
  538. pkg_need_java = NULL;
  539. }
  540. fprintf(cfg, "\tselect ADK_COMPILE_%s\n", toupperstr(pkgdirp->d_name));
  541. if (pkg_dflt != NULL) {
  542. fprintf(cfg, "\tdefault %s\n", pkg_dflt);
  543. pkg_dflt = NULL;
  544. } else {
  545. fprintf(cfg, "\tdefault n\n");
  546. }
  547. fprintf(cfg, "\thelp\n");
  548. fprintf(cfg, "\t %s\n\n", pkg_descr);
  549. if (pkg_url != NULL)
  550. fprintf(cfg, "\t WWW: %s\n", pkg_url);
  551. /* handle special C++ packages */
  552. if (pkg_cxx != NULL) {
  553. fprintf(cfg, "\nchoice\n");
  554. fprintf(cfg, "prompt \"C++ library to use\"\n");
  555. fprintf(cfg, "depends on ADK_COMPILE_%s\n\n", toupperstr(pkgdirp->d_name));
  556. fprintf(cfg, "default ADK_COMPILE_%s_WITH_STDCXX if ADK_TARGET_LIB_GLIBC || ADK_TARGET_LIB_EGLIBC\n", pkg_cxx);
  557. fprintf(cfg, "default ADK_COMPILE_%s_WITH_UCLIBCXX if ADK_TARGET_LIB_UCLIBC\n\n", pkg_cxx);
  558. fprintf(cfg, "config ADK_COMPILE_%s_WITH_STDCXX\n", pkg_cxx);
  559. fprintf(cfg, "\tbool \"GNU C++ library\"\n");
  560. fprintf(cfg, "\tselect ADK_PACKAGE_LIBSTDCXX\n\n");
  561. fprintf(cfg, "config ADK_COMPILE_%s_WITH_UCLIBCXX\n", pkg_cxx);
  562. fprintf(cfg, "\tbool \"uClibc++ library\"\n");
  563. fprintf(cfg, "\tselect ADK_PACKAGE_UCLIBCXX\n\n");
  564. fprintf(cfg, "endchoice\n");
  565. free(pkg_cxx);
  566. pkg_cxx = NULL;
  567. }
  568. /* package flavours */
  569. if (pkg_flavours != NULL) {
  570. token = strtok(pkg_flavours, " ");
  571. while (token != NULL) {
  572. fprintf(cfg, "\nconfig ADK_PACKAGE_%s_%s\n", toupperstr(pkgdirp->d_name),
  573. toupperstr(token));
  574. fprintf(cfg, "\tbool ");
  575. strncat(hkey, "PKGFD_", 6);
  576. strncat(hkey, token, strlen(token));
  577. memset(hvalue, 0 , MAXVALUE);
  578. strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  579. memset(hkey, 0 , MAXVAR);
  580. pkg_fd = strdup(hvalue);
  581. fprintf(cfg, "\"%s\"\n", pkg_fd);
  582. fprintf(cfg, "\tdefault n\n");
  583. fprintf(cfg, "\tdepends on ADK_PACKAGE_%s\n", toupperstr(pkgdirp->d_name));
  584. strncat(hkey, "PKGFS_", 6);
  585. strncat(hkey, token, strlen(token));
  586. result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  587. if (result == 1) {
  588. val = strtok_r(hvalue, " ", &saveptr);
  589. while (val != NULL) {
  590. fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(val));
  591. val = strtok_r(NULL, " ", &saveptr);
  592. }
  593. }
  594. memset(hkey, 0, MAXVAR);
  595. fprintf(cfg, "\thelp\n");
  596. fprintf(cfg, "\t %s\n", pkg_fd);
  597. token = strtok(NULL, " ");
  598. }
  599. free(pkg_flavours);
  600. pkg_flavours = NULL;
  601. }
  602. /* package choices */
  603. if (pkg_choices != NULL) {
  604. fprintf(cfg, "\nchoice\n");
  605. fprintf(cfg, "prompt \"Package flavour choice\"\n");
  606. fprintf(cfg, "depends on ADK_COMPILE_%s\n\n", toupperstr(pkgdirp->d_name));
  607. token = strtok(pkg_choices, " ");
  608. while (token != NULL) {
  609. fprintf(cfg, "config ADK_PACKAGE_%s_%s\n", toupperstr(pkgdirp->d_name),
  610. toupperstr(token));
  611. fprintf(cfg, "\tbool ");
  612. strncat(hkey, "PKGCD_", 6);
  613. strncat(hkey, token, strlen(token));
  614. memset(hvalue, 0 , MAXVALUE);
  615. strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  616. memset(hkey, 0 , MAXVAR);
  617. fprintf(cfg, "\"%s\"\n", hvalue);
  618. strncat(hkey, "PKGCS_", 6);
  619. strncat(hkey, token, strlen(token));
  620. memset(hvalue, 0, MAXVALUE);
  621. result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  622. if (result == 1) {
  623. val = strtok_r(hvalue, " ", &saveptr);
  624. while (val != NULL) {
  625. fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(val));
  626. val = strtok_r(NULL, " ", &saveptr);
  627. }
  628. }
  629. memset(hkey, 0, MAXVAR);
  630. token = strtok(NULL, " ");
  631. }
  632. fprintf(cfg, "\nendchoice\n");
  633. free(pkg_choices);
  634. pkg_choices = NULL;
  635. }
  636. /* close file descriptor, parse next package */
  637. fclose(cfg);
  638. token = strtok_r(NULL, " ", &p_ptr);
  639. }
  640. /* end of package output generation */
  641. free(packages);
  642. packages = NULL;
  643. pkg_need_cxx = NULL;
  644. pkg_need_java = NULL;
  645. /* reset flags, free memory */
  646. free(pkg_name);
  647. free(pkg_descr);
  648. free(pkg_section);
  649. free(pkg_url);
  650. free(pkg_depends);
  651. free(pkg_flavours);
  652. free(pkg_choices);
  653. free(pkg_subpkgs);
  654. free(pkg_arch_depends);
  655. free(pkg_host_depends);
  656. free(pkg_cxx);
  657. free(pkg_dflt);
  658. free(pkg_cfline);
  659. free(pkg_multi);
  660. pkg_name = NULL;
  661. pkg_descr = NULL;
  662. pkg_section = NULL;
  663. pkg_url = NULL;
  664. pkg_depends = NULL;
  665. pkg_flavours = NULL;
  666. pkg_choices = NULL;
  667. pkg_subpkgs = NULL;
  668. pkg_arch_depends = NULL;
  669. pkg_host_depends = NULL;
  670. pkg_cxx = NULL;
  671. pkg_dflt = NULL;
  672. pkg_cfline = NULL;
  673. pkg_multi = NULL;
  674. strmap_delete(pkgmap);
  675. nobinpkgs = 0;
  676. free(hkey);
  677. }
  678. }
  679. /* create Config.in.auto */
  680. strmap_enum(sectionmap, iter, NULL);
  681. strmap_delete(sectionmap);
  682. fclose(menuglobal);
  683. closedir(pkgdir);
  684. /* remove temporary section files */
  685. pkglistdir = opendir("package/pkglist.d");
  686. while ((pkgdirp = readdir(pkglistdir)) != NULL) {
  687. if (strncmp(pkgdirp->d_name, "sectionlst.", 11) == 0) {
  688. if (snprintf(path, MAXPATH, "package/pkglist.d/%s", pkgdirp->d_name) < 0)
  689. fatal_error("creating path variable failed.");
  690. if (unlink(path) < 0)
  691. fatal_error("removing file failed.");
  692. }
  693. }
  694. closedir(pkglistdir);
  695. return(0);
  696. }