]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-config.awk
c5c7968639d66752de5f7e11bb091f32d632d0df
[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         if ( ! basearch )
52                 basearch = arch
53
54         targetLevel[ "all" ] = 1
55         targetLevel[ basearch ] = 2
56         targetLevel[ arch ] = 3
57
58         shouldDie = 0
59
60         lastFile = ""
61 }
62
63 function dieLater( code ) {
64         if ( shouldDie < code )
65                 shouldDie = code
66 }
67
68 {
69         f = FILENAME
70         sub( /^.*\//, "", f ) # strip path
71         if ( f != lastFile ) {
72                 print "\n# file: " f
73                 lastFile = f
74         }
75 }
76
77 # convert special case:
78 # # CONFIG_SOMETHING it not set
79 # to:
80 # SOMETHING all=n
81 /^# CONFIG_[A-Za-z0-9_]+ is not set$/ {
82         match( $0, /CONFIG_[A-Za-z0-9_]+/ )
83         option = substr( $0, RSTART, RLENGTH)
84         $0 = option " all=n"
85 }
86
87 # ignore all the comments and empty lines
88 /^#/ || /^\s*$/ {
89         next
90 }
91
92 !/^[A-Za-z0-9_]+(=|[ \t]+[A-Za-z0-9_-]+=)/ {
93         warn( "ERROR: Incorrect line: " $0 )
94         dieLater( 3 )
95         next
96 }
97
98 !/^CONFIG_/ {
99         $0 = "CONFIG_" $0
100 }
101
102 {
103         option = $1
104         line = $0
105         value = ""
106         if ( option ~ /=/ ) {
107                 sub( /=.*$/, "", option )
108                 sub( /^[^=]*=/, "", line )
109                 value = line
110         } else {
111                 sub( "^" option, "", line )
112                 sub( /^[ \t]*/, "", line )
113
114                 delete archs
115                 if ( line ~ /"/ ) {
116                         # there can be white spaces
117                         i = 0
118                         while ( match( line, /^[^=]+="([^"]|\\")*"/ ) ) {
119                                 archs[ (++i) ] = substr( line, RSTART, RLENGTH )
120                                 line = substr( line, RSTART + RLENGTH )
121                                 sub( /^[ \t]*/, "", line )
122                         }
123                 } else {
124                         split( line, archs )
125                 }
126
127                 level = 0
128                 for ( i in archs ) {
129                         arch = val = archs[ i ]
130                         sub( /=.*$/, "", arch )
131                         sub( /^[^=]*=/, "", val )
132                         tl = targetLevel[ arch ]
133                         if ( tl > level ) {
134                                 value = val
135                                 level = tl
136                         }
137                 }
138         }
139
140         # completely ignore lines with no value
141         if ( length( value ) == 0 )
142                 next
143
144         fileOption = FILENAME "/" option
145         if ( fileOption in outputByFile ) {
146                 warn( "ERROR: " option " already defined in this file at line " outputByFile[ fileOption ] )
147                 dieLater( 2 )
148                 next
149         } else
150                 outputByFile[ fileOption ] = FNR
151
152         if ( option in outputArray ) {
153                 warn( "Warning: " option " already defined in: " outputArray[ option ] )
154                 next
155         } else
156                 outputArray[ option ] = fileLine()
157
158         if ( value == "n" )
159                 out = "# " option " is not set"
160         else {
161                 out = option "=" value
162
163                 if ( value == "y" || value == "m" )
164                         ; # OK
165                 else if ( value ~ /^"([^"]|\\")*"$/ )
166                         ; # OK
167                 else if ( value ~ /^-?[0-9]+$/ || value ~ /^0x[0-9A-Fa-f]+$/ )
168                         ; # OK
169                 else {
170                         warn( "ERROR: Incorrect value: " $0 )
171                         dieLater( 1 )
172                 }
173         }
174         
175         print out
176 }
177
178 END {
179         exit shouldDie
180 }
This page took 0.031825 seconds and 3 git commands to generate.