]> git.pld-linux.org Git - packages/kernel.git/blame - kernel-config.awk
- optionally die if there were errors
[packages/kernel.git] / kernel-config.awk
CommitLineData
c5f08860 1# $Id$
38a2649a 2# A script for building kernel config from multiarch config file.
3# It also has some file merging facilities.
4#
5# usage:
5802a6ba 6# awk -v basearch=%{_target_base_arch} -v arch=%{_target_cpu} -f path/to/kernel-config.awk \
c5f08860 7# kernel-important.config kernel-multiarch.config \
8# kernel-%{arch}.config kernel-%{some_feature}.config \
38a2649a 9# > .config
10#
c5f08860 11# Authors:
12# - Przemysław Iskra <sparky@pld-linux.org>
d91f8167 13# parts based on kernel-config.py, by:
14# - arekm@pld-linux.org
15# - glen@pld-linux.org
c5f08860 16#
38a2649a 17# TODO:
38a2649a 18# - use as many warnings as possible, we want our configs to be clean
c5f08860 19
20# no:
d91f8167 21# CONFIG_SOMETHING=n
22# SOMETHING=n
23# CONFIG_SOMETHING all=n
c5f08860 24# SOMETHING all=n
d91f8167 25# # CONFIG_SOMETHING is not set -- special case
c5f08860 26
27# yes/module/other
28# CONFIG_SOMETHING=y
d91f8167 29# SOMETHING=y
30# CONFIG_SOMETHING all=y
c5f08860 31# SOMETHING all=y
32
33
34# return actual file name (without path) and line number
35function fileLine() {
36 f = FILENAME
d91f8167 37 sub( /^.*\//, "", f ) # strip path
c5f08860 38
39 return f " (" FNR ")"
40}
38a2649a 41
42function warn( msg ) {
c5f08860 43 print fileLine() ": " msg > "/dev/stderr"
38a2649a 44}
45
46BEGIN {
47 if ( ! arch ) {
c5f08860 48 print "arch= must be specified" > "/dev/stderr"
38a2649a 49 exit 1
50 }
6c506f70 51 if ( ! basearch )
52 basearch = arch
53
54 targetLevel[ "all" ] = 1
55 targetLevel[ basearch ] = 2
56 targetLevel[ arch ] = 3
57
32610d56 58 shouldDie = 0
59}
60
61function dieLater( code ) {
62 if ( shouldDie < code )
63 shouldDie = code
38a2649a 64}
65
c5f08860 66# convert special case:
67# # CONFIG_SOMETHING it not set
68# to:
69# SOMETHING all=n
d91f8167 70/^# CONFIG_[A-Za-z0-9_]+ is not set$/ {
71 match( $0, /CONFIG_[A-Za-z0-9_]+/ )
c5f08860 72 option = substr( $0, RSTART, RLENGTH)
73 $0 = option " all=n"
38a2649a 74}
75
d91f8167 76# ignore all the comments and empty lines
38a2649a 77/^#/ || /^\s*$/ {
78 next
79}
80
2b721208 81!/^[A-Za-z0-9_]+(=|[ \t]+[A-Za-z0-9_-]+=)/ {
82 warn( "ERROR: Incorrect line: " $0 )
83 dieLater( 3 )
84 next
85}
86
c5f08860 87!/^CONFIG_/ {
88 $0 = "CONFIG_" $0
38a2649a 89}
90
91{
92 option = $1
93 line = $0
c5f08860 94 value = ""
38a2649a 95 if ( option ~ /=/ ) {
d91f8167 96 sub( /=.*$/, "", option )
97 sub( /^[^=]*=/, "", line )
c5f08860 98 value = line
38a2649a 99 } else {
d91f8167 100 sub( "^" option, "", line )
101 sub( /^[ \t]*/, "", line )
102
4a0f6b46 103 delete archs
d91f8167 104 if ( line ~ /"/ ) {
105 # there can be white spaces
106 i = 0
5802a6ba 107 while ( match( line, /^[^=]+="([^"]|\\")*"/ ) ) {
d91f8167 108 archs[ (++i) ] = substr( line, RSTART, RLENGTH )
109 line = substr( line, RSTART + RLENGTH )
110 sub( /^[ \t]*/, "", line )
111 }
112 } else {
113 split( line, archs )
114 }
6c506f70 115
116 level = 0
c5f08860 117 for ( i in archs ) {
5802a6ba 118 arch = val = archs[ i ]
119 sub( /=.*$/, "", arch )
120 sub( /^[^=]*=/, "", val )
121 tl = targetLevel[ arch ]
6c506f70 122 if ( tl > level ) {
5802a6ba 123 value = val
6c506f70 124 level = tl
c5f08860 125 }
38a2649a 126 }
127 }
38a2649a 128
49e65d69 129 # completely ignore lines with no value
130 if ( length( value ) == 0 )
131 next
132
133 fileOption = FILENAME "/" option
134 if ( fileOption in outputByFile ) {
135 warn( "ERROR: " option " already defined in this file at line " outputByFile[ fileOption ] )
136 dieLater( 2 )
137 next
138 } else
139 outputByFile[ fileOption ] = FNR
140
c5f08860 141 if ( option in outputArray ) {
49e65d69 142 warn( "Warning: " option " already defined in: " outputArray[ option ] )
c5f08860 143 next
49e65d69 144 } else
145 outputArray[ option ] = fileLine()
c5f08860 146
49e65d69 147 if ( value == "n" )
148 out = "# " option " is not set"
149 else {
150 out = option "=" value
151
152 if ( value == "y" || value == "m" )
153 ; # OK
5802a6ba 154 else if ( value ~ /^"([^"]|\\")*"$/ )
49e65d69 155 ; # OK
156 else if ( value ~ /^-?[0-9]+$/ || value ~ /^0x[0-9A-Fa-f]+$/ )
157 ; # OK
32610d56 158 else {
49e65d69 159 warn( "ERROR: Incorrect value: " $0 )
160 dieLater( 1 )
32610d56 161 }
38a2649a 162 }
49e65d69 163
164 print out
38a2649a 165}
166
167END {
32610d56 168 exit shouldDie
38a2649a 169}
This page took 0.20003 seconds and 4 git commands to generate.