pkgmaker.c 38 KB

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