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 )
105 # there can be white spaces
107 while ( match( line, /^[^=]+="([^"]|\\")*"/ ) ) {
108 archs[ (++i) ] = substr( line, RSTART, RLENGTH )
109 line = substr( line, RSTART + RLENGTH )
110 sub( /^[ \t]*/, "", line )
118 arch = val = archs[ i ]
119 sub( /=.*$/, "", arch )
120 sub( /^[^=]*=/, "", val )
121 tl = targetLevel[ arch ]
129 # completely ignore lines with no value
130 if ( length( value ) == 0 )
133 fileOption = FILENAME "/" option
134 if ( fileOption in outputByFile ) {
135 warn( "ERROR: " option " already defined in this file at line " outputByFile[ fileOption ] )
139 outputByFile[ fileOption ] = FNR
141 if ( option in outputArray ) {
142 warn( "Warning: " option " already defined in: " outputArray[ option ] )
145 outputArray[ option ] = fileLine()
148 out = "# " option " is not set"
150 out = option "=" value
152 if ( value == "y" || value == "m" )
154 else if ( value ~ /^"([^"]|\\")*"$/ )
156 else if ( value ~ /^-?[0-9]+$/ || value ~ /^0x[0-9A-Fa-f]+$/ )
159 warn( "ERROR: Incorrect value: " $0 )