diff --git a/scripts/mk_autoconf.pl b/scripts/mk_autoconf.pl index 52e7f4ec..bd311a78 100755 --- a/scripts/mk_autoconf.pl +++ b/scripts/mk_autoconf.pl @@ -1,50 +1,78 @@ #!/usr/bin/perl # GPL Paul Slootman 1998 +# Peter Marschall 2012 # # script to convert .config as generated by 'make menuconfig' into -# scripts/autoconf.h , so that one can edit .config by hand and then -# non-interactively create a configuration ready for building. Useful -# for package building (I'm thinking Debian or Red Hat here). +# scripts/autoconf.h ans scripts/autoconf.mk, so that one can edit +# .config by hand and then non-interactively create a configuration +# ready for building. Useful for package building (I'm thinking Debian +# or Red Hat here). -open(IN, "<.config") || die "Can't open .config: $!\n"; -open(OUT, ">scripts/autoconf.h") || die "Can't open scripts/autoconf.h: $!\n"; +open(IN, "<.config") or die "Can't open .config: $!\n"; +open(OUT_H, ">scripts/autoconf.h") or die "Can't open scripts/autoconf.h: $!\n"; +open(OUT_MK, ">scripts/autoconf.mk") or die "Can't open scripts/autoconf.mk: $!\n"; -while () { - chop; - next if /^#\s*$/; # empty comment line; ignore - if (/^\s*$/) { # empty line; echo - print OUT "\n"; - next; +while (my $line = ) { + chomp($line); + + if ($line =~ /^#\s*$/o) { # empty comment line; ignore for autoconf.h + printf OUT_MK "%s\n", $line; } - if (/^# ([^\s]+) is not set/) { # unset variables - print OUT "#undef $1\n"; - next; + elsif ($line =~ /^\s*$/o) { # empty line; echo + print OUT_H "\n"; + printf OUT_MK "%s\n", $line; } - if (/^#\s+([^\s].*)\s*/) { # comment - print OUT "/*\n * $1\n */\n"; - print OUT "#define AUTOCONF_INCLUDED\n" if /Automatically generated by/; - next; + elsif ($line =~ /^# ([^\s]+) is not set/o) { # unset variables + my $var = $1; + + printf OUT_H "#undef %s\n", $var; + printf OUT_MK "%s\n", $line; } - if (/(\w+)=(.*)/) { # assignment - $var = $1; - $val = $2; - if ($val eq 'y') { # boolean true value - print OUT "#define $var 1\n"; - next; + elsif ($line =~ /^#\s+([^\s].*)\s*/o) { # comment + my $comment = $1; + + $line =~ s/(make menuconfig)/'$1' and '$0'/ + if ($line =~/Automatically generated by/); + + printf OUT_H "/*\n * %s\n */\n", $comment; + print OUT_H "#define AUTOCONF_INCLUDED\n" + if ($line =~/Automatically generated by/); + printf OUT_MK "# %s\n", $comment; + } + elsif ($line =~ /(\w+)=(.*)/o) { # assignment + my ($var,$val) = ($1,$2); + + if ($val =~ /^(?:y|yes|true|on)$/io) { # boolean TRUE value + printf OUT_H "#define %-32s 1\n", $var; + printf OUT_MK "%-32s = y\n", $var; } - if ($val =~ /^['"](.*)["']$/) { # string value - print OUT "#define $var \"$1\"\n"; - next; + elsif ($val =~ /^(?:n|no|false|off)$/io) { # boolean FALSE value; like unset variable + printf OUT_H "#undef %s\n", $var; + printf OUT_MK "# %s is not set\n", $var; } - if ($val =~ /^(\d+)$/) { # numeric value - print OUT "#define $var ($1)\n"; - next; + elsif ($val =~ /^(['"])(.*)\1$/o) { # string value + my $str = $2; + + printf OUT_H "#define %-32s \"%s\"\n", $var, $str; + printf OUT_MK "%-32s = %s\n", $var, $str; } - die "Unexpected input at line $.: $_\n"; + elsif ($val =~ /^(-?\d+)$/) { # numeric value + my $num = $1; + + printf OUT_H "#define %-32s (%s)\n", $var, $num; + printf OUT_MK "%-32s = %s\n", $var, $num; + } + else { + die "Unexpected input in .config at line $.: $line\n"; + } + } + else { + die "Unexpected input in .config at line $.: $line\n"; } } close(IN); -close(OUT); +close(OUT_H); +close(OUT_MK); exit(0);