]> git.pld-linux.org Git - packages/kernel.git/blobdiff - kernel-config.awk
- up to 4.9.210
[packages/kernel.git] / kernel-config.awk
index 30cc398a931b76971f21746f04ec4ec026374bdc..9ac5a946b00117568d519758f1526ee61f09f207 100644 (file)
@@ -3,7 +3,7 @@
 # It also has some file merging facilities.
 #
 # usage:
-#  awk -v arch=%{_target_base_arch} -f path/to/kernel-config.awk \
+#  awk -v basearch=%{_target_base_arch} -v arch=%{_target_cpu} -f path/to/kernel-config.awk \
 #    kernel-important.config kernel-multiarch.config \
 #    kernel-%{arch}.config kernel-%{some_feature}.config \
 #     > .config
@@ -15,8 +15,6 @@
 # - glen@pld-linux.org
 # 
 # TODO:
-#  - smarter arch split, there could be strings with spaces
-#    ( kernel-config.py does not suppoty it either )
 #  - use as many warnings as possible, we want our configs to be clean
 
 # no:
@@ -50,7 +48,14 @@ BEGIN {
                print "arch= must be specified" > "/dev/stderr"
                exit 1
        }
+       split( arch, Archs )
+       for (i = 1; i in Archs; i++) {
+               targetLevel[ Archs[ i ] ] = i
+       }
+
        shouldDie = 0
+
+       lastFile = ""
 }
 
 function dieLater( code ) {
@@ -58,6 +63,15 @@ function dieLater( code ) {
                shouldDie = code
 }
 
+{
+       f = FILENAME
+       sub( /^.*\//, "", f ) # strip path
+       if ( f != lastFile ) {
+               print "\n# file: " f
+               lastFile = f
+       }
+}
+
 # convert special case:
 # # CONFIG_SOMETHING it not set
 # to:
@@ -73,6 +87,12 @@ function dieLater( code ) {
        next
 }
 
+!/^[A-Za-z0-9_]+(=|[ \t]+[A-Za-z0-9_-]+=)/ {
+       warn( "ERROR: Incorrect line: " $0 )
+       dieLater( 3 )
+       next
+}
+
 !/^CONFIG_/ {
        $0 = "CONFIG_" $0
 }
@@ -89,10 +109,11 @@ function dieLater( code ) {
                sub( "^" option, "", line )
                sub( /^[ \t]*/, "", line )
 
+               delete archs
                if ( line ~ /"/ ) {
                        # there can be white spaces
                        i = 0
-                       while ( match( line, /^[^=]+="[^"]*"/ ) ) {
+                       while ( match( line, /^[^=]+="([^"]|\\")*"/ ) ) {
                                archs[ (++i) ] = substr( line, RSTART, RLENGTH )
                                line = substr( line, RSTART + RLENGTH )
                                sub( /^[ \t]*/, "", line )
@@ -100,45 +121,56 @@ function dieLater( code ) {
                } else {
                        split( line, archs )
                }
+
+               level = 0
                for ( i in archs ) {
-                       split( archs[i], opt, "=" );
-                       if ( opt[1] == "all" )
-                               value = opt[2]
-
-                       if ( opt[1] == arch ) {
-                               # found best match, don't look further
-                               value = opt[2]
-                               break
+                       arch = val = archs[ i ]
+                       sub( /=.*$/, "", arch )
+                       sub( /^[^=]*=/, "", val )
+                       tl = targetLevel[ arch ]
+                       if ( tl > level ) {
+                               value = val
+                               level = tl
                        }
                }
        }
 
+       # completely ignore lines with no value
+       if ( length( value ) == 0 )
+               next
+
+       fileOption = FILENAME "/" option
+       if ( fileOption in outputByFile ) {
+               warn( "ERROR: " option " already defined in this file at line " outputByFile[ fileOption ] )
+               dieLater( 2 )
+               next
+       } else
+               outputByFile[ fileOption ] = FNR
+
        if ( option in outputArray ) {
-               warn( option " already defined in: " outputArray[ option ] )
+               warn( "Warning: " option " already defined in: " outputArray[ option ] )
                next
-       }
+       } else
+               outputArray[ option ] = fileLine()
 
-       if ( length( value ) ) {
-               if ( value == "n" )
-                       out = "# " option " is not set"
+       if ( value == "n" )
+               out = "# " option " is not set"
+       else {
+               out = option "=" value
+
+               if ( value == "y" || value == "m" )
+                       ; # OK
+               else if ( value ~ /^"([^"]|\\")*"$/ )
+                       ; # OK
+               else if ( value ~ /^-?[0-9]+$/ || value ~ /^0x[0-9A-Fa-f]+$/ )
+                       ; # OK
                else {
-                       out = option "=" value
-
-                       if ( value == "y" || value == "m" )
-                               ; # OK
-                       else if ( value ~ /^"[^"]*"$/ )
-                               ; # OK
-                       else if ( value ~ /^-?[0-9]+$/ || value ~ /^0x[0-9A-Fa-f]+$/ )
-                               ; # OK
-                       else {
-                               warn( "ERROR: Incorrect value: " $0 )
-                               dieLater( 1 )
-                       }
+                       warn( "ERROR: Incorrect value: " $0 )
+                       dieLater( 1 )
                }
-       
-               print out
-               outputArray[ option ] = fileLine()
        }
+       
+       print out
 }
 
 END {
This page took 0.079035 seconds and 4 git commands to generate.