pkgmaker.c 39 KB

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