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"
52 for (i = 1; i in Archs; i++) {
53 targetLevel[ Archs[ i ] ] = i
61 function dieLater( code ) {
62 if ( shouldDie < code )
68 sub( /^.*\//, "", f ) # strip path
69 if ( f != lastFile ) {
75 # convert special case:
76 # # CONFIG_SOMETHING it not set
79 /^# CONFIG_[A-Za-z0-9_]+ is not set$/ {
80 match( $0, /CONFIG_[A-Za-z0-9_]+/ )
81 option = substr( $0, RSTART, RLENGTH)
85 # ignore all the comments and empty lines
90 !/^[A-Za-z0-9_]+(=|[ \t]+[A-Za-z0-9_-]+=)/ {
91 warn( "ERROR: Incorrect line: " $0 )
104 if ( option ~ /=/ ) {
105 sub( /=.*$/, "", option )
106 sub( /^[^=]*=/, "", line )
109 sub( "^" option, "", line )
110 sub( /^[ \t]*/, "", line )
114 # there can be white spaces
116 while ( match( line, /^[^=]+="([^"]|\\")*"/ ) ) {
117 archs[ (++i) ] = substr( line, RSTART, RLENGTH )
118 line = substr( line, RSTART + RLENGTH )
119 sub( /^[ \t]*/, "", line )
127 arch = val = archs[ i ]
128 sub( /=.*$/, "", arch )
129 sub( /^[^=]*=/, "", val )
130 tl = targetLevel[ arch ]
138 # completely ignore lines with no value
139 if ( length( value ) == 0 )
142 fileOption = FILENAME "/" option
143 if ( fileOption in outputByFile ) {
144 warn( "ERROR: " option " already defined in this file at line " outputByFile[ fileOption ] )
148 outputByFile[ fileOption ] = FNR
150 if ( option in outputArray ) {
151 warn( "Warning: " option " already defined in: " outputArray[ option ] )
154 outputArray[ option ] = fileLine()
157 out = "# " option " is not set"
159 out = option "=" value
161 if ( value == "y" || value == "m" )
163 else if ( value ~ /^"([^"]|\\")*"$/ )
165 else if ( value ~ /^-?[0-9]+$/ || value ~ /^0x[0-9A-Fa-f]+$/ )
168 warn( "ERROR: Incorrect value: " $0 )