add varios patches...
[openadk.git] / tools / adk / pkgmaker.c
blobeeba003049ea45dca2e853830d108606841db52c
1 /*
2 * pkgmaker - create package meta-data for OpenADK buildsystem
4 * Copyright (C) 2010,2011 Waldemar Brodkorb <wbx@openadk.org>
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.
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.
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/>.
20 #include <ctype.h>
21 #include <dirent.h>
22 #include <fcntl.h>
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include <unistd.h>
27 #include <sys/stat.h>
28 #include <sys/types.h>
29 #include "sortfile.h"
30 #include "strmap.h"
32 #define MAXLINE 4096
33 #define MAXVALUE 168
34 #define MAXVAR 64
35 #define MAXPATH 320
36 #define HASHSZ 32
38 static int nobinpkgs;
40 static void fatal_error(const char *message) {
42 fprintf(stderr, "Fatal error. %s\n", message);
43 exit(1);
46 static int parse_var_hash(char *buf, const char *varname, StrMap *strmap) {
48 char *key, *value, *string;
50 string = strstr(buf, varname);
51 if (string != NULL) {
52 string[strlen(string)-1] = '\0';
53 key = strtok(string, ":=");
54 value = strtok(NULL, "=\t");
55 if (value != NULL)
56 strmap_put(strmap, key, value);
57 return(0);
59 return(1);
62 static int parse_var(char *buf, const char *varname, char *pvalue, char **result) {
64 char *pkg_var;
65 char *key, *value, *string;
66 char pkg_str[MAXVAR];
68 if ((pkg_var = malloc(MAXLINE)) != NULL)
69 memset(pkg_var, 0, MAXLINE);
70 else {
71 perror("Can not allocate memory");
72 exit(EXIT_FAILURE);
75 if (snprintf(pkg_str, MAXVAR, "%s:=", varname) < 0)
76 perror("can not create path variable.");
77 string = strstr(buf, pkg_str);
78 if (string != NULL) {
79 string[strlen(string)-1] = '\0';
80 key = strtok(string, ":=");
81 value = strtok(NULL, "=\t");
82 if (value != NULL) {
83 strncat(pkg_var, value, strlen(value));
84 *result = strdup(pkg_var);
85 } else {
86 nobinpkgs = 1;
87 *result = NULL;
89 free(pkg_var);
90 return(0);
91 } else {
92 if (snprintf(pkg_str, MAXVAR, "%s+=", varname) < 0)
93 perror("can not create path variable.");
94 string = strstr(buf, pkg_str);
95 if (string != NULL) {
96 string[strlen(string)-1] = '\0';
97 key = strtok(string, "+=");
98 value = strtok(NULL, "=\t");
99 if (pvalue != NULL)
100 strncat(pkg_var, pvalue, strlen(pvalue));
101 strncat(pkg_var, " ", 1);
102 if (value != NULL)
103 strncat(pkg_var, value, strlen(value));
104 *result = strdup(pkg_var);
105 free(pkg_var);
106 return(0);
109 free(pkg_var);
110 return(1);
114 static void iter_debug(const char *key, const char *value, const void *obj) {
115 fprintf(stderr, "HASHMAP key: %s value: %s\n", key, value);
119 static int hash_str(char *string) {
121 int i;
122 int hash;
124 hash = 0;
125 for (i=0; i<(int)strlen(string); i++) {
126 hash += string[i];
128 return(hash);
131 static void iter(const char *key, const char *value, const void *obj) {
133 FILE *config, *section;
134 int hash;
135 char *valuestr, *pkg, *subpkg;
136 char buf[MAXPATH];
137 char infile[MAXPATH];
138 char outfile[MAXPATH];
140 valuestr = strdup(value);
141 config = fopen("package/Config.in.auto", "a");
142 if (config == NULL)
143 fatal_error("Can not open file package/Config.in.auto");
145 hash = hash_str(valuestr);
146 snprintf(infile, MAXPATH, "package/pkglist.d/sectionlst.%d", hash);
147 snprintf(outfile, MAXPATH, "package/pkglist.d/sectionlst.%d.sorted", hash);
149 if (access(infile, F_OK) == 0) {
150 valuestr[strlen(valuestr)-1] = '\0';
151 fprintf(config, "menu \"%s\"\n", valuestr);
152 sortfile(infile, outfile);
153 /* avoid duplicate section entries */
154 unlink(infile);
155 section = fopen(outfile, "r");
156 while (fgets(buf, MAXPATH, section) != NULL) {
157 buf[strlen(buf)-1] = '\0';
158 if (buf[strlen(buf)-1] == '@') {
159 buf[strlen(buf)-1] = '\0';
160 fprintf(config, "source \"package/%s/Config.in.manual\"\n", buf);
161 } else {
162 subpkg = strtok(buf, "|");
163 subpkg[strlen(subpkg)-1] = '\0';
164 pkg = strtok(NULL, "|");
165 fprintf(config, "source \"package/pkgconfigs.d/%s/Config.in.%s\"\n", pkg, subpkg);
168 fprintf(config, "endmenu\n\n");
169 fclose(section);
171 fclose(config);
174 static char *tolowerstr(char *string) {
176 int i;
177 char *str;
179 /* transform to lowercase variable name */
180 str = strdup(string);
181 for (i=0; i<(int)strlen(str); i++) {
182 if (str[i] == '_')
183 str[i] = '-';
184 str[i] = tolower(str[i]);
186 return(str);
189 static char *toupperstr(char *string) {
191 int i;
192 char *str;
194 /* transform to uppercase variable name */
195 str = strdup(string);
196 for (i=0; i<(int)strlen(str); i++) {
197 if (str[i] == '+')
198 str[i] = 'X';
199 if (str[i] == '-')
200 str[i] = '_';
201 /* remove negation here, useful for package host depends */
202 if (str[i] == '!')
203 str[i] = '_';
204 str[i] = toupper(str[i]);
206 return(str);
210 int main() {
212 DIR *pkgdir, *pkglistdir;
213 struct dirent *pkgdirp;
214 FILE *pkg, *cfg, *menuglobal, *section;
215 char hvalue[MAXVALUE];
216 char buf[MAXPATH];
217 char tbuf[MAXPATH];
218 char path[MAXPATH];
219 char spath[MAXPATH];
220 char dir[MAXPATH];
221 char variable[2*MAXVAR];
222 char *key, *value, *token, *cftoken, *sp, *hkey, *val, *pkg_fd;
223 char *pkg_name, *pkg_depends, *pkg_section, *pkg_descr, *pkg_url;
224 char *pkg_cxx, *pkg_subpkgs, *pkg_cfline, *pkg_dflt, *pkg_multi;
225 char *pkg_need_cxx, *pkg_need_java;
226 char *pkg_host_depends, *pkg_arch_depends, *pkg_flavours, *pkg_choices, *pseudo_name;
227 char *packages, *pkg_name_u, *pkgs;
228 char *saveptr, *p_ptr, *s_ptr;
229 int result;
230 StrMap *pkgmap, *sectionmap;
232 pkg_name = NULL;
233 pkg_descr = NULL;
234 pkg_section = NULL;
235 pkg_url = NULL;
236 pkg_depends = NULL;
237 pkg_flavours = NULL;
238 pkg_choices = NULL;
239 pkg_subpkgs = NULL;
240 pkg_arch_depends = NULL;
241 pkg_host_depends = NULL;
242 pkg_cxx = NULL;
243 pkg_dflt = NULL;
244 pkg_cfline = NULL;
245 pkg_multi = NULL;
246 pkg_need_cxx = NULL;
247 pkg_need_java = NULL;
249 p_ptr = NULL;
250 s_ptr = NULL;
252 unlink("package/Config.in.auto");
253 /* open global sectionfile */
254 menuglobal = fopen("package/Config.in.auto.global", "w");
255 if (menuglobal == NULL)
256 fatal_error("global section file not writable.");
258 /* read section list and create a hash table */
259 section = fopen("package/section.lst", "r");
260 if (section == NULL)
261 fatal_error("section listfile is missing");
263 sectionmap = strmap_new(HASHSZ);
264 while (fgets(tbuf, MAXPATH, section) != NULL) {
265 key = strtok(tbuf, "\t");
266 value = strtok(NULL, "\t");
267 strmap_put(sectionmap, key, value);
269 fclose(section);
271 if (mkdir("package/pkgconfigs.d", S_IRWXU) > 0)
272 fatal_error("creation of package/pkgconfigs.d failed.");
273 if (mkdir("package/pkglist.d", S_IRWXU) > 0)
274 fatal_error("creation of package/pkglist.d failed.");
276 /* read Makefile's for all packages */
277 pkgdir = opendir("package");
278 while ((pkgdirp = readdir(pkgdir)) != NULL) {
279 /* skip dotfiles */
280 if (strncmp(pkgdirp->d_name, ".", 1) > 0) {
281 if (snprintf(path, MAXPATH, "package/%s/Makefile", pkgdirp->d_name) < 0)
282 fatal_error("can not create path variable.");
283 pkg = fopen(path, "r");
284 if (pkg == NULL)
285 continue;
287 /* skip manually maintained packages */
288 if (snprintf(path, MAXPATH, "package/%s/Config.in.manual", pkgdirp->d_name) < 0)
289 fatal_error("can not create path variable.");
290 if (!access(path, F_OK)) {
291 while (fgets(buf, MAXPATH, pkg) != NULL) {
292 if ((parse_var(buf, "PKG_SECTION", NULL, &pkg_section)) == 0)
293 continue;
296 memset(hvalue, 0 , MAXVALUE);
297 result = strmap_get(sectionmap, pkg_section, hvalue, sizeof(hvalue));
298 if (result == 1) {
299 if (snprintf(spath, MAXPATH, "package/pkglist.d/sectionlst.%d", hash_str(hvalue)) < 0)
300 fatal_error("can not create path variable.");
301 section = fopen(spath, "a");
302 if (section != NULL) {
303 fprintf(section, "%s@\n", pkgdirp->d_name);
304 fclose(section);
306 } else
307 fatal_error("Can not find section description for package.");
309 fclose(pkg);
310 continue;
313 nobinpkgs = 0;
315 /* create output directories */
316 if (snprintf(dir, MAXPATH, "package/pkgconfigs.d/%s", pkgdirp->d_name) < 0)
317 fatal_error("can not create dir variable.");
318 if (mkdir(dir, S_IRWXU) > 0)
319 fatal_error("can not create directory.");
321 /* allocate memory */
322 hkey = malloc(MAXVAR);
323 memset(hkey, 0, MAXVAR);
324 memset(variable, 0, 2*MAXVAR);
326 pkgmap = strmap_new(HASHSZ);
328 /* parse package Makefile */
329 while (fgets(buf, MAXPATH, pkg) != NULL) {
330 /* just read variables prefixed with PKG */
331 if (strncmp(buf, "PKG", 3) == 0) {
332 if ((parse_var(buf, "PKG_NAME", NULL, &pkg_name)) == 0)
333 continue;
334 if (pkg_name != NULL)
335 pkg_name_u = toupperstr(pkg_name);
336 else
337 pkg_name_u = toupperstr(pkgdirp->d_name);
339 snprintf(variable, MAXVAR, "PKG_CFLINE_%s", pkg_name_u);
340 if ((parse_var(buf, variable, pkg_cfline, &pkg_cfline)) == 0)
341 continue;
342 snprintf(variable, MAXVAR, "PKG_DFLT_%s", pkg_name_u);
343 if ((parse_var(buf, variable, NULL, &pkg_dflt)) == 0)
344 continue;
345 if ((parse_var(buf, "PKG_HOST_DEPENDS", NULL, &pkg_host_depends)) == 0)
346 continue;
347 if ((parse_var(buf, "PKG_ARCH_DEPENDS", NULL, &pkg_arch_depends)) == 0)
348 continue;
349 if ((parse_var(buf, "PKG_DESCR", NULL, &pkg_descr)) == 0)
350 continue;
351 if ((parse_var(buf, "PKG_SECTION", NULL, &pkg_section)) == 0)
352 continue;
353 if ((parse_var(buf, "PKG_URL", NULL, &pkg_url)) == 0)
354 continue;
355 if ((parse_var(buf, "PKG_CXX", NULL, &pkg_cxx)) == 0)
356 continue;
357 if ((parse_var(buf, "PKG_NEED_CXX", NULL, &pkg_need_cxx)) == 0)
358 continue;
359 if ((parse_var(buf, "PKG_NEED_JAVA", NULL, &pkg_need_java)) == 0)
360 continue;
361 if ((parse_var(buf, "PKG_MULTI", NULL, &pkg_multi)) == 0)
362 continue;
363 if ((parse_var(buf, "PKG_DEPENDS", pkg_depends, &pkg_depends)) == 0)
364 continue;
365 if ((parse_var(buf, "PKG_FLAVOURS", pkg_flavours, &pkg_flavours)) == 0)
366 continue;
367 if ((parse_var_hash(buf, "PKGFD_", pkgmap)) == 0)
368 continue;
369 if ((parse_var_hash(buf, "PKGFS_", pkgmap)) == 0)
370 continue;
371 if ((parse_var(buf, "PKG_CHOICES", pkg_choices, &pkg_choices)) == 0)
372 continue;
373 if ((parse_var_hash(buf, "PKGCD_", pkgmap)) == 0)
374 continue;
375 if ((parse_var_hash(buf, "PKGCS_", pkgmap)) == 0)
376 continue;
377 if ((parse_var(buf, "PKG_SUBPKGS", pkg_subpkgs, &pkg_subpkgs)) == 0)
378 continue;
379 if ((parse_var_hash(buf, "PKGSD_", pkgmap)) == 0)
380 continue;
381 if ((parse_var_hash(buf, "PKGSS_", pkgmap)) == 0)
382 continue;
383 if ((parse_var_hash(buf, "PKGSC_", pkgmap)) == 0)
384 continue;
388 /* end of package Makefile parsing */
389 if (fclose(pkg) != 0)
390 perror("Failed to close file stream for Makefile");
393 if (pkg_name != NULL)
394 fprintf(stderr, "Package name is %s\n", pkg_name);
395 if (pkg_section != NULL)
396 fprintf(stderr, "Package section is %s\n", pkg_section);
397 if (pkg_descr != NULL)
398 fprintf(stderr, "Package description is %s\n", pkg_descr);
399 if (pkg_depends != NULL)
400 fprintf(stderr, "Package dependencies are %s\n", pkg_depends);
401 if (pkg_subpkgs != NULL)
402 fprintf(stderr, "Package subpackages are %s\n", pkg_subpkgs);
403 if (pkg_flavours != NULL)
404 fprintf(stderr, "Package flavours are %s\n", pkg_flavours);
405 if (pkg_choices != NULL)
406 fprintf(stderr, "Package choices are %s\n", pkg_choices);
407 if (pkg_url != NULL)
408 fprintf(stderr, "Package homepage is %s\n", pkg_url);
409 if (pkg_cfline != NULL)
410 fprintf(stderr, "Package cfline is %s\n", pkg_cfline);
411 if (pkg_multi != NULL)
412 fprintf(stderr, "Package multi is %s\n", pkg_multi);
414 strmap_enum(pkgmap, iter_debug, NULL);
417 /* generate master source Config.in file */
418 if (snprintf(path, MAXPATH, "package/pkgconfigs.d/%s/Config.in", pkgdirp->d_name) < 0)
419 fatal_error("path variable creation failed.");
420 fprintf(menuglobal, "source \"%s\"\n", path);
421 /* recreating file is faster than truncating with w+ */
422 unlink(path);
423 cfg = fopen(path, "w");
424 if (cfg == NULL)
425 continue;
427 pkgs = NULL;
428 if (pkg_subpkgs != NULL)
429 pkgs = strdup(pkg_subpkgs);
431 fprintf(cfg, "config ADK_COMPILE_%s\n", toupperstr(pkgdirp->d_name));
432 fprintf(cfg, "\ttristate\n");
433 if (nobinpkgs == 0) {
434 fprintf(cfg, "\tdepends on ");
435 if (pkgs != NULL) {
436 if (pkg_multi != NULL)
437 if (strncmp(pkg_multi, "1", 1) == 0)
438 fprintf(cfg, "ADK_HAVE_DOT_CONFIG || ");
439 token = strtok(pkgs, " ");
440 fprintf(cfg, "ADK_PACKAGE_%s", token);
441 token = strtok(NULL, " ");
442 while (token != NULL) {
443 fprintf(cfg, " || ADK_PACKAGE_%s", token);
444 token = strtok(NULL, " ");
446 fprintf(cfg, "\n");
447 } else {
448 fprintf(cfg, "ADK_PACKAGE_%s\n", toupperstr(pkgdirp->d_name));
451 fprintf(cfg, "\tdefault n\n");
452 fclose(cfg);
453 free(pkgs);
455 /* skip packages without binary package output */
456 if (nobinpkgs == 1)
457 continue;
459 /* generate binary package specific Config.in files */
460 if (pkg_subpkgs != NULL)
461 packages = tolowerstr(pkg_subpkgs);
462 else
463 packages = strdup(pkgdirp->d_name);
465 token = strtok_r(packages, " ", &p_ptr);
466 while (token != NULL) {
467 strncat(hkey, "PKGSC_", 6);
468 strncat(hkey, toupperstr(token), strlen(token));
469 memset(hvalue, 0 , MAXVALUE);
470 result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
471 memset(hkey, 0 , MAXVAR);
472 if (result == 1)
473 pkg_section = strdup(hvalue);
475 strncat(hkey, "PKGSD_", 6);
476 strncat(hkey, toupperstr(token), strlen(token));
477 memset(hvalue, 0 , MAXVALUE);
478 result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
479 memset(hkey, 0 , MAXVAR);
480 if (result == 1)
481 pkg_descr = strdup(hvalue);
483 pseudo_name = malloc(MAXLINE);
484 memset(pseudo_name, 0, MAXLINE);
485 strncat(pseudo_name, token, strlen(token));
486 while (strlen(pseudo_name) < 20)
487 strncat(pseudo_name, ".", 1);
489 if (snprintf(path, MAXPATH, "package/pkgconfigs.d/%s/Config.in.%s", pkgdirp->d_name, token) < 0)
490 fatal_error("failed to create path variable.");
492 /* create temporary section files */
493 memset(hvalue, 0 , MAXVALUE);
494 result = strmap_get(sectionmap, pkg_section, hvalue, sizeof(hvalue));
495 if (result == 1) {
496 if (snprintf(spath, MAXPATH, "package/pkglist.d/sectionlst.%d", hash_str(hvalue)) < 0)
497 fatal_error("failed to create path variable.");
498 section = fopen(spath, "a");
499 if (section != NULL) {
500 fprintf(section, "%s |%s\n", token, pkgdirp->d_name);
501 fclose(section);
503 } else
504 fatal_error("Can not find section description for package");
506 unlink(path);
507 cfg = fopen(path, "w");
508 if (cfg == NULL)
509 perror("Can not open Config.in file");
511 fprintf(cfg, "config ADK_PACKAGE_%s\n", toupperstr(token));
512 fprintf(cfg, "\tprompt \"%s... %s\"\n", pseudo_name, pkg_descr);
513 fprintf(cfg, "\ttristate\n");
514 if (pkg_multi != NULL)
515 if (strncmp(pkg_multi, "1", 1) == 0)
516 if (strncmp(toupperstr(token), toupperstr(pkgdirp->d_name), strlen(token)) != 0)
517 fprintf(cfg, "\tdepends on ADK_PACKAGE_%s\n", toupperstr(pkgdirp->d_name));
519 free(pseudo_name);
521 /* print custom cf line */
522 if (pkg_cfline != NULL) {
523 cftoken = strtok_r(pkg_cfline, "@", &saveptr);
524 while (cftoken != NULL) {
525 fprintf(cfg, "\t%s\n", cftoken);
526 cftoken = strtok_r(NULL, "@", &saveptr);
530 /* add sub package dependencies */
531 strncat(hkey, "PKGSS_", 6);
532 strncat(hkey, toupperstr(token), strlen(token));
533 memset(hvalue, 0, MAXVALUE);
534 result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
535 if (result == 1) {
536 val = strtok_r(hvalue, " ", &saveptr);
537 while (val != NULL) {
538 fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(val));
539 val = strtok_r(NULL, " ", &saveptr);
542 memset(hkey, 0, MAXVAR);
544 /* create package host dependency information */
545 if (pkg_host_depends != NULL) {
546 token = strtok(pkg_host_depends, " ");
547 fprintf(cfg, "\tdepends on ");
548 sp = "";
549 while (token != NULL) {
550 if(strncmp(token, "!", 1) == 0) {
551 fprintf(cfg, "%s!ADK_HOST%s", sp, toupperstr(token));
552 sp = " && ";
553 } else {
554 fprintf(cfg, "%sADK_HOST_%s", sp, toupperstr(token));
555 sp = " || ";
557 token = strtok(NULL, " ");
559 fprintf(cfg, "\n");
562 /* create package target architecture dependency information */
563 if (pkg_arch_depends != NULL) {
564 token = strtok(pkg_arch_depends, " ");
565 fprintf(cfg, "\tdepends on ");
566 sp = "";
567 while (token != NULL) {
568 if(strncmp(token, "!", 1) == 0) {
569 fprintf(cfg, "%s!ADK_LINUX%s", sp, toupperstr(token));
570 sp = " && ";
571 } else {
572 fprintf(cfg, "%sADK_LINUX_%s", sp, toupperstr(token));
573 sp = " || ";
575 token = strtok(NULL, " ");
577 fprintf(cfg, "\n");
580 /* create package dependency information */
581 if (pkg_depends != NULL) {
582 token = strtok(pkg_depends, " ");
583 while (token != NULL) {
584 if (strncmp(token, "kmod", 4) == 0)
585 fprintf(cfg, "\tselect ADK_KPACKAGE_%s\n", toupperstr(token));
586 else
587 fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(token));
588 token = strtok(NULL, " ");
590 free(pkg_depends);
591 pkg_depends = NULL;
594 if (pkg_need_cxx != NULL) {
595 fprintf(cfg, "\tdepends on ADK_TOOLCHAIN_GCC_CXX");
597 if (pkg_need_java != NULL) {
598 fprintf(cfg, "\tdepends on ADK_TOOLCHAIN_GCC_JAVA");
601 fprintf(cfg, "\tselect ADK_COMPILE_%s\n", toupperstr(pkgdirp->d_name));
603 if (pkg_dflt != NULL) {
604 fprintf(cfg, "\tdefault %s\n", pkg_dflt);
605 pkg_dflt = NULL;
606 } else {
607 fprintf(cfg, "\tdefault n\n");
610 fprintf(cfg, "\thelp\n");
611 fprintf(cfg, "\t %s\n\n", pkg_descr);
612 if (pkg_url != NULL)
613 fprintf(cfg, "\t WWW: %s\n", pkg_url);
615 /* handle special C++ packages */
616 if (pkg_cxx != NULL) {
617 fprintf(cfg, "\nchoice\n");
618 fprintf(cfg, "prompt \"C++ library to use\"\n");
619 fprintf(cfg, "depends on ADK_COMPILE_%s\n\n", toupperstr(pkgdirp->d_name));
620 fprintf(cfg, "default ADK_COMPILE_%s_WITH_STDCXX if ADK_TARGET_LIB_GLIBC || ADK_TARGET_LIB_EGLIBC\n", pkg_cxx);
621 fprintf(cfg, "default ADK_COMPILE_%s_WITH_UCLIBCXX if ADK_TARGET_LIB_UCLIBC\n\n", pkg_cxx);
622 fprintf(cfg, "config ADK_COMPILE_%s_WITH_STDCXX\n", pkg_cxx);
623 fprintf(cfg, "\tbool \"GNU C++ library\"\n");
624 fprintf(cfg, "\tselect ADK_PACKAGE_LIBSTDCXX\n\n");
625 fprintf(cfg, "config ADK_COMPILE_%s_WITH_UCLIBCXX\n", pkg_cxx);
626 fprintf(cfg, "\tbool \"uClibc++ library\"\n");
627 fprintf(cfg, "\tselect ADK_PACKAGE_UCLIBCXX\n\n");
628 fprintf(cfg, "endchoice\n");
629 free(pkg_cxx);
630 pkg_cxx = NULL;
633 /* package flavours */
634 if (pkg_flavours != NULL) {
635 token = strtok(pkg_flavours, " ");
636 while (token != NULL) {
637 fprintf(cfg, "\nconfig ADK_PACKAGE_%s_%s\n", toupperstr(pkgdirp->d_name),
638 toupperstr(token));
639 fprintf(cfg, "\tbool ");
640 strncat(hkey, "PKGFD_", 6);
641 strncat(hkey, token, strlen(token));
642 memset(hvalue, 0 , MAXVALUE);
643 strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
644 memset(hkey, 0 , MAXVAR);
645 pkg_fd = strdup(hvalue);
647 fprintf(cfg, "\"%s\"\n", pkg_fd);
648 fprintf(cfg, "\tdefault n\n");
649 fprintf(cfg, "\tdepends on ADK_PACKAGE_%s\n", toupperstr(pkgdirp->d_name));
650 strncat(hkey, "PKGFS_", 6);
651 strncat(hkey, token, strlen(token));
653 result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
654 if (result == 1) {
655 val = strtok_r(hvalue, " ", &saveptr);
656 while (val != NULL) {
657 fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(val));
658 val = strtok_r(NULL, " ", &saveptr);
661 memset(hkey, 0, MAXVAR);
662 fprintf(cfg, "\thelp\n");
663 fprintf(cfg, "\t %s\n", pkg_fd);
664 token = strtok(NULL, " ");
666 free(pkg_flavours);
667 pkg_flavours = NULL;
670 /* package choices */
671 if (pkg_choices != NULL) {
672 fprintf(cfg, "\nchoice\n");
673 fprintf(cfg, "prompt \"Package flavour choice\"\n");
674 fprintf(cfg, "depends on ADK_COMPILE_%s\n\n", toupperstr(pkgdirp->d_name));
675 token = strtok(pkg_choices, " ");
676 while (token != NULL) {
677 fprintf(cfg, "config ADK_PACKAGE_%s_%s\n", toupperstr(pkgdirp->d_name),
678 toupperstr(token));
680 fprintf(cfg, "\tbool ");
681 strncat(hkey, "PKGCD_", 6);
682 strncat(hkey, token, strlen(token));
683 memset(hvalue, 0 , MAXVALUE);
684 strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
685 memset(hkey, 0 , MAXVAR);
686 fprintf(cfg, "\"%s\"\n", hvalue);
688 strncat(hkey, "PKGCS_", 6);
689 strncat(hkey, token, strlen(token));
690 memset(hvalue, 0, MAXVALUE);
691 result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
692 if (result == 1) {
693 val = strtok_r(hvalue, " ", &saveptr);
694 while (val != NULL) {
695 fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(val));
696 val = strtok_r(NULL, " ", &saveptr);
699 memset(hkey, 0, MAXVAR);
700 token = strtok(NULL, " ");
702 fprintf(cfg, "\nendchoice\n");
703 free(pkg_choices);
704 pkg_choices = NULL;
706 /* close file descriptor, parse next package */
707 fclose(cfg);
708 token = strtok_r(NULL, " ", &p_ptr);
711 /* end of package output generation */
712 free(packages);
713 packages = NULL;
715 /* reset flags, free memory */
716 free(pkg_name);
717 free(pkg_descr);
718 free(pkg_section);
719 free(pkg_url);
720 free(pkg_depends);
721 free(pkg_flavours);
722 free(pkg_choices);
723 free(pkg_subpkgs);
724 free(pkg_arch_depends);
725 free(pkg_host_depends);
726 free(pkg_cxx);
727 free(pkg_need_cxx);
728 free(pkg_need_java);
729 free(pkg_dflt);
730 free(pkg_cfline);
731 free(pkg_multi);
732 pkg_name = NULL;
733 pkg_descr = NULL;
734 pkg_section = NULL;
735 pkg_url = NULL;
736 pkg_depends = NULL;
737 pkg_flavours = NULL;
738 pkg_choices = NULL;
739 pkg_subpkgs = NULL;
740 pkg_arch_depends = NULL;
741 pkg_host_depends = NULL;
742 pkg_cxx = NULL;
743 pkg_dflt = NULL;
744 pkg_cfline = NULL;
745 pkg_multi = NULL;
747 strmap_delete(pkgmap);
748 nobinpkgs = 0;
749 free(hkey);
754 /* create Config.in.auto */
755 strmap_enum(sectionmap, iter, NULL);
757 strmap_delete(sectionmap);
758 fclose(menuglobal);
759 closedir(pkgdir);
761 /* remove temporary section files */
762 pkglistdir = opendir("package/pkglist.d");
763 while ((pkgdirp = readdir(pkglistdir)) != NULL) {
764 if (strncmp(pkgdirp->d_name, "sectionlst.", 11) == 0) {
765 if (snprintf(path, MAXPATH, "package/pkglist.d/%s", pkgdirp->d_name) < 0)
766 fatal_error("creating path variable failed.");
767 if (unlink(path) < 0)
768 fatal_error("removing file failed.");
771 closedir(pkglistdir);
772 return(0);