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/>.
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_kdepends
, *pkg_needs
, *pkg_depends_system
, *pkg_depends_libc
, *pkg_section
, *pkg_descr
, *pkg_url
;
331 char *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";
347 pkg_depends_system
= NULL
;
348 pkg_depends_libc
= NULL
;
352 pkg_flavours_string
= NULL
;
355 pkg_arch_depends
= NULL
;
356 pkg_system_depends
= NULL
;
357 pkg_host_depends
= NULL
;
358 pkg_libc_depends
= NULL
;
370 system("rm package/Config.in.auto.* 2>/dev/null");
372 /* open global sectionfile */
373 menuglobal
= fopen("package/Config.in.auto.global", "w");
374 if (menuglobal
== NULL
)
375 fatal_error("global section file not writable.");
377 /* read section list and create a hash table */
378 section
= fopen("package/section.lst", "r");
380 fatal_error("section listfile is missing");
382 sectionmap
= strmap_new(HASHSZ
);
383 while (fgets(tbuf
, MAXPATH
, section
) != NULL
) {
384 key
= strtok(tbuf
, "\t");
385 value
= strtok(NULL
, "\t");
386 strmap_put(sectionmap
, key
, value
);
390 if (mkdir("package/pkgconfigs.d", S_IRWXU
) > 0)
391 fatal_error("creation of package/pkgconfigs.d failed.");
392 if (mkdir("package/pkgconfigs.d/gcc", S_IRWXU
) > 0)
393 fatal_error("creation of package/pkgconfigs.d/gcc failed.");
394 if (mkdir("package/pkglist.d", S_IRWXU
) > 0)
395 fatal_error("creation of package/pkglist.d failed.");
397 /* delete Config.in.dev */
398 if (snprintf(path
, MAXPATH
, "package/pkgconfigs.d/gcc/Config.in.dev") < 0)
399 fatal_error("failed to create path variable.");
401 cfg
= fopen(path
, "w");
403 fatal_error("Config.in.dev can not be opened");
404 fprintf(cfg
, "config ADK_PACKAGE_GLIBC_DEV\n");
405 fprintf(cfg
, "\tprompt \"glibc-dev............ development files for glibc\"\n");
406 fprintf(cfg
, "\tboolean\n");
407 fprintf(cfg
, "\tdefault n\n");
408 fprintf(cfg
, "\tdepends on ADK_TARGET_LIB_GLIBC\n");
409 fprintf(cfg
, "\thelp\n");
410 fprintf(cfg
, "\t GNU C library header files.\n\n");
411 fprintf(cfg
, "config ADK_PACKAGE_UCLIBC_NG_DEV\n");
412 fprintf(cfg
, "\tprompt \"uclibc-ng-dev........ development files for uclibc-ng\"\n");
413 fprintf(cfg
, "\tboolean\n");
414 fprintf(cfg
, "\tdefault n\n");
415 fprintf(cfg
, "\tdepends on ADK_TARGET_LIB_UCLIBC_NG\n");
416 fprintf(cfg
, "\thelp\n");
417 fprintf(cfg
, "\t C library header files.\n\n");
418 fprintf(cfg
, "config ADK_PACKAGE_MUSL_DEV\n");
419 fprintf(cfg
, "\tprompt \"musl-dev............. development files for musl\"\n");
420 fprintf(cfg
, "\tboolean\n");
421 fprintf(cfg
, "\tdefault n\n");
422 fprintf(cfg
, "\tdepends on ADK_TARGET_LIB_MUSL\n");
423 fprintf(cfg
, "\thelp\n");
424 fprintf(cfg
, "\t C library header files.\n\n");
428 /* read Makefile's for all packages */
429 pkgdir
= opendir("package");
430 while ((pkgdirp
= readdir(pkgdir
)) != NULL
) {
432 if (strncmp(pkgdirp
->d_name
, ".", 1) > 0) {
433 if (snprintf(path
, MAXPATH
, "package/%s/Makefile", pkgdirp
->d_name
) < 0)
434 fatal_error("can not create path variable.");
435 pkg
= fopen(path
, "r");
439 /* runtime configuration */
440 if (snprintf(script
, MAXPATH
, "package/%s/files", pkgdirp
->d_name
) < 0)
441 fatal_error("script variable creation failed.");
442 scriptdir
= opendir(script
);
443 if (scriptdir
!= NULL
) {
444 while ((scriptdirp
= readdir(scriptdir
)) != NULL
) {
446 if (strncmp(scriptdirp
->d_name
, ".", 1) > 0) {
447 len
= strlen(scriptdirp
->d_name
);
448 if (strlen(".init") > len
)
450 if (strncmp(scriptdirp
->d_name
+ len
- strlen(".init"), ".init", strlen(".init")) == 0) {
451 if (snprintf(script
, MAXPATH
, "package/%s/files/%s", pkgdirp
->d_name
, scriptdirp
->d_name
) < 0)
452 fatal_error("script variable creation failed.");
453 initscript
= fopen(script
, "r");
454 if (initscript
== NULL
)
457 while (fgets(ibuf
, MAXPATH
, initscript
) != NULL
) {
458 if (strncmp("#PKG", ibuf
, 4) == 0) {
459 sname
= strdup(ibuf
+5);
460 sname
[strlen(sname
)-1] = '\0';
461 sname2
= strdup(scriptdirp
->d_name
);
462 sname2
[strlen(sname2
)-5] = '\0';
463 icfg
= fopen(runtime
, "a");
466 if (strncmp("busybox", sname
, 7) == 0)
467 fprintf(icfg
, "config ADK_RUNTIME_START_%s_%s\n", toupperstr(sname
), toupperstr(sname2
));
469 fprintf(icfg
, "config ADK_RUNTIME_START_%s\n", toupperstr(sname
));
470 fprintf(icfg
, "\tprompt \"Start %s on boot\"\n", sname2
);
471 fprintf(icfg
, "\ttristate\n");
472 if (strncmp("busybox", sname
, 7) == 0)
473 fprintf(icfg
, "\tdepends on BUSYBOX_%s\n", toupperstr(sname2
));
475 fprintf(icfg
, "\tdepends on ADK_PACKAGE_%s\n", toupperstr(sname
));
476 fprintf(icfg
, "\tdepends on ADK_RUNTIME_START_SERVICES\n");
477 fprintf(icfg
, "\tdefault n\n\n");
490 /* skip manually maintained packages */
491 if (snprintf(path
, MAXPATH
, "package/%s/Config.in.manual", pkgdirp
->d_name
) < 0)
492 fatal_error("can not create path variable.");
493 if (!access(path
, F_OK
)) {
494 while (fgets(buf
, MAXPATH
, pkg
) != NULL
) {
495 if ((parse_var(buf
, "PKG_SECTION", NULL
, &pkg_section
)) == 0)
499 memset(hvalue
, 0 , MAXVALUE
);
500 result
= strmap_get(sectionmap
, pkg_section
, hvalue
, sizeof(hvalue
));
502 if (snprintf(spath
, MAXPATH
, "package/pkglist.d/sectionlst.%d", hash_str(hvalue
)) < 0)
503 fatal_error("can not create path variable.");
504 section
= fopen(spath
, "a");
505 if (section
!= NULL
) {
506 fprintf(section
, "%s@\n", pkgdirp
->d_name
);
510 fatal_error("Can not find section description %s for package %s.",
511 pkg_section
, pkgdirp
->d_name
);
519 /* create output directories */
520 if (snprintf(dir
, MAXPATH
, "package/pkgconfigs.d/%s", pkgdirp
->d_name
) < 0)
521 fatal_error("can not create dir variable.");
522 if (mkdir(dir
, S_IRWXU
) > 0)
523 fatal_error("can not create directory.");
526 /* allocate memory */
527 hkey
= malloc(MAXVAR
);
528 memset(hkey
, 0, MAXVAR
);
529 memset(variable
, 0, 2*MAXVAR
);
531 pkgmap
= strmap_new(HASHSZ
);
533 /* parse package Makefile */
534 while (fgets(buf
, MAXPATH
, pkg
) != NULL
) {
535 /* just read variables prefixed with PKG */
536 if (strncmp(buf
, "PKG", 3) == 0) {
537 if ((parse_var(buf
, "PKG_NAME", NULL
, &pkg_name
)) == 0)
539 if (pkg_name
!= NULL
)
540 pkg_name_u
= toupperstr(pkg_name
);
542 pkg_name_u
= toupperstr(pkgdirp
->d_name
);
544 snprintf(variable
, MAXVAR
, "PKG_CFLINE_%s", pkg_name_u
);
545 if ((parse_var(buf
, variable
, pkg_cfline
, &pkg_cfline
)) == 0)
547 snprintf(variable
, MAXVAR
, "PKG_DFLT_%s", pkg_name_u
);
548 if ((parse_var(buf
, variable
, NULL
, &pkg_dflt
)) == 0)
550 if ((parse_var(buf
, "PKG_LIBC_DEPENDS", NULL
, &pkg_libc_depends
)) == 0)
552 if ((parse_var(buf
, "PKG_HOST_DEPENDS", NULL
, &pkg_host_depends
)) == 0)
554 if ((parse_var(buf
, "PKG_ARCH_DEPENDS", NULL
, &pkg_arch_depends
)) == 0)
556 if ((parse_var(buf
, "PKG_SYSTEM_DEPENDS", NULL
, &pkg_system_depends
)) == 0)
558 if ((parse_var(buf
, "PKG_DESCR", NULL
, &pkg_descr
)) == 0)
560 if ((parse_var(buf
, "PKG_SECTION", NULL
, &pkg_section
)) == 0)
562 if ((parse_var(buf
, "PKG_URL", NULL
, &pkg_url
)) == 0)
564 if ((parse_var(buf
, "PKG_BB", NULL
, &pkg_bb
)) == 0)
566 if ((parse_var(buf
, "PKG_DEPENDS", pkg_depends
, &pkg_depends
)) == 0)
568 if ((parse_var(buf
, "PKG_KDEPENDS", pkg_kdepends
, &pkg_kdepends
)) == 0)
570 if ((parse_var(buf
, "PKG_NEEDS", pkg_needs
, &pkg_needs
)) == 0)
572 if ((parse_var_with_system(buf
, "PKG_DEPENDS_", pkg_depends_system
, &pkg_depends_system
, &sysname
, 12)) == 0)
574 if ((parse_var_with_system(buf
, "PKG_DEPENDS_", pkg_depends_libc
, &pkg_depends_libc
, &sysname
, 12)) == 0)
576 if ((parse_var(buf
, "PKG_LIBNAME", pkg_libname
, &pkg_libname
)) == 0)
578 if ((parse_var(buf
, "PKG_OPTS", pkg_opts
, &pkg_opts
)) == 0)
580 if ((parse_var_with_pkg(buf
, "PKG_FLAVOURS_STRING_", pkg_flavours_string
, &pkg_flavours_string
, &pkgname
, 20)) == 0)
582 if ((parse_var_with_pkg(buf
, "PKG_FLAVOURS_", pkg_flavours
, &pkg_flavours
, &pkgname
, 13)) == 0)
584 if ((parse_var_hash(buf
, "PKGFD_", pkgmap
)) == 0)
586 if ((parse_var_hash(buf
, "PKGFX_", pkgmap
)) == 0)
588 if ((parse_var_hash(buf
, "PKGFS_", pkgmap
)) == 0)
590 if ((parse_var_hash(buf
, "PKGFC_", pkgmap
)) == 0)
592 if ((parse_var_with_pkg(buf
, "PKG_CHOICES_", pkg_choices
, &pkg_choices
, &pkgname
, 12)) == 0)
594 if ((parse_var_hash(buf
, "PKGCD_", pkgmap
)) == 0)
596 if ((parse_var_hash(buf
, "PKGCS_", pkgmap
)) == 0)
598 if ((parse_var(buf
, "PKG_SUBPKGS", pkg_subpkgs
, &pkg_subpkgs
)) == 0)
600 if ((parse_var_hash(buf
, "PKGSD_", pkgmap
)) == 0)
602 if ((parse_var_hash(buf
, "PKGSS_", pkgmap
)) == 0)
604 if ((parse_var_hash(buf
, "PKGSC_", pkgmap
)) == 0)
606 if ((parse_var_hash(buf
, "PKGSK_", pkgmap
)) == 0)
608 if ((parse_var_hash(buf
, "PKGSN_", pkgmap
)) == 0)
613 /* when PKG_LIBNAME exist use this instead of PKG_NAME, but only for !libmix */
614 if (pkg_libname
!= NULL
)
615 if (pkg_opts
!= NULL
)
616 if (strstr(pkg_opts
, "libmix") == NULL
)
617 pkg_name
= strdup(pkg_libname
);
619 /* end of package Makefile parsing */
620 if (fclose(pkg
) != 0)
621 perror("Failed to close file stream for Makefile");
624 if (pkg_name
!= NULL
)
625 fprintf(stderr
, "Package name is %s\n", pkg_name
);
626 if (pkg_libname
!= NULL
)
627 fprintf(stderr
, "Package library name is %s\n", pkg_libname
);
628 if (pkg_section
!= NULL
)
629 fprintf(stderr
, "Package section is %s\n", pkg_section
);
630 if (pkg_descr
!= NULL
)
631 fprintf(stderr
, "Package description is %s\n", pkg_descr
);
632 if (pkg_depends
!= NULL
)
633 fprintf(stderr
, "Package dependencies are %s\n", pkg_depends
);
634 if (pkg_needs
!= NULL
)
635 fprintf(stderr
, "Package needing %s\n", pkg_needs
);
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 (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
, "\tbool\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 /* add sub package kernel selections */
809 strncat(hkey
, "PKGSK_", 6);
810 strncat(hkey
, toupperstr(token
), strlen(token
));
811 memset(hvalue
, 0, MAXVALUE
);
812 result
= strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
814 val
= strtok_r(hvalue
, " ", &saveptr
);
815 while (val
!= NULL
) {
816 fprintf(cfg
, "\tselect ADK_KERNEL_%s\n", toupperstr(val
));
817 val
= strtok_r(NULL
, " ", &saveptr
);
820 memset(hkey
, 0, MAXVAR
);
822 /* create package target system dependency information */
823 if (pkg_system_depends
!= NULL
) {
824 pkg_helper
= strdup(pkg_system_depends
);
825 token
= strtok(pkg_helper
, " ");
826 fprintf(cfg
, "\tdepends on ");
828 while (token
!= NULL
) {
829 if(strncmp(token
, "!", 1) == 0) {
830 fprintf(cfg
, "%s!ADK_TARGET_SYSTEM%s", sp
, toupperstr(token
));
833 fprintf(cfg
, "%sADK_TARGET_SYSTEM_%s", sp
, toupperstr(token
));
836 token
= strtok(NULL
, " ");
842 /* create package host dependency information */
843 if (pkg_host_depends
!= NULL
) {
844 pkg_helper
= strdup(pkg_host_depends
);
845 token
= strtok(pkg_helper
, " ");
846 fprintf(cfg
, "\tdepends on ");
848 while (token
!= NULL
) {
849 if(strncmp(token
, "!", 1) == 0) {
850 fprintf(cfg
, "%s!ADK_HOST%s", sp
, toupperstr(token
));
853 fprintf(cfg
, "%sADK_HOST_%s", sp
, toupperstr(token
));
856 token
= strtok(NULL
, " ");
863 /* create package libc dependency information */
864 if (pkg_libc_depends
!= NULL
) {
865 pkg_helper
= strdup(pkg_libc_depends
);
866 token
= strtok(pkg_helper
, " ");
867 fprintf(cfg
, "\tdepends on ");
869 while (token
!= NULL
) {
870 if(strncmp(token
, "!", 1) == 0) {
871 fprintf(cfg
, "%s!ADK_TARGET_LIB_%s", sp
, toupperstr(token
));
874 fprintf(cfg
, "%sADK_TARGET_LIB_%s", sp
, toupperstr(token
));
877 token
= strtok(NULL
, " ");
883 /* create package target architecture dependency information */
884 if (pkg_arch_depends
!= NULL
) {
885 pkg_helper
= strdup(pkg_arch_depends
);
886 token
= strtok(pkg_helper
, " ");
887 fprintf(cfg
, "\tdepends on ");
889 while (token
!= NULL
) {
890 if(strncmp(token
, "!", 1) == 0) {
891 fprintf(cfg
, "%s!ADK_TARGET_ARCH%s", sp
, toupperstr(token
));
894 fprintf(cfg
, "%sADK_TARGET_ARCH_%s", sp
, toupperstr(token
));
897 token
= strtok(NULL
, " ");
904 /* create needs dependency information */
905 if (pkg_needs
!= NULL
) {
906 token
= strtok(pkg_needs
, " ");
907 while (token
!= NULL
) {
908 if (strncmp(token
, "c++", 3) == 0) {
909 fprintf(cfg
, "\tselect ADK_TOOLCHAIN_WITH_CXX\n");
910 fprintf(cfg
, "\tselect ADK_PACKAGE_LIBSTDCXX\n");
912 if (strncmp(token
, "iconv", 5) == 0)
913 fprintf(cfg
, "\tselect ADK_TARGET_LIBC_WITH_LIBICONV if ADK_TARGET_LIB_UCLIBC_NG\n");
914 if (strncmp(token
, "intl", 4) == 0)
915 fprintf(cfg
, "\tselect ADK_TARGET_LIBC_WITH_LIBINTL if ADK_TARGET_LIB_UCLIBC_NG\n");
916 if (strncmp(token
, "locale", 6) == 0)
917 fprintf(cfg
, "\tselect ADK_TARGET_LIBC_WITH_LOCALE if ADK_TARGET_LIB_UCLIBC_NG\n");
918 if (strncmp(token
, "threads", 7) == 0)
919 fprintf(cfg
, "\tselect ADK_TARGET_LIB_WITH_THREADS\n");
920 if (strncmp(token
, "data", 4) == 0)
921 fprintf(cfg
, "\tselect ADK_RUNTIME_DATA_PARTITION\n");
922 if (strncmp(token
, "mmu", 3) == 0)
923 fprintf(cfg
, "\tdepends on ADK_TARGET_WITH_MMU\n");
924 token
= strtok(NULL
, " ");
930 /* create package dependency information */
931 if (pkg_depends
!= NULL
) {
932 token
= strtok(pkg_depends
, " ");
933 while (token
!= NULL
) {
934 fprintf(cfg
, "\tselect ADK_PACKAGE_%s\n", toupperstr(token
));
935 token
= strtok(NULL
, " ");
940 /* create kernel package dependency information */
941 if (pkg_kdepends
!= NULL
) {
942 token
= strtok(pkg_kdepends
, " ");
943 while (token
!= NULL
) {
944 fprintf(cfg
, "\tselect ADK_KERNEL_%s m\n", toupperstr(token
));
945 token
= strtok(NULL
, " ");
950 /* create system specific package dependency information */
951 if (pkg_depends_system
!= NULL
) {
952 token
= strtok(pkg_depends_system
, " ");
953 while (token
!= NULL
) {
954 fprintf(cfg
, "\tselect ADK_PACKAGE_%s if ADK_TARGET_SYSTEM_%s\n", toupperstr(token
), sysname
);
955 token
= strtok(NULL
, " ");
957 free(pkg_depends_system
);
958 pkg_depends_system
= NULL
;
960 /* create libc specific package dependency information */
961 if (pkg_depends_libc
!= NULL
) {
962 token
= strtok(pkg_depends_libc
, " ");
963 while (token
!= NULL
) {
964 fprintf(cfg
, "\tselect ADK_PACKAGE_%s if ADK_TARGET_LIB_%s\n", toupperstr(token
), sysname
);
965 token
= strtok(NULL
, " ");
967 free(pkg_depends_libc
);
968 pkg_depends_libc
= NULL
;
971 if (pkg_bb
!= NULL
) {
972 fprintf(cfg
, "\tdepends on !ADK_PACKAGE_BUSYBOX_HIDE\n");
974 fprintf(cfg
, "\tselect ADK_COMPILE_%s\n", toupperstr(pkgdirp
->d_name
));
976 if (pkg_dflt
!= NULL
) {
977 fprintf(cfg
, "\tdefault %s\n", pkg_dflt
);
980 fprintf(cfg
, "\tdefault n\n");
983 fprintf(cfg
, "\thelp\n");
984 fprintf(cfg
, "\t %s\n\n", pkg_descr
);
986 fprintf(cfg
, "\t WWW: %s\n", pkg_url
);
988 /* handle debug subpackages */
989 fprintf(cfg
, "\nconfig ADK_PACKAGE_%s_DBG\n", toupperstr(pkg_debug
));
990 fprintf(cfg
, "\tbool \"add debug symbols package\"\n");
991 fprintf(cfg
, "\tdepends on ADK_PACKAGE_GDB && ADK_BUILD_WITH_DEBUG\n");
992 fprintf(cfg
, "\tdepends on ADK_DEBUG\n");
993 fprintf(cfg
, "\tdepends on ADK_PACKAGE_%s\n", toupperstr(pkg_debug
));
994 fprintf(cfg
, "\tdefault n\n");
995 fprintf(cfg
, "\thelp\n\n");
997 /* package flavours */
998 if (pkg_flavours
!= NULL
) {
999 token
= strtok(pkg_flavours
, " ");
1000 while (token
!= NULL
) {
1001 fprintf(cfg
, "\nconfig ADK_PACKAGE_%s_%s\n", pkgname
, toupperstr(token
));
1003 // process default value
1004 strncat(hkey
, "PKGFX_", 6);
1005 strncat(hkey
, token
, strlen(token
));
1006 memset(hvalue
, 0 , MAXVALUE
);
1007 strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
1008 memset(hkey
, 0 , MAXVAR
);
1009 pkg_fd
= strdup(hvalue
);
1010 if (strlen(pkg_fd
) > 0)
1011 fprintf(cfg
, "\tdefault %s\n", pkg_fd
);
1013 fprintf(cfg
, "\tdefault n\n");
1016 // process flavour cfline
1017 strncat(hkey
, "PKGFC_", 6);
1018 strncat(hkey
, token
, strlen(token
));
1019 memset(hvalue
, 0 , MAXVALUE
);
1020 strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
1021 memset(hkey
, 0 , MAXVAR
);
1022 pkg_fd
= strdup(hvalue
);
1023 if (strlen(pkg_fd
) > 0)
1024 fprintf(cfg
, "\t%s\n", pkg_fd
);
1026 fprintf(cfg
, "\tboolean ");
1027 strncat(hkey
, "PKGFD_", 6);
1028 strncat(hkey
, token
, strlen(token
));
1029 memset(hvalue
, 0 , MAXVALUE
);
1030 strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
1031 memset(hkey
, 0 , MAXVAR
);
1032 pkg_fd
= strdup(hvalue
);
1034 fprintf(cfg
, "\"%s\"\n", pkg_fd
);
1035 fprintf(cfg
, "\tdepends on ADK_PACKAGE_%s\n", pkgname
);
1036 strncat(hkey
, "PKGFS_", 6);
1037 strncat(hkey
, token
, strlen(token
));
1039 result
= strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
1041 val
= strtok_r(hvalue
, " ", &saveptr
);
1042 while (val
!= NULL
) {
1043 fprintf(cfg
, "\tselect ADK_PACKAGE_%s\n", toupperstr(val
));
1044 val
= strtok_r(NULL
, " ", &saveptr
);
1047 memset(hkey
, 0, MAXVAR
);
1048 fprintf(cfg
, "\thelp\n");
1049 fprintf(cfg
, "\t %s\n", pkg_fd
);
1050 token
= strtok(NULL
, " ");
1053 pkg_flavours
= NULL
;
1056 /* package flavours string */
1057 if (pkg_flavours_string
!= NULL
) {
1058 token
= strtok(pkg_flavours_string
, " ");
1059 while (token
!= NULL
) {
1060 fprintf(cfg
, "\nconfig ADK_PACKAGE_%s_%s\n", pkgname
, toupperstr(token
));
1062 // process default value
1063 strncat(hkey
, "PKGFX_", 6);
1064 strncat(hkey
, token
, strlen(token
));
1065 memset(hvalue
, 0 , MAXVALUE
);
1066 strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
1067 memset(hkey
, 0 , MAXVAR
);
1068 pkg_fd
= strdup(hvalue
);
1069 if (strlen(pkg_fd
) > 0)
1070 fprintf(cfg
, "\tdefault \"%s\"\n", pkg_fd
);
1072 // process flavour cfline
1073 strncat(hkey
, "PKGFC_", 6);
1074 strncat(hkey
, token
, strlen(token
));
1075 memset(hvalue
, 0 , MAXVALUE
);
1076 strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
1077 memset(hkey
, 0 , MAXVAR
);
1078 pkg_fd
= strdup(hvalue
);
1079 if (strlen(pkg_fd
) > 0)
1080 fprintf(cfg
, "\t%s\n", pkg_fd
);
1082 fprintf(cfg
, "\tstring ");
1083 strncat(hkey
, "PKGFD_", 6);
1084 strncat(hkey
, token
, strlen(token
));
1085 memset(hvalue
, 0 , MAXVALUE
);
1086 strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
1087 memset(hkey
, 0 , MAXVAR
);
1088 pkg_fd
= strdup(hvalue
);
1089 fprintf(cfg
, "\"%s\"\n", pkg_fd
);
1091 fprintf(cfg
, "\tdepends on ADK_PACKAGE_%s\n", pkgname
);
1092 strncat(hkey
, "PKGFS_", 6);
1093 strncat(hkey
, token
, strlen(token
));
1095 result
= strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
1097 val
= strtok_r(hvalue
, " ", &saveptr
);
1098 while (val
!= NULL
) {
1099 fprintf(cfg
, "\tselect ADK_PACKAGE_%s\n", toupperstr(val
));
1100 val
= strtok_r(NULL
, " ", &saveptr
);
1103 memset(hkey
, 0, MAXVAR
);
1104 fprintf(cfg
, "\thelp\n");
1105 fprintf(cfg
, "\t %s\n", pkg_fd
);
1106 token
= strtok(NULL
, " ");
1108 free(pkg_flavours_string
);
1109 pkg_flavours_string
= NULL
;
1112 /* package choices */
1113 if (pkg_choices
!= NULL
) {
1114 fprintf(cfg
, "\nchoice\n");
1115 fprintf(cfg
, "prompt \"Package flavour choice\"\n");
1116 fprintf(cfg
, "depends on ADK_PACKAGE_%s\n\n", pkgname
);
1117 token
= strtok(pkg_choices
, " ");
1118 while (token
!= NULL
) {
1119 fprintf(cfg
, "config ADK_PACKAGE_%s_%s\n", pkgname
, toupperstr(token
));
1121 fprintf(cfg
, "\tbool ");
1122 strncat(hkey
, "PKGCD_", 6);
1123 strncat(hkey
, token
, strlen(token
));
1124 memset(hvalue
, 0 , MAXVALUE
);
1125 strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
1126 memset(hkey
, 0 , MAXVAR
);
1127 fprintf(cfg
, "\"%s\"\n", hvalue
);
1129 strncat(hkey
, "PKGCS_", 6);
1130 strncat(hkey
, token
, strlen(token
));
1131 memset(hvalue
, 0, MAXVALUE
);
1132 result
= strmap_get(pkgmap
, hkey
, hvalue
, sizeof(hvalue
));
1134 val
= strtok_r(hvalue
, " ", &saveptr
);
1135 while (val
!= NULL
) {
1136 fprintf(cfg
, "\tselect ADK_PACKAGE_%s\n", toupperstr(val
));
1137 val
= strtok_r(NULL
, " ", &saveptr
);
1140 memset(hkey
, 0, MAXVAR
);
1141 token
= strtok(NULL
, " ");
1143 fprintf(cfg
, "\nendchoice\n");
1147 /* close file descriptor for Config.in file */
1149 /* create Config.in files for development packages */
1150 if (pkg_opts
!= NULL
) {
1151 if (strstr(pkg_opts
, "dev") != NULL
) {
1152 if (snprintf(path
, MAXPATH
, "package/pkgconfigs.d/gcc/Config.in.dev") < 0)
1153 fatal_error("failed to create path variable.");
1154 cfg
= fopen(path
, "a");
1156 perror("Can not open Config.in.dev file");
1158 if (pkg_libname
== NULL
)
1159 pkg_libname
= strdup(pkg_name
);
1162 fprintf(cfg
, "config ADK_PACKAGE_%s_DEV\n", toupperstr(pkg_libname
));
1164 pseudo_name
= malloc(MAXLINE
);
1165 memset(pseudo_name
, 0, MAXLINE
);
1166 strncat(pseudo_name
, pkg_libname
, strlen(pkg_libname
));
1167 strncat(pseudo_name
, "-dev", 4);
1168 while (strlen(pseudo_name
) < 20)
1169 strncat(pseudo_name
, ".", 1);
1171 fprintf(cfg
, "\tprompt \"%s. development files for %s\"\n", pseudo_name
, pkg_libname
);
1172 fprintf(cfg
, "\tboolean\n");
1174 /* create package target architecture dependency information */
1175 if (pkg_arch_depends
!= NULL
) {
1176 pkg_helper
= strdup(pkg_arch_depends
);
1177 token
= strtok(pkg_helper
, " ");
1178 fprintf(cfg
, "\tdepends on ");
1180 while (token
!= NULL
) {
1181 if(strncmp(token
, "!", 1) == 0) {
1182 fprintf(cfg
, "%s!ADK_TARGET_ARCH%s", sp
, toupperstr(token
));
1185 fprintf(cfg
, "%sADK_TARGET_ARCH_%s", sp
, toupperstr(token
));
1188 token
= strtok(NULL
, " ");
1195 fprintf(cfg
, "\tdepends on ADK_PACKAGE_GCC && ADK_PACKAGE_%s\n", toupperstr(pkg_libname
));
1196 fprintf(cfg
, "\tdefault n\n");
1204 /* parse next package */
1205 token
= strtok_r(NULL
, " ", &p_ptr
);
1208 /* end of package output generation */
1212 /* reset flags, free memory */
1221 free(pkg_flavours_string
);
1224 free(pkg_arch_depends
);
1225 free(pkg_system_depends
);
1226 free(pkg_host_depends
);
1227 free(pkg_libc_depends
);
1237 pkg_kdepends
= NULL
;
1238 pkg_flavours
= NULL
;
1239 pkg_flavours_string
= NULL
;
1242 pkg_arch_depends
= NULL
;
1243 pkg_system_depends
= NULL
;
1244 pkg_host_depends
= NULL
;
1245 pkg_libc_depends
= NULL
;
1250 strmap_delete(pkgmap
);
1256 /* add menu to gcc package */
1257 if (snprintf(path
, MAXPATH
, "package/pkgconfigs.d/gcc/Config.in.gcc") < 0)
1258 fatal_error("failed to create path variable.");
1259 cfg
= fopen(path
, "a");
1261 perror("Can not open Config.in.gcc file");
1262 fprintf(cfg
, "menu \"Development packages\"\n");
1263 fprintf(cfg
, "depends on ADK_PACKAGE_GCC\n");
1264 fprintf(cfg
, "source \"package/pkgconfigs.d/gcc/Config.in.dev\"\n");
1265 fprintf(cfg
, "endmenu\n");
1268 /* create Config.in.auto */
1269 strmap_enum(sectionmap
, iter
, NULL
);
1271 strmap_delete(sectionmap
);
1275 /* remove temporary section files */
1276 pkglistdir
= opendir("package/pkglist.d");
1277 while ((pkgdirp
= readdir(pkglistdir
)) != NULL
) {
1278 if (strncmp(pkgdirp
->d_name
, "sectionlst.", 11) == 0) {
1279 if (snprintf(path
, MAXPATH
, "package/pkglist.d/%s", pkgdirp
->d_name
) < 0)
1280 fatal_error("creating path variable failed.");
1281 if (unlink(path
) < 0)
1282 fatal_error("removing file failed.");
1285 closedir(pkglistdir
);