2 * pkgmaker - create package meta-data for OpenADK buildsystem
4 * Copyright (C) 2010-2014 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
);
114 static int parse_var_with_system(char *buf
, const char *varname
, char *pvalue
, char **result
, char **sysname
, int varlen
) {
116 char *pkg_var
, *check
;
117 char *key
, *value
, *string
;
119 if ((pkg_var
= malloc(MAXLINE
)) != NULL
)
120 memset(pkg_var
, 0, MAXLINE
);
122 perror("Can not allocate memory");
126 check
= strstr(buf
, ":=");
128 string
= strstr(buf
, varname
);
129 if (string
!= NULL
) {
130 string
[strlen(string
)-1] = '\0';
131 key
= strtok(string
, ":=");
132 *sysname
= strdup(key
+varlen
);
133 value
= strtok(NULL
, "=\t");
135 strncat(pkg_var
, value
, strlen(value
));
136 *result
= strdup(pkg_var
);
142 string
= strstr(buf
, varname
);
143 if (string
!= NULL
) {
144 string
[strlen(string
)-1] = '\0';
145 key
= strtok(string
, "+=");
146 value
= strtok(NULL
, "=\t");
148 strncat(pkg_var
, pvalue
, strlen(pvalue
));
149 strncat(pkg_var
, " ", 1);
151 strncat(pkg_var
, value
, strlen(value
));
152 *result
= strdup(pkg_var
);
161 static int parse_var_with_pkg(char *buf
, const char *varname
, char *pvalue
, char **result
, char **pkgname
, int varlen
) {
163 char *pkg_var
, *check
;
164 char *key
, *value
, *string
;
166 if ((pkg_var
= malloc(MAXLINE
)) != NULL
)
167 memset(pkg_var
, 0, MAXLINE
);
169 perror("Can not allocate memory");
173 check
= strstr(buf
, ":=");
175 string
= strstr(buf
, varname
);
176 if (string
!= NULL
) {
177 string
[strlen(string
)-1] = '\0';
178 key
= strtok(string
, ":=");
179 *pkgname
= strdup(key
+varlen
);
180 value
= strtok(NULL
, "=\t");
182 strncat(pkg_var
, value
, strlen(value
));
183 *result
= strdup(pkg_var
);
189 string
= strstr(buf
, varname
);
190 if (string
!= NULL
) {
191 string
[strlen(string
)-1] = '\0';
192 key
= strtok(string
, "+=");
193 value
= strtok(NULL
, "=\t");
195 strncat(pkg_var
, pvalue
, strlen(pvalue
));
196 strncat(pkg_var
, " ", 1);
198 strncat(pkg_var
, value
, strlen(value
));
199 *result
= strdup(pkg_var
);
209 static void iter_debug(const char *key
, const char *value
, const void *obj
) {
210 fprintf(stderr
, "HASHMAP key: %s value: %s\n", key
, value
);
214 static int hash_str(char *string
) {
220 for (i
=0; i
<(int)strlen(string
); i
++) {
226 static void iter(const char *key
, const char *value
, const void *obj
) {
228 FILE *config
, *section
, *global
;
230 char *valuestr
, *pkg
, *subpkg
, *subsect
, *sect
, *keystr
;
232 char infile
[MAXPATH
];
233 char outfile
[MAXPATH
];
234 char configsect
[MAXPATH
];
236 keystr
= strdup(key
);
237 sect
= strtok(keystr
, "/");
238 subsect
= strtok(NULL
, "/");
240 snprintf(configsect
, MAXPATH
, "package/Config.in.auto.%s.%s", sect
, subsect
);
242 valuestr
= strdup(value
);
243 config
= fopen(configsect
, "a");
245 fatal_error("Can not open file Config.in.auto.<section>.<subsection>");
247 hash
= hash_str(valuestr
);
248 snprintf(infile
, MAXPATH
, "package/pkglist.d/sectionlst.%d", hash
);
249 snprintf(outfile
, MAXPATH
, "package/pkglist.d/sectionlst.%d.sorted", hash
);
251 if (access(infile
, F_OK
) == 0) {
252 valuestr
[strlen(valuestr
)-1] = '\0';
253 fprintf(config
, "menu \"%s\"\n", valuestr
);
254 sortfile(infile
, outfile
);
255 /* avoid duplicate section entries */
257 section
= fopen(outfile
, "r");
258 while (fgets(buf
, MAXPATH
, section
) != NULL
) {
259 buf
[strlen(buf
)-1] = '\0';
260 if (buf
[strlen(buf
)-1] == '@') {
261 buf
[strlen(buf
)-1] = '\0';
262 fprintf(config
, "source \"package/%s/Config.in.manual\"\n", buf
);
264 subpkg
= strtok(buf
, "|");
265 subpkg
[strlen(subpkg
)-1] = '\0';
266 pkg
= strtok(NULL
, "|");
267 fprintf(config
, "source \"package/pkgconfigs.d/%s/Config.in.%s\"\n", pkg
, subpkg
);
270 fprintf(config
, "endmenu\n\n");
276 static char *tolowerstr(char *string
) {
281 /* transform to lowercase variable name */
282 str
= strdup(string
);
283 for (i
=0; i
<(int)strlen(str
); i
++) {
286 str
[i
] = tolower(str
[i
]);
291 static char *toupperstr(char *string
) {
296 /* transform to uppercase variable name */
297 str
= strdup(string
);
298 for (i
=0; i
<(int)strlen(str
); i
++) {
303 /* remove negation here, useful for package host depends */
306 str
[i
] = toupper(str
[i
]);
314 DIR *pkgdir
, *pkglistdir
, *scriptdir
;
315 struct dirent
*pkgdirp
;
316 struct dirent
*scriptdirp
;
318 FILE *pkg
, *cfg
, *menuglobal
, *section
, *initscript
, *icfg
;
319 char hvalue
[MAXVALUE
];
324 char script
[MAXPATH
];
325 char script2
[MAXPATH
];
328 char variable
[2*MAXVAR
];
329 char *key
, *value
, *token
, *cftoken
, *sp
, *hkey
, *val
, *pkg_fd
;
330 char *pkg_name
, *pkg_depends
, *pkg_depends_system
, *pkg_depends_libc
, *pkg_section
, *pkg_descr
, *pkg_url
;
331 char *pkg_cxx
, *pkg_subpkgs
, *pkg_cfline
, *pkg_dflt
;
332 char *pkgname
, *sysname
, *pkg_debug
, *pkg_bb
;
333 char *pkg_libc_depends
, *pkg_host_depends
, *pkg_system_depends
, *pkg_arch_depends
, *pkg_flavours
, *pkg_flavours_string
, *pkg_choices
, *pseudo_name
;
334 char *packages
, *pkg_name_u
, *pkgs
, *pkg_opts
, *pkg_libname
;
335 char *saveptr
, *p_ptr
, *s_ptr
, *pkg_helper
, *sname
, *sname2
;
337 StrMap
*pkgmap
, *sectionmap
;
338 const char runtime
[] = "target/config/Config.in.scripts";
345 pkg_depends_system
= NULL
;
346 pkg_depends_libc
= NULL
;
350 pkg_flavours_string
= NULL
;
353 pkg_arch_depends
= NULL
;
354 pkg_system_depends
= NULL
;
355 pkg_host_depends
= NULL
;
356 pkg_libc_depends
= NULL
;
369 system("rm package/Config.in.auto.* 2>/dev/null");
371 /* open global sectionfile */
372 menuglobal
= fopen("package/Config.in.auto.global", "w");
373 if (menuglobal
== NULL
)
374 fatal_error("global section file not writable.");
376 /* read section list and create a hash table */
377 section
= fopen("package/section.lst", "r");
379 fatal_error("section listfile is missing");
381 sectionmap
= strmap_new(HASHSZ
);
382 while (fgets(tbuf
, MAXPATH
, section
) != NULL
) {
383 key
= strtok(tbuf
, "\t");
384 value
= strtok(NULL
, "\t");
385 strmap_put(sectionmap
, key
, value
);
389 if (mkdir("package/pkgconfigs.d", S_IRWXU
) > 0)
390 fatal_error("creation of package/pkgconfigs.d failed.");
391 if (mkdir("package/pkgconfigs.d/gcc", S_IRWXU
) > 0)
392 fatal_error("creation of package/pkgconfigs.d/gcc failed.");
393 if (mkdir("package/pkglist.d", S_IRWXU
) > 0)
394 fatal_error("creation of package/pkglist.d failed.");
396 /* delete Config.in.dev */
397 if (snprintf(path
, MAXPATH
, "package/pkgconfigs.d/gcc/Config.in.dev") < 0)
398 fatal_error("failed to create path variable.");
400 cfg
= fopen(path
, "w");
402 fatal_error("Config.in.dev can not be opened");
403 fprintf(cfg
, "config ADK_PACKAGE_GLIBC_DEV\n");
404 fprintf(cfg
, "\tprompt \"glibc-dev............ development files for glibc\"\n");
405 fprintf(cfg
, "\tboolean\n");
406 fprintf(cfg
, "\tdefault n\n");
407 fprintf(cfg
, "\tdepends on ADK_TARGET_LIB_GLIBC\n");
408 fprintf(cfg
, "\thelp\n");
409 fprintf(cfg
, "\t GNU C library header files.\n\n");
410 fprintf(cfg
, "config ADK_PACKAGE_UCLIBC_NG_DEV\n");
411 fprintf(cfg
, "\tprompt \"uclibc-ng-dev........ development files for uclibc-ng\"\n");
412 fprintf(cfg
, "\tboolean\n");
413 fprintf(cfg
, "\tdefault n\n");
414 fprintf(cfg
, "\tdepends on ADK_TARGET_LIB_UCLIBC_NG\n");
415 fprintf(cfg
, "\thelp\n");
416 fprintf(cfg
, "\t C library header files.\n\n");
417 fprintf(cfg
, "config ADK_PACKAGE_UCLIBC_DEV\n");
418 fprintf(cfg
, "\tprompt \"uclibc-dev........... development files for uclibc\"\n");
419 fprintf(cfg
, "\tboolean\n");
420 fprintf(cfg
, "\tdefault n\n");
421 fprintf(cfg
, "\tdepends on ADK_TARGET_LIB_UCLIBC\n");
422 fprintf(cfg
, "\thelp\n");
423 fprintf(cfg
, "\t C library header files.\n\n");
424 fprintf(cfg
, "config ADK_PACKAGE_MUSL_DEV\n");
425 fprintf(cfg
, "\tprompt \"musl-dev............. development files for musl\"\n");
426 fprintf(cfg
, "\tboolean\n");
427 fprintf(cfg
, "\tdefault n\n");
428 fprintf(cfg
, "\tdepends on ADK_TARGET_LIB_MUSL\n");
429 fprintf(cfg
, "\thelp\n");
430 fprintf(cfg
, "\t C library header files.\n\n");
434 /* read Makefile's for all packages */
435 pkgdir
= opendir("package");
436 while ((pkgdirp
= readdir(pkgdir
)) != NULL
) {
438 if (strncmp(pkgdirp
->d_name
, ".", 1) > 0) {
439 if (snprintf(path
, MAXPATH
, "package/%s/Makefile", pkgdirp
->d_name
) < 0)
440 fatal_error("can not create path variable.");
441 pkg
= fopen(path
, "r");
445 /* runtime configuration */
446 if (snprintf(script
, MAXPATH
, "package/%s/files", pkgdirp
->d_name
) < 0)
447 fatal_error("script variable creation failed.");
448 scriptdir
= opendir(script
);
449 if (scriptdir
!= NULL
) {
450 while ((scriptdirp
= readdir(scriptdir
)) != NULL
) {
452 if (strncmp(scriptdirp
->d_name
, ".", 1) > 0) {
453 len
= strlen(scriptdirp
->d_name
);
454 if (strlen(".init") > len
)
456 if (strncmp(scriptdirp
->d_name
+ len
- strlen(".init"), ".init", strlen(".init")) == 0) {
457 if (snprintf(script
, MAXPATH
, "package/%s/files/%s", pkgdirp
->d_name
, scriptdirp
->d_name
) < 0)
458 fatal_error("script variable creation failed.");
459 initscript
= fopen(script
, "r");
460 if (initscript
== NULL
)
463 while (fgets(ibuf
, MAXPATH
, initscript
) != NULL
) {
464 if (strncmp("#PKG", ibuf
, 4) == 0) {
465 sname
= strdup(ibuf
+5);
466 sname
[strlen(sname
)-1] = '\0';
467 sname2
= strdup(scriptdirp
->d_name
);
468 sname2
[strlen(sname2
)-5] = '\0';
469 icfg
= fopen(runtime
, "a");
472 if (strncmp("busybox", sname
, 7) == 0)
473 fprintf(icfg
, "config ADK_RUNTIME_START_%s_%s\n", toupperstr(sname
), toupperstr(sname2
));
475 fprintf(icfg
, "config ADK_RUNTIME_START_%s\n", toupperstr(sname
));
476 fprintf(icfg
, "\tprompt \"Start %s on boot\"\n", sname2
);
477 fprintf(icfg
, "\ttristate\n");
478 if (strncmp("busybox", sname
, 7) == 0)
479 fprintf(icfg
, "\tdepends on BUSYBOX_%s\n", toupperstr(sname2
));
481 fprintf(icfg
, "\tdepends on ADK_PACKAGE_%s\n", toupperstr(sname
));
482 fprintf(icfg
, "\tdepends on ADK_RUNTIME_START_SERVICES\n");
483 fprintf(icfg
, "\tdefault n\n\n");
496 /* skip manually maintained packages */
497 if (snprintf(path
, MAXPATH
, "package/%s/Config.in.manual", pkgdirp
->d_name
) < 0)
498 fatal_error("can not create path variable.");
499 if (!access(path
, F_OK
)) {
500 while (fgets(buf
, MAXPATH
, pkg
) != NULL
) {
501 if ((parse_var(buf
, "PKG_SECTION", NULL
, &pkg_section
)) == 0)
505 memset(hvalue
, 0 , MAXVALUE
);
506 result
= strmap_get(sectionmap
, pkg_section
, hvalue
, sizeof(hvalue
));
508 if (snprintf(spath
, MAXPATH
, "package/pkglist.d/sectionlst.%d", hash_str(hvalue
)) < 0)
509 fatal_error("can not create path variable.");
510 section
= fopen(spath
, "a");
511 if (section
!= NULL
) {
512 fprintf(section
, "%s@\n", pkgdirp
->d_name
);
516 fatal_error("Can not find section description %s for package %s.",
517 pkg_section
, pkgdirp
->d_name
);
525 /* create output directories */
526 if (snprintf(dir
, MAXPATH
, "package/pkgconfigs.d/%s", pkgdirp
->d_name
) < 0)
527 fatal_error("can not create dir variable.");
528 if (mkdir(dir
, S_IRWXU
) > 0)
529 fatal_error("can not create directory.");
532 /* allocate memory */
533 hkey
= malloc(MAXVAR
);
534 memset(hkey
, 0, MAXVAR
);
535 memset(variable
, 0, 2*MAXVAR
);
537 pkgmap
= strmap_new(HASHSZ
);
539 /* parse package Makefile */
540 while (fgets(buf
, MAXPATH
, pkg
) != NULL
) {
541 /* just read variables prefixed with PKG */
542 if (strncmp(buf
, "PKG", 3) == 0) {
543 if ((parse_var(buf
, "PKG_NAME", NULL
, &pkg_name
)) == 0)
545 if (pkg_name
!= NULL
)
546 pkg_name_u
= toupperstr(pkg_name
);
548 pkg_name_u
= toupperstr(pkgdirp
->d_name
);
550 snprintf(variable
, MAXVAR
, "PKG_CFLINE_%s", pkg_name_u
);
551 if ((parse_var(buf
, variable
, pkg_cfline
, &pkg_cfline
)) == 0)
553 snprintf(variable
, MAXVAR
, "PKG_DFLT_%s", pkg_name_u
);
554 if ((parse_var(buf
, variable
, NULL
, &pkg_dflt
)) == 0)
556 if ((parse_var(buf
, "PKG_LIBC_DEPENDS", NULL
, &pkg_libc_depends
)) == 0)
558 if ((parse_var(buf
, "PKG_HOST_DEPENDS", NULL
, &pkg_host_depends
)) == 0)
560 if ((parse_var(buf
, "PKG_ARCH_DEPENDS", NULL
, &pkg_arch_depends
)) == 0)
562 if ((parse_var(buf
, "PKG_SYSTEM_DEPENDS", NULL
, &pkg_system_depends
)) == 0)
564 if ((parse_var(buf
, "PKG_DESCR", NULL
, &pkg_descr
)) == 0)
566 if ((parse_var(buf
, "PKG_SECTION", NULL
, &pkg_section
)) == 0)
568 if ((parse_var(buf
, "PKG_URL", NULL
, &pkg_url
)) == 0)
570 if ((parse_var(buf
, "PKG_CXX", NULL
, &pkg_cxx
)) == 0)
572 if ((parse_var(buf
, "PKG_BB", NULL
, &pkg_bb
)) == 0)
574 if ((parse_var(buf
, "PKG_DEPENDS", pkg_depends
, &pkg_depends
)) == 0)
576 if ((parse_var_with_system(buf
, "PKG_DEPENDS_", pkg_depends_system
, &pkg_depends_system
, &sysname
, 12)) == 0)
578 if ((parse_var_with_system(buf
, "PKG_DEPENDS_", pkg_depends_libc
, &pkg_depends_libc
, &sysname
, 12)) == 0)
580 if ((parse_var(buf
, "PKG_LIBNAME", pkg_libname
, &pkg_libname
)) == 0)
582 if ((parse_var(buf
, "PKG_OPTS", pkg_opts
, &pkg_opts
)) == 0)
584 if ((parse_var_with_pkg(buf
, "PKG_FLAVOURS_STRING_", pkg_flavours_string
, &pkg_flavours_string
, &pkgname
, 20)) == 0)
586 if ((parse_var_with_pkg(buf
, "PKG_FLAVOURS_", pkg_flavours
, &pkg_flavours
, &pkgname
, 13)) == 0)
588 if ((parse_var_hash(buf
, "PKGFD_", pkgmap
)) == 0)
590 if ((parse_var_hash(buf
, "PKGFX_", pkgmap
)) == 0)
592 if ((parse_var_hash(buf
, "PKGFS_", pkgmap
)) == 0)
594 if ((parse_var_hash(buf
, "PKGFC_", pkgmap
)) == 0)
596 if ((parse_var_with_pkg(buf
, "PKG_CHOICES_", pkg_choices
, &pkg_choices
, &pkgname
, 12)) == 0)
598 if ((parse_var_hash(buf
, "PKGCD_", pkgmap
)) == 0)
600 if ((parse_var_hash(buf
, "PKGCS_", pkgmap
)) == 0)
602 if ((parse_var(buf
, "PKG_SUBPKGS", pkg_subpkgs
, &pkg_subpkgs
)) == 0)
604 if ((parse_var_hash(buf
, "PKGSD_", pkgmap
)) == 0)
606 if ((parse_var_hash(buf
, "PKGSS_", pkgmap
)) == 0)
608 if ((parse_var_hash(buf
, "PKGSC_", pkgmap
)) == 0)
610 if ((parse_var_hash(buf
, "PKGSN_", pkgmap
)) == 0)
615 /* when PKG_LIBNAME exist use this instead of PKG_NAME, but only for !libmix */
616 if (pkg_libname
!= NULL
)
617 if (pkg_opts
!= NULL
)
618 if (strstr(pkg_opts
, "libmix") == NULL
)
619 pkg_name
= strdup(pkg_libname
);
621 /* end of package Makefile parsing */
622 if (fclose(pkg
) != 0)
623 perror("Failed to close file stream for Makefile");
626 if (pkg_name
!= NULL
)
627 fprintf(stderr
, "Package name is %s\n", pkg_name
);
628 if (pkg_libname
!= NULL
)
629 fprintf(stderr
, "Package library name is %s\n", pkg_libname
);
630 if (pkg_section
!= NULL
)
631 fprintf(stderr
, "Package section is %s\n", pkg_section
);
632 if (pkg_descr
!= NULL
)
633 fprintf(stderr
, "Package description is %s\n", pkg_descr
);
634 if (pkg_depends
!= NULL
)
635 fprintf(stderr
, "Package dependencies are %s\n", pkg_depends
);
636 if (pkg_depends_system
!= NULL
)
637 fprintf(stderr
, "Package systemspecific dependencies are %s\n", pkg_depends_system
);
638 if (pkg_subpkgs
!= NULL
)
639 fprintf(stderr
, "Package subpackages are %s\n", pkg_subpkgs
);
640 if (pkg_flavours
!= NULL
&& pkgname
!= NULL
)
641 fprintf(stderr
, "Package flavours for %s are %s\n", pkgname
, pkg_flavours
);
642 if (pkg_flavours_string
!= NULL
&& pkgname
!= NULL
)
643 fprintf(stderr
, "Package string flavours for %s are %s\n", pkgname
, pkg_flavours_string
);
644 if (pkg_choices
!= NULL
&& pkgname
!= NULL
)
645 fprintf(stderr
, "Package choices for %s are %s\n", pkgname
, pkg_choices
);
647 fprintf(stderr
, "Package homepage is %s\n", pkg_url
);
648 if (pkg_cfline
!= NULL
)
649 fprintf(stderr
, "Package cfline is %s\n", pkg_cfline
);
650 if (pkg_opts
!= NULL
)
651 fprintf(stderr
, "Package options are %s\n", pkg_opts
);
653 strmap_enum(pkgmap
, iter_debug
, NULL
);
656 /* generate master source Config.in file */
657 if (snprintf(path
, MAXPATH
, "package/pkgconfigs.d/%s/Config.in", pkgdirp
->d_name
) < 0)
658 fatal_error("path variable creation failed.");
659 fprintf(menuglobal
, "source \"%s\"\n", path
);
660 /* recreating file is faster than truncating with w+ */
662 cfg
= fopen(path
, "w");
667 if (pkg_subpkgs
!= NULL
)
668 pkgs
= strdup(pkg_subpkgs
);
670 fprintf(cfg
, "config ADK_COMPILE_%s\n", toupperstr(pkgdirp
->d_name
));
671 fprintf(cfg
, "\tboolean\n");
672 if (nobinpkgs
== 0) {
673 fprintf(cfg
, "\tdepends on ");
675 token
= strtok(pkgs
, " ");
676 fprintf(cfg
, "ADK_PACKAGE_%s", token
);
677 token
= strtok(NULL
, " ");
678 while (token
!= NULL
) {
679 fprintf(cfg
, " || ADK_PACKAGE_%s", token
);
680 token
= strtok(NULL
, " ");
684 fprintf(cfg
, "ADK_PACKAGE_%s\n", toupperstr(pkg_name
));
687 fprintf(cfg
, "\tdefault n\n");
691 /* skip packages without binary package output */
695 /* generate binary package specific Config.in files */
696 if (pkg_subpkgs
!= NULL
)
697 packages
= tolowerstr(pkg_subpkgs
);
699 packages
= strdup(pkg_name
);
701 token
= strtok_r(packages
, " ", &p_ptr
);
702 while (token
!= NULL
) {
703 strncat(hkey
, "PKGSC_", 6);
704 strncat(hkey
, toupperstr(token
), strlen(token
));
705 memset(hvalue
, 0 , MAXVALUE
);
706 result
= strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
707 memset(hkey
, 0 , MAXVAR
);
709 pkg_section
= strdup(hvalue
);
711 strncat(hkey
, "PKGSD_", 6);
712 strncat(hkey
, toupperstr(token
), strlen(token
));
713 memset(hvalue
, 0 , MAXVALUE
);
714 result
= strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
715 memset(hkey
, 0 , MAXVAR
);
717 pkg_descr
= strdup(hvalue
);
719 pseudo_name
= malloc(MAXLINE
);
720 memset(pseudo_name
, 0, MAXLINE
);
721 strncat(pseudo_name
, token
, strlen(token
));
722 while (strlen(pseudo_name
) < 23)
723 strncat(pseudo_name
, ".", 1);
725 if (snprintf(path
, MAXPATH
, "package/pkgconfigs.d/%s/Config.in.%s", pkgdirp
->d_name
, token
) < 0)
726 fatal_error("failed to create path variable.");
728 /* create temporary section files */
729 memset(hvalue
, 0 , MAXVALUE
);
730 result
= strmap_get(sectionmap
, pkg_section
, hvalue
, sizeof(hvalue
));
732 if (snprintf(spath
, MAXPATH
, "package/pkglist.d/sectionlst.%d", hash_str(hvalue
)) < 0)
733 fatal_error("failed to create path variable.");
734 section
= fopen(spath
, "a");
735 if (section
!= NULL
) {
736 fprintf(section
, "%s |%s\n", token
, pkgdirp
->d_name
);
740 fatal_error("Can not find section description for package %s.", pkgdirp
->d_name
);
743 cfg
= fopen(path
, "w");
745 perror("Can not open Config.in file");
747 if (pkg_bb
!= NULL
) {
748 fprintf(cfg
, "comment \"%s... %s (disabled, provided by busybox)\"\n", token
, pkg_descr
);
749 fprintf(cfg
, "depends on ADK_PACKAGE_BUSYBOX_HIDE\n\n");
752 /* save token in pkg_debug */
753 pkg_debug
= strdup(token
);
754 fprintf(cfg
, "config ADK_PACKAGE_%s\n", toupperstr(token
));
755 /* no prompt for devonly packages */
756 if (pkg_opts
!= NULL
) {
757 if (strstr(pkg_opts
, "devonly") != NULL
) {
758 fprintf(cfg
, "\t#prompt \"%s. %s\"\n", pseudo_name
, pkg_descr
);
760 fprintf(cfg
, "\tprompt \"%s. %s\"\n", pseudo_name
, pkg_descr
);
763 fprintf(cfg
, "\tprompt \"%s. %s\"\n", pseudo_name
, pkg_descr
);
766 fprintf(cfg
, "\tboolean\n");
769 /* print custom cf line */
770 if (pkg_cfline
!= NULL
) {
771 cftoken
= strtok_r(pkg_cfline
, "@", &saveptr
);
772 while (cftoken
!= NULL
) {
773 fprintf(cfg
, "\t%s\n", cftoken
);
774 cftoken
= strtok_r(NULL
, "@", &saveptr
);
780 /* add sub package dependencies */
781 strncat(hkey
, "PKGSN_", 6);
782 strncat(hkey
, toupperstr(token
), strlen(token
));
783 memset(hvalue
, 0, MAXVALUE
);
784 result
= strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
786 val
= strtok_r(hvalue
, " ", &saveptr
);
787 while (val
!= NULL
) {
788 fprintf(cfg
, "\tdepends on ADK_PACKAGE_%s\n", toupperstr(val
));
789 val
= strtok_r(NULL
, " ", &saveptr
);
792 memset(hkey
, 0, MAXVAR
);
794 /* add sub package auto selections */
795 strncat(hkey
, "PKGSS_", 6);
796 strncat(hkey
, toupperstr(token
), strlen(token
));
797 memset(hvalue
, 0, MAXVALUE
);
798 result
= strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
800 val
= strtok_r(hvalue
, " ", &saveptr
);
801 while (val
!= NULL
) {
802 fprintf(cfg
, "\tselect ADK_PACKAGE_%s\n", toupperstr(val
));
803 val
= strtok_r(NULL
, " ", &saveptr
);
806 memset(hkey
, 0, MAXVAR
);
808 /* create package target system dependency information */
809 if (pkg_system_depends
!= NULL
) {
810 pkg_helper
= strdup(pkg_system_depends
);
811 token
= strtok(pkg_helper
, " ");
812 fprintf(cfg
, "\tdepends on ");
814 while (token
!= NULL
) {
815 if(strncmp(token
, "!", 1) == 0) {
816 fprintf(cfg
, "%s!ADK_TARGET_SYSTEM%s", sp
, toupperstr(token
));
819 fprintf(cfg
, "%sADK_TARGET_SYSTEM_%s", sp
, toupperstr(token
));
822 token
= strtok(NULL
, " ");
828 /* create package host dependency information */
829 if (pkg_host_depends
!= NULL
) {
830 pkg_helper
= strdup(pkg_host_depends
);
831 token
= strtok(pkg_helper
, " ");
832 fprintf(cfg
, "\tdepends on ");
834 while (token
!= NULL
) {
835 if(strncmp(token
, "!", 1) == 0) {
836 fprintf(cfg
, "%s!ADK_HOST%s", sp
, toupperstr(token
));
839 fprintf(cfg
, "%sADK_HOST_%s", sp
, toupperstr(token
));
842 token
= strtok(NULL
, " ");
849 /* create package libc dependency information */
850 if (pkg_libc_depends
!= NULL
) {
851 pkg_helper
= strdup(pkg_libc_depends
);
852 token
= strtok(pkg_helper
, " ");
853 fprintf(cfg
, "\tdepends on ");
855 while (token
!= NULL
) {
856 if(strncmp(token
, "!", 1) == 0) {
857 fprintf(cfg
, "%s!ADK_TARGET_LIB_%s", sp
, toupperstr(token
));
860 fprintf(cfg
, "%sADK_TARGET_LIB_%s", sp
, toupperstr(token
));
863 token
= strtok(NULL
, " ");
869 /* create package target architecture dependency information */
870 if (pkg_arch_depends
!= NULL
) {
871 pkg_helper
= strdup(pkg_arch_depends
);
872 token
= strtok(pkg_helper
, " ");
873 fprintf(cfg
, "\tdepends on ");
875 while (token
!= NULL
) {
876 if(strncmp(token
, "!", 1) == 0) {
877 fprintf(cfg
, "%s!ADK_TARGET_ARCH%s", sp
, toupperstr(token
));
880 fprintf(cfg
, "%sADK_TARGET_ARCH_%s", sp
, toupperstr(token
));
883 token
= strtok(NULL
, " ");
890 /* create package dependency information */
891 if (pkg_depends
!= NULL
) {
892 token
= strtok(pkg_depends
, " ");
893 while (token
!= NULL
) {
894 fprintf(cfg
, "\tselect ADK_PACKAGE_%s\n", toupperstr(token
));
895 token
= strtok(NULL
, " ");
900 /* create system specific package dependency information */
901 if (pkg_depends_system
!= NULL
) {
902 token
= strtok(pkg_depends_system
, " ");
903 while (token
!= NULL
) {
904 fprintf(cfg
, "\tselect ADK_PACKAGE_%s if ADK_TARGET_SYSTEM_%s\n", toupperstr(token
), sysname
);
905 token
= strtok(NULL
, " ");
907 free(pkg_depends_system
);
908 pkg_depends_system
= NULL
;
910 /* create libc specific package dependency information */
911 if (pkg_depends_libc
!= NULL
) {
912 token
= strtok(pkg_depends_libc
, " ");
913 while (token
!= NULL
) {
914 fprintf(cfg
, "\tselect ADK_PACKAGE_%s if ADK_TARGET_LIB_%s\n", toupperstr(token
), sysname
);
915 token
= strtok(NULL
, " ");
917 free(pkg_depends_libc
);
918 pkg_depends_libc
= NULL
;
921 if (pkg_bb
!= NULL
) {
922 fprintf(cfg
, "\tdepends on !ADK_PACKAGE_BUSYBOX_HIDE\n");
924 fprintf(cfg
, "\tselect ADK_COMPILE_%s\n", toupperstr(pkgdirp
->d_name
));
926 if (pkg_dflt
!= NULL
) {
927 fprintf(cfg
, "\tdefault %s\n", pkg_dflt
);
930 fprintf(cfg
, "\tdefault n\n");
933 fprintf(cfg
, "\thelp\n");
934 fprintf(cfg
, "\t %s\n\n", pkg_descr
);
936 fprintf(cfg
, "\t WWW: %s\n", pkg_url
);
938 /* handle special C++ packages */
939 if (pkg_cxx
!= NULL
) {
940 fprintf(cfg
, "\nchoice\n");
941 fprintf(cfg
, "prompt \"C++ library to use\"\n");
942 fprintf(cfg
, "depends on ADK_COMPILE_%s\n\n", toupperstr(pkgdirp
->d_name
));
943 fprintf(cfg
, "default ADK_COMPILE_%s_WITH_STDCXX if ADK_TARGET_LIB_GLIBC\n", pkg_cxx
);
944 fprintf(cfg
, "default ADK_COMPILE_%s_WITH_UCLIBCXX if ADK_TARGET_LIB_UCLIBC\n\n", pkg_cxx
);
945 fprintf(cfg
, "config ADK_COMPILE_%s_WITH_STDCXX\n", pkg_cxx
);
946 fprintf(cfg
, "\tbool \"GNU C++ library\"\n");
947 fprintf(cfg
, "\tselect ADK_PACKAGE_LIBSTDCXX\n\n");
948 fprintf(cfg
, "config ADK_COMPILE_%s_WITH_UCLIBCXX\n", pkg_cxx
);
949 fprintf(cfg
, "\tbool \"uClibc++ library\"\n");
950 fprintf(cfg
, "\tselect ADK_PACKAGE_UCLIBCXX\n\n");
951 fprintf(cfg
, "endchoice\n");
956 /* handle debug subpackages */
957 fprintf(cfg
, "\nconfig ADK_PACKAGE_%s_DBG\n", toupperstr(pkg_debug
));
958 fprintf(cfg
, "\tbool \"add debug symbols package\"\n");
959 fprintf(cfg
, "\tdepends on ADK_PACKAGE_GDB && ADK_BUILD_WITH_DEBUG\n");
960 fprintf(cfg
, "\tdepends on !ADK_DEBUG\n");
961 fprintf(cfg
, "\tdepends on ADK_PACKAGE_%s\n", toupperstr(pkg_debug
));
962 fprintf(cfg
, "\tdefault n\n");
963 fprintf(cfg
, "\thelp\n\n");
965 /* package flavours */
966 if (pkg_flavours
!= NULL
) {
967 token
= strtok(pkg_flavours
, " ");
968 while (token
!= NULL
) {
969 fprintf(cfg
, "\nconfig ADK_PACKAGE_%s_%s\n", pkgname
, toupperstr(token
));
971 // process default value
972 strncat(hkey
, "PKGFX_", 6);
973 strncat(hkey
, token
, strlen(token
));
974 memset(hvalue
, 0 , MAXVALUE
);
975 strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
976 memset(hkey
, 0 , MAXVAR
);
977 pkg_fd
= strdup(hvalue
);
978 if (strlen(pkg_fd
) > 0)
979 fprintf(cfg
, "\tdefault %s\n", pkg_fd
);
981 fprintf(cfg
, "\tdefault n\n");
984 // process flavour cfline
985 strncat(hkey
, "PKGFC_", 6);
986 strncat(hkey
, token
, strlen(token
));
987 memset(hvalue
, 0 , MAXVALUE
);
988 strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
989 memset(hkey
, 0 , MAXVAR
);
990 pkg_fd
= strdup(hvalue
);
991 if (strlen(pkg_fd
) > 0)
992 fprintf(cfg
, "\t%s\n", pkg_fd
);
994 fprintf(cfg
, "\tboolean ");
995 strncat(hkey
, "PKGFD_", 6);
996 strncat(hkey
, token
, strlen(token
));
997 memset(hvalue
, 0 , MAXVALUE
);
998 strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
999 memset(hkey
, 0 , MAXVAR
);
1000 pkg_fd
= strdup(hvalue
);
1002 fprintf(cfg
, "\"%s\"\n", pkg_fd
);
1003 fprintf(cfg
, "\tdepends on ADK_PACKAGE_%s\n", pkgname
);
1004 strncat(hkey
, "PKGFS_", 6);
1005 strncat(hkey
, token
, strlen(token
));
1007 result
= strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
1009 val
= strtok_r(hvalue
, " ", &saveptr
);
1010 while (val
!= NULL
) {
1011 fprintf(cfg
, "\tselect ADK_PACKAGE_%s\n", toupperstr(val
));
1012 val
= strtok_r(NULL
, " ", &saveptr
);
1015 memset(hkey
, 0, MAXVAR
);
1016 fprintf(cfg
, "\thelp\n");
1017 fprintf(cfg
, "\t %s\n", pkg_fd
);
1018 token
= strtok(NULL
, " ");
1021 pkg_flavours
= NULL
;
1024 /* package flavours string */
1025 if (pkg_flavours_string
!= NULL
) {
1026 token
= strtok(pkg_flavours_string
, " ");
1027 while (token
!= NULL
) {
1028 fprintf(cfg
, "\nconfig ADK_PACKAGE_%s_%s\n", pkgname
, toupperstr(token
));
1030 // process default value
1031 strncat(hkey
, "PKGFX_", 6);
1032 strncat(hkey
, token
, strlen(token
));
1033 memset(hvalue
, 0 , MAXVALUE
);
1034 strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
1035 memset(hkey
, 0 , MAXVAR
);
1036 pkg_fd
= strdup(hvalue
);
1037 if (strlen(pkg_fd
) > 0)
1038 fprintf(cfg
, "\tdefault \"%s\"\n", pkg_fd
);
1040 // process flavour cfline
1041 strncat(hkey
, "PKGFC_", 6);
1042 strncat(hkey
, token
, strlen(token
));
1043 memset(hvalue
, 0 , MAXVALUE
);
1044 strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
1045 memset(hkey
, 0 , MAXVAR
);
1046 pkg_fd
= strdup(hvalue
);
1047 if (strlen(pkg_fd
) > 0)
1048 fprintf(cfg
, "\t%s\n", pkg_fd
);
1050 fprintf(cfg
, "\tstring ");
1051 strncat(hkey
, "PKGFD_", 6);
1052 strncat(hkey
, token
, strlen(token
));
1053 memset(hvalue
, 0 , MAXVALUE
);
1054 strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
1055 memset(hkey
, 0 , MAXVAR
);
1056 pkg_fd
= strdup(hvalue
);
1057 fprintf(cfg
, "\"%s\"\n", pkg_fd
);
1059 fprintf(cfg
, "\tdepends on ADK_PACKAGE_%s\n", pkgname
);
1060 strncat(hkey
, "PKGFS_", 6);
1061 strncat(hkey
, token
, strlen(token
));
1063 result
= strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
1065 val
= strtok_r(hvalue
, " ", &saveptr
);
1066 while (val
!= NULL
) {
1067 fprintf(cfg
, "\tselect ADK_PACKAGE_%s\n", toupperstr(val
));
1068 val
= strtok_r(NULL
, " ", &saveptr
);
1071 memset(hkey
, 0, MAXVAR
);
1072 fprintf(cfg
, "\thelp\n");
1073 fprintf(cfg
, "\t %s\n", pkg_fd
);
1074 token
= strtok(NULL
, " ");
1076 free(pkg_flavours_string
);
1077 pkg_flavours_string
= NULL
;
1080 /* package choices */
1081 if (pkg_choices
!= NULL
) {
1082 fprintf(cfg
, "\nchoice\n");
1083 fprintf(cfg
, "prompt \"Package flavour choice\"\n");
1084 fprintf(cfg
, "depends on ADK_PACKAGE_%s\n\n", pkgname
);
1085 token
= strtok(pkg_choices
, " ");
1086 while (token
!= NULL
) {
1087 fprintf(cfg
, "config ADK_PACKAGE_%s_%s\n", pkgname
, toupperstr(token
));
1089 fprintf(cfg
, "\tbool ");
1090 strncat(hkey
, "PKGCD_", 6);
1091 strncat(hkey
, token
, strlen(token
));
1092 memset(hvalue
, 0 , MAXVALUE
);
1093 strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
1094 memset(hkey
, 0 , MAXVAR
);
1095 fprintf(cfg
, "\"%s\"\n", hvalue
);
1097 strncat(hkey
, "PKGCS_", 6);
1098 strncat(hkey
, token
, strlen(token
));
1099 memset(hvalue
, 0, MAXVALUE
);
1100 result
= strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
1102 val
= strtok_r(hvalue
, " ", &saveptr
);
1103 while (val
!= NULL
) {
1104 fprintf(cfg
, "\tselect ADK_PACKAGE_%s\n", toupperstr(val
));
1105 val
= strtok_r(NULL
, " ", &saveptr
);
1108 memset(hkey
, 0, MAXVAR
);
1109 token
= strtok(NULL
, " ");
1111 fprintf(cfg
, "\nendchoice\n");
1115 /* close file descriptor for Config.in file */
1117 /* create Config.in files for development packages */
1118 if (pkg_opts
!= NULL
) {
1119 if (strstr(pkg_opts
, "dev") != NULL
) {
1120 if (snprintf(path
, MAXPATH
, "package/pkgconfigs.d/gcc/Config.in.dev") < 0)
1121 fatal_error("failed to create path variable.");
1122 cfg
= fopen(path
, "a");
1124 perror("Can not open Config.in.dev file");
1126 if (pkg_libname
== NULL
)
1127 pkg_libname
= strdup(pkg_name
);
1130 fprintf(cfg
, "config ADK_PACKAGE_%s_DEV\n", toupperstr(pkg_libname
));
1132 pseudo_name
= malloc(MAXLINE
);
1133 memset(pseudo_name
, 0, MAXLINE
);
1134 strncat(pseudo_name
, pkg_libname
, strlen(pkg_libname
));
1135 strncat(pseudo_name
, "-dev", 4);
1136 while (strlen(pseudo_name
) < 20)
1137 strncat(pseudo_name
, ".", 1);
1139 fprintf(cfg
, "\tprompt \"%s. development files for %s\"\n", pseudo_name
, pkg_libname
);
1140 fprintf(cfg
, "\tboolean\n");
1142 /* create package target architecture dependency information */
1143 if (pkg_arch_depends
!= NULL
) {
1144 pkg_helper
= strdup(pkg_arch_depends
);
1145 token
= strtok(pkg_helper
, " ");
1146 fprintf(cfg
, "\tdepends on ");
1148 while (token
!= NULL
) {
1149 if(strncmp(token
, "!", 1) == 0) {
1150 fprintf(cfg
, "%s!ADK_TARGET_ARCH%s", sp
, toupperstr(token
));
1153 fprintf(cfg
, "%sADK_TARGET_ARCH_%s", sp
, toupperstr(token
));
1156 token
= strtok(NULL
, " ");
1163 fprintf(cfg
, "\tdepends on ADK_PACKAGE_GCC && ADK_PACKAGE_%s\n", toupperstr(pkg_libname
));
1164 fprintf(cfg
, "\tdefault n\n");
1172 /* parse next package */
1173 token
= strtok_r(NULL
, " ", &p_ptr
);
1176 /* end of package output generation */
1180 /* reset flags, free memory */
1188 free(pkg_flavours_string
);
1191 free(pkg_arch_depends
);
1192 free(pkg_system_depends
);
1193 free(pkg_host_depends
);
1194 free(pkg_libc_depends
);
1205 pkg_flavours
= NULL
;
1206 pkg_flavours_string
= NULL
;
1209 pkg_arch_depends
= NULL
;
1210 pkg_system_depends
= NULL
;
1211 pkg_host_depends
= NULL
;
1212 pkg_libc_depends
= NULL
;
1218 strmap_delete(pkgmap
);
1224 /* add menu to gcc package */
1225 if (snprintf(path
, MAXPATH
, "package/pkgconfigs.d/gcc/Config.in.gcc") < 0)
1226 fatal_error("failed to create path variable.");
1227 cfg
= fopen(path
, "a");
1229 perror("Can not open Config.in.gcc file");
1230 fprintf(cfg
, "menu \"Development packages\"\n");
1231 fprintf(cfg
, "depends on ADK_PACKAGE_GCC\n");
1232 fprintf(cfg
, "source \"package/pkgconfigs.d/gcc/Config.in.dev\"\n");
1233 fprintf(cfg
, "endmenu\n");
1236 /* create Config.in.auto */
1237 strmap_enum(sectionmap
, iter
, NULL
);
1239 strmap_delete(sectionmap
);
1243 /* remove temporary section files */
1244 pkglistdir
= opendir("package/pkglist.d");
1245 while ((pkgdirp
= readdir(pkglistdir
)) != NULL
) {
1246 if (strncmp(pkgdirp
->d_name
, "sectionlst.", 11) == 0) {
1247 if (snprintf(path
, MAXPATH
, "package/pkglist.d/%s", pkgdirp
->d_name
) < 0)
1248 fatal_error("creating path variable failed.");
1249 if (unlink(path
) < 0)
1250 fatal_error("removing file failed.");
1253 closedir(pkglistdir
);