pkgmaker.c 37 KB

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