xenomai: new package, only mercury for now supported
[openadk.git] / adk / tools / pkgmaker.c
blob8ab121234dfd5c7a4ed176a4a0e89df483a6b3a4
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, "mmu", 3) == 0)
921 fprintf(cfg, "\tdepends on ADK_TARGET_WITH_MMU\n");
922 token = strtok(NULL, " ");
924 free(pkg_needs);
925 pkg_needs = NULL;
928 /* create package dependency information */
929 if (pkg_depends != NULL) {
930 token = strtok(pkg_depends, " ");
931 while (token != NULL) {
932 fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(token));
933 token = strtok(NULL, " ");
935 free(pkg_depends);
936 pkg_depends = NULL;
938 /* create kernel package dependency information */
939 if (pkg_kdepends != NULL) {
940 token = strtok(pkg_kdepends, " ");
941 while (token != NULL) {
942 fprintf(cfg, "\tselect ADK_KERNEL_%s m\n", toupperstr(token));
943 token = strtok(NULL, " ");
945 free(pkg_kdepends);
946 pkg_kdepends = NULL;
948 /* create system specific package dependency information */
949 if (pkg_depends_system != NULL) {
950 token = strtok(pkg_depends_system, " ");
951 while (token != NULL) {
952 fprintf(cfg, "\tselect ADK_PACKAGE_%s if ADK_TARGET_SYSTEM_%s\n", toupperstr(token), sysname);
953 token = strtok(NULL, " ");
955 free(pkg_depends_system);
956 pkg_depends_system = NULL;
958 /* create libc specific package dependency information */
959 if (pkg_depends_libc != NULL) {
960 token = strtok(pkg_depends_libc, " ");
961 while (token != NULL) {
962 fprintf(cfg, "\tselect ADK_PACKAGE_%s if ADK_TARGET_LIB_%s\n", toupperstr(token), sysname);
963 token = strtok(NULL, " ");
965 free(pkg_depends_libc);
966 pkg_depends_libc = NULL;
969 if (pkg_bb != NULL) {
970 fprintf(cfg, "\tdepends on !ADK_PACKAGE_BUSYBOX_HIDE\n");
972 fprintf(cfg, "\tselect ADK_COMPILE_%s\n", toupperstr(pkgdirp->d_name));
974 if (pkg_dflt != NULL) {
975 fprintf(cfg, "\tdefault %s\n", pkg_dflt);
976 pkg_dflt = NULL;
977 } else {
978 fprintf(cfg, "\tdefault n\n");
981 fprintf(cfg, "\thelp\n");
982 fprintf(cfg, "\t %s\n\n", pkg_descr);
983 if (pkg_url != NULL)
984 fprintf(cfg, "\t WWW: %s\n", pkg_url);
986 /* handle debug subpackages */
987 fprintf(cfg, "\nconfig ADK_PACKAGE_%s_DBG\n", toupperstr(pkg_debug));
988 fprintf(cfg, "\tbool \"add debug symbols package\"\n");
989 fprintf(cfg, "\tdepends on ADK_PACKAGE_GDB && ADK_BUILD_WITH_DEBUG\n");
990 fprintf(cfg, "\tdepends on ADK_DEBUG\n");
991 fprintf(cfg, "\tdepends on ADK_PACKAGE_%s\n", toupperstr(pkg_debug));
992 fprintf(cfg, "\tdefault n\n");
993 fprintf(cfg, "\thelp\n\n");
995 /* package flavours */
996 if (pkg_flavours != NULL) {
997 token = strtok(pkg_flavours, " ");
998 while (token != NULL) {
999 fprintf(cfg, "\nconfig ADK_PACKAGE_%s_%s\n", pkgname, toupperstr(token));
1001 // process default value
1002 strncat(hkey, "PKGFX_", 6);
1003 strncat(hkey, token, strlen(token));
1004 memset(hvalue, 0 , MAXVALUE);
1005 strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
1006 memset(hkey, 0 , MAXVAR);
1007 pkg_fd = strdup(hvalue);
1008 if (strlen(pkg_fd) > 0)
1009 fprintf(cfg, "\tdefault %s\n", pkg_fd);
1010 else
1011 fprintf(cfg, "\tdefault n\n");
1014 // process flavour cfline
1015 strncat(hkey, "PKGFC_", 6);
1016 strncat(hkey, token, strlen(token));
1017 memset(hvalue, 0 , MAXVALUE);
1018 strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
1019 memset(hkey, 0 , MAXVAR);
1020 pkg_fd = strdup(hvalue);
1021 if (strlen(pkg_fd) > 0)
1022 fprintf(cfg, "\t%s\n", pkg_fd);
1024 fprintf(cfg, "\tboolean ");
1025 strncat(hkey, "PKGFD_", 6);
1026 strncat(hkey, token, strlen(token));
1027 memset(hvalue, 0 , MAXVALUE);
1028 strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
1029 memset(hkey, 0 , MAXVAR);
1030 pkg_fd = strdup(hvalue);
1032 fprintf(cfg, "\"%s\"\n", pkg_fd);
1033 fprintf(cfg, "\tdepends on ADK_PACKAGE_%s\n", pkgname);
1034 strncat(hkey, "PKGFS_", 6);
1035 strncat(hkey, token, strlen(token));
1037 result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
1038 if (result == 1) {
1039 val = strtok_r(hvalue, " ", &saveptr);
1040 while (val != NULL) {
1041 fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(val));
1042 val = strtok_r(NULL, " ", &saveptr);
1045 memset(hkey, 0, MAXVAR);
1046 fprintf(cfg, "\thelp\n");
1047 fprintf(cfg, "\t %s\n", pkg_fd);
1048 token = strtok(NULL, " ");
1050 free(pkg_flavours);
1051 pkg_flavours = NULL;
1054 /* package flavours string */
1055 if (pkg_flavours_string != NULL) {
1056 token = strtok(pkg_flavours_string, " ");
1057 while (token != NULL) {
1058 fprintf(cfg, "\nconfig ADK_PACKAGE_%s_%s\n", pkgname, toupperstr(token));
1060 // process default value
1061 strncat(hkey, "PKGFX_", 6);
1062 strncat(hkey, token, strlen(token));
1063 memset(hvalue, 0 , MAXVALUE);
1064 strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
1065 memset(hkey, 0 , MAXVAR);
1066 pkg_fd = strdup(hvalue);
1067 if (strlen(pkg_fd) > 0)
1068 fprintf(cfg, "\tdefault \"%s\"\n", pkg_fd);
1070 // process flavour cfline
1071 strncat(hkey, "PKGFC_", 6);
1072 strncat(hkey, token, strlen(token));
1073 memset(hvalue, 0 , MAXVALUE);
1074 strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
1075 memset(hkey, 0 , MAXVAR);
1076 pkg_fd = strdup(hvalue);
1077 if (strlen(pkg_fd) > 0)
1078 fprintf(cfg, "\t%s\n", pkg_fd);
1080 fprintf(cfg, "\tstring ");
1081 strncat(hkey, "PKGFD_", 6);
1082 strncat(hkey, token, strlen(token));
1083 memset(hvalue, 0 , MAXVALUE);
1084 strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
1085 memset(hkey, 0 , MAXVAR);
1086 pkg_fd = strdup(hvalue);
1087 fprintf(cfg, "\"%s\"\n", pkg_fd);
1089 fprintf(cfg, "\tdepends on ADK_PACKAGE_%s\n", pkgname);
1090 strncat(hkey, "PKGFS_", 6);
1091 strncat(hkey, token, strlen(token));
1093 result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
1094 if (result == 1) {
1095 val = strtok_r(hvalue, " ", &saveptr);
1096 while (val != NULL) {
1097 fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(val));
1098 val = strtok_r(NULL, " ", &saveptr);
1101 memset(hkey, 0, MAXVAR);
1102 fprintf(cfg, "\thelp\n");
1103 fprintf(cfg, "\t %s\n", pkg_fd);
1104 token = strtok(NULL, " ");
1106 free(pkg_flavours_string);
1107 pkg_flavours_string = NULL;
1110 /* package choices */
1111 if (pkg_choices != NULL) {
1112 fprintf(cfg, "\nchoice\n");
1113 fprintf(cfg, "prompt \"Package flavour choice\"\n");
1114 fprintf(cfg, "depends on ADK_PACKAGE_%s\n\n", pkgname);
1115 token = strtok(pkg_choices, " ");
1116 while (token != NULL) {
1117 fprintf(cfg, "config ADK_PACKAGE_%s_%s\n", pkgname, toupperstr(token));
1119 fprintf(cfg, "\tbool ");
1120 strncat(hkey, "PKGCD_", 6);
1121 strncat(hkey, token, strlen(token));
1122 memset(hvalue, 0 , MAXVALUE);
1123 strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
1124 memset(hkey, 0 , MAXVAR);
1125 fprintf(cfg, "\"%s\"\n", hvalue);
1127 strncat(hkey, "PKGCS_", 6);
1128 strncat(hkey, token, strlen(token));
1129 memset(hvalue, 0, MAXVALUE);
1130 result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
1131 if (result == 1) {
1132 val = strtok_r(hvalue, " ", &saveptr);
1133 while (val != NULL) {
1134 fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(val));
1135 val = strtok_r(NULL, " ", &saveptr);
1138 memset(hkey, 0, MAXVAR);
1139 token = strtok(NULL, " ");
1141 fprintf(cfg, "\nendchoice\n");
1142 free(pkg_choices);
1143 pkg_choices = NULL;
1145 /* close file descriptor for Config.in file */
1146 fclose(cfg);
1147 /* create Config.in files for development packages */
1148 if (pkg_opts != NULL) {
1149 if (strstr(pkg_opts, "dev") != NULL) {
1150 if (snprintf(path, MAXPATH, "package/pkgconfigs.d/gcc/Config.in.dev") < 0)
1151 fatal_error("failed to create path variable.");
1152 cfg = fopen(path, "a");
1153 if (cfg == NULL)
1154 perror("Can not open Config.in.dev file");
1156 if (pkg_libname == NULL)
1157 pkg_libname = strdup(pkg_name);
1159 fprintf(cfg, "\n");
1160 fprintf(cfg, "config ADK_PACKAGE_%s_DEV\n", toupperstr(pkg_libname));
1162 pseudo_name = malloc(MAXLINE);
1163 memset(pseudo_name, 0, MAXLINE);
1164 strncat(pseudo_name, pkg_libname, strlen(pkg_libname));
1165 strncat(pseudo_name, "-dev", 4);
1166 while (strlen(pseudo_name) < 20)
1167 strncat(pseudo_name, ".", 1);
1169 fprintf(cfg, "\tprompt \"%s. development files for %s\"\n", pseudo_name, pkg_libname);
1170 fprintf(cfg, "\tboolean\n");
1172 /* create package target architecture dependency information */
1173 if (pkg_arch_depends != NULL) {
1174 pkg_helper = strdup(pkg_arch_depends);
1175 token = strtok(pkg_helper, " ");
1176 fprintf(cfg, "\tdepends on ");
1177 sp = "";
1178 while (token != NULL) {
1179 if(strncmp(token, "!", 1) == 0) {
1180 fprintf(cfg, "%s!ADK_TARGET_ARCH%s", sp, toupperstr(token));
1181 sp = " && ";
1182 } else {
1183 fprintf(cfg, "%sADK_TARGET_ARCH_%s", sp, toupperstr(token));
1184 sp = " || ";
1186 token = strtok(NULL, " ");
1188 fprintf(cfg, "\n");
1189 free(pkg_helper);
1190 pkg_helper = NULL;
1193 fprintf(cfg, "\tdepends on ADK_PACKAGE_GCC && ADK_PACKAGE_%s\n", toupperstr(pkg_libname));
1194 fprintf(cfg, "\tdefault n\n");
1195 fclose(cfg);
1196 free(pseudo_name);
1197 free(pkg_libname);
1198 pkg_libname = NULL;
1200 pkg_opts = NULL;
1202 /* parse next package */
1203 token = strtok_r(NULL, " ", &p_ptr);
1206 /* end of package output generation */
1207 free(packages);
1208 packages = NULL;
1210 /* reset flags, free memory */
1211 free(pkg_name);
1212 free(pkg_libname);
1213 free(pkg_descr);
1214 free(pkg_section);
1215 free(pkg_url);
1216 free(pkg_depends);
1217 free(pkg_kdepends);
1218 free(pkg_flavours);
1219 free(pkg_flavours_string);
1220 free(pkg_choices);
1221 free(pkg_subpkgs);
1222 free(pkg_arch_depends);
1223 free(pkg_system_depends);
1224 free(pkg_host_depends);
1225 free(pkg_libc_depends);
1226 free(pkg_dflt);
1227 free(pkg_cfline);
1228 free(pkg_bb);
1229 pkg_name = NULL;
1230 pkg_libname = NULL;
1231 pkg_descr = NULL;
1232 pkg_section = NULL;
1233 pkg_url = NULL;
1234 pkg_depends = NULL;
1235 pkg_kdepends = NULL;
1236 pkg_flavours = NULL;
1237 pkg_flavours_string = NULL;
1238 pkg_choices = NULL;
1239 pkg_subpkgs = NULL;
1240 pkg_arch_depends = NULL;
1241 pkg_system_depends = NULL;
1242 pkg_host_depends = NULL;
1243 pkg_libc_depends = NULL;
1244 pkg_dflt = NULL;
1245 pkg_cfline = NULL;
1246 pkg_bb = NULL;
1248 strmap_delete(pkgmap);
1249 nobinpkgs = 0;
1250 free(hkey);
1254 /* add menu to gcc package */
1255 if (snprintf(path, MAXPATH, "package/pkgconfigs.d/gcc/Config.in.gcc") < 0)
1256 fatal_error("failed to create path variable.");
1257 cfg = fopen(path, "a");
1258 if (cfg == NULL)
1259 perror("Can not open Config.in.gcc file");
1260 fprintf(cfg, "menu \"Development packages\"\n");
1261 fprintf(cfg, "depends on ADK_PACKAGE_GCC\n");
1262 fprintf(cfg, "source \"package/pkgconfigs.d/gcc/Config.in.dev\"\n");
1263 fprintf(cfg, "endmenu\n");
1264 fclose(cfg);
1266 /* create Config.in.auto */
1267 strmap_enum(sectionmap, iter, NULL);
1269 strmap_delete(sectionmap);
1270 fclose(menuglobal);
1271 closedir(pkgdir);
1273 /* remove temporary section files */
1274 pkglistdir = opendir("package/pkglist.d");
1275 while ((pkgdirp = readdir(pkglistdir)) != NULL) {
1276 if (strncmp(pkgdirp->d_name, "sectionlst.", 11) == 0) {
1277 if (snprintf(path, MAXPATH, "package/pkglist.d/%s", pkgdirp->d_name) < 0)
1278 fatal_error("creating path variable failed.");
1279 if (unlink(path) < 0)
1280 fatal_error("removing file failed.");
1283 closedir(pkglistdir);
1284 return(0);