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/>.
28 #include <sys/types.h>
40 #define fatal_error(...) { \
41 fprintf(stderr, "Fatal error. "); \
42 fprintf(stderr, __VA_ARGS__); \
43 fprintf(stderr, "\n"); \
47 static int parse_var_hash(char *buf
, const char *varname
, StrMap
*strmap
) {
49 char *key
, *value
, *string
;
51 string
= strstr(buf
, varname
);
53 string
[strlen(string
)-1] = '\0';
54 key
= strtok(string
, ":=");
55 value
= strtok(NULL
, "=\t");
57 strmap_put(strmap
, key
, value
);
63 static int parse_var(char *buf
, const char *varname
, char *pvalue
, char **result
) {
66 char *key
, *value
, *string
;
69 if ((pkg_var
= malloc(MAXLINE
)) != NULL
)
70 memset(pkg_var
, 0, MAXLINE
);
72 perror("Can not allocate memory");
76 if (snprintf(pkg_str
, MAXVAR
, "%s:=", varname
) < 0)
77 perror("can not create path variable.");
78 string
= strstr(buf
, pkg_str
);
80 string
[strlen(string
)-1] = '\0';
81 key
= strtok(string
, ":=");
82 value
= strtok(NULL
, "=\t");
84 strncat(pkg_var
, value
, strlen(value
));
85 *result
= strdup(pkg_var
);
93 if (snprintf(pkg_str
, MAXVAR
, "%s+=", varname
) < 0)
94 perror("can not create path variable.");
95 string
= strstr(buf
, pkg_str
);
97 string
[strlen(string
)-1] = '\0';
98 key
= strtok(string
, "+=");
99 value
= strtok(NULL
, "=\t");
101 strncat(pkg_var
, pvalue
, strlen(pvalue
));
102 strncat(pkg_var
, " ", 1);
104 strncat(pkg_var
, value
, strlen(value
));
105 *result
= strdup(pkg_var
);
115 static void iter_debug(const char *key, const char *value, const void *obj) {
116 fprintf(stderr, "HASHMAP key: %s value: %s\n", key, value);
120 static int hash_str(char *string
) {
126 for (i
=0; i
<(int)strlen(string
); i
++) {
132 static void iter(const char *key
, const char *value
, const void *obj
) {
134 FILE *config
, *section
;
136 char *valuestr
, *pkg
, *subpkg
;
138 char infile
[MAXPATH
];
139 char outfile
[MAXPATH
];
141 valuestr
= strdup(value
);
142 config
= fopen("package/Config.in.auto", "a");
144 fatal_error("Can not open file package/Config.in.auto");
146 hash
= hash_str(valuestr
);
147 snprintf(infile
, MAXPATH
, "package/pkglist.d/sectionlst.%d", hash
);
148 snprintf(outfile
, MAXPATH
, "package/pkglist.d/sectionlst.%d.sorted", hash
);
150 if (access(infile
, F_OK
) == 0) {
151 valuestr
[strlen(valuestr
)-1] = '\0';
152 fprintf(config
, "menu \"%s\"\n", valuestr
);
153 sortfile(infile
, outfile
);
154 /* avoid duplicate section entries */
156 section
= fopen(outfile
, "r");
157 while (fgets(buf
, MAXPATH
, section
) != NULL
) {
158 buf
[strlen(buf
)-1] = '\0';
159 if (buf
[strlen(buf
)-1] == '@') {
160 buf
[strlen(buf
)-1] = '\0';
161 fprintf(config
, "source \"package/%s/Config.in.manual\"\n", buf
);
163 subpkg
= strtok(buf
, "|");
164 subpkg
[strlen(subpkg
)-1] = '\0';
165 pkg
= strtok(NULL
, "|");
166 fprintf(config
, "source \"package/pkgconfigs.d/%s/Config.in.%s\"\n", pkg
, subpkg
);
169 fprintf(config
, "endmenu\n\n");
175 static char *tolowerstr(char *string
) {
180 /* transform to lowercase variable name */
181 str
= strdup(string
);
182 for (i
=0; i
<(int)strlen(str
); i
++) {
185 str
[i
] = tolower(str
[i
]);
190 static char *toupperstr(char *string
) {
195 /* transform to uppercase variable name */
196 str
= strdup(string
);
197 for (i
=0; i
<(int)strlen(str
); i
++) {
202 /* remove negation here, useful for package host depends */
205 str
[i
] = toupper(str
[i
]);
213 DIR *pkgdir
, *pkglistdir
;
214 struct dirent
*pkgdirp
;
215 FILE *pkg
, *cfg
, *menuglobal
, *section
;
216 char hvalue
[MAXVALUE
];
222 char variable
[2*MAXVAR
];
223 char *key
, *value
, *token
, *cftoken
, *sp
, *hkey
, *val
, *pkg_fd
;
224 char *pkg_name
, *pkg_depends
, *pkg_section
, *pkg_descr
, *pkg_url
;
225 char *pkg_cxx
, *pkg_subpkgs
, *pkg_cfline
, *pkg_dflt
, *pkg_multi
;
226 char *pkg_need_cxx
, *pkg_need_java
;
227 char *pkg_host_depends
, *pkg_arch_depends
, *pkg_flavours
, *pkg_choices
, *pseudo_name
;
228 char *packages
, *pkg_name_u
, *pkgs
;
229 char *saveptr
, *p_ptr
, *s_ptr
;
231 StrMap
*pkgmap
, *sectionmap
;
241 pkg_arch_depends
= NULL
;
242 pkg_host_depends
= NULL
;
248 pkg_need_java
= NULL
;
253 unlink("package/Config.in.auto");
254 /* open global sectionfile */
255 menuglobal
= fopen("package/Config.in.auto.global", "w");
256 if (menuglobal
== NULL
)
257 fatal_error("global section file not writable.");
259 /* read section list and create a hash table */
260 section
= fopen("package/section.lst", "r");
262 fatal_error("section listfile is missing");
264 sectionmap
= strmap_new(HASHSZ
);
265 while (fgets(tbuf
, MAXPATH
, section
) != NULL
) {
266 key
= strtok(tbuf
, "\t");
267 value
= strtok(NULL
, "\t");
268 strmap_put(sectionmap
, key
, value
);
272 if (mkdir("package/pkgconfigs.d", S_IRWXU
) > 0)
273 fatal_error("creation of package/pkgconfigs.d failed.");
274 if (mkdir("package/pkglist.d", S_IRWXU
) > 0)
275 fatal_error("creation of package/pkglist.d failed.");
277 /* read Makefile's for all packages */
278 pkgdir
= opendir("package");
279 while ((pkgdirp
= readdir(pkgdir
)) != NULL
) {
281 if (strncmp(pkgdirp
->d_name
, ".", 1) > 0) {
282 if (snprintf(path
, MAXPATH
, "package/%s/Makefile", pkgdirp
->d_name
) < 0)
283 fatal_error("can not create path variable.");
284 pkg
= fopen(path
, "r");
288 /* skip manually maintained packages */
289 if (snprintf(path
, MAXPATH
, "package/%s/Config.in.manual", pkgdirp
->d_name
) < 0)
290 fatal_error("can not create path variable.");
291 if (!access(path
, F_OK
)) {
292 while (fgets(buf
, MAXPATH
, pkg
) != NULL
) {
293 if ((parse_var(buf
, "PKG_SECTION", NULL
, &pkg_section
)) == 0)
297 memset(hvalue
, 0 , MAXVALUE
);
298 result
= strmap_get(sectionmap
, pkg_section
, hvalue
, sizeof(hvalue
));
300 if (snprintf(spath
, MAXPATH
, "package/pkglist.d/sectionlst.%d", hash_str(hvalue
)) < 0)
301 fatal_error("can not create path variable.");
302 section
= fopen(spath
, "a");
303 if (section
!= NULL
) {
304 fprintf(section
, "%s@\n", pkgdirp
->d_name
);
308 fatal_error("Can not find section description for package %s.",
317 /* create output directories */
318 if (snprintf(dir
, MAXPATH
, "package/pkgconfigs.d/%s", pkgdirp
->d_name
) < 0)
319 fatal_error("can not create dir variable.");
320 if (mkdir(dir
, S_IRWXU
) > 0)
321 fatal_error("can not create directory.");
323 /* allocate memory */
324 hkey
= malloc(MAXVAR
);
325 memset(hkey
, 0, MAXVAR
);
326 memset(variable
, 0, 2*MAXVAR
);
328 pkgmap
= strmap_new(HASHSZ
);
330 /* parse package Makefile */
331 while (fgets(buf
, MAXPATH
, pkg
) != NULL
) {
332 /* just read variables prefixed with PKG */
333 if (strncmp(buf
, "PKG", 3) == 0) {
334 if ((parse_var(buf
, "PKG_NAME", NULL
, &pkg_name
)) == 0)
336 if (pkg_name
!= NULL
)
337 pkg_name_u
= toupperstr(pkg_name
);
339 pkg_name_u
= toupperstr(pkgdirp
->d_name
);
341 snprintf(variable
, MAXVAR
, "PKG_CFLINE_%s", pkg_name_u
);
342 if ((parse_var(buf
, variable
, pkg_cfline
, &pkg_cfline
)) == 0)
344 snprintf(variable
, MAXVAR
, "PKG_DFLT_%s", pkg_name_u
);
345 if ((parse_var(buf
, variable
, NULL
, &pkg_dflt
)) == 0)
347 if ((parse_var(buf
, "PKG_HOST_DEPENDS", NULL
, &pkg_host_depends
)) == 0)
349 if ((parse_var(buf
, "PKG_ARCH_DEPENDS", NULL
, &pkg_arch_depends
)) == 0)
351 if ((parse_var(buf
, "PKG_DESCR", NULL
, &pkg_descr
)) == 0)
353 if ((parse_var(buf
, "PKG_SECTION", NULL
, &pkg_section
)) == 0)
355 if ((parse_var(buf
, "PKG_URL", NULL
, &pkg_url
)) == 0)
357 if ((parse_var(buf
, "PKG_CXX", NULL
, &pkg_cxx
)) == 0)
359 if ((parse_var(buf
, "PKG_NEED_CXX", NULL
, &pkg_need_cxx
)) == 0)
361 if ((parse_var(buf
, "PKG_NEED_JAVA", NULL
, &pkg_need_java
)) == 0)
363 if ((parse_var(buf
, "PKG_MULTI", NULL
, &pkg_multi
)) == 0)
365 if ((parse_var(buf
, "PKG_DEPENDS", pkg_depends
, &pkg_depends
)) == 0)
367 if ((parse_var(buf
, "PKG_FLAVOURS", pkg_flavours
, &pkg_flavours
)) == 0)
369 if ((parse_var_hash(buf
, "PKGFD_", pkgmap
)) == 0)
371 if ((parse_var_hash(buf
, "PKGFS_", pkgmap
)) == 0)
373 if ((parse_var(buf
, "PKG_CHOICES", pkg_choices
, &pkg_choices
)) == 0)
375 if ((parse_var_hash(buf
, "PKGCD_", pkgmap
)) == 0)
377 if ((parse_var_hash(buf
, "PKGCS_", pkgmap
)) == 0)
379 if ((parse_var(buf
, "PKG_SUBPKGS", pkg_subpkgs
, &pkg_subpkgs
)) == 0)
381 if ((parse_var_hash(buf
, "PKGSD_", pkgmap
)) == 0)
383 if ((parse_var_hash(buf
, "PKGSS_", pkgmap
)) == 0)
385 if ((parse_var_hash(buf
, "PKGSC_", pkgmap
)) == 0)
390 /* end of package Makefile parsing */
391 if (fclose(pkg
) != 0)
392 perror("Failed to close file stream for Makefile");
395 if (pkg_name != NULL)
396 fprintf(stderr, "Package name is %s\n", pkg_name);
397 if (pkg_section != NULL)
398 fprintf(stderr, "Package section is %s\n", pkg_section);
399 if (pkg_descr != NULL)
400 fprintf(stderr, "Package description is %s\n", pkg_descr);
401 if (pkg_depends != NULL)
402 fprintf(stderr, "Package dependencies are %s\n", pkg_depends);
403 if (pkg_subpkgs != NULL)
404 fprintf(stderr, "Package subpackages are %s\n", pkg_subpkgs);
405 if (pkg_flavours != NULL)
406 fprintf(stderr, "Package flavours are %s\n", pkg_flavours);
407 if (pkg_choices != NULL)
408 fprintf(stderr, "Package choices are %s\n", pkg_choices);
410 fprintf(stderr, "Package homepage is %s\n", pkg_url);
411 if (pkg_cfline != NULL)
412 fprintf(stderr, "Package cfline is %s\n", pkg_cfline);
413 if (pkg_multi != NULL)
414 fprintf(stderr, "Package multi is %s\n", pkg_multi);
416 strmap_enum(pkgmap, iter_debug, NULL);
419 /* generate master source Config.in file */
420 if (snprintf(path
, MAXPATH
, "package/pkgconfigs.d/%s/Config.in", pkgdirp
->d_name
) < 0)
421 fatal_error("path variable creation failed.");
422 fprintf(menuglobal
, "source \"%s\"\n", path
);
423 /* recreating file is faster than truncating with w+ */
425 cfg
= fopen(path
, "w");
430 if (pkg_subpkgs
!= NULL
)
431 pkgs
= strdup(pkg_subpkgs
);
433 fprintf(cfg
, "config ADK_COMPILE_%s\n", toupperstr(pkgdirp
->d_name
));
434 fprintf(cfg
, "\ttristate\n");
435 if (nobinpkgs
== 0) {
436 fprintf(cfg
, "\tdepends on ");
438 if (pkg_multi
!= NULL
)
439 if (strncmp(pkg_multi
, "1", 1) == 0)
440 fprintf(cfg
, "ADK_HAVE_DOT_CONFIG || ");
441 token
= strtok(pkgs
, " ");
442 fprintf(cfg
, "ADK_PACKAGE_%s", token
);
443 token
= strtok(NULL
, " ");
444 while (token
!= NULL
) {
445 fprintf(cfg
, " || ADK_PACKAGE_%s", token
);
446 token
= strtok(NULL
, " ");
450 fprintf(cfg
, "ADK_PACKAGE_%s\n", toupperstr(pkgdirp
->d_name
));
453 fprintf(cfg
, "\tdefault n\n");
457 /* skip packages without binary package output */
461 /* generate binary package specific Config.in files */
462 if (pkg_subpkgs
!= NULL
)
463 packages
= tolowerstr(pkg_subpkgs
);
465 packages
= strdup(pkgdirp
->d_name
);
467 token
= strtok_r(packages
, " ", &p_ptr
);
468 while (token
!= NULL
) {
469 strncat(hkey
, "PKGSC_", 6);
470 strncat(hkey
, toupperstr(token
), strlen(token
));
471 memset(hvalue
, 0 , MAXVALUE
);
472 result
= strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
473 memset(hkey
, 0 , MAXVAR
);
475 pkg_section
= strdup(hvalue
);
477 strncat(hkey
, "PKGSD_", 6);
478 strncat(hkey
, toupperstr(token
), strlen(token
));
479 memset(hvalue
, 0 , MAXVALUE
);
480 result
= strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
481 memset(hkey
, 0 , MAXVAR
);
483 pkg_descr
= strdup(hvalue
);
485 pseudo_name
= malloc(MAXLINE
);
486 memset(pseudo_name
, 0, MAXLINE
);
487 strncat(pseudo_name
, token
, strlen(token
));
488 while (strlen(pseudo_name
) < 20)
489 strncat(pseudo_name
, ".", 1);
491 if (snprintf(path
, MAXPATH
, "package/pkgconfigs.d/%s/Config.in.%s", pkgdirp
->d_name
, token
) < 0)
492 fatal_error("failed to create path variable.");
494 /* create temporary section files */
495 memset(hvalue
, 0 , MAXVALUE
);
496 result
= strmap_get(sectionmap
, pkg_section
, hvalue
, sizeof(hvalue
));
498 if (snprintf(spath
, MAXPATH
, "package/pkglist.d/sectionlst.%d", hash_str(hvalue
)) < 0)
499 fatal_error("failed to create path variable.");
500 section
= fopen(spath
, "a");
501 if (section
!= NULL
) {
502 fprintf(section
, "%s |%s\n", token
, pkgdirp
->d_name
);
506 fatal_error("Can not find section description for package %s.", pkgdirp
->d_name
);
509 cfg
= fopen(path
, "w");
511 perror("Can not open Config.in file");
513 if (pkg_need_cxx
!= NULL
) {
514 fprintf(cfg
, "comment \"%s... %s (disabled, c++ missing)\"\n", token
, pkg_descr
);
515 fprintf(cfg
, "depends on !ADK_TOOLCHAIN_GCC_CXX\n\n");
517 fprintf(cfg
, "config ADK_PACKAGE_%s\n", toupperstr(token
));
518 fprintf(cfg
, "\tprompt \"%s. %s\"\n", pseudo_name
, pkg_descr
);
519 fprintf(cfg
, "\ttristate\n");
520 if (pkg_multi
!= NULL
)
521 if (strncmp(pkg_multi
, "1", 1) == 0)
522 if (strncmp(toupperstr(token
), toupperstr(pkgdirp
->d_name
), strlen(token
)) != 0)
523 fprintf(cfg
, "\tdepends on ADK_PACKAGE_%s\n", toupperstr(pkgdirp
->d_name
));
527 /* print custom cf line */
528 if (pkg_cfline
!= NULL
) {
529 cftoken
= strtok_r(pkg_cfline
, "@", &saveptr
);
530 while (cftoken
!= NULL
) {
531 fprintf(cfg
, "\t%s\n", cftoken
);
532 cftoken
= strtok_r(NULL
, "@", &saveptr
);
536 /* add sub package dependencies */
537 strncat(hkey
, "PKGSS_", 6);
538 strncat(hkey
, toupperstr(token
), strlen(token
));
539 memset(hvalue
, 0, MAXVALUE
);
540 result
= strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
542 val
= strtok_r(hvalue
, " ", &saveptr
);
543 while (val
!= NULL
) {
544 fprintf(cfg
, "\tselect ADK_PACKAGE_%s\n", toupperstr(val
));
545 val
= strtok_r(NULL
, " ", &saveptr
);
548 memset(hkey
, 0, MAXVAR
);
550 /* create package host dependency information */
551 if (pkg_host_depends
!= NULL
) {
552 token
= strtok(pkg_host_depends
, " ");
553 fprintf(cfg
, "\tdepends on ");
555 while (token
!= NULL
) {
556 if(strncmp(token
, "!", 1) == 0) {
557 fprintf(cfg
, "%s!ADK_HOST%s", sp
, toupperstr(token
));
560 fprintf(cfg
, "%sADK_HOST_%s", sp
, toupperstr(token
));
563 token
= strtok(NULL
, " ");
568 /* create package target architecture dependency information */
569 if (pkg_arch_depends
!= NULL
) {
570 token
= strtok(pkg_arch_depends
, " ");
571 fprintf(cfg
, "\tdepends on ");
573 while (token
!= NULL
) {
574 if(strncmp(token
, "!", 1) == 0) {
575 fprintf(cfg
, "%s!ADK_LINUX%s", sp
, toupperstr(token
));
578 fprintf(cfg
, "%sADK_LINUX_%s", sp
, toupperstr(token
));
581 token
= strtok(NULL
, " ");
586 /* create package dependency information */
587 if (pkg_depends
!= NULL
) {
588 token
= strtok(pkg_depends
, " ");
589 while (token
!= NULL
) {
590 if (strncmp(token
, "kmod", 4) == 0)
591 fprintf(cfg
, "\tselect ADK_KPACKAGE_%s\n", toupperstr(token
));
593 fprintf(cfg
, "\tselect ADK_PACKAGE_%s\n", toupperstr(token
));
594 token
= strtok(NULL
, " ");
600 if (pkg_need_cxx
!= NULL
) {
601 fprintf(cfg
, "\tdepends on ADK_TOOLCHAIN_GCC_CXX\n");
603 if (pkg_need_java
!= NULL
) {
604 fprintf(cfg
, "\tdepends on ADK_TOOLCHAIN_GCC_JAVA\n");
605 pkg_need_java
= NULL
;
608 fprintf(cfg
, "\tselect ADK_COMPILE_%s\n", toupperstr(pkgdirp
->d_name
));
610 if (pkg_dflt
!= NULL
) {
611 fprintf(cfg
, "\tdefault %s\n", pkg_dflt
);
614 fprintf(cfg
, "\tdefault n\n");
617 fprintf(cfg
, "\thelp\n");
618 fprintf(cfg
, "\t %s\n\n", pkg_descr
);
620 fprintf(cfg
, "\t WWW: %s\n", pkg_url
);
622 /* handle special C++ packages */
623 if (pkg_cxx
!= NULL
) {
624 fprintf(cfg
, "\nchoice\n");
625 fprintf(cfg
, "prompt \"C++ library to use\"\n");
626 fprintf(cfg
, "depends on ADK_COMPILE_%s\n\n", toupperstr(pkgdirp
->d_name
));
627 fprintf(cfg
, "default ADK_COMPILE_%s_WITH_STDCXX if ADK_TARGET_LIB_GLIBC || ADK_TARGET_LIB_EGLIBC\n", pkg_cxx
);
628 fprintf(cfg
, "default ADK_COMPILE_%s_WITH_UCLIBCXX if ADK_TARGET_LIB_UCLIBC\n\n", pkg_cxx
);
629 fprintf(cfg
, "config ADK_COMPILE_%s_WITH_STDCXX\n", pkg_cxx
);
630 fprintf(cfg
, "\tbool \"GNU C++ library\"\n");
631 fprintf(cfg
, "\tselect ADK_PACKAGE_LIBSTDCXX\n\n");
632 fprintf(cfg
, "config ADK_COMPILE_%s_WITH_UCLIBCXX\n", pkg_cxx
);
633 fprintf(cfg
, "\tbool \"uClibc++ library\"\n");
634 fprintf(cfg
, "\tselect ADK_PACKAGE_UCLIBCXX\n\n");
635 fprintf(cfg
, "endchoice\n");
640 /* package flavours */
641 if (pkg_flavours
!= NULL
) {
642 token
= strtok(pkg_flavours
, " ");
643 while (token
!= NULL
) {
644 fprintf(cfg
, "\nconfig ADK_PACKAGE_%s_%s\n", toupperstr(pkgdirp
->d_name
),
646 fprintf(cfg
, "\tbool ");
647 strncat(hkey
, "PKGFD_", 6);
648 strncat(hkey
, token
, strlen(token
));
649 memset(hvalue
, 0 , MAXVALUE
);
650 strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
651 memset(hkey
, 0 , MAXVAR
);
652 pkg_fd
= strdup(hvalue
);
654 fprintf(cfg
, "\"%s\"\n", pkg_fd
);
655 fprintf(cfg
, "\tdefault n\n");
656 fprintf(cfg
, "\tdepends on ADK_PACKAGE_%s\n", toupperstr(pkgdirp
->d_name
));
657 strncat(hkey
, "PKGFS_", 6);
658 strncat(hkey
, token
, strlen(token
));
660 result
= strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
662 val
= strtok_r(hvalue
, " ", &saveptr
);
663 while (val
!= NULL
) {
664 fprintf(cfg
, "\tselect ADK_PACKAGE_%s\n", toupperstr(val
));
665 val
= strtok_r(NULL
, " ", &saveptr
);
668 memset(hkey
, 0, MAXVAR
);
669 fprintf(cfg
, "\thelp\n");
670 fprintf(cfg
, "\t %s\n", pkg_fd
);
671 token
= strtok(NULL
, " ");
677 /* package choices */
678 if (pkg_choices
!= NULL
) {
679 fprintf(cfg
, "\nchoice\n");
680 fprintf(cfg
, "prompt \"Package flavour choice\"\n");
681 fprintf(cfg
, "depends on ADK_COMPILE_%s\n\n", toupperstr(pkgdirp
->d_name
));
682 token
= strtok(pkg_choices
, " ");
683 while (token
!= NULL
) {
684 fprintf(cfg
, "config ADK_PACKAGE_%s_%s\n", toupperstr(pkgdirp
->d_name
),
687 fprintf(cfg
, "\tbool ");
688 strncat(hkey
, "PKGCD_", 6);
689 strncat(hkey
, token
, strlen(token
));
690 memset(hvalue
, 0 , MAXVALUE
);
691 strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
692 memset(hkey
, 0 , MAXVAR
);
693 fprintf(cfg
, "\"%s\"\n", hvalue
);
695 strncat(hkey
, "PKGCS_", 6);
696 strncat(hkey
, token
, strlen(token
));
697 memset(hvalue
, 0, MAXVALUE
);
698 result
= strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
700 val
= strtok_r(hvalue
, " ", &saveptr
);
701 while (val
!= NULL
) {
702 fprintf(cfg
, "\tselect ADK_PACKAGE_%s\n", toupperstr(val
));
703 val
= strtok_r(NULL
, " ", &saveptr
);
706 memset(hkey
, 0, MAXVAR
);
707 token
= strtok(NULL
, " ");
709 fprintf(cfg
, "\nendchoice\n");
713 /* close file descriptor, parse next package */
715 token
= strtok_r(NULL
, " ", &p_ptr
);
718 /* end of package output generation */
723 pkg_need_java
= NULL
;
724 /* reset flags, free memory */
733 free(pkg_arch_depends
);
734 free(pkg_host_depends
);
747 pkg_arch_depends
= NULL
;
748 pkg_host_depends
= NULL
;
754 strmap_delete(pkgmap
);
761 /* create Config.in.auto */
762 strmap_enum(sectionmap
, iter
, NULL
);
764 strmap_delete(sectionmap
);
768 /* remove temporary section files */
769 pkglistdir
= opendir("package/pkglist.d");
770 while ((pkgdirp
= readdir(pkglistdir
)) != NULL
) {
771 if (strncmp(pkgdirp
->d_name
, "sectionlst.", 11) == 0) {
772 if (snprintf(path
, MAXPATH
, "package/pkglist.d/%s", pkgdirp
->d_name
) < 0)
773 fatal_error("creating path variable failed.");
774 if (unlink(path
) < 0)
775 fatal_error("removing file failed.");
778 closedir(pkglistdir
);