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 static void fatal_error(const char *message
) {
42 fprintf(stderr
, "Fatal error. %s\n", message
);
46 static int parse_var_hash(char *buf
, const char *varname
, StrMap
*strmap
) {
48 char *key
, *value
, *string
;
50 string
= strstr(buf
, varname
);
52 string
[strlen(string
)-1] = '\0';
53 key
= strtok(string
, ":=");
54 value
= strtok(NULL
, "=\t");
56 strmap_put(strmap
, key
, value
);
62 static int parse_var(char *buf
, const char *varname
, char *pvalue
, char **result
) {
65 char *key
, *value
, *string
;
68 if ((pkg_var
= malloc(MAXLINE
)) != NULL
)
69 memset(pkg_var
, 0, MAXLINE
);
71 perror("Can not allocate memory");
75 if (snprintf(pkg_str
, MAXVAR
, "%s:=", varname
) < 0)
76 perror("can not create path variable.");
77 string
= strstr(buf
, pkg_str
);
79 string
[strlen(string
)-1] = '\0';
80 key
= strtok(string
, ":=");
81 value
= strtok(NULL
, "=\t");
83 strncat(pkg_var
, value
, strlen(value
));
84 *result
= strdup(pkg_var
);
92 if (snprintf(pkg_str
, MAXVAR
, "%s+=", varname
) < 0)
93 perror("can not create path variable.");
94 string
= strstr(buf
, pkg_str
);
96 string
[strlen(string
)-1] = '\0';
97 key
= strtok(string
, "+=");
98 value
= strtok(NULL
, "=\t");
100 strncat(pkg_var
, pvalue
, strlen(pvalue
));
101 strncat(pkg_var
, " ", 1);
103 strncat(pkg_var
, value
, strlen(value
));
104 *result
= strdup(pkg_var
);
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
) {
125 for (i
=0; i
<(int)strlen(string
); i
++) {
131 static void iter(const char *key
, const char *value
, const void *obj
) {
133 FILE *config
, *section
;
135 char *valuestr
, *pkg
, *subpkg
;
137 char infile
[MAXPATH
];
138 char outfile
[MAXPATH
];
140 valuestr
= strdup(value
);
141 config
= fopen("package/Config.in.auto", "a");
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 */
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
);
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");
174 static char *tolowerstr(char *string
) {
179 /* transform to lowercase variable name */
180 str
= strdup(string
);
181 for (i
=0; i
<(int)strlen(str
); i
++) {
184 str
[i
] = tolower(str
[i
]);
189 static char *toupperstr(char *string
) {
194 /* transform to uppercase variable name */
195 str
= strdup(string
);
196 for (i
=0; i
<(int)strlen(str
); i
++) {
201 /* remove negation here, useful for package host depends */
204 str
[i
] = toupper(str
[i
]);
212 DIR *pkgdir
, *pkglistdir
;
213 struct dirent
*pkgdirp
;
214 FILE *pkg
, *cfg
, *menuglobal
, *section
;
215 char hvalue
[MAXVALUE
];
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
;
230 StrMap
*pkgmap
, *sectionmap
;
240 pkg_arch_depends
= NULL
;
241 pkg_host_depends
= NULL
;
247 pkg_need_java
= 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");
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
);
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
) {
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");
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)
296 memset(hvalue
, 0 , MAXVALUE
);
297 result
= strmap_get(sectionmap
, pkg_section
, hvalue
, sizeof(hvalue
));
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
);
307 fatal_error("Can not find section description for package.");
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)
334 if (pkg_name
!= NULL
)
335 pkg_name_u
= toupperstr(pkg_name
);
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)
342 snprintf(variable
, MAXVAR
, "PKG_DFLT_%s", pkg_name_u
);
343 if ((parse_var(buf
, variable
, NULL
, &pkg_dflt
)) == 0)
345 if ((parse_var(buf
, "PKG_HOST_DEPENDS", NULL
, &pkg_host_depends
)) == 0)
347 if ((parse_var(buf
, "PKG_ARCH_DEPENDS", NULL
, &pkg_arch_depends
)) == 0)
349 if ((parse_var(buf
, "PKG_DESCR", NULL
, &pkg_descr
)) == 0)
351 if ((parse_var(buf
, "PKG_SECTION", NULL
, &pkg_section
)) == 0)
353 if ((parse_var(buf
, "PKG_URL", NULL
, &pkg_url
)) == 0)
355 if ((parse_var(buf
, "PKG_CXX", NULL
, &pkg_cxx
)) == 0)
357 if ((parse_var(buf
, "PKG_NEED_CXX", NULL
, &pkg_need_cxx
)) == 0)
359 if ((parse_var(buf
, "PKG_NEED_JAVA", NULL
, &pkg_need_java
)) == 0)
361 if ((parse_var(buf
, "PKG_MULTI", NULL
, &pkg_multi
)) == 0)
363 if ((parse_var(buf
, "PKG_DEPENDS", pkg_depends
, &pkg_depends
)) == 0)
365 if ((parse_var(buf
, "PKG_FLAVOURS", pkg_flavours
, &pkg_flavours
)) == 0)
367 if ((parse_var_hash(buf
, "PKGFD_", pkgmap
)) == 0)
369 if ((parse_var_hash(buf
, "PKGFS_", pkgmap
)) == 0)
371 if ((parse_var(buf
, "PKG_CHOICES", pkg_choices
, &pkg_choices
)) == 0)
373 if ((parse_var_hash(buf
, "PKGCD_", pkgmap
)) == 0)
375 if ((parse_var_hash(buf
, "PKGCS_", pkgmap
)) == 0)
377 if ((parse_var(buf
, "PKG_SUBPKGS", pkg_subpkgs
, &pkg_subpkgs
)) == 0)
379 if ((parse_var_hash(buf
, "PKGSD_", pkgmap
)) == 0)
381 if ((parse_var_hash(buf
, "PKGSS_", pkgmap
)) == 0)
383 if ((parse_var_hash(buf
, "PKGSC_", pkgmap
)) == 0)
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);
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+ */
423 cfg
= fopen(path
, "w");
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 ");
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
, " ");
448 fprintf(cfg
, "ADK_PACKAGE_%s\n", toupperstr(pkgdirp
->d_name
));
451 fprintf(cfg
, "\tdefault n\n");
455 /* skip packages without binary package output */
459 /* generate binary package specific Config.in files */
460 if (pkg_subpkgs
!= NULL
)
461 packages
= tolowerstr(pkg_subpkgs
);
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
);
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
);
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
));
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
);
504 fatal_error("Can not find section description for package");
507 cfg
= fopen(path
, "w");
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
));
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
));
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 ");
549 while (token
!= NULL
) {
550 if(strncmp(token
, "!", 1) == 0) {
551 fprintf(cfg
, "%s!ADK_HOST%s", sp
, toupperstr(token
));
554 fprintf(cfg
, "%sADK_HOST_%s", sp
, toupperstr(token
));
557 token
= strtok(NULL
, " ");
562 /* create package target architecture dependency information */
563 if (pkg_arch_depends
!= NULL
) {
564 token
= strtok(pkg_arch_depends
, " ");
565 fprintf(cfg
, "\tdepends on ");
567 while (token
!= NULL
) {
568 if(strncmp(token
, "!", 1) == 0) {
569 fprintf(cfg
, "%s!ADK_LINUX%s", sp
, toupperstr(token
));
572 fprintf(cfg
, "%sADK_LINUX_%s", sp
, toupperstr(token
));
575 token
= strtok(NULL
, " ");
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
));
587 fprintf(cfg
, "\tselect ADK_PACKAGE_%s\n", toupperstr(token
));
588 token
= strtok(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
);
607 fprintf(cfg
, "\tdefault n\n");
610 fprintf(cfg
, "\thelp\n");
611 fprintf(cfg
, "\t %s\n\n", pkg_descr
);
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");
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
),
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
));
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
, " ");
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
),
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
));
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");
706 /* close file descriptor, parse next package */
708 token
= strtok_r(NULL
, " ", &p_ptr
);
711 /* end of package output generation */
715 /* reset flags, free memory */
724 free(pkg_arch_depends
);
725 free(pkg_host_depends
);
740 pkg_arch_depends
= NULL
;
741 pkg_host_depends
= NULL
;
747 strmap_delete(pkgmap
);
754 /* create Config.in.auto */
755 strmap_enum(sectionmap
, iter
, NULL
);
757 strmap_delete(sectionmap
);
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
);