#!/usr/bin/perl # GPL Paul Slootman 1998 # Peter Marschall 2012 # # script to convert .config as generated by 'make menuconfig' into # 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") 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 (my $line = ) { chomp($line); if ($line =~ /^#\s*$/o) { # empty comment line; ignore for autoconf.h printf OUT_MK "%s\n", $line; } elsif ($line =~ /^\s*$/o) { # empty line; echo print OUT_H "\n"; printf OUT_MK "%s\n", $line; } 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; } 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; } 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; } 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; } 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_H); close(OUT_MK); exit(0);