]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-config.awk
- kernel-config.py replacement written in awk
[packages/kernel.git] / kernel-config.awk
1 # A script for building kernel config from multiarch config file.
2 # It also has some file merging facilities.
3 #
4 # usage:
5 #  awk -v arch=%{_target_base_arch} -f path/to/kernel-config.awk \
6 #    kernel-multiarch.config kernel-%{arch}.config kernel-%{some_feature}.config \
7 #     > .config
8 #
9 # TODO:
10 #  - check value correctness, should allow only:
11 #    y, m, n, -[0-9]+, 0x[0-9A-Fa-f]+, ".*"
12 #  - smarter arch split, there could be strings with spaces
13 #    ( kernel-config.py does not suppoty it either )
14 #  - use as many warnings as possible, we want our configs to be clean
15 #  - allow more multiarch configs
16
17 function warn( msg ) {
18         print FILENAME " (" FNR "): " msg > "/dev/stderr"
19 }
20
21 BEGIN {
22         if ( ! arch ) {
23                 warn( "arch= must be specified" )
24                 exit 1
25         }
26         firstfile = 1
27 }
28
29 {
30         # remember first file name
31         if ( ! file )
32                 file = FILENAME
33
34         else if ( file != FILENAME ) { # second and following files
35                 if ( match( $0, /CONFIG_[A-Za-z0-9_-]+/ ) ) {
36                         option = substr( $0, RSTART, RLENGTH )
37                         if ( $0 ~ "^" option "=.+$" || $0 ~ "^# " option " is not set$" ) {
38                                 if ( option in outputArray )
39                                         warn( option " already defined in: " outputArray[ option ] )
40                                 else {
41                                         print
42                                         outputArray[ option ] = FILENAME " (" FNR ")"
43                                 }
44                         } else {
45                                 if ( ! /^#/ )
46                                         warn( "Incorrect line: " $0 )
47                         }
48                 } else if ( ! /^\s*$/ && ! /^#/ ) {
49                         warn( "Incorrect line: " $0 )
50                 }
51                 next
52         }
53 }
54
55 # multiarch file proxessing
56
57 /^#/ || /^\s*$/ {
58         next
59 }
60
61 /^CONFIG_/ {
62         warn( "Options should not start with CONFIG_" )
63         gsub( /^CONFIG_/, "" )
64 }
65
66 {
67         option = $1
68         line = $0
69         if ( option ~ /=/ ) {
70                 warn( $0 " should have explicit ` all='" )
71                 gsub( /=.*$/, "", option )
72                 gsub( /^[^=]*=/, "", line )
73                 line = "all=" line
74         } else {
75                 gsub( "^" option, "", line )
76         }
77         split( line, archs )
78
79         dest = ""
80         for ( inx in archs ) {
81                 split( archs[inx], opt, "=" );
82                 if ( opt[1] == "all" )
83                         dest = opt[2]
84
85                 if ( opt[1] == arch ) {
86                         dest = opt[2]
87                         break
88                 }
89         }
90         if ( length( dest ) ) {
91                 option = "CONFIG_" option
92
93                 if ( dest == "n" )
94                         out = "# " option " is not set"
95                 else
96                         out = option "=" dest
97                 print out
98
99                 outputArray[ option ] = FILENAME " (" FNR ")"
100         }
101 }
102
103 END {
104 }
This page took 0.033457 seconds and 4 git commands to generate.