pkgmaker.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  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. 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. /*
  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. */
  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_host_depends, *pkg_arch_depends, *pkg_flavours, *pkg_choices, *pseudo_name;
  242. char *packages, *pkg_name_u, *pkgs;
  243. char *saveptr, *p_ptr, *s_ptr;
  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_flavours = NULL;
  252. pkg_choices = NULL;
  253. pkg_subpkgs = NULL;
  254. pkg_arch_depends = NULL;
  255. pkg_host_depends = NULL;
  256. pkg_cxx = NULL;
  257. pkg_dflt = NULL;
  258. pkg_cfline = NULL;
  259. pkg_multi = NULL;
  260. pkg_need_cxx = NULL;
  261. pkg_need_java = NULL;
  262. pkgname = NULL;
  263. p_ptr = NULL;
  264. s_ptr = NULL;
  265. unlink("package/Config.in.auto");
  266. /* open global sectionfile */
  267. menuglobal = fopen("package/Config.in.auto.global", "w");
  268. if (menuglobal == NULL)
  269. fatal_error("global section file not writable.");
  270. /* read section list and create a hash table */
  271. section = fopen("package/section.lst", "r");
  272. if (section == NULL)
  273. fatal_error("section listfile is missing");
  274. sectionmap = strmap_new(HASHSZ);
  275. while (fgets(tbuf, MAXPATH, section) != NULL) {
  276. key = strtok(tbuf, "\t");
  277. value = strtok(NULL, "\t");
  278. strmap_put(sectionmap, key, value);
  279. }
  280. fclose(section);
  281. if (mkdir("package/pkgconfigs.d", S_IRWXU) > 0)
  282. fatal_error("creation of package/pkgconfigs.d failed.");
  283. if (mkdir("package/pkglist.d", S_IRWXU) > 0)
  284. fatal_error("creation of package/pkglist.d failed.");
  285. /* read Makefile's for all packages */
  286. pkgdir = opendir("package");
  287. while ((pkgdirp = readdir(pkgdir)) != NULL) {
  288. /* skip dotfiles */
  289. if (strncmp(pkgdirp->d_name, ".", 1) > 0) {
  290. if (snprintf(path, MAXPATH, "package/%s/Makefile", pkgdirp->d_name) < 0)
  291. fatal_error("can not create path variable.");
  292. pkg = fopen(path, "r");
  293. if (pkg == NULL)
  294. continue;
  295. /* skip manually maintained packages */
  296. if (snprintf(path, MAXPATH, "package/%s/Config.in.manual", pkgdirp->d_name) < 0)
  297. fatal_error("can not create path variable.");
  298. if (!access(path, F_OK)) {
  299. while (fgets(buf, MAXPATH, pkg) != NULL) {
  300. if ((parse_var(buf, "PKG_SECTION", NULL, &pkg_section)) == 0)
  301. continue;
  302. }
  303. memset(hvalue, 0 , MAXVALUE);
  304. result = strmap_get(sectionmap, pkg_section, hvalue, sizeof(hvalue));
  305. if (result == 1) {
  306. if (snprintf(spath, MAXPATH, "package/pkglist.d/sectionlst.%d", hash_str(hvalue)) < 0)
  307. fatal_error("can not create path variable.");
  308. section = fopen(spath, "a");
  309. if (section != NULL) {
  310. fprintf(section, "%s@\n", pkgdirp->d_name);
  311. fclose(section);
  312. }
  313. } else
  314. fatal_error("Can not find section description for package %s.",
  315. pkgdirp->d_name);
  316. fclose(pkg);
  317. continue;
  318. }
  319. nobinpkgs = 0;
  320. /* create output directories */
  321. if (snprintf(dir, MAXPATH, "package/pkgconfigs.d/%s", pkgdirp->d_name) < 0)
  322. fatal_error("can not create dir variable.");
  323. if (mkdir(dir, S_IRWXU) > 0)
  324. fatal_error("can not create directory.");
  325. /* allocate memory */
  326. hkey = malloc(MAXVAR);
  327. memset(hkey, 0, MAXVAR);
  328. memset(variable, 0, 2*MAXVAR);
  329. pkgmap = strmap_new(HASHSZ);
  330. /* parse package Makefile */
  331. while (fgets(buf, MAXPATH, pkg) != NULL) {
  332. /* just read variables prefixed with PKG */
  333. if (strncmp(buf, "PKG", 3) == 0) {
  334. if ((parse_var(buf, "PKG_NAME", NULL, &pkg_name)) == 0)
  335. continue;
  336. if (pkg_name != NULL)
  337. pkg_name_u = toupperstr(pkg_name);
  338. else
  339. pkg_name_u = toupperstr(pkgdirp->d_name);
  340. snprintf(variable, MAXVAR, "PKG_CFLINE_%s", pkg_name_u);
  341. if ((parse_var(buf, variable, pkg_cfline, &pkg_cfline)) == 0)
  342. continue;
  343. snprintf(variable, MAXVAR, "PKG_DFLT_%s", pkg_name_u);
  344. if ((parse_var(buf, variable, NULL, &pkg_dflt)) == 0)
  345. continue;
  346. if ((parse_var(buf, "PKG_HOST_DEPENDS", NULL, &pkg_host_depends)) == 0)
  347. continue;
  348. if ((parse_var(buf, "PKG_ARCH_DEPENDS", NULL, &pkg_arch_depends)) == 0)
  349. continue;
  350. if ((parse_var(buf, "PKG_DESCR", NULL, &pkg_descr)) == 0)
  351. continue;
  352. if ((parse_var(buf, "PKG_SECTION", NULL, &pkg_section)) == 0)
  353. continue;
  354. if ((parse_var(buf, "PKG_URL", NULL, &pkg_url)) == 0)
  355. continue;
  356. if ((parse_var(buf, "PKG_CXX", NULL, &pkg_cxx)) == 0)
  357. continue;
  358. if ((parse_var(buf, "PKG_NEED_CXX", NULL, &pkg_need_cxx)) == 0)
  359. continue;
  360. if ((parse_var(buf, "PKG_NEED_JAVA", NULL, &pkg_need_java)) == 0)
  361. continue;
  362. if ((parse_var(buf, "PKG_MULTI", NULL, &pkg_multi)) == 0)
  363. continue;
  364. if ((parse_var(buf, "PKG_DEPENDS", pkg_depends, &pkg_depends)) == 0)
  365. continue;
  366. if ((parse_var_with_pkg(buf, "PKG_FLAVOURS_", pkg_flavours, &pkg_flavours, &pkgname, 13)) == 0)
  367. continue;
  368. if ((parse_var_hash(buf, "PKGFD_", pkgmap)) == 0)
  369. continue;
  370. if ((parse_var_hash(buf, "PKGFS_", pkgmap)) == 0)
  371. continue;
  372. if ((parse_var_with_pkg(buf, "PKG_CHOICES_", pkg_choices, &pkg_choices, &pkgname, 12)) == 0)
  373. continue;
  374. if ((parse_var_hash(buf, "PKGCD_", pkgmap)) == 0)
  375. continue;
  376. if ((parse_var_hash(buf, "PKGCS_", pkgmap)) == 0)
  377. continue;
  378. if ((parse_var(buf, "PKG_SUBPKGS", pkg_subpkgs, &pkg_subpkgs)) == 0)
  379. continue;
  380. if ((parse_var_hash(buf, "PKGSD_", pkgmap)) == 0)
  381. continue;
  382. if ((parse_var_hash(buf, "PKGSS_", pkgmap)) == 0)
  383. continue;
  384. if ((parse_var_hash(buf, "PKGSC_", pkgmap)) == 0)
  385. continue;
  386. }
  387. }
  388. /* end of package Makefile parsing */
  389. if (fclose(pkg) != 0)
  390. perror("Failed to close file stream for Makefile");
  391. #if 0
  392. if (pkg_name != NULL)
  393. fprintf(stderr, "Package name is %s\n", pkg_name);
  394. if (pkg_section != NULL)
  395. fprintf(stderr, "Package section is %s\n", pkg_section);
  396. if (pkg_descr != NULL)
  397. fprintf(stderr, "Package description is %s\n", pkg_descr);
  398. if (pkg_depends != NULL)
  399. fprintf(stderr, "Package dependencies are %s\n", pkg_depends);
  400. if (pkg_subpkgs != NULL)
  401. fprintf(stderr, "Package subpackages are %s\n", pkg_subpkgs);
  402. if (pkg_flavours != NULL && pkgname != NULL)
  403. fprintf(stderr, "Package flavours for %s are %s\n", pkgname, pkg_flavours);
  404. if (pkg_choices != NULL && pkgname != NULL)
  405. fprintf(stderr, "Package choices for %s are %s\n", pkgname, pkg_choices);
  406. if (pkg_url != NULL)
  407. fprintf(stderr, "Package homepage is %s\n", pkg_url);
  408. if (pkg_cfline != NULL)
  409. fprintf(stderr, "Package cfline is %s\n", pkg_cfline);
  410. if (pkg_multi != NULL)
  411. fprintf(stderr, "Package multi is %s\n", pkg_multi);
  412. strmap_enum(pkgmap, iter_debug, NULL);
  413. #endif
  414. /* generate master source Config.in file */
  415. if (snprintf(path, MAXPATH, "package/pkgconfigs.d/%s/Config.in", pkgdirp->d_name) < 0)
  416. fatal_error("path variable creation failed.");
  417. fprintf(menuglobal, "source \"%s\"\n", path);
  418. /* recreating file is faster than truncating with w+ */
  419. unlink(path);
  420. cfg = fopen(path, "w");
  421. if (cfg == NULL)
  422. continue;
  423. pkgs = NULL;
  424. if (pkg_subpkgs != NULL)
  425. pkgs = strdup(pkg_subpkgs);
  426. fprintf(cfg, "config ADK_COMPILE_%s\n", toupperstr(pkgdirp->d_name));
  427. fprintf(cfg, "\ttristate\n");
  428. if (nobinpkgs == 0) {
  429. fprintf(cfg, "\tdepends on ");
  430. if (pkgs != NULL) {
  431. if (pkg_multi != NULL)
  432. if (strncmp(pkg_multi, "1", 1) == 0)
  433. fprintf(cfg, "ADK_HAVE_DOT_CONFIG || ");
  434. token = strtok(pkgs, " ");
  435. fprintf(cfg, "ADK_PACKAGE_%s", token);
  436. token = strtok(NULL, " ");
  437. while (token != NULL) {
  438. fprintf(cfg, " || ADK_PACKAGE_%s", token);
  439. token = strtok(NULL, " ");
  440. }
  441. fprintf(cfg, "\n");
  442. } else {
  443. fprintf(cfg, "ADK_PACKAGE_%s\n", toupperstr(pkgdirp->d_name));
  444. }
  445. }
  446. fprintf(cfg, "\tdefault n\n");
  447. fclose(cfg);
  448. free(pkgs);
  449. /* skip packages without binary package output */
  450. if (nobinpkgs == 1)
  451. continue;
  452. /* generate binary package specific Config.in files */
  453. if (pkg_subpkgs != NULL)
  454. packages = tolowerstr(pkg_subpkgs);
  455. else
  456. packages = strdup(pkgdirp->d_name);
  457. token = strtok_r(packages, " ", &p_ptr);
  458. while (token != NULL) {
  459. strncat(hkey, "PKGSC_", 6);
  460. strncat(hkey, toupperstr(token), strlen(token));
  461. memset(hvalue, 0 , MAXVALUE);
  462. result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  463. memset(hkey, 0 , MAXVAR);
  464. if (result == 1)
  465. pkg_section = strdup(hvalue);
  466. strncat(hkey, "PKGSD_", 6);
  467. strncat(hkey, toupperstr(token), strlen(token));
  468. memset(hvalue, 0 , MAXVALUE);
  469. result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  470. memset(hkey, 0 , MAXVAR);
  471. if (result == 1)
  472. pkg_descr = strdup(hvalue);
  473. pseudo_name = malloc(MAXLINE);
  474. memset(pseudo_name, 0, MAXLINE);
  475. strncat(pseudo_name, token, strlen(token));
  476. while (strlen(pseudo_name) < 20)
  477. strncat(pseudo_name, ".", 1);
  478. if (snprintf(path, MAXPATH, "package/pkgconfigs.d/%s/Config.in.%s", pkgdirp->d_name, token) < 0)
  479. fatal_error("failed to create path variable.");
  480. /* create temporary section files */
  481. memset(hvalue, 0 , MAXVALUE);
  482. result = strmap_get(sectionmap, pkg_section, hvalue, sizeof(hvalue));
  483. if (result == 1) {
  484. if (snprintf(spath, MAXPATH, "package/pkglist.d/sectionlst.%d", hash_str(hvalue)) < 0)
  485. fatal_error("failed to create path variable.");
  486. section = fopen(spath, "a");
  487. if (section != NULL) {
  488. fprintf(section, "%s |%s\n", token, pkgdirp->d_name);
  489. fclose(section);
  490. }
  491. } else
  492. fatal_error("Can not find section description for package %s.", pkgdirp->d_name);
  493. unlink(path);
  494. cfg = fopen(path, "w");
  495. if (cfg == NULL)
  496. perror("Can not open Config.in file");
  497. if (pkg_need_cxx != NULL) {
  498. fprintf(cfg, "comment \"%s... %s (disabled, c++ missing)\"\n", token, pkg_descr);
  499. fprintf(cfg, "depends on !ADK_TOOLCHAIN_GCC_CXX\n\n");
  500. }
  501. fprintf(cfg, "config ADK_PACKAGE_%s\n", toupperstr(token));
  502. fprintf(cfg, "\tprompt \"%s. %s\"\n", pseudo_name, pkg_descr);
  503. fprintf(cfg, "\ttristate\n");
  504. if (pkg_multi != NULL)
  505. if (strncmp(pkg_multi, "1", 1) == 0)
  506. if (strncmp(toupperstr(token), toupperstr(pkgdirp->d_name), strlen(token)) != 0)
  507. fprintf(cfg, "\tdepends on ADK_PACKAGE_%s\n", toupperstr(pkgdirp->d_name));
  508. free(pseudo_name);
  509. /* print custom cf line */
  510. if (pkg_cfline != NULL) {
  511. cftoken = strtok_r(pkg_cfline, "@", &saveptr);
  512. while (cftoken != NULL) {
  513. fprintf(cfg, "\t%s\n", cftoken);
  514. cftoken = strtok_r(NULL, "@", &saveptr);
  515. }
  516. free(pkg_cfline);
  517. pkg_cfline = NULL;
  518. }
  519. /* add sub package dependencies */
  520. strncat(hkey, "PKGSS_", 6);
  521. strncat(hkey, toupperstr(token), strlen(token));
  522. memset(hvalue, 0, MAXVALUE);
  523. result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  524. if (result == 1) {
  525. val = strtok_r(hvalue, " ", &saveptr);
  526. while (val != NULL) {
  527. if (strncmp(val, "kmod", 4) == 0)
  528. fprintf(cfg, "\tselect ADK_KPACKAGE_%s\n", toupperstr(val));
  529. else
  530. fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(val));
  531. val = strtok_r(NULL, " ", &saveptr);
  532. }
  533. }
  534. memset(hkey, 0, MAXVAR);
  535. /* create package host dependency information */
  536. if (pkg_host_depends != NULL) {
  537. token = strtok(pkg_host_depends, " ");
  538. fprintf(cfg, "\tdepends on ");
  539. sp = "";
  540. while (token != NULL) {
  541. if(strncmp(token, "!", 1) == 0) {
  542. fprintf(cfg, "%s!ADK_HOST%s", sp, toupperstr(token));
  543. sp = " && ";
  544. } else {
  545. fprintf(cfg, "%sADK_HOST_%s", sp, toupperstr(token));
  546. sp = " || ";
  547. }
  548. token = strtok(NULL, " ");
  549. }
  550. fprintf(cfg, "\n");
  551. }
  552. /* create package target architecture dependency information */
  553. if (pkg_arch_depends != NULL) {
  554. token = strtok(pkg_arch_depends, " ");
  555. fprintf(cfg, "\tdepends on ");
  556. sp = "";
  557. while (token != NULL) {
  558. if(strncmp(token, "!", 1) == 0) {
  559. fprintf(cfg, "%s!ADK_LINUX%s", sp, toupperstr(token));
  560. sp = " && ";
  561. } else {
  562. fprintf(cfg, "%sADK_LINUX_%s", sp, toupperstr(token));
  563. sp = " || ";
  564. }
  565. token = strtok(NULL, " ");
  566. }
  567. fprintf(cfg, "\n");
  568. }
  569. /* create package dependency information */
  570. if (pkg_depends != NULL) {
  571. token = strtok(pkg_depends, " ");
  572. while (token != NULL) {
  573. if (strncmp(token, "kmod", 4) == 0)
  574. fprintf(cfg, "\tselect ADK_KPACKAGE_%s\n", toupperstr(token));
  575. else
  576. fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(token));
  577. token = strtok(NULL, " ");
  578. }
  579. free(pkg_depends);
  580. pkg_depends = NULL;
  581. }
  582. if (pkg_need_cxx != NULL) {
  583. fprintf(cfg, "\tdepends on ADK_TOOLCHAIN_GCC_CXX\n");
  584. }
  585. if (pkg_need_java != NULL) {
  586. fprintf(cfg, "\tdepends on ADK_TOOLCHAIN_GCC_JAVA\n");
  587. pkg_need_java = NULL;
  588. }
  589. fprintf(cfg, "\tselect ADK_COMPILE_%s\n", toupperstr(pkgdirp->d_name));
  590. if (pkg_dflt != NULL) {
  591. fprintf(cfg, "\tdefault %s\n", pkg_dflt);
  592. pkg_dflt = NULL;
  593. } else {
  594. fprintf(cfg, "\tdefault n\n");
  595. }
  596. fprintf(cfg, "\thelp\n");
  597. fprintf(cfg, "\t %s\n\n", pkg_descr);
  598. if (pkg_url != NULL)
  599. fprintf(cfg, "\t WWW: %s\n", pkg_url);
  600. /* handle special C++ packages */
  601. if (pkg_cxx != NULL) {
  602. fprintf(cfg, "\nchoice\n");
  603. fprintf(cfg, "prompt \"C++ library to use\"\n");
  604. fprintf(cfg, "depends on ADK_COMPILE_%s\n\n", toupperstr(pkgdirp->d_name));
  605. fprintf(cfg, "default ADK_COMPILE_%s_WITH_STDCXX if ADK_TARGET_LIB_GLIBC || ADK_TARGET_LIB_EGLIBC\n", pkg_cxx);
  606. fprintf(cfg, "default ADK_COMPILE_%s_WITH_UCLIBCXX if ADK_TARGET_LIB_UCLIBC\n\n", pkg_cxx);
  607. fprintf(cfg, "config ADK_COMPILE_%s_WITH_STDCXX\n", pkg_cxx);
  608. fprintf(cfg, "\tbool \"GNU C++ library\"\n");
  609. fprintf(cfg, "\tselect ADK_PACKAGE_LIBSTDCXX\n\n");
  610. fprintf(cfg, "config ADK_COMPILE_%s_WITH_UCLIBCXX\n", pkg_cxx);
  611. fprintf(cfg, "\tbool \"uClibc++ library\"\n");
  612. fprintf(cfg, "\tselect ADK_PACKAGE_UCLIBCXX\n\n");
  613. fprintf(cfg, "endchoice\n");
  614. free(pkg_cxx);
  615. pkg_cxx = NULL;
  616. }
  617. /* package flavours */
  618. if (pkg_flavours != NULL) {
  619. token = strtok(pkg_flavours, " ");
  620. while (token != NULL) {
  621. fprintf(cfg, "\nconfig ADK_PACKAGE_%s_%s\n", pkgname, toupperstr(token));
  622. fprintf(cfg, "\tboolean ");
  623. strncat(hkey, "PKGFD_", 6);
  624. strncat(hkey, token, strlen(token));
  625. memset(hvalue, 0 , MAXVALUE);
  626. strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  627. memset(hkey, 0 , MAXVAR);
  628. pkg_fd = strdup(hvalue);
  629. fprintf(cfg, "\"%s\"\n", pkg_fd);
  630. fprintf(cfg, "\tdefault n\n");
  631. fprintf(cfg, "\tdepends on ADK_PACKAGE_%s\n", pkgname);
  632. strncat(hkey, "PKGFS_", 6);
  633. strncat(hkey, token, strlen(token));
  634. result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  635. if (result == 1) {
  636. val = strtok_r(hvalue, " ", &saveptr);
  637. while (val != NULL) {
  638. if (strncmp(val, "kmod", 4) == 0)
  639. fprintf(cfg, "\tselect ADK_KPACKAGE_%s\n", toupperstr(val));
  640. else
  641. fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(val));
  642. val = strtok_r(NULL, " ", &saveptr);
  643. }
  644. }
  645. memset(hkey, 0, MAXVAR);
  646. fprintf(cfg, "\thelp\n");
  647. fprintf(cfg, "\t %s\n", pkg_fd);
  648. token = strtok(NULL, " ");
  649. }
  650. free(pkg_flavours);
  651. pkg_flavours = NULL;
  652. }
  653. /* package choices */
  654. if (pkg_choices != NULL) {
  655. fprintf(cfg, "\nchoice\n");
  656. fprintf(cfg, "prompt \"Package flavour choice\"\n");
  657. fprintf(cfg, "depends on ADK_PACKAGE_%s\n\n", pkgname);
  658. token = strtok(pkg_choices, " ");
  659. while (token != NULL) {
  660. fprintf(cfg, "config ADK_PACKAGE_%s_%s\n", pkgname, toupperstr(token));
  661. fprintf(cfg, "\tbool ");
  662. strncat(hkey, "PKGCD_", 6);
  663. strncat(hkey, token, strlen(token));
  664. memset(hvalue, 0 , MAXVALUE);
  665. strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  666. memset(hkey, 0 , MAXVAR);
  667. fprintf(cfg, "\"%s\"\n", hvalue);
  668. strncat(hkey, "PKGCS_", 6);
  669. strncat(hkey, token, strlen(token));
  670. memset(hvalue, 0, MAXVALUE);
  671. result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  672. if (result == 1) {
  673. val = strtok_r(hvalue, " ", &saveptr);
  674. while (val != NULL) {
  675. if (strncmp(val, "kmod", 4) == 0)
  676. fprintf(cfg, "\tselect ADK_KPACKAGE_%s\n", toupperstr(val));
  677. else
  678. fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(val));
  679. val = strtok_r(NULL, " ", &saveptr);
  680. }
  681. }
  682. memset(hkey, 0, MAXVAR);
  683. token = strtok(NULL, " ");
  684. }
  685. fprintf(cfg, "\nendchoice\n");
  686. free(pkg_choices);
  687. pkg_choices = NULL;
  688. }
  689. /* close file descriptor, parse next package */
  690. fclose(cfg);
  691. token = strtok_r(NULL, " ", &p_ptr);
  692. }
  693. /* end of package output generation */
  694. free(packages);
  695. packages = NULL;
  696. pkg_need_cxx = NULL;
  697. pkg_need_java = NULL;
  698. /* reset flags, free memory */
  699. free(pkg_name);
  700. free(pkg_descr);
  701. free(pkg_section);
  702. free(pkg_url);
  703. free(pkg_depends);
  704. free(pkg_flavours);
  705. free(pkg_choices);
  706. free(pkg_subpkgs);
  707. free(pkg_arch_depends);
  708. free(pkg_host_depends);
  709. free(pkg_cxx);
  710. free(pkg_dflt);
  711. free(pkg_cfline);
  712. free(pkg_multi);
  713. pkg_name = NULL;
  714. pkg_descr = NULL;
  715. pkg_section = NULL;
  716. pkg_url = NULL;
  717. pkg_depends = NULL;
  718. pkg_flavours = NULL;
  719. pkg_choices = NULL;
  720. pkg_subpkgs = NULL;
  721. pkg_arch_depends = NULL;
  722. pkg_host_depends = NULL;
  723. pkg_cxx = NULL;
  724. pkg_dflt = NULL;
  725. pkg_cfline = NULL;
  726. pkg_multi = NULL;
  727. strmap_delete(pkgmap);
  728. nobinpkgs = 0;
  729. free(hkey);
  730. }
  731. }
  732. /* create Config.in.auto */
  733. strmap_enum(sectionmap, iter, NULL);
  734. strmap_delete(sectionmap);
  735. fclose(menuglobal);
  736. closedir(pkgdir);
  737. /* remove temporary section files */
  738. pkglistdir = opendir("package/pkglist.d");
  739. while ((pkgdirp = readdir(pkglistdir)) != NULL) {
  740. if (strncmp(pkgdirp->d_name, "sectionlst.", 11) == 0) {
  741. if (snprintf(path, MAXPATH, "package/pkglist.d/%s", pkgdirp->d_name) < 0)
  742. fatal_error("creating path variable failed.");
  743. if (unlink(path) < 0)
  744. fatal_error("removing file failed.");
  745. }
  746. }
  747. closedir(pkglistdir);
  748. return(0);
  749. }