aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/kconfig/confdata.c342
-rw-r--r--scripts/kconfig/lkc.h5
-rw-r--r--scripts/kconfig/lkc_proto.h1
-rw-r--r--scripts/kconfig/symbol.c46
4 files changed, 266 insertions, 128 deletions
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index a49cf4f7dca5..be6952c7fb29 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -422,64 +422,228 @@ int conf_read(const char *name)
422 return 0; 422 return 0;
423} 423}
424 424
425/* Write a S_STRING */ 425/*
426static void conf_write_string(bool headerfile, const char *name, 426 * Kconfig configuration printer
427 const char *str, FILE *out) 427 *
428 * This printer is used when generating the resulting configuration after
429 * kconfig invocation and `defconfig' files. Unset symbol might be omitted by
430 * passing a non-NULL argument to the printer.
431 *
432 */
433static void
434kconfig_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg)
435{
436
437 switch (sym->type) {
438 case S_BOOLEAN:
439 case S_TRISTATE:
440 if (*value == 'n') {
441 bool skip_unset = (arg != NULL);
442
443 if (!skip_unset)
444 fprintf(fp, "# %s%s is not set\n",
445 CONFIG_, sym->name);
446 return;
447 }
448 break;
449 default:
450 break;
451 }
452
453 fprintf(fp, "%s%s=%s\n", CONFIG_, sym->name, value);
454}
455
456static void
457kconfig_print_comment(FILE *fp, const char *value, void *arg)
428{ 458{
429 int l; 459 const char *p = value;
430 if (headerfile) 460 size_t l;
431 fprintf(out, "#define %s%s \"", CONFIG_, name); 461
432 else 462 for (;;) {
433 fprintf(out, "%s%s=\"", CONFIG_, name); 463 l = strcspn(p, "\n");
434 464 fprintf(fp, "#");
435 while (1) {
436 l = strcspn(str, "\"\\");
437 if (l) { 465 if (l) {
438 xfwrite(str, l, 1, out); 466 fprintf(fp, " ");
439 str += l; 467 fwrite(p, l, 1, fp);
468 p += l;
440 } 469 }
441 if (!*str) 470 fprintf(fp, "\n");
471 if (*p++ == '\0')
442 break; 472 break;
443 fprintf(out, "\\%c", *str++);
444 } 473 }
445 fputs("\"\n", out);
446} 474}
447 475
448static void conf_write_symbol(struct symbol *sym, FILE *out, bool write_no) 476static struct conf_printer kconfig_printer_cb =
449{ 477{
450 const char *str; 478 .print_symbol = kconfig_print_symbol,
479 .print_comment = kconfig_print_comment,
480};
481
482/*
483 * Header printer
484 *
485 * This printer is used when generating the `include/generated/autoconf.h' file.
486 */
487static void
488header_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg)
489{
490 const char *suffix = "";
451 491
452 switch (sym->type) { 492 switch (sym->type) {
453 case S_BOOLEAN: 493 case S_BOOLEAN:
454 case S_TRISTATE: 494 case S_TRISTATE:
455 switch (sym_get_tristate_value(sym)) { 495 switch (*value) {
456 case no: 496 case 'n':
457 if (write_no) 497 return;
458 fprintf(out, "# %s%s is not set\n", 498 case 'm':
459 CONFIG_, sym->name); 499 suffix = "_MODULE";
460 break; 500 /* FALLTHROUGH */
461 case mod: 501 default:
462 fprintf(out, "%s%s=m\n", CONFIG_, sym->name); 502 value = "1";
463 break;
464 case yes:
465 fprintf(out, "%s%s=y\n", CONFIG_, sym->name);
466 break;
467 } 503 }
468 break; 504 break;
469 case S_STRING: 505 default:
470 conf_write_string(false, sym->name, sym_get_string_value(sym), out);
471 break; 506 break;
472 case S_HEX: 507 }
473 case S_INT: 508
474 str = sym_get_string_value(sym); 509 fprintf(fp, "#define %s%s%s %s\n",
475 fprintf(out, "%s%s=%s\n", CONFIG_, sym->name, str); 510 CONFIG_, sym->name, suffix, value);
511}
512
513static void
514header_print_comment(FILE *fp, const char *value, void *arg)
515{
516 const char *p = value;
517 size_t l;
518
519 fprintf(fp, "/*\n");
520 for (;;) {
521 l = strcspn(p, "\n");
522 fprintf(fp, " *");
523 if (l) {
524 fprintf(fp, " ");
525 fwrite(p, l, 1, fp);
526 p += l;
527 }
528 fprintf(fp, "\n");
529 if (*p++ == '\0')
530 break;
531 }
532 fprintf(fp, " */\n");
533}
534
535static struct conf_printer header_printer_cb =
536{
537 .print_symbol = header_print_symbol,
538 .print_comment = header_print_comment,
539};
540
541/*
542 * Function-style header printer
543 *
544 * This printer is used to generate the config_is_xxx() function-style macros
545 * in `include/generated/autoconf.h'
546 */
547static void
548header_function_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg)
549{
550 int val = 0;
551 char c;
552 char *tmp, *d;
553
554 switch (sym->type) {
555 case S_BOOLEAN:
556 case S_TRISTATE:
476 break; 557 break;
558 default:
559 return;
560 }
561 if (*value == 'm')
562 val = 2;
563 else if (*value == 'y')
564 val = 1;
565
566 d = strdup(CONFIG_);
567 tmp = d;
568 while ((c = *d)) {
569 *d = tolower(c);
570 d++;
571 }
572
573 fprintf(fp, "#define %sis_", tmp);
574 free(tmp);
575
576 d = strdup(sym->name);
577 tmp = d;
578 while ((c = *d)) {
579 *d = tolower(c);
580 d++;
581 }
582 fprintf(fp, "%s%s() %d\n", tmp, (val > 1) ? "_module" : "",
583