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
63 function dieLater( code ) {
64 if ( shouldDie < code )
70 sub( /^.*\//, "", f ) # strip path
71 if ( f != lastFile ) {
77 # convert special case:
78 # # CONFIG_SOMETHING it not set
81 /^# CONFIG_[A-Za-z0-9_]+ is not set$/ {
82 match( $0, /CONFIG_[A-Za-z0-9_]+/ )
83 option = substr( $0, RSTART, RLENGTH)
87 # ignore all the comments and empty lines
92 !/^[A-Za-z0-9_]+(=|[ \t]+[A-Za-z0-9_-]+=)/ {
93 warn( "ERROR: Incorrect line: " $0 )
106 if ( option ~ /=/ ) {
107 sub( /=.*$/, "", option )
108 sub( /^[^=]*=/, "", line )
111 sub( "^" option, "", line )
112 sub( /^[ \t]*/, "", line )
116 # there can be white spaces
118 while ( match( line, /^[^=]+="([^"]|\\")*"/ ) ) {
119 archs[ (++i) ] = substr( line, RSTART, RLENGTH )
120 line = substr( line, RSTART + RLENGTH )
121 sub( /^[ \t]*/, "", line )
129 arch = val = archs[ i ]
130 sub( /=.*$/, "", arch )
131 sub( /^[^=]*=/, "", val )
132 tl = targetLevel[ arch ]
140 # completely ignore lines with no value
141 if ( length( value ) == 0 )
144 fileOption = FILENAME "/" option
145 if ( fileOption in outputByFile ) {
146 warn( "ERROR: " option " already defined in this file at line " outputByFile[ fileOption ] )
150 outputByFile[ fileOption ] = FNR
152 if ( option in outputArray ) {
153 warn( "Warning: " option " already defined in: " outputArray[ option ] )
156 outputArray[ option ] = fileLine()
159 out = "# " option " is not set"
161 out = option "=" value
163 if ( value == "y" || value == "m" )
165 else if ( value ~ /^"([^"]|\\")*"$/ )
167 else if ( value ~ /^-?[0-9]+$/ || value ~ /^0x[0-9A-Fa-f]+$/ )
170 warn( "ERROR: Incorrect value: " $0 )