]> git.pld-linux.org Git - packages/kernel.git/blame - kernel-config.awk
- allow basearch and specific arch
[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 }
6c506f70 53 if ( ! basearch )
54 basearch = arch
55
56 targetLevel[ "all" ] = 1
57 targetLevel[ basearch ] = 2
58 targetLevel[ arch ] = 3
59
32610d56 60 shouldDie = 0
61}
62
63function dieLater( code ) {
64 if ( shouldDie < code )
65 shouldDie = code
38a2649a 66}
67
c5f08860 68# convert special case:
69# # CONFIG_SOMETHING it not set
70# to:
71# SOMETHING all=n
d91f8167 72/^# CONFIG_[A-Za-z0-9_]+ is not set$/ {
73 match( $0, /CONFIG_[A-Za-z0-9_]+/ )
c5f08860 74 option = substr( $0, RSTART, RLENGTH)
75 $0 = option " all=n"
38a2649a 76}
77
d91f8167 78# ignore all the comments and empty lines
38a2649a 79/^#/ || /^\s*$/ {
80 next
81}
82
c5f08860 83!/^CONFIG_/ {
84 $0 = "CONFIG_" $0
38a2649a 85}
86
87{
88 option = $1
89 line = $0
c5f08860 90 value = ""
38a2649a 91 if ( option ~ /=/ ) {
d91f8167 92 sub( /=.*$/, "", option )
93 sub( /^[^=]*=/, "", line )
c5f08860 94 value = line
38a2649a 95 } else {
d91f8167 96 sub( "^" option, "", line )
97 sub( /^[ \t]*/, "", line )
98
99 if ( line ~ /"/ ) {
100 # there can be white spaces
101 i = 0
102 while ( match( line, /^[^=]+="[^"]*"/ ) ) {
103 archs[ (++i) ] = substr( line, RSTART, RLENGTH )
104 line = substr( line, RSTART + RLENGTH )
105 sub( /^[ \t]*/, "", line )
106 }
107 } else {
108 split( line, archs )
109 }
6c506f70 110
111 level = 0
c5f08860 112 for ( i in archs ) {
113 split( archs[i], opt, "=" );
6c506f70 114 tl = targetLevel[ opt[ 1 ] ]
115 if ( tl > level ) {
c5f08860 116 value = opt[2]
6c506f70 117 level = tl
c5f08860 118 }
38a2649a 119 }
120 }
38a2649a 121
49e65d69 122 # completely ignore lines with no value
123 if ( length( value ) == 0 )
124 next
125
126 fileOption = FILENAME "/" option
127 if ( fileOption in outputByFile ) {
128 warn( "ERROR: " option " already defined in this file at line " outputByFile[ fileOption ] )
129 dieLater( 2 )
130 next
131 } else
132 outputByFile[ fileOption ] = FNR
133
c5f08860 134 if ( option in outputArray ) {
49e65d69 135 warn( "Warning: " option " already defined in: " outputArray[ option ] )
c5f08860 136 next
49e65d69 137 } else
138 outputArray[ option ] = fileLine()
c5f08860 139
49e65d69 140 if ( value == "n" )
141 out = "# " option " is not set"
142 else {
143 out = option "=" value
144
145 if ( value == "y" || value == "m" )
146 ; # OK
147 else if ( value ~ /^"[^"]*"$/ )
148 ; # OK
149 else if ( value ~ /^-?[0-9]+$/ || value ~ /^0x[0-9A-Fa-f]+$/ )
150 ; # OK
32610d56 151 else {
49e65d69 152 warn( "ERROR: Incorrect value: " $0 )
153 dieLater( 1 )
32610d56 154 }
38a2649a 155 }
49e65d69 156
157 print out
38a2649a 158}
159
160END {
32610d56 161 exit shouldDie
38a2649a 162}
This page took 0.066404 seconds and 4 git commands to generate.