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