package/libnetfilter_cttimeout: drop ltmain.sh patch
[openadk.git] / adk / tools / pkgmaker.c
blobcde0f178d6bedd0e0965ae4e38209e5ef28139c7
1 /*
2 * pkgmaker - create package meta-data for OpenADK buildsystem
4 * Copyright (C) 2010-2014 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_depends_system, *pkg_depends_libc, *pkg_section, *pkg_descr, *pkg_url;
331 char *pkg_cxx, *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_depends_system = NULL;
346 pkg_depends_libc = NULL;
347 pkg_opts = NULL;
348 pkg_libname = NULL;
349 pkg_flavours = NULL;
350 pkg_flavours_string = NULL;
351 pkg_choices = NULL;
352 pkg_subpkgs = NULL;
353 pkg_arch_depends = NULL;
354 pkg_system_depends = NULL;
355 pkg_host_depends = NULL;
356 pkg_libc_depends = NULL;
357 pkg_cxx = NULL;
358 pkg_dflt = NULL;
359 pkg_cfline = NULL;
360 pkgname = NULL;
361 sysname = NULL;
362 pkg_helper = NULL;
363 pkg_debug = NULL;
364 pkg_bb = NULL;
366 p_ptr = NULL;
367 s_ptr = NULL;
369 system("rm package/Config.in.auto.* 2>/dev/null");
370 unlink(runtime);
371 /* open global sectionfile */
372 menuglobal = fopen("package/Config.in.auto.global", "w");
373 if (menuglobal == NULL)
374 fatal_error("global section file not writable.");
376 /* read section list and create a hash table */
377 section = fopen("package/section.lst", "r");
378 if (section == NULL)
379 fatal_error("section listfile is missing");
381 sectionmap = strmap_new(HASHSZ);
382 while (fgets(tbuf, MAXPATH, section) != NULL) {
383 key = strtok(tbuf, "\t");
384 value = strtok(NULL, "\t");
385 strmap_put(sectionmap, key, value);
387 fclose(section);
389 if (mkdir("package/pkgconfigs.d", S_IRWXU) > 0)
390 fatal_error("creation of package/pkgconfigs.d failed.");
391 if (mkdir("package/pkgconfigs.d/gcc", S_IRWXU) > 0)
392 fatal_error("creation of package/pkgconfigs.d/gcc failed.");
393 if (mkdir("package/pkglist.d", S_IRWXU) > 0)
394 fatal_error("creation of package/pkglist.d failed.");
396 /* delete Config.in.dev */
397 if (snprintf(path, MAXPATH, "package/pkgconfigs.d/gcc/Config.in.dev") < 0)
398 fatal_error("failed to create path variable.");
399 unlink(path);
400 cfg = fopen(path, "w");
401 if (cfg == NULL)
402 fatal_error("Config.in.dev can not be opened");
403 fprintf(cfg, "config ADK_PACKAGE_GLIBC_DEV\n");
404 fprintf(cfg, "\tprompt \"glibc-dev............ development files for glibc\"\n");
405 fprintf(cfg, "\tboolean\n");
406 fprintf(cfg, "\tdefault n\n");
407 fprintf(cfg, "\tdepends on ADK_TARGET_LIB_GLIBC\n");
408 fprintf(cfg, "\thelp\n");
409 fprintf(cfg, "\t GNU C library header files.\n\n");
410 fprintf(cfg, "config ADK_PACKAGE_UCLIBC_NG_DEV\n");
411 fprintf(cfg, "\tprompt \"uclibc-ng-dev........ development files for uclibc-ng\"\n");
412 fprintf(cfg, "\tboolean\n");
413 fprintf(cfg, "\tdefault n\n");
414 fprintf(cfg, "\tdepends on ADK_TARGET_LIB_UCLIBC_NG\n");
415 fprintf(cfg, "\thelp\n");
416 fprintf(cfg, "\t C library header files.\n\n");
417 fprintf(cfg, "config ADK_PACKAGE_UCLIBC_DEV\n");
418 fprintf(cfg, "\tprompt \"uclibc-dev........... development files for uclibc\"\n");
419 fprintf(cfg, "\tboolean\n");
420 fprintf(cfg, "\tdefault n\n");
421 fprintf(cfg, "\tdepends on ADK_TARGET_LIB_UCLIBC\n");
422 fprintf(cfg, "\thelp\n");
423 fprintf(cfg, "\t C library header files.\n\n");
424 fprintf(cfg, "config ADK_PACKAGE_MUSL_DEV\n");
425 fprintf(cfg, "\tprompt \"musl-dev............. development files for musl\"\n");
426 fprintf(cfg, "\tboolean\n");
427 fprintf(cfg, "\tdefault n\n");
428 fprintf(cfg, "\tdepends on ADK_TARGET_LIB_MUSL\n");
429 fprintf(cfg, "\thelp\n");
430 fprintf(cfg, "\t C library header files.\n\n");
431 fclose(cfg);
434 /* read Makefile's for all packages */
435 pkgdir = opendir("package");
436 while ((pkgdirp = readdir(pkgdir)) != NULL) {
437 /* skip dotfiles */
438 if (strncmp(pkgdirp->d_name, ".", 1) > 0) {
439 if (snprintf(path, MAXPATH, "package/%s/Makefile", pkgdirp->d_name) < 0)
440 fatal_error("can not create path variable.");
441 pkg = fopen(path, "r");
442 if (pkg == NULL)
443 continue;
445 /* runtime configuration */
446 if (snprintf(script, MAXPATH, "package/%s/files", pkgdirp->d_name) < 0)
447 fatal_error("script variable creation failed.");
448 scriptdir = opendir(script);
449 if (scriptdir != NULL) {
450 while ((scriptdirp = readdir(scriptdir)) != NULL) {
451 /* skip dotfiles */
452 if (strncmp(scriptdirp->d_name, ".", 1) > 0) {
453 len = strlen(scriptdirp->d_name);
454 if (strlen(".init") > len)
455 continue;
456 if (strncmp(scriptdirp->d_name + len - strlen(".init"), ".init", strlen(".init")) == 0) {
457 if (snprintf(script, MAXPATH, "package/%s/files/%s", pkgdirp->d_name, scriptdirp->d_name) < 0)
458 fatal_error("script variable creation failed.");
459 initscript = fopen(script, "r");
460 if (initscript == NULL)
461 continue;
463 while (fgets(ibuf, MAXPATH, initscript) != NULL) {
464 if (strncmp("#PKG", ibuf, 4) == 0) {
465 sname = strdup(ibuf+5);
466 sname[strlen(sname)-1] = '\0';
467 sname2 = strdup(scriptdirp->d_name);
468 sname2[strlen(sname2)-5] = '\0';
469 icfg = fopen(runtime, "a");
470 if (icfg == NULL)
471 continue;
472 if (strncmp("busybox", sname, 7) == 0)
473 fprintf(icfg, "config ADK_RUNTIME_START_%s_%s\n", toupperstr(sname), toupperstr(sname2));
474 else
475 fprintf(icfg, "config ADK_RUNTIME_START_%s\n", toupperstr(sname));
476 fprintf(icfg, "\tprompt \"Start %s on boot\"\n", sname2);
477 fprintf(icfg, "\ttristate\n");
478 if (strncmp("busybox", sname, 7) == 0)
479 fprintf(icfg, "\tdepends on BUSYBOX_%s\n", toupperstr(sname2));
480 else
481 fprintf(icfg, "\tdepends on ADK_PACKAGE_%s\n", toupperstr(sname));
482 fprintf(icfg, "\tdepends on ADK_RUNTIME_START_SERVICES\n");
483 fprintf(icfg, "\tdefault n\n\n");
484 fclose(icfg);
486 continue;
487 free(sname);
488 free(sname2);
493 closedir(scriptdir);
496 /* skip manually maintained packages */
497 if (snprintf(path, MAXPATH, "package/%s/Config.in.manual", pkgdirp->d_name) < 0)
498 fatal_error("can not create path variable.");
499 if (!access(path, F_OK)) {
500 while (fgets(buf, MAXPATH, pkg) != NULL) {
501 if ((parse_var(buf, "PKG_SECTION", NULL, &pkg_section)) == 0)
502 continue;
505 memset(hvalue, 0 , MAXVALUE);
506 result = strmap_get(sectionmap, pkg_section, hvalue, sizeof(hvalue));
507 if (result == 1) {
508 if (snprintf(spath, MAXPATH, "package/pkglist.d/sectionlst.%d", hash_str(hvalue)) < 0)
509 fatal_error("can not create path variable.");
510 section = fopen(spath, "a");
511 if (section != NULL) {
512 fprintf(section, "%s@\n", pkgdirp->d_name);
513 fclose(section);
515 } else
516 fatal_error("Can not find section description %s for package %s.",
517 pkg_section, pkgdirp->d_name);
519 fclose(pkg);
520 continue;
523 nobinpkgs = 0;
525 /* create output directories */
526 if (snprintf(dir, MAXPATH, "package/pkgconfigs.d/%s", pkgdirp->d_name) < 0)
527 fatal_error("can not create dir variable.");
528 if (mkdir(dir, S_IRWXU) > 0)
529 fatal_error("can not create directory.");
532 /* allocate memory */
533 hkey = malloc(MAXVAR);
534 memset(hkey, 0, MAXVAR);
535 memset(variable, 0, 2*MAXVAR);
537 pkgmap = strmap_new(HASHSZ);
539 /* parse package Makefile */
540 while (fgets(buf, MAXPATH, pkg) != NULL) {
541 /* just read variables prefixed with PKG */
542 if (strncmp(buf, "PKG", 3) == 0) {
543 if ((parse_var(buf, "PKG_NAME", NULL, &pkg_name)) == 0)
544 continue;
545 if (pkg_name != NULL)
546 pkg_name_u = toupperstr(pkg_name);
547 else
548 pkg_name_u = toupperstr(pkgdirp->d_name);
550 snprintf(variable, MAXVAR, "PKG_CFLINE_%s", pkg_name_u);
551 if ((parse_var(buf, variable, pkg_cfline, &pkg_cfline)) == 0)
552 continue;
553 snprintf(variable, MAXVAR, "PKG_DFLT_%s", pkg_name_u);
554 if ((parse_var(buf, variable, NULL, &pkg_dflt)) == 0)
555 continue;
556 if ((parse_var(buf, "PKG_LIBC_DEPENDS", NULL, &pkg_libc_depends)) == 0)
557 continue;
558 if ((parse_var(buf, "PKG_HOST_DEPENDS", NULL, &pkg_host_depends)) == 0)
559 continue;
560 if ((parse_var(buf, "PKG_ARCH_DEPENDS", NULL, &pkg_arch_depends)) == 0)
561 continue;
562 if ((parse_var(buf, "PKG_SYSTEM_DEPENDS", NULL, &pkg_system_depends)) == 0)
563 continue;
564 if ((parse_var(buf, "PKG_DESCR", NULL, &pkg_descr)) == 0)
565 continue;
566 if ((parse_var(buf, "PKG_SECTION", NULL, &pkg_section)) == 0)
567 continue;
568 if ((parse_var(buf, "PKG_URL", NULL, &pkg_url)) == 0)
569 continue;
570 if ((parse_var(buf, "PKG_CXX", NULL, &pkg_cxx)) == 0)
571 continue;
572 if ((parse_var(buf, "PKG_BB", NULL, &pkg_bb)) == 0)
573 continue;
574 if ((parse_var(buf, "PKG_DEPENDS", pkg_depends, &pkg_depends)) == 0)
575 continue;
576 if ((parse_var_with_system(buf, "PKG_DEPENDS_", pkg_depends_system, &pkg_depends_system, &sysname, 12)) == 0)
577 continue;
578 if ((parse_var_with_system(buf, "PKG_DEPENDS_", pkg_depends_libc, &pkg_depends_libc, &sysname, 12)) == 0)
579 continue;
580 if ((parse_var(buf, "PKG_LIBNAME", pkg_libname, &pkg_libname)) == 0)
581 continue;
582 if ((parse_var(buf, "PKG_OPTS", pkg_opts, &pkg_opts)) == 0)
583 continue;
584 if ((parse_var_with_pkg(buf, "PKG_FLAVOURS_STRING_", pkg_flavours_string, &pkg_flavours_string, &pkgname, 20)) == 0)
585 continue;
586 if ((parse_var_with_pkg(buf, "PKG_FLAVOURS_", pkg_flavours, &pkg_flavours, &pkgname, 13)) == 0)
587 continue;
588 if ((parse_var_hash(buf, "PKGFD_", pkgmap)) == 0)
589 continue;
590 if ((parse_var_hash(buf, "PKGFX_", pkgmap)) == 0)
591 continue;
592 if ((parse_var_hash(buf, "PKGFS_", pkgmap)) == 0)
593 continue;
594 if ((parse_var_hash(buf, "PKGFC_", pkgmap)) == 0)
595 continue;
596 if ((parse_var_with_pkg(buf, "PKG_CHOICES_", pkg_choices, &pkg_choices, &pkgname, 12)) == 0)
597 continue;
598 if ((parse_var_hash(buf, "PKGCD_", pkgmap)) == 0)
599 continue;
600 if ((parse_var_hash(buf, "PKGCS_", pkgmap)) == 0)
601 continue;
602 if ((parse_var(buf, "PKG_SUBPKGS", pkg_subpkgs, &pkg_subpkgs)) == 0)
603 continue;
604 if ((parse_var_hash(buf, "PKGSD_", pkgmap)) == 0)
605 continue;
606 if ((parse_var_hash(buf, "PKGSS_", pkgmap)) == 0)
607 continue;
608 if ((parse_var_hash(buf, "PKGSC_", pkgmap)) == 0)
609 continue;
610 if ((parse_var_hash(buf, "PKGSN_", pkgmap)) == 0)
611 continue;
615 /* when PKG_LIBNAME exist use this instead of PKG_NAME, but only for !libmix */
616 if (pkg_libname != NULL)
617 if (pkg_opts != NULL)
618 if (strstr(pkg_opts, "libmix") == NULL)
619 pkg_name = strdup(pkg_libname);
621 /* end of package Makefile parsing */
622 if (fclose(pkg) != 0)
623 perror("Failed to close file stream for Makefile");
625 #if 0
626 if (pkg_name != NULL)
627 fprintf(stderr, "Package name is %s\n", pkg_name);
628 if (pkg_libname != NULL)
629 fprintf(stderr, "Package library name is %s\n", pkg_libname);
630 if (pkg_section != NULL)
631 fprintf(stderr, "Package section is %s\n", pkg_section);
632 if (pkg_descr != NULL)
633 fprintf(stderr, "Package description is %s\n", pkg_descr);
634 if (pkg_depends != NULL)
635 fprintf(stderr, "Package dependencies are %s\n", pkg_depends);
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 (disabled, 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, "\tboolean\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 /* create package target system dependency information */
809 if (pkg_system_depends != NULL) {
810 pkg_helper = strdup(pkg_system_depends);
811 token = strtok(pkg_helper, " ");
812 fprintf(cfg, "\tdepends on ");
813 sp = "";
814 while (token != NULL) {
815 if(strncmp(token, "!", 1) == 0) {
816 fprintf(cfg, "%s!ADK_TARGET_SYSTEM%s", sp, toupperstr(token));
817 sp = " && ";
818 } else {
819 fprintf(cfg, "%sADK_TARGET_SYSTEM_%s", sp, toupperstr(token));
820 sp = " || ";
822 token = strtok(NULL, " ");
824 fprintf(cfg, "\n");
825 free(pkg_helper);
826 pkg_helper = NULL;
828 /* create package host dependency information */
829 if (pkg_host_depends != NULL) {
830 pkg_helper = strdup(pkg_host_depends);
831 token = strtok(pkg_helper, " ");
832 fprintf(cfg, "\tdepends on ");
833 sp = "";
834 while (token != NULL) {
835 if(strncmp(token, "!", 1) == 0) {
836 fprintf(cfg, "%s!ADK_HOST%s", sp, toupperstr(token));
837 sp = " && ";
838 } else {
839 fprintf(cfg, "%sADK_HOST_%s", sp, toupperstr(token));
840 sp = " || ";
842 token = strtok(NULL, " ");
844 fprintf(cfg, "\n");
845 free(pkg_helper);
846 pkg_helper = NULL;
849 /* create package libc dependency information */
850 if (pkg_libc_depends != NULL) {
851 pkg_helper = strdup(pkg_libc_depends);
852 token = strtok(pkg_helper, " ");
853 fprintf(cfg, "\tdepends on ");
854 sp = "";
855 while (token != NULL) {
856 if(strncmp(token, "!", 1) == 0) {
857 fprintf(cfg, "%s!ADK_TARGET_LIB_%s", sp, toupperstr(token));
858 sp = " && ";
859 } else {
860 fprintf(cfg, "%sADK_TARGET_LIB_%s", sp, toupperstr(token));
861 sp = " || ";
863 token = strtok(NULL, " ");
865 fprintf(cfg, "\n");
866 free(pkg_helper);
867 pkg_helper = NULL;
869 /* create package target architecture dependency information */
870 if (pkg_arch_depends != NULL) {
871 pkg_helper = strdup(pkg_arch_depends);
872 token = strtok(pkg_helper, " ");
873 fprintf(cfg, "\tdepends on ");
874 sp = "";
875 while (token != NULL) {
876 if(strncmp(token, "!", 1) == 0) {
877 fprintf(cfg, "%s!ADK_TARGET_ARCH%s", sp, toupperstr(token));
878 sp = " && ";
879 } else {
880 fprintf(cfg, "%sADK_TARGET_ARCH_%s", sp, toupperstr(token));
881 sp = " || ";
883 token = strtok(NULL, " ");
885 fprintf(cfg, "\n");
886 free(pkg_helper);
887 pkg_helper = NULL;
890 /* create package dependency information */
891 if (pkg_depends != NULL) {
892 token = strtok(pkg_depends, " ");
893 while (token != NULL) {
894 fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(token));
895 token = strtok(NULL, " ");
897 free(pkg_depends);
898 pkg_depends = NULL;
900 /* create system specific package dependency information */
901 if (pkg_depends_system != NULL) {
902 token = strtok(pkg_depends_system, " ");
903 while (token != NULL) {
904 fprintf(cfg, "\tselect ADK_PACKAGE_%s if ADK_TARGET_SYSTEM_%s\n", toupperstr(token), sysname);
905 token = strtok(NULL, " ");
907 free(pkg_depends_system);
908 pkg_depends_system = NULL;
910 /* create libc specific package dependency information */
911 if (pkg_depends_libc != NULL) {
912 token = strtok(pkg_depends_libc, " ");
913 while (token != NULL) {
914 fprintf(cfg, "\tselect ADK_PACKAGE_%s if ADK_TARGET_LIB_%s\n", toupperstr(token), sysname);
915 token = strtok(NULL, " ");
917 free(pkg_depends_libc);
918 pkg_depends_libc = NULL;
921 if (pkg_bb != NULL) {
922 fprintf(cfg, "\tdepends on !ADK_PACKAGE_BUSYBOX_HIDE\n");
924 fprintf(cfg, "\tselect ADK_COMPILE_%s\n", toupperstr(pkgdirp->d_name));
926 if (pkg_dflt != NULL) {
927 fprintf(cfg, "\tdefault %s\n", pkg_dflt);
928 pkg_dflt = NULL;
929 } else {
930 fprintf(cfg, "\tdefault n\n");
933 fprintf(cfg, "\thelp\n");
934 fprintf(cfg, "\t %s\n\n", pkg_descr);
935 if (pkg_url != NULL)
936 fprintf(cfg, "\t WWW: %s\n", pkg_url);
938 /* handle special C++ packages */
939 if (pkg_cxx != NULL) {
940 fprintf(cfg, "\nchoice\n");
941 fprintf(cfg, "prompt \"C++ library to use\"\n");
942 fprintf(cfg, "depends on ADK_COMPILE_%s\n\n", toupperstr(pkgdirp->d_name));
943 fprintf(cfg, "default ADK_COMPILE_%s_WITH_STDCXX if ADK_TARGET_LIB_GLIBC\n", pkg_cxx);
944 fprintf(cfg, "default ADK_COMPILE_%s_WITH_UCLIBCXX if ADK_TARGET_LIB_UCLIBC\n\n", pkg_cxx);
945 fprintf(cfg, "config ADK_COMPILE_%s_WITH_STDCXX\n", pkg_cxx);
946 fprintf(cfg, "\tbool \"GNU C++ library\"\n");
947 fprintf(cfg, "\tselect ADK_PACKAGE_LIBSTDCXX\n\n");
948 fprintf(cfg, "config ADK_COMPILE_%s_WITH_UCLIBCXX\n", pkg_cxx);
949 fprintf(cfg, "\tbool \"uClibc++ library\"\n");
950 fprintf(cfg, "\tselect ADK_PACKAGE_UCLIBCXX\n\n");
951 fprintf(cfg, "endchoice\n");
952 free(pkg_cxx);
953 pkg_cxx = NULL;
956 /* handle debug subpackages */
957 fprintf(cfg, "\nconfig ADK_PACKAGE_%s_DBG\n", toupperstr(pkg_debug));
958 fprintf(cfg, "\tbool \"add debug symbols package\"\n");
959 fprintf(cfg, "\tdepends on ADK_PACKAGE_GDB && ADK_BUILD_WITH_DEBUG\n");
960 fprintf(cfg, "\tdepends on !ADK_DEBUG\n");
961 fprintf(cfg, "\tdepends on ADK_PACKAGE_%s\n", toupperstr(pkg_debug));
962 fprintf(cfg, "\tdefault n\n");
963 fprintf(cfg, "\thelp\n\n");
965 /* package flavours */
966 if (pkg_flavours != NULL) {
967 token = strtok(pkg_flavours, " ");
968 while (token != NULL) {
969 fprintf(cfg, "\nconfig ADK_PACKAGE_%s_%s\n", pkgname, toupperstr(token));
971 // process default value
972 strncat(hkey, "PKGFX_", 6);
973 strncat(hkey, token, strlen(token));
974 memset(hvalue, 0 , MAXVALUE);
975 strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
976 memset(hkey, 0 , MAXVAR);
977 pkg_fd = strdup(hvalue);
978 if (strlen(pkg_fd) > 0)
979 fprintf(cfg, "\tdefault %s\n", pkg_fd);
980 else
981 fprintf(cfg, "\tdefault n\n");
984 // process flavour cfline
985 strncat(hkey, "PKGFC_", 6);
986 strncat(hkey, token, strlen(token));
987 memset(hvalue, 0 , MAXVALUE);
988 strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
989 memset(hkey, 0 , MAXVAR);
990 pkg_fd = strdup(hvalue);
991 if (strlen(pkg_fd) > 0)
992 fprintf(cfg, "\t%s\n", pkg_fd);
994 fprintf(cfg, "\tboolean ");
995 strncat(hkey, "PKGFD_", 6);
996 strncat(hkey, token, strlen(token));
997 memset(hvalue, 0 , MAXVALUE);
998 strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
999 memset(hkey, 0 , MAXVAR);
1000 pkg_fd = strdup(hvalue);
1002 fprintf(cfg, "\"%s\"\n", pkg_fd);
1003 fprintf(cfg, "\tdepends on ADK_PACKAGE_%s\n", pkgname);
1004 strncat(hkey, "PKGFS_", 6);
1005 strncat(hkey, token, strlen(token));
1007 result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
1008 if (result == 1) {
1009 val = strtok_r(hvalue, " ", &saveptr);
1010 while (val != NULL) {
1011 fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(val));
1012 val = strtok_r(NULL, " ", &saveptr);
1015 memset(hkey, 0, MAXVAR);
1016 fprintf(cfg, "\thelp\n");
1017 fprintf(cfg, "\t %s\n", pkg_fd);
1018 token = strtok(NULL, " ");
1020 free(pkg_flavours);
1021 pkg_flavours = NULL;
1024 /* package flavours string */
1025 if (pkg_flavours_string != NULL) {
1026 token = strtok(pkg_flavours_string, " ");
1027 while (token != NULL) {
1028 fprintf(cfg, "\nconfig ADK_PACKAGE_%s_%s\n", pkgname, toupperstr(token));
1030 // process default value
1031 strncat(hkey, "PKGFX_", 6);
1032 strncat(hkey, token, strlen(token));
1033 memset(hvalue, 0 , MAXVALUE);
1034 strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
1035 memset(hkey, 0 , MAXVAR);
1036 pkg_fd = strdup(hvalue);
1037 if (strlen(pkg_fd) > 0)
1038 fprintf(cfg, "\tdefault \"%s\"\n", pkg_fd);
1040 // process flavour cfline
1041 strncat(hkey, "PKGFC_", 6);
1042 strncat(hkey, token, strlen(token));
1043 memset(hvalue, 0 , MAXVALUE);
1044 strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
1045 memset(hkey, 0 , MAXVAR);
1046 pkg_fd = strdup(hvalue);
1047 if (strlen(pkg_fd) > 0)
1048 fprintf(cfg, "\t%s\n", pkg_fd);
1050 fprintf(cfg, "\tstring ");
1051 strncat(hkey, "PKGFD_", 6);
1052 strncat(hkey, token, strlen(token));
1053 memset(hvalue, 0 , MAXVALUE);
1054 strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
1055 memset(hkey, 0 , MAXVAR);
1056 pkg_fd = strdup(hvalue);
1057 fprintf(cfg, "\"%s\"\n", pkg_fd);
1059 fprintf(cfg, "\tdepends on ADK_PACKAGE_%s\n", pkgname);
1060 strncat(hkey, "PKGFS_", 6);
1061 strncat(hkey, token, strlen(token));
1063 result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
1064 if (result == 1) {
1065 val = strtok_r(hvalue, " ", &saveptr);
1066 while (val != NULL) {
1067 fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(val));
1068 val = strtok_r(NULL, " ", &saveptr);
1071 memset(hkey, 0, MAXVAR);
1072 fprintf(cfg, "\thelp\n");
1073 fprintf(cfg, "\t %s\n", pkg_fd);
1074 token = strtok(NULL, " ");
1076 free(pkg_flavours_string);
1077 pkg_flavours_string = NULL;
1080 /* package choices */
1081 if (pkg_choices != NULL) {
1082 fprintf(cfg, "\nchoice\n");
1083 fprintf(cfg, "prompt \"Package flavour choice\"\n");
1084 fprintf(cfg, "depends on ADK_PACKAGE_%s\n\n", pkgname);
1085 token = strtok(pkg_choices, " ");
1086 while (token != NULL) {
1087 fprintf(cfg, "config ADK_PACKAGE_%s_%s\n", pkgname, toupperstr(token));
1089 fprintf(cfg, "\tbool ");
1090 strncat(hkey, "PKGCD_", 6);
1091 strncat(hkey, token, strlen(token));
1092 memset(hvalue, 0 , MAXVALUE);
1093 strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
1094 memset(hkey, 0 , MAXVAR);
1095 fprintf(cfg, "\"%s\"\n", hvalue);
1097 strncat(hkey, "PKGCS_", 6);
1098 strncat(hkey, token, strlen(token));
1099 memset(hvalue, 0, MAXVALUE);
1100 result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
1101 if (result == 1) {
1102 val = strtok_r(hvalue, " ", &saveptr);
1103 while (val != NULL) {
1104 fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(val));
1105 val = strtok_r(NULL, " ", &saveptr);
1108 memset(hkey, 0, MAXVAR);
1109 token = strtok(NULL, " ");
1111 fprintf(cfg, "\nendchoice\n");
1112 free(pkg_choices);
1113 pkg_choices = NULL;
1115 /* close file descriptor for Config.in file */
1116 fclose(cfg);
1117 /* create Config.in files for development packages */
1118 if (pkg_opts != NULL) {
1119 if (strstr(pkg_opts, "dev") != NULL) {
1120 if (snprintf(path, MAXPATH, "package/pkgconfigs.d/gcc/Config.in.dev") < 0)
1121 fatal_error("failed to create path variable.");
1122 cfg = fopen(path, "a");
1123 if (cfg == NULL)
1124 perror("Can not open Config.in.dev file");
1126 if (pkg_libname == NULL)
1127 pkg_libname = strdup(pkg_name);
1129 fprintf(cfg, "\n");
1130 fprintf(cfg, "config ADK_PACKAGE_%s_DEV\n", toupperstr(pkg_libname));
1132 pseudo_name = malloc(MAXLINE);
1133 memset(pseudo_name, 0, MAXLINE);
1134 strncat(pseudo_name, pkg_libname, strlen(pkg_libname));
1135 strncat(pseudo_name, "-dev", 4);
1136 while (strlen(pseudo_name) < 20)
1137 strncat(pseudo_name, ".", 1);
1139 fprintf(cfg, "\tprompt \"%s. development files for %s\"\n", pseudo_name, pkg_libname);
1140 fprintf(cfg, "\tboolean\n");
1142 /* create package target architecture dependency information */
1143 if (pkg_arch_depends != NULL) {
1144 pkg_helper = strdup(pkg_arch_depends);
1145 token = strtok(pkg_helper, " ");
1146 fprintf(cfg, "\tdepends on ");
1147 sp = "";
1148 while (token != NULL) {
1149 if(strncmp(token, "!", 1) == 0) {
1150 fprintf(cfg, "%s!ADK_TARGET_ARCH%s", sp, toupperstr(token));
1151 sp = " && ";
1152 } else {
1153 fprintf(cfg, "%sADK_TARGET_ARCH_%s", sp, toupperstr(token));
1154 sp = " || ";
1156 token = strtok(NULL, " ");
1158 fprintf(cfg, "\n");
1159 free(pkg_helper);
1160 pkg_helper = NULL;
1163 fprintf(cfg, "\tdepends on ADK_PACKAGE_GCC && ADK_PACKAGE_%s\n", toupperstr(pkg_libname));
1164 fprintf(cfg, "\tdefault n\n");
1165 fclose(cfg);
1166 free(pseudo_name);
1167 free(pkg_libname);
1168 pkg_libname = NULL;
1170 pkg_opts = NULL;
1172 /* parse next package */
1173 token = strtok_r(NULL, " ", &p_ptr);
1176 /* end of package output generation */
1177 free(packages);
1178 packages = NULL;
1180 /* reset flags, free memory */
1181 free(pkg_name);
1182 free(pkg_libname);
1183 free(pkg_descr);
1184 free(pkg_section);
1185 free(pkg_url);
1186 free(pkg_depends);
1187 free(pkg_flavours);
1188 free(pkg_flavours_string);
1189 free(pkg_choices);
1190 free(pkg_subpkgs);
1191 free(pkg_arch_depends);
1192 free(pkg_system_depends);
1193 free(pkg_host_depends);
1194 free(pkg_libc_depends);
1195 free(pkg_cxx);
1196 free(pkg_dflt);
1197 free(pkg_cfline);
1198 free(pkg_bb);
1199 pkg_name = NULL;
1200 pkg_libname = NULL;
1201 pkg_descr = NULL;
1202 pkg_section = NULL;
1203 pkg_url = NULL;
1204 pkg_depends = NULL;
1205 pkg_flavours = NULL;
1206 pkg_flavours_string = NULL;
1207 pkg_choices = NULL;
1208 pkg_subpkgs = NULL;
1209 pkg_arch_depends = NULL;
1210 pkg_system_depends = NULL;
1211 pkg_host_depends = NULL;
1212 pkg_libc_depends = NULL;
1213 pkg_cxx = NULL;
1214 pkg_dflt = NULL;
1215 pkg_cfline = NULL;
1216 pkg_bb = NULL;
1218 strmap_delete(pkgmap);
1219 nobinpkgs = 0;
1220 free(hkey);
1224 /* add menu to gcc package */
1225 if (snprintf(path, MAXPATH, "package/pkgconfigs.d/gcc/Config.in.gcc") < 0)
1226 fatal_error("failed to create path variable.");
1227 cfg = fopen(path, "a");
1228 if (cfg == NULL)
1229 perror("Can not open Config.in.gcc file");
1230 fprintf(cfg, "menu \"Development packages\"\n");
1231 fprintf(cfg, "depends on ADK_PACKAGE_GCC\n");
1232 fprintf(cfg, "source \"package/pkgconfigs.d/gcc/Config.in.dev\"\n");
1233 fprintf(cfg, "endmenu\n");
1234 fclose(cfg);
1236 /* create Config.in.auto */
1237 strmap_enum(sectionmap, iter, NULL);
1239 strmap_delete(sectionmap);
1240 fclose(menuglobal);
1241 closedir(pkgdir);
1243 /* remove temporary section files */
1244 pkglistdir = opendir("package/pkglist.d");
1245 while ((pkgdirp = readdir(pkglistdir)) != NULL) {
1246 if (strncmp(pkgdirp->d_name, "sectionlst.", 11) == 0) {
1247 if (snprintf(path, MAXPATH, "package/pkglist.d/%s", pkgdirp->d_name) < 0)
1248 fatal_error("creating path variable failed.");
1249 if (unlink(path) < 0)
1250 fatal_error("removing file failed.");
1253 closedir(pkglistdir);
1254 return(0);