pkgmaker.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230
  1. /*
  2. * pkgmaker - create package meta-data for OpenADK buildsystem
  3. *
  4. * Copyright (C) 2010-2014 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 96
  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_system(char *buf, const char *varname, char *pvalue, char **result, char **sysname, 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. *sysname = 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. static int parse_var_with_pkg(char *buf, const char *varname, char *pvalue, char **result, char **pkgname, int varlen) {
  146. char *pkg_var, *check;
  147. char *key, *value, *string;
  148. if ((pkg_var = malloc(MAXLINE)) != NULL)
  149. memset(pkg_var, 0, MAXLINE);
  150. else {
  151. perror("Can not allocate memory");
  152. exit(EXIT_FAILURE);
  153. }
  154. check = strstr(buf, ":=");
  155. if (check != NULL) {
  156. string = strstr(buf, varname);
  157. if (string != NULL) {
  158. string[strlen(string)-1] = '\0';
  159. key = strtok(string, ":=");
  160. *pkgname = strdup(key+varlen);
  161. value = strtok(NULL, "=\t");
  162. if (value != NULL) {
  163. strncat(pkg_var, value, strlen(value));
  164. *result = strdup(pkg_var);
  165. }
  166. free(pkg_var);
  167. return(0);
  168. }
  169. } else {
  170. string = strstr(buf, varname);
  171. if (string != NULL) {
  172. string[strlen(string)-1] = '\0';
  173. key = strtok(string, "+=");
  174. value = strtok(NULL, "=\t");
  175. if (pvalue != NULL)
  176. strncat(pkg_var, pvalue, strlen(pvalue));
  177. strncat(pkg_var, " ", 1);
  178. if (value != NULL)
  179. strncat(pkg_var, value, strlen(value));
  180. *result = strdup(pkg_var);
  181. free(pkg_var);
  182. return(0);
  183. }
  184. }
  185. free(pkg_var);
  186. return(1);
  187. }
  188. #if 0
  189. static void iter_debug(const char *key, const char *value, const void *obj) {
  190. fprintf(stderr, "HASHMAP key: %s value: %s\n", key, value);
  191. }
  192. #endif
  193. static int hash_str(char *string) {
  194. int i;
  195. int hash;
  196. hash = 0;
  197. for (i=0; i<(int)strlen(string); i++) {
  198. hash += string[i];
  199. }
  200. return(hash);
  201. }
  202. static void iter(const char *key, const char *value, const void *obj) {
  203. FILE *config, *section;
  204. int hash;
  205. char *valuestr, *pkg, *subpkg;
  206. char buf[MAXPATH];
  207. char infile[MAXPATH];
  208. char outfile[MAXPATH];
  209. valuestr = strdup(value);
  210. config = fopen("package/Config.in.auto", "a");
  211. if (config == NULL)
  212. fatal_error("Can not open file package/Config.in.auto");
  213. hash = hash_str(valuestr);
  214. snprintf(infile, MAXPATH, "package/pkglist.d/sectionlst.%d", hash);
  215. snprintf(outfile, MAXPATH, "package/pkglist.d/sectionlst.%d.sorted", hash);
  216. if (access(infile, F_OK) == 0) {
  217. valuestr[strlen(valuestr)-1] = '\0';
  218. fprintf(config, "menu \"%s\"\n", valuestr);
  219. sortfile(infile, outfile);
  220. /* avoid duplicate section entries */
  221. unlink(infile);
  222. section = fopen(outfile, "r");
  223. while (fgets(buf, MAXPATH, section) != NULL) {
  224. buf[strlen(buf)-1] = '\0';
  225. if (buf[strlen(buf)-1] == '@') {
  226. buf[strlen(buf)-1] = '\0';
  227. fprintf(config, "source \"package/%s/Config.in.manual\"\n", buf);
  228. } else {
  229. subpkg = strtok(buf, "|");
  230. subpkg[strlen(subpkg)-1] = '\0';
  231. pkg = strtok(NULL, "|");
  232. fprintf(config, "source \"package/pkgconfigs.d/%s/Config.in.%s\"\n", pkg, subpkg);
  233. }
  234. }
  235. fprintf(config, "endmenu\n\n");
  236. fclose(section);
  237. }
  238. fclose(config);
  239. }
  240. static char *tolowerstr(char *string) {
  241. int i;
  242. char *str;
  243. /* transform to lowercase variable name */
  244. str = strdup(string);
  245. for (i=0; i<(int)strlen(str); i++) {
  246. if (str[i] == '_')
  247. str[i] = '-';
  248. str[i] = tolower(str[i]);
  249. }
  250. return(str);
  251. }
  252. static char *toupperstr(char *string) {
  253. int i;
  254. char *str;
  255. /* transform to uppercase variable name */
  256. str = strdup(string);
  257. for (i=0; i<(int)strlen(str); i++) {
  258. if (str[i] == '+')
  259. str[i] = 'X';
  260. if (str[i] == '-')
  261. str[i] = '_';
  262. /* remove negation here, useful for package host depends */
  263. if (str[i] == '!')
  264. str[i] = '_';
  265. str[i] = toupper(str[i]);
  266. }
  267. return(str);
  268. }
  269. int main() {
  270. DIR *pkgdir, *pkglistdir, *scriptdir;
  271. struct dirent *pkgdirp;
  272. struct dirent *scriptdirp;
  273. size_t len;
  274. FILE *pkg, *cfg, *menuglobal, *section, *initscript, *icfg;
  275. char hvalue[MAXVALUE];
  276. char buf[MAXPATH];
  277. char ibuf[MAXPATH];
  278. char tbuf[MAXPATH];
  279. char path[MAXPATH];
  280. char script[MAXPATH];
  281. char script2[MAXPATH];
  282. char spath[MAXPATH];
  283. char dir[MAXPATH];
  284. char variable[2*MAXVAR];
  285. char *key, *value, *token, *cftoken, *sp, *hkey, *val, *pkg_fd;
  286. char *pkg_name, *pkg_depends, *pkg_depends_system, *pkg_section, *pkg_descr, *pkg_url;
  287. char *pkg_cxx, *pkg_subpkgs, *pkg_cfline, *pkg_dflt;
  288. char *pkgname, *sysname, *pkg_debug, *pkg_bb;
  289. char *pkg_libc_depends, *pkg_host_depends, *pkg_system_depends, *pkg_arch_depends, *pkg_flavours, *pkg_flavours_string, *pkg_choices, *pseudo_name;
  290. char *packages, *pkg_name_u, *pkgs, *pkg_opts, *pkg_libname;
  291. char *saveptr, *p_ptr, *s_ptr, *pkg_helper, *sname, *sname2;
  292. int result;
  293. StrMap *pkgmap, *sectionmap;
  294. const char runtime[] = "target/config/Config.in.scripts";
  295. pkg_name = NULL;
  296. pkg_descr = NULL;
  297. pkg_section = NULL;
  298. pkg_url = NULL;
  299. pkg_depends = NULL;
  300. pkg_depends_system = NULL;
  301. pkg_opts = NULL;
  302. pkg_libname = NULL;
  303. pkg_flavours = NULL;
  304. pkg_flavours_string = NULL;
  305. pkg_choices = NULL;
  306. pkg_subpkgs = NULL;
  307. pkg_arch_depends = NULL;
  308. pkg_system_depends = NULL;
  309. pkg_host_depends = NULL;
  310. pkg_libc_depends = NULL;
  311. pkg_cxx = NULL;
  312. pkg_dflt = NULL;
  313. pkg_cfline = NULL;
  314. pkgname = NULL;
  315. sysname = NULL;
  316. pkg_helper = NULL;
  317. pkg_debug = NULL;
  318. pkg_bb = NULL;
  319. p_ptr = NULL;
  320. s_ptr = NULL;
  321. unlink("package/Config.in.auto");
  322. unlink(runtime);
  323. /* open global sectionfile */
  324. menuglobal = fopen("package/Config.in.auto.global", "w");
  325. if (menuglobal == NULL)
  326. fatal_error("global section file not writable.");
  327. /* read section list and create a hash table */
  328. section = fopen("package/section.lst", "r");
  329. if (section == NULL)
  330. fatal_error("section listfile is missing");
  331. sectionmap = strmap_new(HASHSZ);
  332. while (fgets(tbuf, MAXPATH, section) != NULL) {
  333. key = strtok(tbuf, "\t");
  334. value = strtok(NULL, "\t");
  335. strmap_put(sectionmap, key, value);
  336. }
  337. fclose(section);
  338. if (mkdir("package/pkgconfigs.d", S_IRWXU) > 0)
  339. fatal_error("creation of package/pkgconfigs.d failed.");
  340. if (mkdir("package/pkgconfigs.d/gcc", S_IRWXU) > 0)
  341. fatal_error("creation of package/pkgconfigs.d/gcc failed.");
  342. if (mkdir("package/pkglist.d", S_IRWXU) > 0)
  343. fatal_error("creation of package/pkglist.d failed.");
  344. /* delete Config.in.dev */
  345. if (snprintf(path, MAXPATH, "package/pkgconfigs.d/gcc/Config.in.dev") < 0)
  346. fatal_error("failed to create path variable.");
  347. unlink(path);
  348. cfg = fopen(path, "w");
  349. if (cfg == NULL)
  350. fatal_error("Config.in.dev can not be opened");
  351. fprintf(cfg, "config ADK_PACKAGE_GLIBC_DEV\n");
  352. fprintf(cfg, "\tprompt \"glibc-dev............ development files for glibc\"\n");
  353. fprintf(cfg, "\tboolean\n");
  354. fprintf(cfg, "\tdefault n\n");
  355. fprintf(cfg, "\tdepends on ADK_TARGET_LIB_GLIBC\n");
  356. fprintf(cfg, "\thelp\n");
  357. fprintf(cfg, "\t GNU C library header files.\n\n");
  358. fprintf(cfg, "config ADK_PACKAGE_UCLIBC_DEV\n");
  359. fprintf(cfg, "\tprompt \"uclibc-dev........... development files for uclibc\"\n");
  360. fprintf(cfg, "\tboolean\n");
  361. fprintf(cfg, "\tdefault n\n");
  362. fprintf(cfg, "\tdepends on ADK_TARGET_LIB_UCLIBC\n");
  363. fprintf(cfg, "\thelp\n");
  364. fprintf(cfg, "\t C library header files.\n\n");
  365. fprintf(cfg, "config ADK_PACKAGE_MUSL_DEV\n");
  366. fprintf(cfg, "\tprompt \"musl-dev............. development files for musl\"\n");
  367. fprintf(cfg, "\tboolean\n");
  368. fprintf(cfg, "\tdefault n\n");
  369. fprintf(cfg, "\tdepends on ADK_TARGET_LIB_MUSL\n");
  370. fprintf(cfg, "\thelp\n");
  371. fprintf(cfg, "\t C library header files.\n\n");
  372. fclose(cfg);
  373. /* read Makefile's for all packages */
  374. pkgdir = opendir("package");
  375. while ((pkgdirp = readdir(pkgdir)) != NULL) {
  376. /* skip dotfiles */
  377. if (strncmp(pkgdirp->d_name, ".", 1) > 0) {
  378. if (snprintf(path, MAXPATH, "package/%s/Makefile", pkgdirp->d_name) < 0)
  379. fatal_error("can not create path variable.");
  380. pkg = fopen(path, "r");
  381. if (pkg == NULL)
  382. continue;
  383. /* runtime configuration */
  384. if (snprintf(script, MAXPATH, "package/%s/files", pkgdirp->d_name) < 0)
  385. fatal_error("script variable creation failed.");
  386. scriptdir = opendir(script);
  387. if (scriptdir != NULL) {
  388. while ((scriptdirp = readdir(scriptdir)) != NULL) {
  389. /* skip dotfiles */
  390. if (strncmp(scriptdirp->d_name, ".", 1) > 0) {
  391. len = strlen(scriptdirp->d_name);
  392. if (strlen(".init") > len)
  393. continue;
  394. if (strncmp(scriptdirp->d_name + len - strlen(".init"), ".init", strlen(".init")) == 0) {
  395. if (snprintf(script, MAXPATH, "package/%s/files/%s", pkgdirp->d_name, scriptdirp->d_name) < 0)
  396. fatal_error("script variable creation failed.");
  397. initscript = fopen(script, "r");
  398. if (initscript == NULL)
  399. continue;
  400. while (fgets(ibuf, MAXPATH, initscript) != NULL) {
  401. if (strncmp("#PKG", ibuf, 4) == 0) {
  402. sname = strdup(ibuf+5);
  403. sname[strlen(sname)-1] = '\0';
  404. sname2 = strdup(scriptdirp->d_name);
  405. sname2[strlen(sname2)-5] = '\0';
  406. icfg = fopen(runtime, "a");
  407. if (icfg == NULL)
  408. continue;
  409. if (strncmp("busybox", sname, 7) == 0)
  410. fprintf(icfg, "config ADK_RUNTIME_START_%s_%s\n", toupperstr(sname), toupperstr(sname2));
  411. else
  412. fprintf(icfg, "config ADK_RUNTIME_START_%s\n", toupperstr(sname));
  413. fprintf(icfg, "\tprompt \"Start %s on boot\"\n", sname2);
  414. fprintf(icfg, "\tboolean\n");
  415. if (strncmp("busybox", sname, 7) == 0)
  416. fprintf(icfg, "\tdepends on BUSYBOX_%s\n", toupperstr(sname2));
  417. else
  418. fprintf(icfg, "\tdepends on ADK_PACKAGE_%s\n", toupperstr(sname));
  419. fprintf(icfg, "\tdepends on ADK_RUNTIME_START_SERVICES\n");
  420. fprintf(icfg, "\tdefault n\n\n");
  421. fclose(icfg);
  422. }
  423. continue;
  424. free(sname);
  425. free(sname2);
  426. }
  427. }
  428. }
  429. }
  430. closedir(scriptdir);
  431. }
  432. /* skip manually maintained packages */
  433. if (snprintf(path, MAXPATH, "package/%s/Config.in.manual", pkgdirp->d_name) < 0)
  434. fatal_error("can not create path variable.");
  435. if (!access(path, F_OK)) {
  436. while (fgets(buf, MAXPATH, pkg) != NULL) {
  437. if ((parse_var(buf, "PKG_SECTION", NULL, &pkg_section)) == 0)
  438. continue;
  439. }
  440. memset(hvalue, 0 , MAXVALUE);
  441. result = strmap_get(sectionmap, pkg_section, hvalue, sizeof(hvalue));
  442. if (result == 1) {
  443. if (snprintf(spath, MAXPATH, "package/pkglist.d/sectionlst.%d", hash_str(hvalue)) < 0)
  444. fatal_error("can not create path variable.");
  445. section = fopen(spath, "a");
  446. if (section != NULL) {
  447. fprintf(section, "%s@\n", pkgdirp->d_name);
  448. fclose(section);
  449. }
  450. } else
  451. fatal_error("Can not find section description for package %s.",
  452. pkgdirp->d_name);
  453. fclose(pkg);
  454. continue;
  455. }
  456. nobinpkgs = 0;
  457. /* create output directories */
  458. if (snprintf(dir, MAXPATH, "package/pkgconfigs.d/%s", pkgdirp->d_name) < 0)
  459. fatal_error("can not create dir variable.");
  460. if (mkdir(dir, S_IRWXU) > 0)
  461. fatal_error("can not create directory.");
  462. /* allocate memory */
  463. hkey = malloc(MAXVAR);
  464. memset(hkey, 0, MAXVAR);
  465. memset(variable, 0, 2*MAXVAR);
  466. pkgmap = strmap_new(HASHSZ);
  467. /* parse package Makefile */
  468. while (fgets(buf, MAXPATH, pkg) != NULL) {
  469. /* just read variables prefixed with PKG */
  470. if (strncmp(buf, "PKG", 3) == 0) {
  471. if ((parse_var(buf, "PKG_NAME", NULL, &pkg_name)) == 0)
  472. continue;
  473. if (pkg_name != NULL)
  474. pkg_name_u = toupperstr(pkg_name);
  475. else
  476. pkg_name_u = toupperstr(pkgdirp->d_name);
  477. snprintf(variable, MAXVAR, "PKG_CFLINE_%s", pkg_name_u);
  478. if ((parse_var(buf, variable, pkg_cfline, &pkg_cfline)) == 0)
  479. continue;
  480. snprintf(variable, MAXVAR, "PKG_DFLT_%s", pkg_name_u);
  481. if ((parse_var(buf, variable, NULL, &pkg_dflt)) == 0)
  482. continue;
  483. if ((parse_var(buf, "PKG_LIBC_DEPENDS", NULL, &pkg_libc_depends)) == 0)
  484. continue;
  485. if ((parse_var(buf, "PKG_HOST_DEPENDS", NULL, &pkg_host_depends)) == 0)
  486. continue;
  487. if ((parse_var(buf, "PKG_ARCH_DEPENDS", NULL, &pkg_arch_depends)) == 0)
  488. continue;
  489. if ((parse_var(buf, "PKG_SYSTEM_DEPENDS", NULL, &pkg_system_depends)) == 0)
  490. continue;
  491. if ((parse_var(buf, "PKG_DESCR", NULL, &pkg_descr)) == 0)
  492. continue;
  493. if ((parse_var(buf, "PKG_SECTION", NULL, &pkg_section)) == 0)
  494. continue;
  495. if ((parse_var(buf, "PKG_URL", NULL, &pkg_url)) == 0)
  496. continue;
  497. if ((parse_var(buf, "PKG_CXX", NULL, &pkg_cxx)) == 0)
  498. continue;
  499. if ((parse_var(buf, "PKG_BB", NULL, &pkg_bb)) == 0)
  500. continue;
  501. if ((parse_var(buf, "PKG_DEPENDS", pkg_depends, &pkg_depends)) == 0)
  502. continue;
  503. if ((parse_var_with_system(buf, "PKG_DEPENDS_", pkg_depends_system, &pkg_depends_system, &sysname, 12)) == 0)
  504. continue;
  505. if ((parse_var(buf, "PKG_LIBNAME", pkg_libname, &pkg_libname)) == 0)
  506. continue;
  507. if ((parse_var(buf, "PKG_OPTS", pkg_opts, &pkg_opts)) == 0)
  508. continue;
  509. if ((parse_var_with_pkg(buf, "PKG_FLAVOURS_STRING_", pkg_flavours_string, &pkg_flavours_string, &pkgname, 20)) == 0)
  510. continue;
  511. if ((parse_var_with_pkg(buf, "PKG_FLAVOURS_", pkg_flavours, &pkg_flavours, &pkgname, 13)) == 0)
  512. continue;
  513. if ((parse_var_hash(buf, "PKGFD_", pkgmap)) == 0)
  514. continue;
  515. if ((parse_var_hash(buf, "PKGFX_", pkgmap)) == 0)
  516. continue;
  517. if ((parse_var_hash(buf, "PKGFS_", pkgmap)) == 0)
  518. continue;
  519. if ((parse_var_hash(buf, "PKGFC_", pkgmap)) == 0)
  520. continue;
  521. if ((parse_var_with_pkg(buf, "PKG_CHOICES_", pkg_choices, &pkg_choices, &pkgname, 12)) == 0)
  522. continue;
  523. if ((parse_var_hash(buf, "PKGCD_", pkgmap)) == 0)
  524. continue;
  525. if ((parse_var_hash(buf, "PKGCS_", pkgmap)) == 0)
  526. continue;
  527. if ((parse_var(buf, "PKG_SUBPKGS", pkg_subpkgs, &pkg_subpkgs)) == 0)
  528. continue;
  529. if ((parse_var_hash(buf, "PKGSD_", pkgmap)) == 0)
  530. continue;
  531. if ((parse_var_hash(buf, "PKGSS_", pkgmap)) == 0)
  532. continue;
  533. if ((parse_var_hash(buf, "PKGSC_", pkgmap)) == 0)
  534. continue;
  535. if ((parse_var_hash(buf, "PKGSN_", pkgmap)) == 0)
  536. continue;
  537. }
  538. }
  539. /* when PKG_LIBNAME exist use this instead of PKG_NAME, but only for !libmix */
  540. if (pkg_libname != NULL)
  541. if (pkg_opts != NULL)
  542. if (strstr(pkg_opts, "libmix") == NULL)
  543. pkg_name = strdup(pkg_libname);
  544. /* end of package Makefile parsing */
  545. if (fclose(pkg) != 0)
  546. perror("Failed to close file stream for Makefile");
  547. #if 0
  548. if (pkg_name != NULL)
  549. fprintf(stderr, "Package name is %s\n", pkg_name);
  550. if (pkg_libname != NULL)
  551. fprintf(stderr, "Package library name is %s\n", pkg_libname);
  552. if (pkg_section != NULL)
  553. fprintf(stderr, "Package section is %s\n", pkg_section);
  554. if (pkg_descr != NULL)
  555. fprintf(stderr, "Package description is %s\n", pkg_descr);
  556. if (pkg_depends != NULL)
  557. fprintf(stderr, "Package dependencies are %s\n", pkg_depends);
  558. if (pkg_depends_system != NULL)
  559. fprintf(stderr, "Package systemspecific dependencies are %s\n", pkg_depends_system);
  560. if (pkg_subpkgs != NULL)
  561. fprintf(stderr, "Package subpackages are %s\n", pkg_subpkgs);
  562. if (pkg_flavours != NULL && pkgname != NULL)
  563. fprintf(stderr, "Package flavours for %s are %s\n", pkgname, pkg_flavours);
  564. if (pkg_flavours_string != NULL && pkgname != NULL)
  565. fprintf(stderr, "Package string flavours for %s are %s\n", pkgname, pkg_flavours_string);
  566. if (pkg_choices != NULL && pkgname != NULL)
  567. fprintf(stderr, "Package choices for %s are %s\n", pkgname, pkg_choices);
  568. if (pkg_url != NULL)
  569. fprintf(stderr, "Package homepage is %s\n", pkg_url);
  570. if (pkg_cfline != NULL)
  571. fprintf(stderr, "Package cfline is %s\n", pkg_cfline);
  572. if (pkg_opts != NULL)
  573. fprintf(stderr, "Package options are %s\n", pkg_opts);
  574. strmap_enum(pkgmap, iter_debug, NULL);
  575. #endif
  576. /* generate master source Config.in file */
  577. if (snprintf(path, MAXPATH, "package/pkgconfigs.d/%s/Config.in", pkgdirp->d_name) < 0)
  578. fatal_error("path variable creation failed.");
  579. fprintf(menuglobal, "source \"%s\"\n", path);
  580. /* recreating file is faster than truncating with w+ */
  581. unlink(path);
  582. cfg = fopen(path, "w");
  583. if (cfg == NULL)
  584. continue;
  585. pkgs = NULL;
  586. if (pkg_subpkgs != NULL)
  587. pkgs = strdup(pkg_subpkgs);
  588. fprintf(cfg, "config ADK_COMPILE_%s\n", toupperstr(pkgdirp->d_name));
  589. fprintf(cfg, "\tboolean\n");
  590. if (nobinpkgs == 0) {
  591. fprintf(cfg, "\tdepends on ");
  592. if (pkgs != NULL) {
  593. token = strtok(pkgs, " ");
  594. fprintf(cfg, "ADK_PACKAGE_%s", token);
  595. token = strtok(NULL, " ");
  596. while (token != NULL) {
  597. fprintf(cfg, " || ADK_PACKAGE_%s", token);
  598. token = strtok(NULL, " ");
  599. }
  600. fprintf(cfg, "\n");
  601. } else {
  602. fprintf(cfg, "ADK_PACKAGE_%s\n", toupperstr(pkg_name));
  603. }
  604. }
  605. fprintf(cfg, "\tdefault n\n");
  606. fclose(cfg);
  607. free(pkgs);
  608. /* skip packages without binary package output */
  609. if (nobinpkgs == 1)
  610. continue;
  611. /* generate binary package specific Config.in files */
  612. if (pkg_subpkgs != NULL)
  613. packages = tolowerstr(pkg_subpkgs);
  614. else
  615. packages = strdup(pkg_name);
  616. token = strtok_r(packages, " ", &p_ptr);
  617. while (token != NULL) {
  618. strncat(hkey, "PKGSC_", 6);
  619. strncat(hkey, toupperstr(token), strlen(token));
  620. memset(hvalue, 0 , MAXVALUE);
  621. result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  622. memset(hkey, 0 , MAXVAR);
  623. if (result == 1)
  624. pkg_section = strdup(hvalue);
  625. strncat(hkey, "PKGSD_", 6);
  626. strncat(hkey, toupperstr(token), strlen(token));
  627. memset(hvalue, 0 , MAXVALUE);
  628. result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  629. memset(hkey, 0 , MAXVAR);
  630. if (result == 1)
  631. pkg_descr = strdup(hvalue);
  632. pseudo_name = malloc(MAXLINE);
  633. memset(pseudo_name, 0, MAXLINE);
  634. strncat(pseudo_name, token, strlen(token));
  635. while (strlen(pseudo_name) < 20)
  636. strncat(pseudo_name, ".", 1);
  637. if (snprintf(path, MAXPATH, "package/pkgconfigs.d/%s/Config.in.%s", pkgdirp->d_name, token) < 0)
  638. fatal_error("failed to create path variable.");
  639. /* create temporary section files */
  640. memset(hvalue, 0 , MAXVALUE);
  641. result = strmap_get(sectionmap, pkg_section, hvalue, sizeof(hvalue));
  642. if (result == 1) {
  643. if (snprintf(spath, MAXPATH, "package/pkglist.d/sectionlst.%d", hash_str(hvalue)) < 0)
  644. fatal_error("failed to create path variable.");
  645. section = fopen(spath, "a");
  646. if (section != NULL) {
  647. fprintf(section, "%s |%s\n", token, pkgdirp->d_name);
  648. fclose(section);
  649. }
  650. } else
  651. fatal_error("Can not find section description for package %s.", pkgdirp->d_name);
  652. unlink(path);
  653. cfg = fopen(path, "w");
  654. if (cfg == NULL)
  655. perror("Can not open Config.in file");
  656. if (pkg_bb != NULL) {
  657. fprintf(cfg, "comment \"%s... %s (disabled, provided by busybox)\"\n", token, pkg_descr);
  658. fprintf(cfg, "depends on ADK_PACKAGE_BUSYBOX_HIDE\n\n");
  659. }
  660. /* save token in pkg_debug */
  661. pkg_debug = strdup(token);
  662. fprintf(cfg, "config ADK_PACKAGE_%s\n", toupperstr(token));
  663. /* no prompt for devonly packages */
  664. if (pkg_opts != NULL) {
  665. if (strstr(pkg_opts, "devonly") != NULL) {
  666. fprintf(cfg, "\t#prompt \"%s. %s\"\n", pseudo_name, pkg_descr);
  667. } else {
  668. fprintf(cfg, "\tprompt \"%s. %s\"\n", pseudo_name, pkg_descr);
  669. }
  670. } else {
  671. fprintf(cfg, "\tprompt \"%s. %s\"\n", pseudo_name, pkg_descr);
  672. }
  673. fprintf(cfg, "\tboolean\n");
  674. free(pseudo_name);
  675. /* print custom cf line */
  676. if (pkg_cfline != NULL) {
  677. cftoken = strtok_r(pkg_cfline, "@", &saveptr);
  678. while (cftoken != NULL) {
  679. fprintf(cfg, "\t%s\n", cftoken);
  680. cftoken = strtok_r(NULL, "@", &saveptr);
  681. }
  682. free(pkg_cfline);
  683. pkg_cfline = NULL;
  684. }
  685. /* add sub package dependencies */
  686. strncat(hkey, "PKGSN_", 6);
  687. strncat(hkey, toupperstr(token), strlen(token));
  688. memset(hvalue, 0, MAXVALUE);
  689. result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  690. if (result == 1) {
  691. val = strtok_r(hvalue, " ", &saveptr);
  692. while (val != NULL) {
  693. fprintf(cfg, "\tdepends on ADK_PACKAGE_%s\n", toupperstr(val));
  694. val = strtok_r(NULL, " ", &saveptr);
  695. }
  696. }
  697. memset(hkey, 0, MAXVAR);
  698. /* add sub package auto selections */
  699. strncat(hkey, "PKGSS_", 6);
  700. strncat(hkey, toupperstr(token), strlen(token));
  701. memset(hvalue, 0, MAXVALUE);
  702. result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  703. if (result == 1) {
  704. val = strtok_r(hvalue, " ", &saveptr);
  705. while (val != NULL) {
  706. fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(val));
  707. val = strtok_r(NULL, " ", &saveptr);
  708. }
  709. }
  710. memset(hkey, 0, MAXVAR);
  711. /* create package target system dependency information */
  712. if (pkg_system_depends != NULL) {
  713. pkg_helper = strdup(pkg_system_depends);
  714. token = strtok(pkg_helper, " ");
  715. fprintf(cfg, "\tdepends on ");
  716. sp = "";
  717. while (token != NULL) {
  718. if(strncmp(token, "!", 1) == 0) {
  719. fprintf(cfg, "%s!ADK_TARGET_SYSTEM%s", sp, toupperstr(token));
  720. sp = " && ";
  721. } else {
  722. fprintf(cfg, "%sADK_TARGET_SYSTEM_%s", sp, toupperstr(token));
  723. sp = " || ";
  724. }
  725. token = strtok(NULL, " ");
  726. }
  727. fprintf(cfg, "\n");
  728. free(pkg_helper);
  729. pkg_helper = NULL;
  730. }
  731. /* create package host dependency information */
  732. if (pkg_host_depends != NULL) {
  733. pkg_helper = strdup(pkg_host_depends);
  734. token = strtok(pkg_helper, " ");
  735. fprintf(cfg, "\tdepends on ");
  736. sp = "";
  737. while (token != NULL) {
  738. if(strncmp(token, "!", 1) == 0) {
  739. fprintf(cfg, "%s!ADK_HOST%s", sp, toupperstr(token));
  740. sp = " && ";
  741. } else {
  742. fprintf(cfg, "%sADK_HOST_%s", sp, toupperstr(token));
  743. sp = " || ";
  744. }
  745. token = strtok(NULL, " ");
  746. }
  747. fprintf(cfg, "\n");
  748. free(pkg_helper);
  749. pkg_helper = NULL;
  750. }
  751. /* create package libc dependency information */
  752. if (pkg_libc_depends != NULL) {
  753. pkg_helper = strdup(pkg_libc_depends);
  754. token = strtok(pkg_helper, " ");
  755. fprintf(cfg, "\tdepends on ");
  756. sp = "";
  757. while (token != NULL) {
  758. if(strncmp(token, "!", 1) == 0) {
  759. fprintf(cfg, "%s!ADK_TARGET_LIB_%s", sp, toupperstr(token));
  760. sp = " && ";
  761. } else {
  762. fprintf(cfg, "%sADK_TARGET_LIB_%s", sp, toupperstr(token));
  763. sp = " || ";
  764. }
  765. token = strtok(NULL, " ");
  766. }
  767. fprintf(cfg, "\n");
  768. free(pkg_helper);
  769. pkg_helper = NULL;
  770. }
  771. /* create package target architecture dependency information */
  772. if (pkg_arch_depends != NULL) {
  773. pkg_helper = strdup(pkg_arch_depends);
  774. token = strtok(pkg_helper, " ");
  775. fprintf(cfg, "\tdepends on ");
  776. sp = "";
  777. while (token != NULL) {
  778. if(strncmp(token, "!", 1) == 0) {
  779. fprintf(cfg, "%s!ADK_LINUX%s", sp, toupperstr(token));
  780. sp = " && ";
  781. } else {
  782. fprintf(cfg, "%sADK_LINUX_%s", sp, toupperstr(token));
  783. sp = " || ";
  784. }
  785. token = strtok(NULL, " ");
  786. }
  787. fprintf(cfg, "\n");
  788. free(pkg_helper);
  789. pkg_helper = NULL;
  790. }
  791. /* create package dependency information */
  792. if (pkg_depends != NULL) {
  793. token = strtok(pkg_depends, " ");
  794. while (token != NULL) {
  795. fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(token));
  796. token = strtok(NULL, " ");
  797. }
  798. free(pkg_depends);
  799. pkg_depends = NULL;
  800. }
  801. /* create system specific package dependency information */
  802. if (pkg_depends_system != NULL) {
  803. token = strtok(pkg_depends_system, " ");
  804. while (token != NULL) {
  805. fprintf(cfg, "\tselect ADK_PACKAGE_%s if ADK_TARGET_SYSTEM_%s\n", toupperstr(token), sysname);
  806. token = strtok(NULL, " ");
  807. }
  808. free(pkg_depends_system);
  809. pkg_depends_system = NULL;
  810. }
  811. if (pkg_bb != NULL) {
  812. fprintf(cfg, "\tdepends on !ADK_PACKAGE_BUSYBOX_HIDE\n");
  813. }
  814. fprintf(cfg, "\tselect ADK_COMPILE_%s\n", toupperstr(pkgdirp->d_name));
  815. if (pkg_dflt != NULL) {
  816. fprintf(cfg, "\tdefault %s\n", pkg_dflt);
  817. pkg_dflt = NULL;
  818. } else {
  819. fprintf(cfg, "\tdefault n\n");
  820. }
  821. fprintf(cfg, "\thelp\n");
  822. fprintf(cfg, "\t %s\n\n", pkg_descr);
  823. if (pkg_url != NULL)
  824. fprintf(cfg, "\t WWW: %s\n", pkg_url);
  825. /* handle special C++ packages */
  826. if (pkg_cxx != NULL) {
  827. fprintf(cfg, "\nchoice\n");
  828. fprintf(cfg, "prompt \"C++ library to use\"\n");
  829. fprintf(cfg, "depends on ADK_COMPILE_%s\n\n", toupperstr(pkgdirp->d_name));
  830. fprintf(cfg, "default ADK_COMPILE_%s_WITH_STDCXX if ADK_TARGET_LIB_GLIBC\n", pkg_cxx);
  831. fprintf(cfg, "default ADK_COMPILE_%s_WITH_UCLIBCXX if ADK_TARGET_LIB_UCLIBC\n\n", pkg_cxx);
  832. fprintf(cfg, "config ADK_COMPILE_%s_WITH_STDCXX\n", pkg_cxx);
  833. fprintf(cfg, "\tbool \"GNU C++ library\"\n");
  834. fprintf(cfg, "\tselect ADK_PACKAGE_LIBSTDCXX\n\n");
  835. fprintf(cfg, "config ADK_COMPILE_%s_WITH_UCLIBCXX\n", pkg_cxx);
  836. fprintf(cfg, "\tbool \"uClibc++ library\"\n");
  837. fprintf(cfg, "\tselect ADK_PACKAGE_UCLIBCXX\n\n");
  838. fprintf(cfg, "endchoice\n");
  839. free(pkg_cxx);
  840. pkg_cxx = NULL;
  841. }
  842. /* handle debug subpackages */
  843. fprintf(cfg, "\nconfig ADK_PACKAGE_%s_DBG\n", toupperstr(pkg_debug));
  844. fprintf(cfg, "\tprompt \"add debug symbols package\"\n");
  845. fprintf(cfg, "\tboolean\n");
  846. fprintf(cfg, "\tdepends on ADK_PACKAGE_GDB\n");
  847. fprintf(cfg, "\tdepends on !ADK_DEBUG\n");
  848. fprintf(cfg, "\tdepends on ADK_PACKAGE_%s\n", toupperstr(pkg_debug));
  849. fprintf(cfg, "\tdefault n\n");
  850. fprintf(cfg, "\thelp\n\n");
  851. /* package flavours */
  852. if (pkg_flavours != NULL) {
  853. token = strtok(pkg_flavours, " ");
  854. while (token != NULL) {
  855. fprintf(cfg, "\nconfig ADK_PACKAGE_%s_%s\n", pkgname, toupperstr(token));
  856. // process default value
  857. strncat(hkey, "PKGFX_", 6);
  858. strncat(hkey, token, strlen(token));
  859. memset(hvalue, 0 , MAXVALUE);
  860. strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  861. memset(hkey, 0 , MAXVAR);
  862. pkg_fd = strdup(hvalue);
  863. if (strlen(pkg_fd) > 0)
  864. fprintf(cfg, "\tdefault %s\n", pkg_fd);
  865. else
  866. fprintf(cfg, "\tdefault n\n");
  867. // process flavour cfline
  868. strncat(hkey, "PKGFC_", 6);
  869. strncat(hkey, token, strlen(token));
  870. memset(hvalue, 0 , MAXVALUE);
  871. strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  872. memset(hkey, 0 , MAXVAR);
  873. pkg_fd = strdup(hvalue);
  874. if (strlen(pkg_fd) > 0)
  875. fprintf(cfg, "\t%s\n", pkg_fd);
  876. fprintf(cfg, "\tboolean ");
  877. strncat(hkey, "PKGFD_", 6);
  878. strncat(hkey, token, strlen(token));
  879. memset(hvalue, 0 , MAXVALUE);
  880. strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  881. memset(hkey, 0 , MAXVAR);
  882. pkg_fd = strdup(hvalue);
  883. fprintf(cfg, "\"%s\"\n", pkg_fd);
  884. fprintf(cfg, "\tdepends on ADK_PACKAGE_%s\n", pkgname);
  885. strncat(hkey, "PKGFS_", 6);
  886. strncat(hkey, token, strlen(token));
  887. result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  888. if (result == 1) {
  889. val = strtok_r(hvalue, " ", &saveptr);
  890. while (val != NULL) {
  891. fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(val));
  892. val = strtok_r(NULL, " ", &saveptr);
  893. }
  894. }
  895. memset(hkey, 0, MAXVAR);
  896. fprintf(cfg, "\thelp\n");
  897. fprintf(cfg, "\t %s\n", pkg_fd);
  898. token = strtok(NULL, " ");
  899. }
  900. free(pkg_flavours);
  901. pkg_flavours = NULL;
  902. }
  903. /* package flavours string */
  904. if (pkg_flavours_string != NULL) {
  905. token = strtok(pkg_flavours_string, " ");
  906. while (token != NULL) {
  907. fprintf(cfg, "\nconfig ADK_PACKAGE_%s_%s\n", pkgname, toupperstr(token));
  908. // process default value
  909. strncat(hkey, "PKGFX_", 6);
  910. strncat(hkey, token, strlen(token));
  911. memset(hvalue, 0 , MAXVALUE);
  912. strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  913. memset(hkey, 0 , MAXVAR);
  914. pkg_fd = strdup(hvalue);
  915. if (strlen(pkg_fd) > 0)
  916. fprintf(cfg, "\tdefault \"%s\"\n", pkg_fd);
  917. // process flavour cfline
  918. strncat(hkey, "PKGFC_", 6);
  919. strncat(hkey, token, strlen(token));
  920. memset(hvalue, 0 , MAXVALUE);
  921. strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  922. memset(hkey, 0 , MAXVAR);
  923. pkg_fd = strdup(hvalue);
  924. if (strlen(pkg_fd) > 0)
  925. fprintf(cfg, "\t%s\n", pkg_fd);
  926. fprintf(cfg, "\tstring ");
  927. strncat(hkey, "PKGFD_", 6);
  928. strncat(hkey, token, strlen(token));
  929. memset(hvalue, 0 , MAXVALUE);
  930. strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  931. memset(hkey, 0 , MAXVAR);
  932. pkg_fd = strdup(hvalue);
  933. fprintf(cfg, "\"%s\"\n", pkg_fd);
  934. fprintf(cfg, "\tdepends on ADK_PACKAGE_%s\n", pkgname);
  935. strncat(hkey, "PKGFS_", 6);
  936. strncat(hkey, token, strlen(token));
  937. result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  938. if (result == 1) {
  939. val = strtok_r(hvalue, " ", &saveptr);
  940. while (val != NULL) {
  941. fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(val));
  942. val = strtok_r(NULL, " ", &saveptr);
  943. }
  944. }
  945. memset(hkey, 0, MAXVAR);
  946. fprintf(cfg, "\thelp\n");
  947. fprintf(cfg, "\t %s\n", pkg_fd);
  948. token = strtok(NULL, " ");
  949. }
  950. free(pkg_flavours_string);
  951. pkg_flavours_string = NULL;
  952. }
  953. /* package choices */
  954. if (pkg_choices != NULL) {
  955. fprintf(cfg, "\nchoice\n");
  956. fprintf(cfg, "prompt \"Package flavour choice\"\n");
  957. fprintf(cfg, "depends on ADK_PACKAGE_%s\n\n", pkgname);
  958. token = strtok(pkg_choices, " ");
  959. while (token != NULL) {
  960. fprintf(cfg, "config ADK_PACKAGE_%s_%s\n", pkgname, toupperstr(token));
  961. fprintf(cfg, "\tbool ");
  962. strncat(hkey, "PKGCD_", 6);
  963. strncat(hkey, token, strlen(token));
  964. memset(hvalue, 0 , MAXVALUE);
  965. strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  966. memset(hkey, 0 , MAXVAR);
  967. fprintf(cfg, "\"%s\"\n", hvalue);
  968. strncat(hkey, "PKGCS_", 6);
  969. strncat(hkey, token, strlen(token));
  970. memset(hvalue, 0, MAXVALUE);
  971. result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  972. if (result == 1) {
  973. val = strtok_r(hvalue, " ", &saveptr);
  974. while (val != NULL) {
  975. fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(val));
  976. val = strtok_r(NULL, " ", &saveptr);
  977. }
  978. }
  979. memset(hkey, 0, MAXVAR);
  980. token = strtok(NULL, " ");
  981. }
  982. fprintf(cfg, "\nendchoice\n");
  983. free(pkg_choices);
  984. pkg_choices = NULL;
  985. }
  986. /* close file descriptor for Config.in file */
  987. fclose(cfg);
  988. /* create Config.in files for development packages */
  989. if (pkg_opts != NULL) {
  990. if (strstr(pkg_opts, "dev") != NULL) {
  991. if (snprintf(path, MAXPATH, "package/pkgconfigs.d/gcc/Config.in.dev") < 0)
  992. fatal_error("failed to create path variable.");
  993. cfg = fopen(path, "a");
  994. if (cfg == NULL)
  995. perror("Can not open Config.in.dev file");
  996. if (pkg_libname == NULL)
  997. pkg_libname = strdup(pkg_name);
  998. fprintf(cfg, "\n");
  999. fprintf(cfg, "config ADK_PACKAGE_%s_DEV\n", toupperstr(pkg_libname));
  1000. pseudo_name = malloc(MAXLINE);
  1001. memset(pseudo_name, 0, MAXLINE);
  1002. strncat(pseudo_name, pkg_libname, strlen(pkg_libname));
  1003. strncat(pseudo_name, "-dev", 4);
  1004. while (strlen(pseudo_name) < 20)
  1005. strncat(pseudo_name, ".", 1);
  1006. fprintf(cfg, "\tprompt \"%s. development files for %s\"\n", pseudo_name, pkg_libname);
  1007. fprintf(cfg, "\tboolean\n");
  1008. /* create package target architecture dependency information */
  1009. if (pkg_arch_depends != NULL) {
  1010. pkg_helper = strdup(pkg_arch_depends);
  1011. token = strtok(pkg_helper, " ");
  1012. fprintf(cfg, "\tdepends on ");
  1013. sp = "";
  1014. while (token != NULL) {
  1015. if(strncmp(token, "!", 1) == 0) {
  1016. fprintf(cfg, "%s!ADK_LINUX%s", sp, toupperstr(token));
  1017. sp = " && ";
  1018. } else {
  1019. fprintf(cfg, "%sADK_LINUX_%s", sp, toupperstr(token));
  1020. sp = " || ";
  1021. }
  1022. token = strtok(NULL, " ");
  1023. }
  1024. fprintf(cfg, "\n");
  1025. free(pkg_helper);
  1026. pkg_helper = NULL;
  1027. }
  1028. fprintf(cfg, "\tdepends on ADK_PACKAGE_GCC\n");
  1029. fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(pkg_libname));
  1030. fprintf(cfg, "\tdefault n\n");
  1031. fclose(cfg);
  1032. free(pseudo_name);
  1033. free(pkg_libname);
  1034. pkg_libname = NULL;
  1035. }
  1036. pkg_opts = NULL;
  1037. }
  1038. /* parse next package */
  1039. token = strtok_r(NULL, " ", &p_ptr);
  1040. }
  1041. /* end of package output generation */
  1042. free(packages);
  1043. packages = NULL;
  1044. /* reset flags, free memory */
  1045. free(pkg_name);
  1046. free(pkg_libname);
  1047. free(pkg_descr);
  1048. free(pkg_section);
  1049. free(pkg_url);
  1050. free(pkg_depends);
  1051. free(pkg_flavours);
  1052. free(pkg_flavours_string);
  1053. free(pkg_choices);
  1054. free(pkg_subpkgs);
  1055. free(pkg_arch_depends);
  1056. free(pkg_system_depends);
  1057. free(pkg_host_depends);
  1058. free(pkg_libc_depends);
  1059. free(pkg_cxx);
  1060. free(pkg_dflt);
  1061. free(pkg_cfline);
  1062. free(pkg_bb);
  1063. pkg_name = NULL;
  1064. pkg_libname = NULL;
  1065. pkg_descr = NULL;
  1066. pkg_section = NULL;
  1067. pkg_url = NULL;
  1068. pkg_depends = NULL;
  1069. pkg_flavours = NULL;
  1070. pkg_flavours_string = NULL;
  1071. pkg_choices = NULL;
  1072. pkg_subpkgs = NULL;
  1073. pkg_arch_depends = NULL;
  1074. pkg_system_depends = NULL;
  1075. pkg_host_depends = NULL;
  1076. pkg_libc_depends = NULL;
  1077. pkg_cxx = NULL;
  1078. pkg_dflt = NULL;
  1079. pkg_cfline = NULL;
  1080. pkg_bb = NULL;
  1081. strmap_delete(pkgmap);
  1082. nobinpkgs = 0;
  1083. free(hkey);
  1084. }
  1085. }
  1086. /* add menu to gcc package */
  1087. if (snprintf(path, MAXPATH, "package/pkgconfigs.d/gcc/Config.in.gcc") < 0)
  1088. fatal_error("failed to create path variable.");
  1089. cfg = fopen(path, "a");
  1090. if (cfg == NULL)
  1091. perror("Can not open Config.in.gcc file");
  1092. fprintf(cfg, "menu \"Development packages\"\n");
  1093. fprintf(cfg, "depends on ADK_PACKAGE_GCC\n");
  1094. fprintf(cfg, "source \"package/pkgconfigs.d/gcc/Config.in.dev\"\n");
  1095. fprintf(cfg, "endmenu\n");
  1096. fclose(cfg);
  1097. /* create Config.in.auto */
  1098. strmap_enum(sectionmap, iter, NULL);
  1099. strmap_delete(sectionmap);
  1100. fclose(menuglobal);
  1101. closedir(pkgdir);
  1102. /* remove temporary section files */
  1103. pkglistdir = opendir("package/pkglist.d");
  1104. while ((pkgdirp = readdir(pkglistdir)) != NULL) {
  1105. if (strncmp(pkgdirp->d_name, "sectionlst.", 11) == 0) {
  1106. if (snprintf(path, MAXPATH, "package/pkglist.d/%s", pkgdirp->d_name) < 0)
  1107. fatal_error("creating path variable failed.");
  1108. if (unlink(path) < 0)
  1109. fatal_error("removing file failed.");
  1110. }
  1111. }
  1112. closedir(pkglistdir);
  1113. return(0);
  1114. }