1
0

pkgmaker.c 35 KB

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