]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-config.awk
- handle string options with white spaces inside, \" not supported yet
[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 arch=%{_target_base_arch} -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 #  - smarter arch split, there could be strings with spaces
19 #    ( kernel-config.py does not suppoty it either )
20 #  - use as many warnings as possible, we want our configs to be clean
21
22 # no:
23 # CONFIG_SOMETHING=n
24 # SOMETHING=n
25 # CONFIG_SOMETHING all=n
26 # SOMETHING all=n
27 # # CONFIG_SOMETHING is not set -- special case
28
29 # yes/module/other
30 # CONFIG_SOMETHING=y
31 # SOMETHING=y
32 # CONFIG_SOMETHING all=y
33 # SOMETHING all=y
34
35
36 # return actual file name (without path) and line number
37 function fileLine() {
38         f = FILENAME
39         sub( /^.*\//, "", f ) # strip path
40
41         return f " (" FNR ")"
42 }
43
44 function warn( msg ) {
45         print fileLine() ": " msg > "/dev/stderr"
46 }
47
48 BEGIN {
49         if ( ! arch ) {
50                 print "arch= must be specified" > "/dev/stderr"
51                 exit 1
52         }
53         shouldDie = 0
54 }
55
56 function dieLater( code ) {
57         if ( shouldDie < code )
58                 shouldDie = code
59 }
60
61 # convert special case:
62 # # CONFIG_SOMETHING it not set
63 # to:
64 # SOMETHING all=n
65 /^# CONFIG_[A-Za-z0-9_]+ is not set$/ {
66         match( $0, /CONFIG_[A-Za-z0-9_]+/ )
67         option = substr( $0, RSTART, RLENGTH)
68         $0 = option " all=n"
69 }
70
71 # ignore all the comments and empty lines
72 /^#/ || /^\s*$/ {
73         next
74 }
75
76 !/^CONFIG_/ {
77         $0 = "CONFIG_" $0
78 }
79
80 {
81         option = $1
82         line = $0
83         value = ""
84         if ( option ~ /=/ ) {
85                 sub( /=.*$/, "", option )
86                 sub( /^[^=]*=/, "", line )
87                 value = line
88         } else {
89                 sub( "^" option, "", line )
90                 sub( /^[ \t]*/, "", line )
91
92                 if ( line ~ /"/ ) {
93                         # there can be white spaces
94                         i = 0
95                         while ( match( line, /^[^=]+="[^"]*"/ ) ) {
96                                 archs[ (++i) ] = substr( line, RSTART, RLENGTH )
97                                 line = substr( line, RSTART + RLENGTH )
98                                 sub( /^[ \t]*/, "", line )
99                         }
100                 } else {
101                         split( line, archs )
102                 }
103                 for ( i in archs ) {
104                         split( archs[i], opt, "=" );
105                         if ( opt[1] == "all" )
106                                 value = opt[2]
107
108                         if ( opt[1] == arch ) {
109                                 # found best match, don't look further
110                                 value = opt[2]
111                                 break
112                         }
113                 }
114         }
115
116         if ( option in outputArray ) {
117                 warn( option " already defined in: " outputArray[ option ] )
118                 next
119         }
120
121         if ( length( value ) ) {
122                 if ( value == "n" )
123                         out = "# " option " is not set"
124                 else {
125                         out = option "=" value
126
127                         if ( value == "y" || value == "m" )
128                                 ; # OK
129                         else if ( value ~ /^"[^"]*"$/ )
130                                 ; # OK
131                         else if ( value ~ /^-?[0-9]+$/ || value ~ /^0x[0-9A-Fa-f]+$/ )
132                                 ; # OK
133                         else {
134                                 warn( "ERROR: Incorrect value: " $0 )
135                                 dieLater( 1 )
136                         }
137                 }
138         
139                 print out
140                 outputArray[ option ] = fileLine()
141         }
142 }
143
144 END {
145         exit shouldDie
146 }
This page took 0.062158 seconds and 4 git commands to generate.