linux: required h8300 patch for edosk2674
[openadk.git] / adk / tools / pkgmaker.c
blobca5dbfa2c0ee59092fa7ddc35c264ddd9a5018a3
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 <fcntl.h>
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include <unistd.h>
27 #include <sys/stat.h>
28 #include <sys/types.h>
29 #include "sortfile.h"
30 #include "strmap.h"
32 #define MAXLINE 4096
33 #define MAXVALUE 168
34 #define MAXVAR 64
35 #define MAXPATH 320
36 #define HASHSZ 96
38 static int nobinpkgs;
40 #define fatal_error(...) { \
41 fprintf(stderr, "Fatal error. "); \
42 fprintf(stderr, __VA_ARGS__); \
43 fprintf(stderr, "\n"); \
44 exit(1); \
47 static int parse_var_hash(char *buf, const char *varname, StrMap *strmap) {
49 char *key, *value, *string;
51 string = strstr(buf, varname);
52 if (string != NULL) {
53 string[strlen(string)-1] = '\0';
54 key = strtok(string, ":=");
55 value = strtok(NULL, "=\t");
56 if (value != NULL)
57 strmap_put(strmap, key, value);
58 return(0);
60 return(1);
63 static int parse_var(char *buf, const char *varname, char *pvalue, char **result) {
65 char *pkg_var;
66 char *key, *value, *string;
67 char pkg_str[MAXVAR];
69 if ((pkg_var = malloc(MAXLINE)) != NULL)
70 memset(pkg_var, 0, MAXLINE);
71 else {
72 perror("Can not allocate memory");
73 exit(EXIT_FAILURE);
76 if (snprintf(pkg_str, MAXVAR, "%s:=", varname) < 0)
77 perror("can not create path variable.");
78 string = strstr(buf, pkg_str);
79 if (string != NULL) {
80 string[strlen(string)-1] = '\0';
81 key = strtok(string, ":=");
82 value = strtok(NULL, "=\t");
83 if (value != NULL) {
84 strncat(pkg_var, value, strlen(value));
85 *result = strdup(pkg_var);
86 } else {
87 nobinpkgs = 1;
88 *result = NULL;
90 free(pkg_var);
91 return(0);
92 } else {
93 if (snprintf(pkg_str, MAXVAR, "%s+=", varname) < 0)
94 perror("can not create path variable.");
95 string = strstr(buf, pkg_str);
96 if (string != NULL) {
97 string[strlen(string)-1] = '\0';
98 key = strtok(string, "+=");
99 value = strtok(NULL, "=\t");
100 if (pvalue != NULL)
101 strncat(pkg_var, pvalue, strlen(pvalue));
102 strncat(pkg_var, " ", 1);
103 if (value != NULL)
104 strncat(pkg_var, value, strlen(value));
105 *result = strdup(pkg_var);
106 free(pkg_var);
107 return(0);
110 free(pkg_var);
111 return(1);
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);
121 else {
122 perror("Can not allocate memory");
123 exit(EXIT_FAILURE);
126 check = strstr(buf, ":=");
127 if (check != NULL) {
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");
134 if (value != NULL) {
135 strncat(pkg_var, value, strlen(value));
136 *result = strdup(pkg_var);
138 free(pkg_var);
139 return(0);
141 } else {
142 string = strstr(buf, varname);
143 if (string != NULL) {
144 string[strlen(string)-1] = '\0';
145 key = strtok(string, "+=");
146 value = strtok(NULL, "=\t");
147 if (pvalue != NULL)
148 strncat(pkg_var, pvalue, strlen(pvalue));
149 strncat(pkg_var, " ", 1);
150 if (value != NULL)
151 strncat(pkg_var, value, strlen(value));
152 *result = strdup(pkg_var);
153 free(pkg_var);
154 return(0);
157 free(pkg_var);
158 return(1);
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);
168 else {
169 perror("Can not allocate memory");
170 exit(EXIT_FAILURE);
173 check = strstr(buf, ":=");
174 if (check != NULL) {
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");
181 if (value != NULL) {
182 strncat(pkg_var, value, strlen(value));
183 *result = strdup(pkg_var);
185 free(pkg_var);
186 return(0);
188 } else {
189 string = strstr(buf, varname);
190 if (string != NULL) {
191 string[strlen(string)-1] = '\0';
192 key = strtok(string, "+=");
193 value = strtok(NULL, "=\t");
194 if (pvalue != NULL)
195 strncat(pkg_var, pvalue, strlen(pvalue));
196 strncat(pkg_var, " ", 1);
197 if (value != NULL)
198 strncat(pkg_var, value, strlen(value));
199 *result = strdup(pkg_var);
200 free(pkg_var);
201 return(0);
204 free(pkg_var);
205 return(1);
208 #if 0
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);
212 #endif
214 static int hash_str(char *string) {
216 int i;
217 int hash;
219 hash = 0;
220 for (i=0; i<(int)strlen(string); i++) {
221 hash += string[i];
223 return(hash);
226 static void iter(const char *key, const char *value, const void *obj) {
228 FILE *config, *section, *global;
229 int hash;
230 char *valuestr, *pkg, *subpkg, *subsect, *sect, *keystr;
231 char buf[MAXPATH];
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");
244 if (config == NULL)
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 */
256 unlink(infile);
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);
263 } else {
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");
271 fclose(section);
273 fclose(config);
276 static char *tolowerstr(char *string) {
278 int i;
279 char *str;
281 /* transform to lowercase variable name */
282 str = strdup(string);
283 for (i=0; i<(int)strlen(str); i++) {
284 if (str[i] == '_')
285 str[i] = '-';
286 str[i] = tolower(str[i]);
288 return(str);
291 static char *toupperstr(char *string) {
293 int i;
294 char *str;
296 /* transform to uppercase variable name */
297 str = strdup(string);
298 for (i=0; i<(int)strlen(str); i++) {
299 if (str[i] == '+')
300 str[i] = 'X';
301 if (str[i] == '-')
302 str[i] = '_';
303 /* remove negation here, useful for package host depends */
304 if (str[i] == '!')
305 str[i] = '_';
306 str[i] = toupper(str[i]);
308 return(str);
312 int main() {
314 DIR *pkgdir, *pkglistdir, *scriptdir;
315 struct dirent *pkgdirp;
316 struct dirent *scriptdirp;
317 size_t len;
318 FILE *pkg, *cfg, *menuglobal, *section, *initscript, *icfg;
319 char hvalue[MAXVALUE];
320 char buf[MAXPATH];
321 char ibuf[MAXPATH];
322 char tbuf[MAXPATH];
323 char path[MAXPATH];
324 char script[MAXPATH];
325 char script2[MAXPATH];
326 char spath[MAXPATH];
327 char dir[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;
336 int result;
337 StrMap *pkgmap, *sectionmap;
338 const char runtime[] = "target/config/Config.in.scripts";
340 pkg_name = NULL;
341 pkg_descr = NULL;
342 pkg_section = NULL;
343 pkg_url = NULL;
344 pkg_depends = NULL;
345 pkg_kdepends = NULL;
346 pkg_needs = NULL;
347 pkg_depends_system = NULL;
348 pkg_depends_libc = NULL;
349 pkg_opts = NULL;
350 pkg_libname = NULL;
351 pkg_flavours = NULL;
352 pkg_flavours_string = NULL;
353 pkg_choices = NULL;
354 pkg_subpkgs = NULL;
355 pkg_arch_depends = NULL;
356 pkg_system_depends = NULL;
357 pkg_host_depends = NULL;
358 pkg_libc_depends = NULL;
359 pkg_dflt = NULL;
360 pkg_cfline = NULL;
361 pkgname = NULL;
362 sysname = NULL;
363 pkg_helper = NULL;
364 pkg_debug = NULL;
365 pkg_bb = NULL;
367 p_ptr = NULL;
368 s_ptr = NULL;
370 system("rm package/Config.in.auto.* 2>/dev/null");
371 unlink(runtime);
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");
379 if (section == NULL)
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);
388 fclose(section);
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.");
400 unlink(path);
401 cfg = fopen(path, "w");
402 if (cfg == NULL)
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");
425 fclose(cfg);
428 /* read Makefile's for all packages */
429 pkgdir = opendir("package");
430 while ((pkgdirp = readdir(pkgdir)) != NULL) {
431 /* skip dotfiles */
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");
436 if (pkg == NULL)
437 continue;
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) {
445 /* skip dotfiles */
446 if (strncmp(scriptdirp->d_name, ".", 1) > 0) {
447 len = strlen(scriptdirp->d_name);
448 if (strlen(".init") > len)
449 continue;
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)
455 continue;
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");
464 if (icfg == NULL)
465 continue;
466 if (strncmp("busybox", sname, 7) == 0)
467 fprintf(icfg, "config ADK_RUNTIME_START_%s_%s\n", toupperstr(sname), toupperstr(sname2));
468 else
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));
474 else
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");
478 fclose(icfg);
480 continue;
481 free(sname);
482 free(sname2);
487 closedir(scriptdir);
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)
496 continue;
499 memset(hvalue, 0 , MAXVALUE);
500 result = strmap_get(sectionmap, pkg_section, hvalue, sizeof(hvalue));
501 if (result == 1) {
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);
507 fclose(section);
509 } else
510 fatal_error("Can not find section description %s for package %s.",
511 pkg_section, pkgdirp->d_name);
513 fclose(pkg);
514 continue;
517 nobinpkgs = 0;
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)
538 continue;
539 if (pkg_name != NULL)
540 pkg_name_u = toupperstr(pkg_name);
541 else
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)
546 continue;
547 snprintf(variable, MAXVAR, "PKG_DFLT_%s", pkg_name_u);
548 if ((parse_var(buf, variable, NULL, &pkg_dflt)) == 0)
549 continue;
550 if ((parse_var(buf, "PKG_LIBC_DEPENDS", NULL, &pkg_libc_depends)) == 0)
551 continue;
552 if ((parse_var(buf, "PKG_HOST_DEPENDS", NULL, &pkg_host_depends)) == 0)
553 continue;
554 if ((parse_var(buf, "PKG_ARCH_DEPENDS", NULL, &pkg_arch_depends)) == 0)
555 continue;
556 if ((parse_var(buf, "PKG_SYSTEM_DEPENDS", NULL, &pkg_system_depends)) == 0)
557 continue;
558 if ((parse_var(buf, "PKG_DESCR", NULL, &pkg_descr)) == 0)
559 continue;
560 if ((parse_var(buf, "PKG_SECTION", NULL, &pkg_section)) == 0)
561 continue;
562 if ((parse_var(buf, "PKG_URL", NULL, &pkg_url)) == 0)
563 continue;
564 if ((parse_var(buf, "PKG_BB", NULL, &pkg_bb)) == 0)
565 continue;
566 if ((parse_var(buf, "PKG_DEPENDS", pkg_depends, &pkg_depends)) == 0)
567 continue;
568 if ((parse_var(buf, "PKG_KDEPENDS", pkg_kdepends, &pkg_kdepends)) == 0)
569 continue;
570 if ((parse_var(buf, "PKG_NEEDS", pkg_needs, &pkg_needs)) == 0)
571 continue;
572 if ((parse_var_with_system(buf, "PKG_DEPENDS_", pkg_depends_system, &pkg_depends_system, &sysname, 12)) == 0)
573 continue;
574 if ((parse_var_with_system(buf, "PKG_DEPENDS_", pkg_depends_libc, &pkg_depends_libc, &sysname, 12)) == 0)
575 continue;
576 if ((parse_var(buf, "PKG_LIBNAME", pkg_libname, &pkg_libname)) == 0)
577 continue;
578 if ((parse_var(buf, "PKG_OPTS", pkg_opts, &pkg_opts)) == 0)
579 continue;
580 if ((parse_var_with_pkg(buf, "PKG_FLAVOURS_STRING_", pkg_flavours_string, &pkg_flavours_string, &pkgname, 20)) == 0)
581 continue;
582 if ((parse_var_with_pkg(buf, "PKG_FLAVOURS_", pkg_flavours, &pkg_flavours, &pkgname, 13)) == 0)
583 continue;
584 if ((parse_var_hash(buf, "PKGFD_", pkgmap)) == 0)
585 continue;
586 if ((parse_var_hash(buf, "PKGFX_", pkgmap)) == 0)
587 continue;
588 if ((parse_var_hash(buf, "PKGFS_", pkgmap)) == 0)
589 continue;
590 if ((parse_var_hash(buf, "PKGFC_", pkgmap)) == 0)
591 continue;
592 if ((parse_var_with_pkg(buf, "PKG_CHOICES_", pkg_choices, &pkg_choices, &pkgname, 12)) == 0)
593 continue;
594 if ((parse_var_hash(buf, "PKGCD_", pkgmap)) == 0)
595 continue;
596 if ((parse_var_hash(buf, "PKGCS_", pkgmap)) == 0)
597 continue;
598 if ((parse_var(buf, "PKG_SUBPKGS", pkg_subpkgs, &pkg_subpkgs)) == 0)
599 continue;
600 if ((parse_var_hash(buf, "PKGSD_", pkgmap)) == 0)
601 continue;
602 if ((parse_var_hash(buf, "PKGSS_", pkgmap)) == 0)
603 continue;
604 if ((parse_var_hash(buf, "PKGSC_", pkgmap)) == 0)
605 continue;
606 if ((parse_var_hash(buf, "PKGSK_", pkgmap)) == 0)
607 continue;
608 if ((parse_var_hash(buf, "PKGSN_", pkgmap)) == 0)
609 continue;
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");
623 #if 0
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);
646 if (pkg_url != NULL)
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);
654 #endif
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+ */
661 unlink(path);
662 cfg = fopen(path, "w");
663 if (cfg == NULL)
664 continue;
666 pkgs = NULL;
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 ");
674 if (pkgs != NULL) {
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, " ");
682 fprintf(cfg, "\n");
683 } else {
684 fprintf(cfg, "ADK_PACKAGE_%s\n", toupperstr(pkg_name));
687 fprintf(cfg, "\tdefault n\n");
688 fclose(cfg);
689 free(pkgs);
691 /* skip packages without binary package output */
692 if (nobinpkgs == 1)
693 continue;
695 /* generate binary package specific Config.in files */
696 if (pkg_subpkgs != NULL)
697 packages = tolowerstr(pkg_subpkgs);
698 else
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);
708 if (result == 1)
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);
716 if (result == 1)
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));
731 if (result == 1) {
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);
737 fclose(section);
739 } else
740 fatal_error("Can not find section description for package %s.", pkgdirp->d_name);
742 unlink(path);
743 cfg = fopen(path, "w");
744 if (cfg == NULL)
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);
759 } else {
760 fprintf(cfg, "\tprompt \"%s. %s\"\n", pseudo_name, pkg_descr);
762 } else {
763 fprintf(cfg, "\tprompt \"%s. %s\"\n", pseudo_name, pkg_descr);
766 fprintf(cfg, "\tbool\n");
767 free(pseudo_name);
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);
776 free(pkg_cfline);
777 pkg_cfline = NULL;
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));
785 if (result == 1) {
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));
799 if (result == 1) {
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));
813 if (result == 1) {
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 ");
827 sp = "";
828 while (token != NULL) {
829 if(strncmp(token, "!", 1) == 0) {
830 fprintf(cfg, "%s!ADK_TARGET_SYSTEM%s", sp, toupperstr(token));
831 sp = " && ";
832 } else {
833 fprintf(cfg, "%sADK_TARGET_SYSTEM_%s", sp, toupperstr(token));
834 sp = " || ";
836 token = strtok(NULL, " ");
838 fprintf(cfg, "\n");
839 free(pkg_helper);
840 pkg_helper = 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 ");
847 sp = "";
848 while (token != NULL) {
849 if(strncmp(token, "!", 1) == 0) {
850 fprintf(cfg, "%s!ADK_HOST%s", sp, toupperstr(token));
851 sp = " && ";
852 } else {
853 fprintf(cfg, "%sADK_HOST_%s", sp, toupperstr(token));
854 sp = " || ";
856 token = strtok(NULL, " ");
858 fprintf(cfg, "\n");
859 free(pkg_helper);
860 pkg_helper = 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 ");
868 sp = "";
869 while (token != NULL) {
870 if(strncmp(token, "!", 1) == 0) {
871 fprintf(cfg, "%s!ADK_TARGET_LIB_%s", sp, toupperstr(token));
872 sp = " && ";
873 } else {
874 fprintf(cfg, "%sADK_TARGET_LIB_%s", sp, toupperstr(token));
875 sp = " || ";
877 token = strtok(NULL, " ");
879 fprintf(cfg, "\n");
880 free(pkg_helper);
881 pkg_helper = 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 ");
888 sp = "";
889 while (token != NULL) {
890 if(strncmp(token, "!", 1) == 0) {
891 fprintf(cfg, "%s!ADK_TARGET_ARCH%s", sp, toupperstr(token));
892 sp = " && ";
893 } else {
894 fprintf(cfg, "%sADK_TARGET_ARCH_%s", sp, toupperstr(token));
895 sp = " || ";
897 token = strtok(NULL, " ");
899 fprintf(cfg, "\n");
900 free(pkg_helper);
901 pkg_helper = 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, " ");
926 free(pkg_needs);
927 pkg_needs = 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, " ");
937 free(pkg_depends);
938 pkg_depends = 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, " ");
947 free(pkg_kdepends);
948 pkg_kdepends = 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);
978 pkg_dflt = NULL;
979 } else {
980 fprintf(cfg, "\tdefault n\n");
983 fprintf(cfg, "\thelp\n");
984 fprintf(cfg, "\t %s\n\n", pkg_descr);
985 if (pkg_url != NULL)
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);
1012 else
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));
1040 if (result == 1) {
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, " ");
1052 free(pkg_flavours);
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));
1096 if (result == 1) {
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));
1133 if (result == 1) {
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");
1144 free(pkg_choices);
1145 pkg_choices = NULL;
1147 /* close file descriptor for Config.in file */
1148 fclose(cfg);
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");
1155 if (cfg == NULL)
1156 perror("Can not open Config.in.dev file");
1158 if (pkg_libname == NULL)
1159 pkg_libname = strdup(pkg_name);
1161 fprintf(cfg, "\n");
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 ");
1179 sp = "";
1180 while (token != NULL) {
1181 if(strncmp(token, "!", 1) == 0) {
1182 fprintf(cfg, "%s!ADK_TARGET_ARCH%s", sp, toupperstr(token));
1183 sp = " && ";
1184 } else {
1185 fprintf(cfg, "%sADK_TARGET_ARCH_%s", sp, toupperstr(token));
1186 sp = " || ";
1188 token = strtok(NULL, " ");
1190 fprintf(cfg, "\n");
1191 free(pkg_helper);
1192 pkg_helper = NULL;
1195 fprintf(cfg, "\tdepends on ADK_PACKAGE_GCC && ADK_PACKAGE_%s\n", toupperstr(pkg_libname));
1196 fprintf(cfg, "\tdefault n\n");
1197 fclose(cfg);
1198 free(pseudo_name);
1199 free(pkg_libname);
1200 pkg_libname = NULL;
1202 pkg_opts = NULL;
1204 /* parse next package */
1205 token = strtok_r(NULL, " ", &p_ptr);
1208 /* end of package output generation */
1209 free(packages);
1210 packages = NULL;
1212 /* reset flags, free memory */
1213 free(pkg_name);
1214 free(pkg_libname);
1215 free(pkg_descr);
1216 free(pkg_section);
1217 free(pkg_url);
1218 free(pkg_depends);
1219 free(pkg_kdepends);
1220 free(pkg_flavours);
1221 free(pkg_flavours_string);
1222 free(pkg_choices);
1223 free(pkg_subpkgs);
1224 free(pkg_arch_depends);
1225 free(pkg_system_depends);
1226 free(pkg_host_depends);
1227 free(pkg_libc_depends);
1228 free(pkg_dflt);
1229 free(pkg_cfline);
1230 free(pkg_bb);
1231 pkg_name = NULL;
1232 pkg_libname = NULL;
1233 pkg_descr = NULL;
1234 pkg_section = NULL;
1235 pkg_url = NULL;
1236 pkg_depends = NULL;
1237 pkg_kdepends = NULL;
1238 pkg_flavours = NULL;
1239 pkg_flavours_string = NULL;
1240 pkg_choices = NULL;
1241 pkg_subpkgs = NULL;
1242 pkg_arch_depends = NULL;
1243 pkg_system_depends = NULL;
1244 pkg_host_depends = NULL;
1245 pkg_libc_depends = NULL;
1246 pkg_dflt = NULL;
1247 pkg_cfline = NULL;
1248 pkg_bb = NULL;
1250 strmap_delete(pkgmap);
1251 nobinpkgs = 0;
1252 free(hkey);
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");
1260 if (cfg == NULL)
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");
1266 fclose(cfg);
1268 /* create Config.in.auto */
1269 strmap_enum(sectionmap, iter, NULL);
1271 strmap_delete(sectionmap);
1272 fclose(menuglobal);
1273 closedir(pkgdir);
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);
1286 return(0);