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