2 * pkgmaker - create package meta-data for OpenADK buildsystem
4 * Copyright (C) 2010-2016 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/>.
29 #include <sys/types.h>
41 #define fatal_error(...) { \
42 fprintf(stderr, "Fatal error. "); \
43 fprintf(stderr, __VA_ARGS__); \
44 fprintf(stderr, "\n"); \
48 static int parse_var_hash(char *buf
, const char *varname
, StrMap
*strmap
) {
50 char *key
, *value
, *string
;
52 string
= strstr(buf
, varname
);
54 string
[strlen(string
)-1] = '\0';
55 key
= strtok(string
, ":=");
56 value
= strtok(NULL
, "=\t");
58 strmap_put(strmap
, key
, value
);
64 static int parse_var(char *buf
, const char *varname
, char *pvalue
, char **result
) {
67 char *key
, *value
, *string
;
70 if ((pkg_var
= malloc(MAXLINE
)) != NULL
)
71 memset(pkg_var
, 0, MAXLINE
);
73 perror("Can not allocate memory");
77 if (snprintf(pkg_str
, MAXVAR
, "%s:=", varname
) < 0)
78 perror("can not create path variable.");
79 string
= strstr(buf
, pkg_str
);
81 string
[strlen(string
)-1] = '\0';
82 key
= strtok(string
, ":=");
83 value
= strtok(NULL
, "=\t");
85 strncat(pkg_var
, value
, strlen(value
));
86 *result
= strdup(pkg_var
);
94 if (snprintf(pkg_str
, MAXVAR
, "%s+=", varname
) < 0)
95 perror("can not create path variable.");
96 string
= strstr(buf
, pkg_str
);
98 string
[strlen(string
)-1] = '\0';
99 key
= strtok(string
, "+=");
100 value
= strtok(NULL
, "=\t");
102 strncat(pkg_var
, pvalue
, strlen(pvalue
));
103 strncat(pkg_var
, " ", 1);
105 strncat(pkg_var
, value
, strlen(value
));
106 *result
= strdup(pkg_var
);
115 static int parse_var_with_system(char *buf
, const char *varname
, char *pvalue
, char **result
, char **sysname
, int varlen
) {
117 char *pkg_var
, *check
;
118 char *key
, *value
, *string
;
120 if ((pkg_var
= malloc(MAXLINE
)) != NULL
)
121 memset(pkg_var
, 0, MAXLINE
);
123 perror("Can not allocate memory");
127 check
= strstr(buf
, ":=");
129 string
= strstr(buf
, varname
);
130 if (string
!= NULL
) {
131 string
[strlen(string
)-1] = '\0';
132 key
= strtok(string
, ":=");
133 *sysname
= strdup(key
+varlen
);
134 value
= strtok(NULL
, "=\t");
136 strncat(pkg_var
, value
, strlen(value
));
137 *result
= strdup(pkg_var
);
143 string
= strstr(buf
, varname
);
144 if (string
!= NULL
) {
145 string
[strlen(string
)-1] = '\0';
146 key
= strtok(string
, "+=");
147 value
= strtok(NULL
, "=\t");
149 strncat(pkg_var
, pvalue
, strlen(pvalue
));
150 strncat(pkg_var
, " ", 1);
152 strncat(pkg_var
, value
, strlen(value
));
153 *result
= strdup(pkg_var
);
162 static int parse_var_with_pkg(char *buf
, const char *varname
, char *pvalue
, char **result
, char **pkgname
, int varlen
) {
164 char *pkg_var
, *check
;
165 char *key
, *value
, *string
;
167 if ((pkg_var
= malloc(MAXLINE
)) != NULL
)
168 memset(pkg_var
, 0, MAXLINE
);
170 perror("Can not allocate memory");
174 check
= strstr(buf
, ":=");
176 string
= strstr(buf
, varname
);
177 if (string
!= NULL
) {
178 string
[strlen(string
)-1] = '\0';
179 key
= strtok(string
, ":=");
180 *pkgname
= strdup(key
+varlen
);
181 value
= strtok(NULL
, "=\t");
183 strncat(pkg_var
, value
, strlen(value
));
184 *result
= strdup(pkg_var
);
190 string
= strstr(buf
, varname
);
191 if (string
!= NULL
) {
192 string
[strlen(string
)-1] = '\0';
193 key
= strtok(string
, "+=");
194 value
= strtok(NULL
, "=\t");
196 strncat(pkg_var
, pvalue
, strlen(pvalue
));
197 strncat(pkg_var
, " ", 1);
199 strncat(pkg_var
, value
, strlen(value
));
200 *result
= strdup(pkg_var
);
210 static void iter_debug(const char *key
, const char *value
, const void *obj
) {
211 fprintf(stderr
, "HASHMAP key: %s value: %s\n", key
, value
);
215 static int hash_str(char *string
) {
221 for (i
=0; i
<(int)strlen(string
); i
++) {
227 static void iter(const char *key
, const char *value
, const void *obj
) {
229 FILE *config
, *section
, *global
;
231 char *valuestr
, *pkg
, *subpkg
, *subsect
, *sect
, *keystr
;
233 char infile
[MAXPATH
];
234 char outfile
[MAXPATH
];
235 char configsect
[MAXPATH
];
237 keystr
= strdup(key
);
238 sect
= strtok(keystr
, "/");
239 subsect
= strtok(NULL
, "/");
241 snprintf(configsect
, MAXPATH
, "package/Config.in.auto.%s.%s", sect
, subsect
);
243 valuestr
= strdup(value
);
244 config
= fopen(configsect
, "a");
246 fatal_error("Can not open file Config.in.auto.<section>.<subsection>");
248 hash
= hash_str(valuestr
);
249 snprintf(infile
, MAXPATH
, "package/pkglist.d/sectionlst.%d", hash
);
250 snprintf(outfile
, MAXPATH
, "package/pkglist.d/sectionlst.%d.sorted", hash
);
252 if (access(infile
, F_OK
) == 0) {
253 valuestr
[strlen(valuestr
)-1] = '\0';
254 fprintf(config
, "menu \"%s\"\n", valuestr
);
255 sortfile(infile
, outfile
);
256 /* avoid duplicate section entries */
258 section
= fopen(outfile
, "r");
259 while (fgets(buf
, MAXPATH
, section
) != NULL
) {
260 buf
[strlen(buf
)-1] = '\0';
261 if (buf
[strlen(buf
)-1] == '@') {
262 buf
[strlen(buf
)-1] = '\0';
263 fprintf(config
, "source \"package/%s/Config.in.manual\"\n", buf
);
265 subpkg
= strtok(buf
, "|");
266 subpkg
[strlen(subpkg
)-1] = '\0';
267 pkg
= strtok(NULL
, "|");
268 fprintf(config
, "source \"package/pkgconfigs.d/%s/Config.in.%s\"\n", pkg
, subpkg
);
271 fprintf(config
, "endmenu\n\n");
277 static char *tolowerstr(char *string
) {
282 /* transform to lowercase variable name */
283 str
= strdup(string
);
284 for (i
=0; i
<(int)strlen(str
); i
++) {
287 str
[i
] = tolower(str
[i
]);
292 static char *toupperstr(char *string
) {
294 static char *sdup
= NULL
;
295 static int sduplen
= 0;
304 if (sduplen
<= strlen(string
)) {
305 sduplen
= strlen(string
) + 1;
306 sdup
= realloc(sdup
, sduplen
);
308 fatal_error("%s: memory allocation failed: %s\n",
309 __func__
, strerror(errno
));
312 /* transform to uppercase variable name */
313 for (i
= 0; i
< strlen(string
) + 1; i
++) {
328 sdup
[i
] = toupper(string
[i
]);
337 DIR *pkgdir
, *pkglistdir
, *scriptdir
;
338 struct dirent
*pkgdirp
;
339 struct dirent
*scriptdirp
;
341 FILE *pkg
, *cfg
, *menuglobal
, *section
, *initscript
, *icfg
;
342 char hvalue
[MAXVALUE
];
347 char script
[MAXPATH
];
348 char script2
[MAXPATH
];
351 char variable
[2*MAXVAR
];
352 char *key
, *value
, *token
, *cftoken
, *sp
, *hkey
, *val
, *pkg_fd
;
353 char *pkg_name
, *pkg_depends
, *pkg_kdepends
, *pkg_needs
, *pkg_depends_system
, *pkg_depends_libc
, *pkg_section
, *pkg_descr
, *pkg_url
;
354 char *pkg_subpkgs
, *pkg_cfline
, *pkg_dflt
;
355 char *pkgname
, *sysname
, *pkg_debug
, *pkg_bb
;
356 char *pkg_libc_depends
, *pkg_host_depends
, *pkg_system_depends
, *pkg_arch_depends
, *pkg_flavours
, *pkg_flavours_string
, *pkg_choices
, *pseudo_name
;
357 char *packages
, *pkg_name_u
, *pkgs
, *pkg_opts
, *pkg_libname
;
358 char *saveptr
, *p_ptr
, *s_ptr
, *pkg_helper
, *sname
, *sname2
;
360 StrMap
*pkgmap
, *sectionmap
;
361 const char runtime
[] = "target/config/Config.in.scripts";
370 pkg_depends_system
= NULL
;
371 pkg_depends_libc
= NULL
;
375 pkg_flavours_string
= NULL
;
378 pkg_arch_depends
= NULL
;
379 pkg_system_depends
= NULL
;
380 pkg_host_depends
= NULL
;
381 pkg_libc_depends
= NULL
;
393 system("rm package/Config.in.auto.* 2>/dev/null");
395 /* open global sectionfile */
396 menuglobal
= fopen("package/Config.in.auto.global", "w");
397 if (menuglobal
== NULL
)
398 fatal_error("global section file not writable.");
400 /* read section list and create a hash table */
401 section
= fopen("package/section.lst", "r");
403 fatal_error("section listfile is missing");
405 sectionmap
= strmap_new(HASHSZ
);
406 while (fgets(tbuf
, MAXPATH
, section
) != NULL
) {
407 key
= strtok(tbuf
, "\t");
408 value
= strtok(NULL
, "\t");
409 strmap_put(sectionmap
, key
, value
);
413 if (mkdir("package/pkgconfigs.d", S_IRWXU
) > 0)
414 fatal_error("creation of package/pkgconfigs.d failed.");
415 if (mkdir("package/pkgconfigs.d/gcc", S_IRWXU
) > 0)
416 fatal_error("creation of package/pkgconfigs.d/gcc failed.");
417 if (mkdir("package/pkglist.d", S_IRWXU
) > 0)
418 fatal_error("creation of package/pkglist.d failed.");
420 /* delete Config.in.dev */
421 if (snprintf(path
, MAXPATH
, "package/pkgconfigs.d/gcc/Config.in.dev") < 0)
422 fatal_error("failed to create path variable.");
424 cfg
= fopen(path
, "w");
426 fatal_error("Config.in.dev can not be opened");
427 fprintf(cfg
, "config ADK_PACKAGE_GLIBC_DEV\n");
428 fprintf(cfg
, "\tprompt \"glibc-dev............ development files for glibc\"\n");
429 fprintf(cfg
, "\tboolean\n");
430 fprintf(cfg
, "\tdefault n\n");
431 fprintf(cfg
, "\tdepends on ADK_TARGET_LIB_GLIBC\n");
432 fprintf(cfg
, "\thelp\n");
433 fprintf(cfg
, "\t GNU C library header files.\n\n");
434 fprintf(cfg
, "config ADK_PACKAGE_UCLIBC_NG_DEV\n");
435 fprintf(cfg
, "\tprompt \"uclibc-ng-dev........ development files for uclibc-ng\"\n");
436 fprintf(cfg
, "\tboolean\n");
437 fprintf(cfg
, "\tdefault n\n");
438 fprintf(cfg
, "\tdepends on ADK_TARGET_LIB_UCLIBC_NG\n");
439 fprintf(cfg
, "\thelp\n");
440 fprintf(cfg
, "\t C library header files.\n\n");
441 fprintf(cfg
, "config ADK_PACKAGE_MUSL_DEV\n");
442 fprintf(cfg
, "\tprompt \"musl-dev............. development files for musl\"\n");
443 fprintf(cfg
, "\tboolean\n");
444 fprintf(cfg
, "\tdefault n\n");
445 fprintf(cfg
, "\tdepends on ADK_TARGET_LIB_MUSL\n");
446 fprintf(cfg
, "\thelp\n");
447 fprintf(cfg
, "\t C library header files.\n\n");
451 /* read Makefile's for all packages */
452 pkgdir
= opendir("package");
453 while ((pkgdirp
= readdir(pkgdir
)) != NULL
) {
455 if (strncmp(pkgdirp
->d_name
, ".", 1) > 0) {
456 if (snprintf(path
, MAXPATH
, "package/%s/Makefile", pkgdirp
->d_name
) < 0)
457 fatal_error("can not create path variable.");
458 pkg
= fopen(path
, "r");
462 /* runtime configuration */
463 if (snprintf(script
, MAXPATH
, "package/%s/files", pkgdirp
->d_name
) < 0)
464 fatal_error("script variable creation failed.");
465 scriptdir
= opendir(script
);
466 if (scriptdir
!= NULL
) {
467 while ((scriptdirp
= readdir(scriptdir
)) != NULL
) {
469 if (strncmp(scriptdirp
->d_name
, ".", 1) > 0) {
470 len
= strlen(scriptdirp
->d_name
);
471 if (strlen(".init") > len
)
473 if (strncmp(scriptdirp
->d_name
+ len
- strlen(".init"), ".init", strlen(".init")) == 0) {
474 if (snprintf(script
, MAXPATH
, "package/%s/files/%s", pkgdirp
->d_name
, scriptdirp
->d_name
) < 0)
475 fatal_error("script variable creation failed.");
476 initscript
= fopen(script
, "r");
477 if (initscript
== NULL
)
480 while (fgets(ibuf
, MAXPATH
, initscript
) != NULL
) {
481 if (strncmp("#PKG", ibuf
, 4) == 0) {
482 sname
= strdup(ibuf
+5);
483 sname
[strlen(sname
)-1] = '\0';
484 sname2
= strdup(scriptdirp
->d_name
);
485 sname2
[strlen(sname2
)-5] = '\0';
486 icfg
= fopen(runtime
, "a");
489 if (strncmp("busybox", sname
, 7) == 0) {
490 fprintf(icfg
, "config ADK_RUNTIME_START_%s", toupperstr(sname
));
491 fprintf(icfg
, "_%s\n", toupperstr(sname2
));
493 fprintf(icfg
, "config ADK_RUNTIME_START_%s\n", toupperstr(sname
));
495 fprintf(icfg
, "\tprompt \"Start %s on boot\"\n", sname2
);
496 fprintf(icfg
, "\ttristate\n");
497 if (strncmp("busybox", sname
, 7) == 0)
498 fprintf(icfg
, "\tdepends on BUSYBOX_%s\n", toupperstr(sname2
));
500 fprintf(icfg
, "\tdepends on ADK_PACKAGE_%s\n", toupperstr(sname
));
501 fprintf(icfg
, "\tdepends on ADK_RUNTIME_START_SERVICES\n");
502 fprintf(icfg
, "\tdefault n\n\n");
515 /* skip manually maintained packages */
516 if (snprintf(path
, MAXPATH
, "package/%s/Config.in.manual", pkgdirp
->d_name
) < 0)
517 fatal_error("can not create path variable.");
518 if (!access(path
, F_OK
)) {
519 while (fgets(buf
, MAXPATH
, pkg
) != NULL
) {
520 if ((parse_var(buf
, "PKG_SECTION", NULL
, &pkg_section
)) == 0)
524 memset(hvalue
, 0 , MAXVALUE
);
525 result
= strmap_get(sectionmap
, pkg_section
, hvalue
, sizeof(hvalue
));
527 if (snprintf(spath
, MAXPATH
, "package/pkglist.d/sectionlst.%d", hash_str(hvalue
)) < 0)
528 fatal_error("can not create path variable.");
529 section
= fopen(spath
, "a");
530 if (section
!= NULL
) {
531 fprintf(section
, "%s@\n", pkgdirp
->d_name
);
535 fatal_error("Can not find section description %s for package %s.",
536 pkg_section
, pkgdirp
->d_name
);
544 /* create output directories */
545 if (snprintf(dir
, MAXPATH
, "package/pkgconfigs.d/%s", pkgdirp
->d_name
) < 0)
546 fatal_error("can not create dir variable.");
547 if (mkdir(dir
, S_IRWXU
) > 0)
548 fatal_error("can not create directory.");
551 /* allocate memory */
552 hkey
= malloc(MAXVAR
);
553 memset(hkey
, 0, MAXVAR
);
554 memset(variable
, 0, 2*MAXVAR
);
556 pkgmap
= strmap_new(HASHSZ
);
558 /* parse package Makefile */
559 while (fgets(buf
, MAXPATH
, pkg
) != NULL
) {
560 /* just read variables prefixed with PKG */
561 if (strncmp(buf
, "PKG", 3) == 0) {
562 if ((parse_var(buf
, "PKG_NAME", NULL
, &pkg_name
)) == 0)
564 if (pkg_name
!= NULL
)
565 pkg_name_u
= toupperstr(pkg_name
);
567 pkg_name_u
= toupperstr(pkgdirp
->d_name
);
569 snprintf(variable
, MAXVAR
, "PKG_CFLINE_%s", pkg_name_u
);
570 if ((parse_var(buf
, variable
, pkg_cfline
, &pkg_cfline
)) == 0)
572 snprintf(variable
, MAXVAR
, "PKG_DFLT_%s", pkg_name_u
);
573 if ((parse_var(buf
, variable
, NULL
, &pkg_dflt
)) == 0)
575 if ((parse_var(buf
, "PKG_LIBC_DEPENDS", NULL
, &pkg_libc_depends
)) == 0)
577 if ((parse_var(buf
, "PKG_HOST_DEPENDS", NULL
, &pkg_host_depends
)) == 0)
579 if ((parse_var(buf
, "PKG_ARCH_DEPENDS", NULL
, &pkg_arch_depends
)) == 0)
581 if ((parse_var(buf
, "PKG_SYSTEM_DEPENDS", NULL
, &pkg_system_depends
)) == 0)
583 if ((parse_var(buf
, "PKG_DESCR", NULL
, &pkg_descr
)) == 0)
585 if ((parse_var(buf
, "PKG_SECTION", NULL
, &pkg_section
)) == 0)
587 if ((parse_var(buf
, "PKG_URL", NULL
, &pkg_url
)) == 0)
589 if ((parse_var(buf
, "PKG_BB", NULL
, &pkg_bb
)) == 0)
591 if ((parse_var(buf
, "PKG_DEPENDS", pkg_depends
, &pkg_depends
)) == 0)
593 if ((parse_var(buf
, "PKG_KDEPENDS", pkg_kdepends
, &pkg_kdepends
)) == 0)
595 if ((parse_var(buf
, "PKG_NEEDS", pkg_needs
, &pkg_needs
)) == 0)
597 if ((parse_var_with_system(buf
, "PKG_DEPENDS_", pkg_depends_system
, &pkg_depends_system
, &sysname
, 12)) == 0)
599 if ((parse_var_with_system(buf
, "PKG_DEPENDS_", pkg_depends_libc
, &pkg_depends_libc
, &sysname
, 12)) == 0)
601 if ((parse_var(buf
, "PKG_LIBNAME", pkg_libname
, &pkg_libname
)) == 0)
603 if ((parse_var(buf
, "PKG_OPTS", pkg_opts
, &pkg_opts
)) == 0)
605 if ((parse_var_with_pkg(buf
, "PKG_FLAVOURS_STRING_", pkg_flavours_string
, &pkg_flavours_string
, &pkgname
, 20)) == 0)
607 if ((parse_var_with_pkg(buf
, "PKG_FLAVOURS_", pkg_flavours
, &pkg_flavours
, &pkgname
, 13)) == 0)
609 if ((parse_var_hash(buf
, "PKGFD_", pkgmap
)) == 0)
611 if ((parse_var_hash(buf
, "PKGFX_", pkgmap
)) == 0)
613 if ((parse_var_hash(buf
, "PKGFS_", pkgmap
)) == 0)
615 if ((parse_var_hash(buf
, "PKGFC_", pkgmap
)) == 0)
617 if ((parse_var_with_pkg(buf
, "PKG_CHOICES_", pkg_choices
, &pkg_choices
, &pkgname
, 12)) == 0)
619 if ((parse_var_hash(buf
, "PKGCD_", pkgmap
)) == 0)
621 if ((parse_var_hash(buf
, "PKGCS_", pkgmap
)) == 0)
623 if ((parse_var(buf
, "PKG_SUBPKGS", pkg_subpkgs
, &pkg_subpkgs
)) == 0)
625 if ((parse_var_hash(buf
, "PKGSD_", pkgmap
)) == 0)
627 if ((parse_var_hash(buf
, "PKGSS_", pkgmap
)) == 0)
629 if ((parse_var_hash(buf
, "PKGSC_", pkgmap
)) == 0)
631 if ((parse_var_hash(buf
, "PKGSK_", pkgmap
)) == 0)
633 if ((parse_var_hash(buf
, "PKGSN_", pkgmap
)) == 0)
638 /* when PKG_LIBNAME exist use this instead of PKG_NAME, but only for !libmix */
639 if (pkg_libname
!= NULL
)
640 if (pkg_opts
!= NULL
)
641 if (strstr(pkg_opts
, "libmix") == NULL
)
642 pkg_name
= strdup(pkg_libname
);
644 /* end of package Makefile parsing */
645 if (fclose(pkg
) != 0)
646 perror("Failed to close file stream for Makefile");
649 if (pkg_name
!= NULL
)
650 fprintf(stderr
, "Package name is %s\n", pkg_name
);
651 if (pkg_libname
!= NULL
)
652 fprintf(stderr
, "Package library name is %s\n", pkg_libname
);
653 if (pkg_section
!= NULL
)
654 fprintf(stderr
, "Package section is %s\n", pkg_section
);
655 if (pkg_descr
!= NULL
)
656 fprintf(stderr
, "Package description is %s\n", pkg_descr
);
657 if (pkg_depends
!= NULL
)
658 fprintf(stderr
, "Package dependencies are %s\n", pkg_depends
);
659 if (pkg_needs
!= NULL
)
660 fprintf(stderr
, "Package needing %s\n", pkg_needs
);
661 if (pkg_depends_system
!= NULL
)
662 fprintf(stderr
, "Package systemspecific dependencies are %s\n", pkg_depends_system
);
663 if (pkg_subpkgs
!= NULL
)
664 fprintf(stderr
, "Package subpackages are %s\n", pkg_subpkgs
);
665 if (pkg_flavours
!= NULL
&& pkgname
!= NULL
)
666 fprintf(stderr
, "Package flavours for %s are %s\n", pkgname
, pkg_flavours
);
667 if (pkg_flavours_string
!= NULL
&& pkgname
!= NULL
)
668 fprintf(stderr
, "Package string flavours for %s are %s\n", pkgname
, pkg_flavours_string
);
669 if (pkg_choices
!= NULL
&& pkgname
!= NULL
)
670 fprintf(stderr
, "Package choices for %s are %s\n", pkgname
, pkg_choices
);
672 fprintf(stderr
, "Package homepage is %s\n", pkg_url
);
673 if (pkg_cfline
!= NULL
)
674 fprintf(stderr
, "Package cfline is %s\n", pkg_cfline
);
675 if (pkg_opts
!= NULL
)
676 fprintf(stderr
, "Package options are %s\n", pkg_opts
);
678 strmap_enum(pkgmap
, iter_debug
, NULL
);
681 /* generate master source Config.in file */
682 if (snprintf(path
, MAXPATH
, "package/pkgconfigs.d/%s/Config.in", pkgdirp
->d_name
) < 0)
683 fatal_error("path variable creation failed.");
684 fprintf(menuglobal
, "source \"%s\"\n", path
);
685 /* recreating file is faster than truncating with w+ */
687 cfg
= fopen(path
, "w");
692 if (pkg_subpkgs
!= NULL
)
693 pkgs
= strdup(pkg_subpkgs
);
695 fprintf(cfg
, "config ADK_COMPILE_%s\n", toupperstr(pkgdirp
->d_name
));
696 fprintf(cfg
, "\tboolean\n");
697 if (nobinpkgs
== 0) {
698 fprintf(cfg
, "\tdepends on ");
700 token
= strtok(pkgs
, " ");
701 fprintf(cfg
, "ADK_PACKAGE_%s", token
);
702 token
= strtok(NULL
, " ");
703 while (token
!= NULL
) {
704 fprintf(cfg
, " || ADK_PACKAGE_%s", token
);
705 token
= strtok(NULL
, " ");
709 fprintf(cfg
, "ADK_PACKAGE_%s\n", toupperstr(pkg_name
));
712 fprintf(cfg
, "\tdefault n\n");
716 /* skip packages without binary package output */
720 /* generate binary package specific Config.in files */
721 if (pkg_subpkgs
!= NULL
)
722 packages
= tolowerstr(pkg_subpkgs
);
724 packages
= strdup(pkg_name
);
726 token
= strtok_r(packages
, " ", &p_ptr
);
727 while (token
!= NULL
) {
728 strncat(hkey
, "PKGSC_", 6);
729 strncat(hkey
, toupperstr(token
), strlen(token
));
730 memset(hvalue
, 0 , MAXVALUE
);
731 result
= strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
732 memset(hkey
, 0 , MAXVAR
);
734 pkg_section
= strdup(hvalue
);
736 strncat(hkey
, "PKGSD_", 6);
737 strncat(hkey
, toupperstr(token
), strlen(token
));
738 memset(hvalue
, 0 , MAXVALUE
);
739 result
= strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
740 memset(hkey
, 0 , MAXVAR
);
742 pkg_descr
= strdup(hvalue
);
744 pseudo_name
= malloc(MAXLINE
);
745 memset(pseudo_name
, 0, MAXLINE
);
746 strncat(pseudo_name
, token
, strlen(token
));
747 while (strlen(pseudo_name
) < 23)
748 strncat(pseudo_name
, ".", 1);
750 if (snprintf(path
, MAXPATH
, "package/pkgconfigs.d/%s/Config.in.%s", pkgdirp
->d_name
, token
) < 0)
751 fatal_error("failed to create path variable.");
753 /* create temporary section files */
754 memset(hvalue
, 0 , MAXVALUE
);
755 result
= strmap_get(sectionmap
, pkg_section
, hvalue
, sizeof(hvalue
));
757 if (snprintf(spath
, MAXPATH
, "package/pkglist.d/sectionlst.%d", hash_str(hvalue
)) < 0)
758 fatal_error("failed to create path variable.");
759 section
= fopen(spath
, "a");
760 if (section
!= NULL
) {
761 fprintf(section
, "%s |%s\n", token
, pkgdirp
->d_name
);
765 fatal_error("Can not find section description for package %s.", pkgdirp
->d_name
);
768 cfg
= fopen(path
, "w");
770 perror("Can not open Config.in file");
772 if (pkg_bb
!= NULL
) {
773 fprintf(cfg
, "comment \"%s... %s (provided by busybox)\"\n", token
, pkg_descr
);
774 fprintf(cfg
, "depends on ADK_PACKAGE_BUSYBOX_HIDE\n\n");
777 /* save token in pkg_debug */
778 pkg_debug
= strdup(token
);
779 fprintf(cfg
, "config ADK_PACKAGE_%s\n", toupperstr(token
));
780 /* no prompt for devonly packages */
781 if (pkg_opts
!= NULL
) {
782 if (strstr(pkg_opts
, "devonly") != NULL
) {
783 fprintf(cfg
, "\t#prompt \"%s. %s\"\n", pseudo_name
, pkg_descr
);
785 fprintf(cfg
, "\tprompt \"%s. %s\"\n", pseudo_name
, pkg_descr
);
788 fprintf(cfg
, "\tprompt \"%s. %s\"\n", pseudo_name
, pkg_descr
);
791 fprintf(cfg
, "\tbool\n");
794 /* print custom cf line */
795 if (pkg_cfline
!= NULL
) {
796 cftoken
= strtok_r(pkg_cfline
, "@", &saveptr
);
797 while (cftoken
!= NULL
) {
798 fprintf(cfg
, "\t%s\n", cftoken
);
799 cftoken
= strtok_r(NULL
, "@", &saveptr
);
805 /* add sub package dependencies */
806 strncat(hkey
, "PKGSN_", 6);
807 strncat(hkey
, toupperstr(token
), strlen(token
));
808 memset(hvalue
, 0, MAXVALUE
);
809 result
= strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
811 val
= strtok_r(hvalue
, " ", &saveptr
);
812 while (val
!= NULL
) {
813 fprintf(cfg
, "\tdepends on ADK_PACKAGE_%s\n", toupperstr(val
));
814 val
= strtok_r(NULL
, " ", &saveptr
);
817 memset(hkey
, 0, MAXVAR
);
819 /* add sub package auto selections */
820 strncat(hkey
, "PKGSS_", 6);
821 strncat(hkey
, toupperstr(token
), strlen(token
));
822 memset(hvalue
, 0, MAXVALUE
);
823 result
= strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
825 val
= strtok_r(hvalue
, " ", &saveptr
);
826 while (val
!= NULL
) {
827 fprintf(cfg
, "\tselect ADK_PACKAGE_%s\n", toupperstr(val
));
828 val
= strtok_r(NULL
, " ", &saveptr
);
831 memset(hkey
, 0, MAXVAR
);
833 /* add sub package kernel selections */
834 strncat(hkey
, "PKGSK_", 6);
835 strncat(hkey
, toupperstr(token
), strlen(token
));
836 memset(hvalue
, 0, MAXVALUE
);
837 result
= strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
839 val
= strtok_r(hvalue
, " ", &saveptr
);
840 while (val
!= NULL
) {
841 fprintf(cfg
, "\tselect ADK_LINUX_KERNEL_%s\n", toupperstr(val
));
842 val
= strtok_r(NULL
, " ", &saveptr
);
845 memset(hkey
, 0, MAXVAR
);
847 /* create package target system dependency information */
848 if (pkg_system_depends
!= NULL
) {
849 pkg_helper
= strdup(pkg_system_depends
);
850 token
= strtok(pkg_helper
, " ");
851 fprintf(cfg
, "\tdepends on ");
853 while (token
!= NULL
) {
854 if(strncmp(token
, "!", 1) == 0) {
855 fprintf(cfg
, "%s!ADK_TARGET_SYSTEM%s", sp
, toupperstr(token
));
858 fprintf(cfg
, "%sADK_TARGET_SYSTEM_%s", sp
, toupperstr(token
));
861 token
= strtok(NULL
, " ");
867 /* create package host dependency information */
868 if (pkg_host_depends
!= NULL
) {
869 pkg_helper
= strdup(pkg_host_depends
);
870 token
= strtok(pkg_helper
, " ");
871 fprintf(cfg
, "\tdepends on ");
873 while (token
!= NULL
) {
874 if(strncmp(token
, "!", 1) == 0) {
875 fprintf(cfg
, "%s!ADK_HOST%s", sp
, toupperstr(token
));
878 fprintf(cfg
, "%sADK_HOST_%s", sp
, toupperstr(token
));
881 token
= strtok(NULL
, " ");
888 /* create package libc dependency information */
889 if (pkg_libc_depends
!= NULL
) {
890 pkg_helper
= strdup(pkg_libc_depends
);
891 token
= strtok(pkg_helper
, " ");
892 fprintf(cfg
, "\tdepends on ");
894 while (token
!= NULL
) {
895 if(strncmp(token
, "!", 1) == 0) {
896 fprintf(cfg
, "%s!ADK_TARGET_LIB_%s", sp
, toupperstr(token
));
899 fprintf(cfg
, "%sADK_TARGET_LIB_%s", sp
, toupperstr(token
));
902 token
= strtok(NULL
, " ");
908 /* create package target architecture dependency information */
909 if (pkg_arch_depends
!= NULL
) {
910 pkg_helper
= strdup(pkg_arch_depends
);
911 token
= strtok(pkg_helper
, " ");
912 fprintf(cfg
, "\tdepends on ");
914 while (token
!= NULL
) {
915 if(strncmp(token
, "!", 1) == 0) {
916 fprintf(cfg
, "%s!ADK_TARGET_ARCH%s", sp
, toupperstr(token
));
919 fprintf(cfg
, "%sADK_TARGET_ARCH_%s", sp
, toupperstr(token
));
922 token
= strtok(NULL
, " ");
929 /* create needs dependency information */
930 if (pkg_needs
!= NULL
) {
931 token
= strtok(pkg_needs
, " ");
932 while (token
!= NULL
) {
933 if (strncmp(token
, "c++", 3) == 0) {
934 fprintf(cfg
, "\tselect ADK_TOOLCHAIN_WITH_CXX\n");
935 fprintf(cfg
, "\tselect ADK_PACKAGE_LIBSTDCXX\n");
937 if (strncmp(token
, "iconv", 5) == 0)
938 fprintf(cfg
, "\tselect ADK_TARGET_LIBC_WITH_LIBICONV if ADK_TARGET_LIB_UCLIBC_NG && !ADK_PACKAGE_LIBICONV\n");
939 if (strncmp(token
, "intl", 4) == 0)
940 fprintf(cfg
, "\tselect ADK_TARGET_LIBC_WITH_LIBINTL if ADK_TARGET_LIB_UCLIBC_NG\n");
941 if (strncmp(token
, "locale", 6) == 0)
942 fprintf(cfg
, "\tselect ADK_TARGET_LIBC_WITH_LOCALE if ADK_TARGET_LIB_UCLIBC_NG\n");
943 if (strncmp(token
, "threads", 7) == 0)
944 fprintf(cfg
, "\tselect ADK_TARGET_LIB_WITH_THREADS\n");
945 if (strncmp(token
, "data", 4) == 0)
946 fprintf(cfg
, "\tselect ADK_RUNTIME_DATA_PARTITION\n");
947 if (strncmp(token
, "mmu", 3) == 0)
948 fprintf(cfg
, "\tdepends on ADK_TARGET_WITH_MMU\n");
949 token
= strtok(NULL
, " ");
955 /* create package dependency information */
956 if (pkg_depends
!= NULL
) {
957 token
= strtok(pkg_depends
, " ");
958 while (token
!= NULL
) {
959 fprintf(cfg
, "\tselect ADK_PACKAGE_%s\n", toupperstr(token
));
960 token
= strtok(NULL
, " ");
965 /* create kernel package dependency information */
966 if (pkg_kdepends
!= NULL
) {
967 token
= strtok(pkg_kdepends
, " ");
968 while (token
!= NULL
) {
969 fprintf(cfg
, "\tselect ADK_LINUX_KERNEL_%s m if ADK_TARGET_OS_LINUX\n", toupperstr(token
));
970 token
= strtok(NULL
, " ");
975 /* create system specific package dependency information */
976 if (pkg_depends_system
!= NULL
) {
977 token
= strtok(pkg_depends_system
, " ");
978 while (token
!= NULL
) {
979 fprintf(cfg
, "\tselect ADK_PACKAGE_%s if ADK_TARGET_SYSTEM_%s\n", toupperstr(token
), sysname
);
980 token
= strtok(NULL
, " ");
982 free(pkg_depends_system
);
983 pkg_depends_system
= NULL
;
985 /* create libc specific package dependency information */
986 if (pkg_depends_libc
!= NULL
) {
987 token
= strtok(pkg_depends_libc
, " ");
988 while (token
!= NULL
) {
989 fprintf(cfg
, "\tselect ADK_PACKAGE_%s if ADK_TARGET_LIB_%s\n", toupperstr(token
), sysname
);
990 token
= strtok(NULL
, " ");
992 free(pkg_depends_libc
);
993 pkg_depends_libc
= NULL
;
996 if (pkg_bb
!= NULL
) {
997 fprintf(cfg
, "\tdepends on !ADK_PACKAGE_BUSYBOX_HIDE\n");
999 fprintf(cfg
, "\tselect ADK_COMPILE_%s\n", toupperstr(pkgdirp
->d_name
));
1001 if (pkg_dflt
!= NULL
) {
1002 fprintf(cfg
, "\tdefault %s\n", pkg_dflt
);
1005 fprintf(cfg
, "\tdefault n\n");
1008 fprintf(cfg
, "\thelp\n");
1009 fprintf(cfg
, "\t %s\n\n", pkg_descr
);
1010 if (pkg_url
!= NULL
)
1011 fprintf(cfg
, "\t WWW: %s\n", pkg_url
);
1013 /* handle debug subpackages */
1014 fprintf(cfg
, "\nconfig ADK_PACKAGE_%s_DBG\n", toupperstr(pkg_debug
));
1015 fprintf(cfg
, "\tbool \"add debug symbols package\"\n");
1016 fprintf(cfg
, "\tdepends on ADK_PACKAGE_GDB && ADK_BUILD_WITH_DEBUG\n");
1017 fprintf(cfg
, "\tdepends on ADK_DEBUG\n");
1018 fprintf(cfg
, "\tdepends on ADK_PACKAGE_%s\n", toupperstr(pkg_debug
));
1019 fprintf(cfg
, "\tdefault n\n");
1020 fprintf(cfg
, "\thelp\n\n");
1022 /* package flavours */
1023 if (pkg_flavours
!= NULL
) {
1024 token
= strtok(pkg_flavours
, " ");
1025 while (token
!= NULL
) {
1026 fprintf(cfg
, "\nconfig ADK_PACKAGE_%s_%s\n", pkgname
, toupperstr(token
));
1028 // process default value
1029 strncat(hkey
, "PKGFX_", 6);
1030 strncat(hkey
, token
, strlen(token
));
1031 memset(hvalue
, 0 , MAXVALUE
);
1032 strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
1033 memset(hkey
, 0 , MAXVAR
);
1034 pkg_fd
= strdup(hvalue
);
1035 if (strlen(pkg_fd
) > 0)
1036 fprintf(cfg
, "\tdefault %s\n", pkg_fd
);
1038 fprintf(cfg
, "\tdefault n\n");
1041 // process flavour cfline
1042 strncat(hkey
, "PKGFC_", 6);
1043 strncat(hkey
, token
, strlen(token
));
1044 memset(hvalue
, 0 , MAXVALUE
);
1045 strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
1046 memset(hkey
, 0 , MAXVAR
);
1047 pkg_fd
= strdup(hvalue
);
1048 if (strlen(pkg_fd
) > 0)
1049 fprintf(cfg
, "\t%s\n", pkg_fd
);
1051 fprintf(cfg
, "\tboolean ");
1052 strncat(hkey
, "PKGFD_", 6);
1053 strncat(hkey
, token
, strlen(token
));
1054 memset(hvalue
, 0 , MAXVALUE
);
1055 strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
1056 memset(hkey
, 0 , MAXVAR
);
1057 pkg_fd
= strdup(hvalue
);
1059 fprintf(cfg
, "\"%s\"\n", pkg_fd
);
1060 fprintf(cfg
, "\tdepends on ADK_PACKAGE_%s\n", pkgname
);
1061 strncat(hkey
, "PKGFS_", 6);
1062 strncat(hkey
, token
, strlen(token
));
1064 result
= strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
1066 val
= strtok_r(hvalue
, " ", &saveptr
);
1067 while (val
!= NULL
) {
1068 fprintf(cfg
, "\tselect ADK_PACKAGE_%s\n", toupperstr(val
));
1069 val
= strtok_r(NULL
, " ", &saveptr
);
1072 memset(hkey
, 0, MAXVAR
);
1073 fprintf(cfg
, "\thelp\n");
1074 fprintf(cfg
, "\t %s\n", pkg_fd
);
1075 token
= strtok(NULL
, " ");
1078 pkg_flavours
= NULL
;
1081 /* package flavours string */
1082 if (pkg_flavours_string
!= NULL
) {
1083 token
= strtok(pkg_flavours_string
, " ");
1084 while (token
!= NULL
) {
1085 fprintf(cfg
, "\nconfig ADK_PACKAGE_%s_%s\n", pkgname
, toupperstr(token
));
1087 // process default value
1088 strncat(hkey
, "PKGFX_", 6);
1089 strncat(hkey
, token
, strlen(token
));
1090 memset(hvalue
, 0 , MAXVALUE
);
1091 strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
1092 memset(hkey
, 0 , MAXVAR
);
1093 pkg_fd
= strdup(hvalue
);
1094 if (strlen(pkg_fd
) > 0)
1095 fprintf(cfg
, "\tdefault \"%s\"\n", pkg_fd
);
1097 // process flavour cfline
1098 strncat(hkey
, "PKGFC_", 6);
1099 strncat(hkey
, token
, strlen(token
));
1100 memset(hvalue
, 0 , MAXVALUE
);
1101 strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
1102 memset(hkey
, 0 , MAXVAR
);
1103 pkg_fd
= strdup(hvalue
);
1104 if (strlen(pkg_fd
) > 0)
1105 fprintf(cfg
, "\t%s\n", pkg_fd
);
1107 fprintf(cfg
, "\tstring ");
1108 strncat(hkey
, "PKGFD_", 6);
1109 strncat(hkey
, token
, strlen(token
));
1110 memset(hvalue
, 0 , MAXVALUE
);
1111 strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
1112 memset(hkey
, 0 , MAXVAR
);
1113 pkg_fd
= strdup(hvalue
);
1114 fprintf(cfg
, "\"%s\"\n", pkg_fd
);
1116 fprintf(cfg
, "\tdepends on ADK_PACKAGE_%s\n", pkgname
);
1117 strncat(hkey
, "PKGFS_", 6);
1118 strncat(hkey
, token
, strlen(token
));
1120 result
= strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
1122 val
= strtok_r(hvalue
, " ", &saveptr
);
1123 while (val
!= NULL
) {
1124 fprintf(cfg
, "\tselect ADK_PACKAGE_%s\n", toupperstr(val
));
1125 val
= strtok_r(NULL
, " ", &saveptr
);
1128 memset(hkey
, 0, MAXVAR
);
1129 fprintf(cfg
, "\thelp\n");
1130 fprintf(cfg
, "\t %s\n", pkg_fd
);
1131 token
= strtok(NULL
, " ");
1133 free(pkg_flavours_string
);
1134 pkg_flavours_string
= NULL
;
1137 /* package choices */
1138 if (pkg_choices
!= NULL
) {
1139 fprintf(cfg
, "\nchoice\n");
1140 fprintf(cfg
, "prompt \"Package flavour choice\"\n");
1141 fprintf(cfg
, "depends on ADK_PACKAGE_%s\n\n", pkgname
);
1142 token
= strtok(pkg_choices
, " ");
1143 while (token
!= NULL
) {
1144 fprintf(cfg
, "config ADK_PACKAGE_%s_%s\n", pkgname
, toupperstr(token
));
1146 fprintf(cfg
, "\tbool ");
1147 strncat(hkey
, "PKGCD_", 6);
1148 strncat(hkey
, token
, strlen(token
));
1149 memset(hvalue
, 0 , MAXVALUE
);
1150 strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
1151 memset(hkey
, 0 , MAXVAR
);
1152 fprintf(cfg
, "\"%s\"\n", hvalue
);
1154 strncat(hkey
, "PKGCS_", 6);
1155 strncat(hkey
, token
, strlen(token
));
1156 memset(hvalue
, 0, MAXVALUE
);
1157 result
= strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
1159 val
= strtok_r(hvalue
, " ", &saveptr
);
1160 while (val
!= NULL
) {
1161 fprintf(cfg
, "\tselect ADK_PACKAGE_%s\n", toupperstr(val
));
1162 val
= strtok_r(NULL
, " ", &saveptr
);
1165 memset(hkey
, 0, MAXVAR
);
1166 token
= strtok(NULL
, " ");
1168 fprintf(cfg
, "\nendchoice\n");
1172 /* close file descriptor for Config.in file */
1174 /* create Config.in files for development packages */
1175 if (pkg_opts
!= NULL
) {
1176 if (strstr(pkg_opts
, "dev") != NULL
) {
1177 if (snprintf(path
, MAXPATH
, "package/pkgconfigs.d/gcc/Config.in.dev") < 0)
1178 fatal_error("failed to create path variable.");
1179 cfg
= fopen(path
, "a");
1181 perror("Can not open Config.in.dev file");
1183 if (pkg_libname
== NULL
)
1184 pkg_libname
= strdup(pkg_name
);
1187 fprintf(cfg
, "config ADK_PACKAGE_%s_DEV\n", toupperstr(pkg_libname
));
1189 pseudo_name
= malloc(MAXLINE
);
1190 memset(pseudo_name
, 0, MAXLINE
);
1191 strncat(pseudo_name
, pkg_libname
, strlen(pkg_libname
));
1192 strncat(pseudo_name
, "-dev", 4);
1193 while (strlen(pseudo_name
) < 20)
1194 strncat(pseudo_name
, ".", 1);
1196 fprintf(cfg
, "\tprompt \"%s. development files for %s\"\n", pseudo_name
, pkg_libname
);
1197 fprintf(cfg
, "\tboolean\n");
1199 /* create package target architecture dependency information */
1200 if (pkg_arch_depends
!= NULL
) {
1201 pkg_helper
= strdup(pkg_arch_depends
);
1202 token
= strtok(pkg_helper
, " ");
1203 fprintf(cfg
, "\tdepends on ");
1205 while (token
!= NULL
) {
1206 if(strncmp(token
, "!", 1) == 0) {
1207 fprintf(cfg
, "%s!ADK_TARGET_ARCH%s", sp
, toupperstr(token
));
1210 fprintf(cfg
, "%sADK_TARGET_ARCH_%s", sp
, toupperstr(token
));
1213 token
= strtok(NULL
, " ");
1220 fprintf(cfg
, "\tdepends on ADK_PACKAGE_GCC && ADK_PACKAGE_%s\n", toupperstr(pkg_libname
));
1221 fprintf(cfg
, "\tdefault n\n");
1229 /* parse next package */
1230 token
= strtok_r(NULL
, " ", &p_ptr
);
1233 /* end of package output generation */
1237 /* reset flags, free memory */
1246 free(pkg_flavours_string
);
1249 free(pkg_arch_depends
);
1250 free(pkg_system_depends
);
1251 free(pkg_host_depends
);
1252 free(pkg_libc_depends
);
1262 pkg_kdepends
= NULL
;
1263 pkg_flavours
= NULL
;
1264 pkg_flavours_string
= NULL
;
1267 pkg_arch_depends
= NULL
;
1268 pkg_system_depends
= NULL
;
1269 pkg_host_depends
= NULL
;
1270 pkg_libc_depends
= NULL
;
1275 strmap_delete(pkgmap
);
1281 /* add menu to gcc package */
1282 if (snprintf(path
, MAXPATH
, "package/pkgconfigs.d/gcc/Config.in.gcc") < 0)
1283 fatal_error("failed to create path variable.");
1284 cfg
= fopen(path
, "a");
1286 perror("Can not open Config.in.gcc file");
1287 fprintf(cfg
, "menu \"Development packages\"\n");
1288 fprintf(cfg
, "depends on ADK_PACKAGE_GCC\n");
1289 fprintf(cfg
, "source \"package/pkgconfigs.d/gcc/Config.in.dev\"\n");
1290 fprintf(cfg
, "endmenu\n");
1293 /* create Config.in.auto */
1294 strmap_enum(sectionmap
, iter
, NULL
);
1296 strmap_delete(sectionmap
);
1300 /* remove temporary section files */
1301 pkglistdir
= opendir("package/pkglist.d");
1302 while ((pkgdirp
= readdir(pkglistdir
)) != NULL
) {
1303 if (strncmp(pkgdirp
->d_name
, "sectionlst.", 11) == 0) {
1304 if (snprintf(path
, MAXPATH
, "package/pkglist.d/%s", pkgdirp
->d_name
) < 0)
1305 fatal_error("creating path variable failed.");
1306 if (unlink(path
) < 0)
1307 fatal_error("removing file failed.");
1311 closedir(pkglistdir
);