pkgmaker.c 38 KB

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