pkgmaker.c 38 KB

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