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