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