pkgmaker.c 38 KB

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