2 # A script for building kernel config from multiarch config file.
3 # It also has some file merging facilities.
6 # awk -v basearch=%{_target_base_arch} -v arch=%{_target_cpu} -f path/to/kernel-config.awk \
7 # kernel-important.config kernel-multiarch.config \
8 # kernel-%{arch}.config kernel-%{some_feature}.config \
12 # - Przemysław Iskra <sparky@pld-linux.org>
13 # parts based on kernel-config.py, by:
14 # - arekm@pld-linux.org
15 # - glen@pld-linux.org
18 # - use as many warnings as possible, we want our configs to be clean
23 # CONFIG_SOMETHING all=n
25 # # CONFIG_SOMETHING is not set -- special case
30 # CONFIG_SOMETHING all=y
34 # return actual file name (without path) and line number
37 sub( /^.*\//, "", f ) # strip path
42 function warn( msg ) {
43 print fileLine() ": " msg > "/dev/stderr"
48 print "arch= must be specified" > "/dev/stderr"
54 targetLevel[ "all" ] = 1
55 targetLevel[ basearch ] = 2
56 targetLevel[ arch ] = 3
61 function dieLater( code ) {
62 if ( shouldDie < code )
66 # convert special case:
67 # # CONFIG_SOMETHING it not set
70 /^# CONFIG_[A-Za-z0-9_]+ is not set$/ {
71 match( $0, /CONFIG_[A-Za-z0-9_]+/ )
72 option = substr( $0, RSTART, RLENGTH)
76 # ignore all the comments and empty lines
81 !/^[A-Za-z0-9_]+(=|[ \t]+[A-Za-z0-9_-]+=)/ {
82 warn( "ERROR: Incorrect line: " $0 )
96 sub( /=.*$/, "", option )
97 sub( /^[^=]*=/, "", line )
100 sub( "^" option, "", line )
101 sub( /^[ \t]*/, "", line )
104 # there can be white spaces
106 while ( match( line, /^[^=]+="([^"]|\\")*"/ ) ) {
107 archs[ (++i) ] = substr( line, RSTART, RLENGTH )
108 line = substr( line, RSTART + RLENGTH )
109 sub( /^[ \t]*/, "", line )
117 arch = val = archs[ i ]
118 sub( /=.*$/, "", arch )
119 sub( /^[^=]*=/, "", val )
120 tl = targetLevel[ arch ]
128 # completely ignore lines with no value
129 if ( length( value ) == 0 )
132 fileOption = FILENAME "/" option
133 if ( fileOption in outputByFile ) {
134 warn( "ERROR: " option " already defined in this file at line " outputByFile[ fileOption ] )
138 outputByFile[ fileOption ] = FNR
140 if ( option in outputArray ) {
141 warn( "Warning: " option " already defined in: " outputArray[ option ] )
144 outputArray[ option ] = fileLine()
147 out = "# " option " is not set"
149 out = option "=" value
151 if ( value == "y" || value == "m" )
153 else if ( value ~ /^"([^"]|\\")*"$/ )
155 else if ( value ~ /^-?[0-9]+$/ || value ~ /^0x[0-9A-Fa-f]+$/ )
158 warn( "ERROR: Incorrect value: " $0 )