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