openssl: update to 3.0.14
[openadk.git] / adk / tools / pkgmaker.c
blob30a0d11ca9804e9a2a42627c00c7f40fd89a788e
1 /*
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/>.
20 #include <ctype.h>
21 #include <dirent.h>
22 #include <errno.h>
23 #include <fcntl.h>
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include <string.h>
27 #include <unistd.h>
28 #include <sys/stat.h>
29 #include <sys/types.h>
30 #include "sortfile.h"
31 #include "strmap.h"
33 #define MAXLINE 4096
34 #define MAXVALUE 168
35 #define MAXVAR 64
36 #define MAXPATH 320
37 #define HASHSZ 96
39 static int nobinpkgs;
41 #define fatal_error(...) { \
42 fprintf(stderr, "Fatal error. "); \
43 fprintf(stderr, __VA_ARGS__); \
44 fprintf(stderr, "\n"); \
45 exit(1); \
48 static int parse_var_hash(char *buf, const char *varname, StrMap *strmap) {
50 char *key, *value, *string;
52 string = strstr(buf, varname);
53 if (string != NULL) {
54 string[strlen(string)-1] = '\0';
55 key = strtok(string, ":=");
56 value = strtok(NULL, "=\t");
57 if (value != NULL)
58 strmap_put(strmap, key, value);
59 return(0);
61 return(1);
64 static int parse_var(char *buf, const char *varname, char *pvalue, char **result) {
66 char *pkg_var;
67 char *key, *value, *string;
68 char pkg_str[MAXVAR];
70 if ((pkg_var = malloc(MAXLINE)) != NULL)
71 memset(pkg_var, 0, MAXLINE);
72 else {
73 perror("Can not allocate memory");
74 exit(EXIT_FAILURE);
77 if (snprintf(pkg_str, MAXVAR, "%s:=", varname) < 0)
78 perror("can not create path variable.");
79 string = strstr(buf, pkg_str);
80 if (string != NULL) {
81 string[strlen(string)-1] = '\0';
82 key = strtok(string, ":=");
83 value = strtok(NULL, "=\t");
84 if (value != NULL) {
85 strncat(pkg_var, value, strlen(value));
86 *result = strdup(pkg_var);
87 } else {
88 nobinpkgs = 1;
89 *result = NULL;
91 free(pkg_var);
92 return(0);
93 } else {
94 if (snprintf(pkg_str, MAXVAR, "%s+=", varname) < 0)
95 perror("can not create path variable.");
96 string = strstr(buf, pkg_str);
97 if (string != NULL) {
98 string[strlen(string)-1] = '\0';
99 key = strtok(string, "+=");
100 value = strtok(NULL, "=\t");
101 if (pvalue != NULL)
102 strncat(pkg_var, pvalue, strlen(pvalue));
103 strncat(pkg_var, " ", 1);
104 if (value != NULL)
105 strncat(pkg_var, value, strlen(value));
106 *result = strdup(pkg_var);
107 free(pkg_var);
108 return(0);
111 free(pkg_var);
112 return(1);
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);
122 else {
123 perror("Can not allocate memory");
124 exit(EXIT_FAILURE);
127 check = strstr(buf, ":=");
128 if (check != NULL) {
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");
135 if (value != NULL) {
136 strncat(pkg_var, value, strlen(value));
137 *result = strdup(pkg_var);
139 free(pkg_var);
140 return(0);
142 } else {
143 string = strstr(buf, varname);
144 if (string != NULL) {
145 string[strlen(string)-1] = '\0';
146 key = strtok(string, "+=");
147 value = strtok(NULL, "=\t");
148 if (pvalue != NULL)
149 strncat(pkg_var, pvalue, strlen(pvalue));
150 strncat(pkg_var, " ", 1);
151 if (value != NULL)
152 strncat(pkg_var, value, strlen(value));
153 *result = strdup(pkg_var);
154 free(pkg_var);
155 return(0);
158 free(pkg_var);
159 return(1);
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);
169 else {
170 perror("Can not allocate memory");
171 exit(EXIT_FAILURE);
174 check = strstr(buf, ":=");
175 if (check != NULL) {
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");
182 if (value != NULL) {
183 strncat(pkg_var, value, strlen(value));
184 *result = strdup(pkg_var);
186 free(pkg_var);
187 return(0);
189 } else {
190 string = strstr(buf, varname);
191 if (string != NULL) {
192 string[strlen(string)-1] = '\0';
193 key = strtok(string, "+=");
194 value = strtok(NULL, "=\t");
195 if (pvalue != NULL)
196 strncat(pkg_var, pvalue, strlen(pvalue));
197 strncat(pkg_var, " ", 1);
198 if (value != NULL)
199 strncat(pkg_var, value, strlen(value));
200 *result = strdup(pkg_var);
201 free(pkg_var);
202 return(0);
205 free(pkg_var);
206 return(1);
209 #if 0
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);
213 #endif
215 static int hash_str(char *string) {
217 int i;
218 int hash;
220 hash = 0;
221 for (i=0; i<(int)strlen(string); i++) {
222 hash += string[i];
224 return(hash);
227 static void iter(const char *key, const char *value, const void *obj) {
229 FILE *config, *section, *global;
230 int hash;
231 char *valuestr, *pkg, *subpkg, *subsect, *sect, *keystr;
232 char buf[MAXPATH];
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");
245 if (config == NULL)
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 */
257 unlink(infile);
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);
264 } else {
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");
272 fclose(section);
274 fclose(config);
277 static char *tolowerstr(char *string) {
279 int i;
280 char *str;
282 /* transform to lowercase variable name */
283 str = strdup(string);
284 for (i=0; i<(int)strlen(str); i++) {
285 if (str[i] == '_')
286 str[i] = '-';
287 str[i] = tolower(str[i]);
289 return(str);
292 static char *toupperstr(char *string) {
294 static char *sdup = NULL;
295 static int sduplen = 0;
296 int i;
298 if (!string) {
299 free(sdup);
300 sduplen = 0;
301 return NULL;
304 if (sduplen <= strlen(string)) {
305 sduplen = strlen(string) + 1;
306 sdup = realloc(sdup, sduplen);
307 if (!sdup)
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++) {
314 switch (string[i]) {
315 case '+':
316 sdup[i] = 'X';
317 break;
318 case '-':
319 sdup[i] = '_';
320 break;
321 case '!':
322 sdup[i] = '_';
323 break;
324 case '\0':
325 sdup[i] = '\0';
326 break;
327 default:
328 sdup[i] = toupper(string[i]);
331 return sdup;
335 int main() {
337 DIR *pkgdir, *pkglistdir, *scriptdir;
338 struct dirent *pkgdirp;
339 struct dirent *scriptdirp;
340 size_t len;
341 FILE *pkg, *cfg, *menuglobal, *section, *initscript, *icfg;
342 char hvalue[MAXVALUE];
343 char buf[MAXPATH];
344 char ibuf[MAXPATH];
345 char tbuf[MAXPATH];
346 char path[MAXPATH];
347 char script[MAXPATH];
348 char script2[MAXPATH];
349 char spath[MAXPATH];
350 char dir[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;
359 int result;
360 StrMap *pkgmap, *sectionmap;
361 const char runtime[] = "target/config/Config.in.scripts";
363 pkg_name = NULL;
364 pkg_descr = NULL;
365 pkg_section = NULL;
366 pkg_url = NULL;
367 pkg_depends = NULL;
368 pkg_kdepends = NULL;
369 pkg_needs = NULL;
370 pkg_depends_system = NULL;
371 pkg_depends_libc = NULL;
372 pkg_opts = NULL;
373 pkg_libname = NULL;
374 pkg_flavours = NULL;
375 pkg_flavours_string = NULL;
376 pkg_choices = NULL;
377 pkg_subpkgs = NULL;
378 pkg_arch_depends = NULL;
379 pkg_system_depends = NULL;
380 pkg_host_depends = NULL;
381 pkg_libc_depends = NULL;
382 pkg_dflt = NULL;
383 pkg_cfline = NULL;
384 pkgname = NULL;
385 sysname = NULL;
386 pkg_helper = NULL;
387 pkg_debug = NULL;
388 pkg_bb = NULL;
390 p_ptr = NULL;
391 s_ptr = NULL;
393 system("rm package/Config.in.auto.* 2>/dev/null");
394 unlink(runtime);
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");
402 if (section == NULL)
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);
411 fclose(section);
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.");
423 unlink(path);
424 cfg = fopen(path, "w");
425 if (cfg == NULL)
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");
448 fclose(cfg);
451 /* read Makefile's for all packages */
452 pkgdir = opendir("package");
453 while ((pkgdirp = readdir(pkgdir)) != NULL) {
454 /* skip dotfiles */
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");
459 if (pkg == NULL)
460 continue;
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) {
468 /* skip dotfiles */
469 if (strncmp(scriptdirp->d_name, ".", 1) > 0) {
470 len = strlen(scriptdirp->d_name);
471 if (strlen(".init") > len)
472 continue;
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)
478 continue;
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");
487 if (icfg == NULL)
488 continue;
489 if (strncmp("busybox", sname, 7) == 0) {
490 fprintf(icfg, "config ADK_RUNTIME_START_%s", toupperstr(sname));
491 fprintf(icfg, "_%s\n", toupperstr(sname2));
492 } else {
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));
499 else
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");
503 fclose(icfg);
505 continue;
506 free(sname);
507 free(sname2);
512 closedir(scriptdir);
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)
521 continue;
524 memset(hvalue, 0 , MAXVALUE);
525 result = strmap_get(sectionmap, pkg_section, hvalue, sizeof(hvalue));
526 if (result == 1) {
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);
532 fclose(section);
534 } else
535 fatal_error("Can not find section description %s for package %s.",
536 pkg_section, pkgdirp->d_name);
538 fclose(pkg);
539 continue;
542 nobinpkgs = 0;
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)
563 continue;
564 if (pkg_name != NULL)
565 pkg_name_u = toupperstr(pkg_name);
566 else
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)
571 continue;
572 snprintf(variable, MAXVAR, "PKG_DFLT_%s", pkg_name_u);
573 if ((parse_var(buf, variable, NULL, &pkg_dflt)) == 0)
574 continue;
575 if ((parse_var(buf, "PKG_LIBC_DEPENDS", NULL, &pkg_libc_depends)) == 0)
576 continue;
577 if ((parse_var(buf, "PKG_HOST_DEPENDS", NULL, &pkg_host_depends)) == 0)
578 continue;
579 if ((parse_var(buf, "PKG_ARCH_DEPENDS", NULL, &pkg_arch_depends)) == 0)
580 continue;
581 if ((parse_var(buf, "PKG_SYSTEM_DEPENDS", NULL, &pkg_system_depends)) == 0)
582 continue;
583 if ((parse_var(buf, "PKG_DESCR", NULL, &pkg_descr)) == 0)
584 continue;
585 if ((parse_var(buf, "PKG_SECTION", NULL, &pkg_section)) == 0)
586 continue;
587 if ((parse_var(buf, "PKG_URL", NULL, &pkg_url)) == 0)
588 continue;
589 if ((parse_var(buf, "PKG_BB", NULL, &pkg_bb)) == 0)
590 continue;
591 if ((parse_var(buf, "PKG_DEPENDS", pkg_depends, &pkg_depends)) == 0)
592 continue;
593 if ((parse_var(buf, "PKG_KDEPENDS", pkg_kdepends, &pkg_kdepends)) == 0)
594 continue;
595 if ((parse_var(buf, "PKG_NEEDS", pkg_needs, &pkg_needs)) == 0)
596 continue;
597 if ((parse_var_with_system(buf, "PKG_DEPENDS_", pkg_depends_system, &pkg_depends_system, &sysname, 12)) == 0)
598 continue;
599 if ((parse_var_with_system(buf, "PKG_DEPENDS_", pkg_depends_libc, &pkg_depends_libc, &sysname, 12)) == 0)
600 continue;
601 if ((parse_var(buf, "PKG_LIBNAME", pkg_libname, &pkg_libname)) == 0)
602 continue;
603 if ((parse_var(buf, "PKG_OPTS", pkg_opts, &pkg_opts)) == 0)
604 continue;
605 if ((parse_var_with_pkg(buf, "PKG_FLAVOURS_STRING_", pkg_flavours_string, &pkg_flavours_string, &pkgname, 20)) == 0)
606 continue;
607 if ((parse_var_with_pkg(buf, "PKG_FLAVOURS_", pkg_flavours, &pkg_flavours, &pkgname, 13)) == 0)
608 continue;
609 if ((parse_var_hash(buf, "PKGFD_", pkgmap)) == 0)
610 continue;
611 if ((parse_var_hash(buf, "PKGFX_", pkgmap)) == 0)
612 continue;
613 if ((parse_var_hash(buf, "PKGFS_", pkgmap)) == 0)
614 continue;
615 if ((parse_var_hash(buf, "PKGFC_", pkgmap)) == 0)
616 continue;
617 if ((parse_var_with_pkg(buf, "PKG_CHOICES_", pkg_choices, &pkg_choices, &pkgname, 12)) == 0)
618 continue;
619 if ((parse_var_hash(buf, "PKGCD_", pkgmap)) == 0)
620 continue;
621 if ((parse_var_hash(buf, "PKGCS_", pkgmap)) == 0)
622 continue;
623 if ((parse_var(buf, "PKG_SUBPKGS", pkg_subpkgs, &pkg_subpkgs)) == 0)
624 continue;
625 if ((parse_var_hash(buf, "PKGSD_", pkgmap)) == 0)
626 continue;
627 if ((parse_var_hash(buf, "PKGSS_", pkgmap)) == 0)
628 continue;
629 if ((parse_var_hash(buf, "PKGSC_", pkgmap)) == 0)
630 continue;
631 if ((parse_var_hash(buf, "PKGSK_", pkgmap)) == 0)
632 continue;
633 if ((parse_var_hash(buf, "PKGSN_", pkgmap)) == 0)
634 continue;
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");
648 #if 0
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);
671 if (pkg_url != NULL)
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);
679 #endif
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+ */
686 unlink(path);
687 cfg = fopen(path, "w");
688 if (cfg == NULL)
689 continue;
691 pkgs = NULL;
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 ");
699 if (pkgs != NULL) {
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, " ");
707 fprintf(cfg, "\n");
708 } else {
709 fprintf(cfg, "ADK_PACKAGE_%s\n", toupperstr(pkg_name));
712 fprintf(cfg, "\tdefault n\n");
713 fclose(cfg);
714 free(pkgs);
716 /* skip packages without binary package output */
717 if (nobinpkgs == 1)
718 continue;
720 /* generate binary package specific Config.in files */
721 if (pkg_subpkgs != NULL)
722 packages = tolowerstr(pkg_subpkgs);
723 else
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);
733 if (result == 1)
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);
741 if (result == 1)
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));
756 if (result == 1) {
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);
762 fclose(section);
764 } else
765 fatal_error("Can not find section description for package %s.", pkgdirp->d_name);
767 unlink(path);
768 cfg = fopen(path, "w");
769 if (cfg == NULL)
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);
784 } else {
785 fprintf(cfg, "\tprompt \"%s. %s\"\n", pseudo_name, pkg_descr);
787 } else {
788 fprintf(cfg, "\tprompt \"%s. %s\"\n", pseudo_name, pkg_descr);
791 fprintf(cfg, "\tbool\n");
792 free(pseudo_name);
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);
801 free(pkg_cfline);
802 pkg_cfline = NULL;
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));
810 if (result == 1) {
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));
824 if (result == 1) {
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));
838 if (result == 1) {
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 ");
852 sp = "";
853 while (token != NULL) {
854 if(strncmp(token, "!", 1) == 0) {
855 fprintf(cfg, "%s!ADK_TARGET_SYSTEM%s", sp, toupperstr(token));
856 sp = " && ";
857 } else {
858 fprintf(cfg, "%sADK_TARGET_SYSTEM_%s", sp, toupperstr(token));
859 sp = " || ";
861 token = strtok(NULL, " ");
863 fprintf(cfg, "\n");
864 free(pkg_helper);
865 pkg_helper = 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 ");
872 sp = "";
873 while (token != NULL) {
874 if(strncmp(token, "!", 1) == 0) {
875 fprintf(cfg, "%s!ADK_HOST%s", sp, toupperstr(token));
876 sp = " && ";
877 } else {
878 fprintf(cfg, "%sADK_HOST_%s", sp, toupperstr(token));
879 sp = " || ";
881 token = strtok(NULL, " ");
883 fprintf(cfg, "\n");
884 free(pkg_helper);
885 pkg_helper = 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 ");
893 sp = "";
894 while (token != NULL) {
895 if(strncmp(token, "!", 1) == 0) {
896 fprintf(cfg, "%s!ADK_TARGET_LIB_%s", sp, toupperstr(token));
897 sp = " && ";
898 } else {
899 fprintf(cfg, "%sADK_TARGET_LIB_%s", sp, toupperstr(token));
900 sp = " || ";
902 token = strtok(NULL, " ");
904 fprintf(cfg, "\n");
905 free(pkg_helper);
906 pkg_helper = 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 ");
913 sp = "";
914 while (token != NULL) {
915 if(strncmp(token, "!", 1) == 0) {
916 fprintf(cfg, "%s!ADK_TARGET_ARCH%s", sp, toupperstr(token));
917 sp = " && ";
918 } else {
919 fprintf(cfg, "%sADK_TARGET_ARCH_%s", sp, toupperstr(token));
920 sp = " || ";
922 token = strtok(NULL, " ");
924 fprintf(cfg, "\n");
925 free(pkg_helper);
926 pkg_helper = 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, " ");
951 free(pkg_needs);
952 pkg_needs = 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, " ");
962 free(pkg_depends);
963 pkg_depends = 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, " ");
972 free(pkg_kdepends);
973 pkg_kdepends = 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);
1003 pkg_dflt = NULL;
1004 } else {
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);
1037 else
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));
1065 if (result == 1) {
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, " ");
1077 free(pkg_flavours);
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));
1121 if (result == 1) {
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));
1158 if (result == 1) {
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");
1169 free(pkg_choices);
1170 pkg_choices = NULL;
1172 /* close file descriptor for Config.in file */
1173 fclose(cfg);
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");
1180 if (cfg == NULL)
1181 perror("Can not open Config.in.dev file");
1183 if (pkg_libname == NULL)
1184 pkg_libname = strdup(pkg_name);
1186 fprintf(cfg, "\n");
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 ");
1204 sp = "";
1205 while (token != NULL) {
1206 if(strncmp(token, "!", 1) == 0) {
1207 fprintf(cfg, "%s!ADK_TARGET_ARCH%s", sp, toupperstr(token));
1208 sp = " && ";
1209 } else {
1210 fprintf(cfg, "%sADK_TARGET_ARCH_%s", sp, toupperstr(token));
1211 sp = " || ";
1213 token = strtok(NULL, " ");
1215 fprintf(cfg, "\n");
1216 free(pkg_helper);
1217 pkg_helper = NULL;
1220 fprintf(cfg, "\tdepends on ADK_PACKAGE_GCC && ADK_PACKAGE_%s\n", toupperstr(pkg_libname));
1221 fprintf(cfg, "\tdefault n\n");
1222 fclose(cfg);
1223 free(pseudo_name);
1224 free(pkg_libname);
1225 pkg_libname = NULL;
1227 pkg_opts = NULL;
1229 /* parse next package */
1230 token = strtok_r(NULL, " ", &p_ptr);
1233 /* end of package output generation */
1234 free(packages);
1235 packages = NULL;
1237 /* reset flags, free memory */
1238 free(pkg_name);
1239 free(pkg_libname);
1240 free(pkg_descr);
1241 free(pkg_section);
1242 free(pkg_url);
1243 free(pkg_depends);
1244 free(pkg_kdepends);
1245 free(pkg_flavours);
1246 free(pkg_flavours_string);
1247 free(pkg_choices);
1248 free(pkg_subpkgs);
1249 free(pkg_arch_depends);
1250 free(pkg_system_depends);
1251 free(pkg_host_depends);
1252 free(pkg_libc_depends);
1253 free(pkg_dflt);
1254 free(pkg_cfline);
1255 free(pkg_bb);
1256 pkg_name = NULL;
1257 pkg_libname = NULL;
1258 pkg_descr = NULL;
1259 pkg_section = NULL;
1260 pkg_url = NULL;
1261 pkg_depends = NULL;
1262 pkg_kdepends = NULL;
1263 pkg_flavours = NULL;
1264 pkg_flavours_string = NULL;
1265 pkg_choices = NULL;
1266 pkg_subpkgs = NULL;
1267 pkg_arch_depends = NULL;
1268 pkg_system_depends = NULL;
1269 pkg_host_depends = NULL;
1270 pkg_libc_depends = NULL;
1271 pkg_dflt = NULL;
1272 pkg_cfline = NULL;
1273 pkg_bb = NULL;
1275 strmap_delete(pkgmap);
1276 nobinpkgs = 0;
1277 free(hkey);
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");
1285 if (cfg == NULL)
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");
1291 fclose(cfg);
1293 /* create Config.in.auto */
1294 strmap_enum(sectionmap, iter, NULL);
1296 strmap_delete(sectionmap);
1297 fclose(menuglobal);
1298 closedir(pkgdir);
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.");
1310 toupperstr(NULL);
1311 closedir(pkglistdir);
1312 return(0);