pkgmaker: improve error message on missing package category
[openadk.git] / tools / adk / pkgmaker.c
blobdd4b90f4645bb1cab9fe004152811dac5b7eb553
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 #define fatal_error(...) { \
41 fprintf(stderr, "Fatal error. "); \
42 fprintf(stderr, __VA_ARGS__); \
43 fprintf(stderr, "\n"); \
44 exit(1); \
47 static int parse_var_hash(char *buf, const char *varname, StrMap *strmap) {
49 char *key, *value, *string;
51 string = strstr(buf, varname);
52 if (string != NULL) {
53 string[strlen(string)-1] = '\0';
54 key = strtok(string, ":=");
55 value = strtok(NULL, "=\t");
56 if (value != NULL)
57 strmap_put(strmap, key, value);
58 return(0);
60 return(1);
63 static int parse_var(char *buf, const char *varname, char *pvalue, char **result) {
65 char *pkg_var;
66 char *key, *value, *string;
67 char pkg_str[MAXVAR];
69 if ((pkg_var = malloc(MAXLINE)) != NULL)
70 memset(pkg_var, 0, MAXLINE);
71 else {
72 perror("Can not allocate memory");
73 exit(EXIT_FAILURE);
76 if (snprintf(pkg_str, MAXVAR, "%s:=", varname) < 0)
77 perror("can not create path variable.");
78 string = strstr(buf, pkg_str);
79 if (string != NULL) {
80 string[strlen(string)-1] = '\0';
81 key = strtok(string, ":=");
82 value = strtok(NULL, "=\t");
83 if (value != NULL) {
84 strncat(pkg_var, value, strlen(value));
85 *result = strdup(pkg_var);
86 } else {
87 nobinpkgs = 1;
88 *result = NULL;
90 free(pkg_var);
91 return(0);
92 } else {
93 if (snprintf(pkg_str, MAXVAR, "%s+=", varname) < 0)
94 perror("can not create path variable.");
95 string = strstr(buf, pkg_str);
96 if (string != NULL) {
97 string[strlen(string)-1] = '\0';
98 key = strtok(string, "+=");
99 value = strtok(NULL, "=\t");
100 if (pvalue != NULL)
101 strncat(pkg_var, pvalue, strlen(pvalue));
102 strncat(pkg_var, " ", 1);
103 if (value != NULL)
104 strncat(pkg_var, value, strlen(value));
105 *result = strdup(pkg_var);
106 free(pkg_var);
107 return(0);
110 free(pkg_var);
111 return(1);
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) {
122 int i;
123 int hash;
125 hash = 0;
126 for (i=0; i<(int)strlen(string); i++) {
127 hash += string[i];
129 return(hash);
132 static void iter(const char *key, const char *value, const void *obj) {
134 FILE *config, *section;
135 int hash;
136 char *valuestr, *pkg, *subpkg;
137 char buf[MAXPATH];
138 char infile[MAXPATH];
139 char outfile[MAXPATH];
141 valuestr = strdup(value);
142 config = fopen("package/Config.in.auto", "a");
143 if (config == NULL)
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 */
155 unlink(infile);
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);
162 } else {
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");
170 fclose(section);
172 fclose(config);
175 static char *tolowerstr(char *string) {
177 int i;
178 char *str;
180 /* transform to lowercase variable name */
181 str = strdup(string);
182 for (i=0; i<(int)strlen(str); i++) {
183 if (str[i] == '_')
184 str[i] = '-';
185 str[i] = tolower(str[i]);
187 return(str);
190 static char *toupperstr(char *string) {
192 int i;
193 char *str;
195 /* transform to uppercase variable name */
196 str = strdup(string);
197 for (i=0; i<(int)strlen(str); i++) {
198 if (str[i] == '+')
199 str[i] = 'X';
200 if (str[i] == '-')
201 str[i] = '_';
202 /* remove negation here, useful for package host depends */
203 if (str[i] == '!')
204 str[i] = '_';
205 str[i] = toupper(str[i]);
207 return(str);
211 int main() {
213 DIR *pkgdir, *pkglistdir;
214 struct dirent *pkgdirp;
215 FILE *pkg, *cfg, *menuglobal, *section;
216 char hvalue[MAXVALUE];
217 char buf[MAXPATH];
218 char tbuf[MAXPATH];
219 char path[MAXPATH];
220 char spath[MAXPATH];
221 char dir[MAXPATH];
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;
230 int result;
231 StrMap *pkgmap, *sectionmap;
233 pkg_name = NULL;
234 pkg_descr = NULL;
235 pkg_section = NULL;
236 pkg_url = NULL;
237 pkg_depends = NULL;
238 pkg_flavours = NULL;
239 pkg_choices = NULL;
240 pkg_subpkgs = NULL;
241 pkg_arch_depends = NULL;
242 pkg_host_depends = NULL;
243 pkg_cxx = NULL;
244 pkg_dflt = NULL;
245 pkg_cfline = NULL;
246 pkg_multi = NULL;
247 pkg_need_cxx = NULL;
248 pkg_need_java = NULL;
250 p_ptr = NULL;
251 s_ptr = 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");
261 if (section == NULL)
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);
270 fclose(section);
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) {
280 /* skip dotfiles */
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");
285 if (pkg == NULL)
286 continue;
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)
294 continue;
297 memset(hvalue, 0 , MAXVALUE);
298 result = strmap_get(sectionmap, pkg_section, hvalue, sizeof(hvalue));
299 if (result == 1) {
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);
305 fclose(section);
307 } else
308 fatal_error("Can not find section description for package %s.",
309 pkgdirp->d_name);
311 fclose(pkg);
312 continue;
315 nobinpkgs = 0;
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)
335 continue;
336 if (pkg_name != NULL)
337 pkg_name_u = toupperstr(pkg_name);
338 else
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)
343 continue;
344 snprintf(variable, MAXVAR, "PKG_DFLT_%s", pkg_name_u);
345 if ((parse_var(buf, variable, NULL, &pkg_dflt)) == 0)
346 continue;
347 if ((parse_var(buf, "PKG_HOST_DEPENDS", NULL, &pkg_host_depends)) == 0)
348 continue;
349 if ((parse_var(buf, "PKG_ARCH_DEPENDS", NULL, &pkg_arch_depends)) == 0)
350 continue;
351 if ((parse_var(buf, "PKG_DESCR", NULL, &pkg_descr)) == 0)
352 continue;
353 if ((parse_var(buf, "PKG_SECTION", NULL, &pkg_section)) == 0)
354 continue;
355 if ((parse_var(buf, "PKG_URL", NULL, &pkg_url)) == 0)
356 continue;
357 if ((parse_var(buf, "PKG_CXX", NULL, &pkg_cxx)) == 0)
358 continue;
359 if ((parse_var(buf, "PKG_NEED_CXX", NULL, &pkg_need_cxx)) == 0)
360 continue;
361 if ((parse_var(buf, "PKG_NEED_JAVA", NULL, &pkg_need_java)) == 0)
362 continue;
363 if ((parse_var(buf, "PKG_MULTI", NULL, &pkg_multi)) == 0)
364 continue;
365 if ((parse_var(buf, "PKG_DEPENDS", pkg_depends, &pkg_depends)) == 0)
366 continue;
367 if ((parse_var(buf, "PKG_FLAVOURS", pkg_flavours, &pkg_flavours)) == 0)
368 continue;
369 if ((parse_var_hash(buf, "PKGFD_", pkgmap)) == 0)
370 continue;
371 if ((parse_var_hash(buf, "PKGFS_", pkgmap)) == 0)
372 continue;
373 if ((parse_var(buf, "PKG_CHOICES", pkg_choices, &pkg_choices)) == 0)
374 continue;
375 if ((parse_var_hash(buf, "PKGCD_", pkgmap)) == 0)
376 continue;
377 if ((parse_var_hash(buf, "PKGCS_", pkgmap)) == 0)
378 continue;
379 if ((parse_var(buf, "PKG_SUBPKGS", pkg_subpkgs, &pkg_subpkgs)) == 0)
380 continue;
381 if ((parse_var_hash(buf, "PKGSD_", pkgmap)) == 0)
382 continue;
383 if ((parse_var_hash(buf, "PKGSS_", pkgmap)) == 0)
384 continue;
385 if ((parse_var_hash(buf, "PKGSC_", pkgmap)) == 0)
386 continue;
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);
409 if (pkg_url != NULL)
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+ */
424 unlink(path);
425 cfg = fopen(path, "w");
426 if (cfg == NULL)
427 continue;
429 pkgs = NULL;
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 ");
437 if (pkgs != NULL) {
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, " ");
448 fprintf(cfg, "\n");
449 } else {
450 fprintf(cfg, "ADK_PACKAGE_%s\n", toupperstr(pkgdirp->d_name));
453 fprintf(cfg, "\tdefault n\n");
454 fclose(cfg);
455 free(pkgs);
457 /* skip packages without binary package output */
458 if (nobinpkgs == 1)
459 continue;
461 /* generate binary package specific Config.in files */
462 if (pkg_subpkgs != NULL)
463 packages = tolowerstr(pkg_subpkgs);
464 else
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);
474 if (result == 1)
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);
482 if (result == 1)
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));
497 if (result == 1) {
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);
503 fclose(section);
505 } else
506 fatal_error("Can not find section description for package %s.", pkgdirp->d_name);
508 unlink(path);
509 cfg = fopen(path, "w");
510 if (cfg == NULL)
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));
525 free(pseudo_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));
541 if (result == 1) {
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 ");
554 sp = "";
555 while (token != NULL) {
556 if(strncmp(token, "!", 1) == 0) {
557 fprintf(cfg, "%s!ADK_HOST%s", sp, toupperstr(token));
558 sp = " && ";
559 } else {
560 fprintf(cfg, "%sADK_HOST_%s", sp, toupperstr(token));
561 sp = " || ";
563 token = strtok(NULL, " ");
565 fprintf(cfg, "\n");
568 /* create package target architecture dependency information */
569 if (pkg_arch_depends != NULL) {
570 token = strtok(pkg_arch_depends, " ");
571 fprintf(cfg, "\tdepends on ");
572 sp = "";
573 while (token != NULL) {
574 if(strncmp(token, "!", 1) == 0) {
575 fprintf(cfg, "%s!ADK_LINUX%s", sp, toupperstr(token));
576 sp = " && ";
577 } else {
578 fprintf(cfg, "%sADK_LINUX_%s", sp, toupperstr(token));
579 sp = " || ";
581 token = strtok(NULL, " ");
583 fprintf(cfg, "\n");
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));
592 else
593 fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(token));
594 token = strtok(NULL, " ");
596 free(pkg_depends);
597 pkg_depends = 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);
612 pkg_dflt = NULL;
613 } else {
614 fprintf(cfg, "\tdefault n\n");
617 fprintf(cfg, "\thelp\n");
618 fprintf(cfg, "\t %s\n\n", pkg_descr);
619 if (pkg_url != NULL)
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");
636 free(pkg_cxx);
637 pkg_cxx = NULL;
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),
645 toupperstr(token));
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));
661 if (result == 1) {
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, " ");
673 free(pkg_flavours);
674 pkg_flavours = 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),
685 toupperstr(token));
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));
699 if (result == 1) {
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");
710 free(pkg_choices);
711 pkg_choices = NULL;
713 /* close file descriptor, parse next package */
714 fclose(cfg);
715 token = strtok_r(NULL, " ", &p_ptr);
718 /* end of package output generation */
719 free(packages);
720 packages = NULL;
722 pkg_need_cxx = NULL;
723 pkg_need_java = NULL;
724 /* reset flags, free memory */
725 free(pkg_name);
726 free(pkg_descr);
727 free(pkg_section);
728 free(pkg_url);
729 free(pkg_depends);
730 free(pkg_flavours);
731 free(pkg_choices);
732 free(pkg_subpkgs);
733 free(pkg_arch_depends);
734 free(pkg_host_depends);
735 free(pkg_cxx);
736 free(pkg_dflt);
737 free(pkg_cfline);
738 free(pkg_multi);
739 pkg_name = NULL;
740 pkg_descr = NULL;
741 pkg_section = NULL;
742 pkg_url = NULL;
743 pkg_depends = NULL;
744 pkg_flavours = NULL;
745 pkg_choices = NULL;
746 pkg_subpkgs = NULL;
747 pkg_arch_depends = NULL;
748 pkg_host_depends = NULL;
749 pkg_cxx = NULL;
750 pkg_dflt = NULL;
751 pkg_cfline = NULL;
752 pkg_multi = NULL;
754 strmap_delete(pkgmap);
755 nobinpkgs = 0;
756 free(hkey);
761 /* create Config.in.auto */
762 strmap_enum(sectionmap, iter, NULL);
764 strmap_delete(sectionmap);
765 fclose(menuglobal);
766 closedir(pkgdir);
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);
779 return(0);