]>
Commit | Line | Data |
---|---|---|
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 | |
35 | function fileLine() { | |
36 | f = FILENAME | |
d91f8167 | 37 | sub( /^.*\//, "", f ) # strip path |
c5f08860 | 38 | |
39 | return f " (" FNR ")" | |
40 | } | |
38a2649a | 41 | |
42 | function warn( msg ) { | |
c5f08860 | 43 | print fileLine() ": " msg > "/dev/stderr" |
38a2649a | 44 | } |
45 | ||
46 | BEGIN { | |
47 | if ( ! arch ) { | |
c5f08860 | 48 | print "arch= must be specified" > "/dev/stderr" |
38a2649a | 49 | exit 1 |
50 | } | |
ebafdfec | 51 | split( arch, Archs ) |
52 | for (i = 1; i in Archs; i++) { | |
53 | targetLevel[ Archs[ i ] ] = i | |
54 | } | |
6c506f70 | 55 | |
32610d56 | 56 | shouldDie = 0 |
4772cfa4 | 57 | |
58 | lastFile = "" | |
32610d56 | 59 | } |
60 | ||
61 | function dieLater( code ) { | |
62 | if ( shouldDie < code ) | |
63 | shouldDie = code | |
38a2649a | 64 | } |
65 | ||
4772cfa4 | 66 | { |
67 | f = FILENAME | |
68 | sub( /^.*\//, "", f ) # strip path | |
69 | if ( f != lastFile ) { | |
70 | print "\n# file: " f | |
71 | lastFile = f | |
72 | } | |
73 | } | |
74 | ||
c5f08860 | 75 | # convert special case: |
76 | # # CONFIG_SOMETHING it not set | |
77 | # to: | |
78 | # SOMETHING all=n | |
d91f8167 | 79 | /^# CONFIG_[A-Za-z0-9_]+ is not set$/ { |
80 | match( $0, /CONFIG_[A-Za-z0-9_]+/ ) | |
c5f08860 | 81 | option = substr( $0, RSTART, RLENGTH) |
82 | $0 = option " all=n" | |
38a2649a | 83 | } |
84 | ||
d91f8167 | 85 | # ignore all the comments and empty lines |
38a2649a | 86 | /^#/ || /^\s*$/ { |
87 | next | |
88 | } | |
89 | ||
2b721208 | 90 | !/^[A-Za-z0-9_]+(=|[ \t]+[A-Za-z0-9_-]+=)/ { |
91 | warn( "ERROR: Incorrect line: " $0 ) | |
92 | dieLater( 3 ) | |
93 | next | |
94 | } | |
95 | ||
c5f08860 | 96 | !/^CONFIG_/ { |
97 | $0 = "CONFIG_" $0 | |
38a2649a | 98 | } |
99 | ||
100 | { | |
101 | option = $1 | |
102 | line = $0 | |
c5f08860 | 103 | value = "" |
38a2649a | 104 | if ( option ~ /=/ ) { |
d91f8167 | 105 | sub( /=.*$/, "", option ) |
106 | sub( /^[^=]*=/, "", line ) | |
c5f08860 | 107 | value = line |
38a2649a | 108 | } else { |
d91f8167 | 109 | sub( "^" option, "", line ) |
110 | sub( /^[ \t]*/, "", line ) | |
111 | ||
4a0f6b46 | 112 | delete archs |
d91f8167 | 113 | if ( line ~ /"/ ) { |
114 | # there can be white spaces | |
115 | i = 0 | |
5802a6ba | 116 | while ( match( line, /^[^=]+="([^"]|\\")*"/ ) ) { |
d91f8167 | 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 | } | |
6c506f70 | 124 | |
125 | level = 0 | |
c5f08860 | 126 | for ( i in archs ) { |
5802a6ba | 127 | arch = val = archs[ i ] |
128 | sub( /=.*$/, "", arch ) | |
129 | sub( /^[^=]*=/, "", val ) | |
130 | tl = targetLevel[ arch ] | |
6c506f70 | 131 | if ( tl > level ) { |
5802a6ba | 132 | value = val |
6c506f70 | 133 | level = tl |
c5f08860 | 134 | } |
38a2649a | 135 | } |
136 | } | |
38a2649a | 137 | |
49e65d69 | 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 | ||
c5f08860 | 150 | if ( option in outputArray ) { |
49e65d69 | 151 | warn( "Warning: " option " already defined in: " outputArray[ option ] ) |
c5f08860 | 152 | next |
49e65d69 | 153 | } else |
154 | outputArray[ option ] = fileLine() | |
c5f08860 | 155 | |
49e65d69 | 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 | |
5802a6ba | 163 | else if ( value ~ /^"([^"]|\\")*"$/ ) |
49e65d69 | 164 | ; # OK |
165 | else if ( value ~ /^-?[0-9]+$/ || value ~ /^0x[0-9A-Fa-f]+$/ ) | |
166 | ; # OK | |
32610d56 | 167 | else { |
49e65d69 | 168 | warn( "ERROR: Incorrect value: " $0 ) |
169 | dieLater( 1 ) | |
32610d56 | 170 | } |
38a2649a | 171 | } |
49e65d69 | 172 | |
173 | print out | |
38a2649a | 174 | } |
175 | ||
176 | END { | |
32610d56 | 177 | exit shouldDie |
38a2649a | 178 | } |