SOURCES: kernel-config.awk - rewritten and simplified, now it allows any co...

sparky sparky at pld-linux.org
Thu Sep 18 15:00:31 CEST 2008


Author: sparky                       Date: Thu Sep 18 13:00:31 2008 GMT
Module: SOURCES                       Tag: HEAD
---- Log message:
- rewritten and simplified, now it allows any combination of normal
  and multiarch options

---- Files affected:
SOURCES:
   kernel-config.awk (1.1 -> 1.2) 

---- Diffs:

================================================================
Index: SOURCES/kernel-config.awk
diff -u SOURCES/kernel-config.awk:1.1 SOURCES/kernel-config.awk:1.2
--- SOURCES/kernel-config.awk:1.1	Thu Sep 18 03:16:11 2008
+++ SOURCES/kernel-config.awk	Thu Sep 18 15:00:25 2008
@@ -1,102 +1,112 @@
+# $Id$
 # A script for building kernel config from multiarch config file.
 # It also has some file merging facilities.
 #
 # usage:
 #  awk -v arch=%{_target_base_arch} -f path/to/kernel-config.awk \
-#    kernel-multiarch.config kernel-%{arch}.config kernel-%{some_feature}.config \
+#    kernel-important.config kernel-multiarch.config \
+#    kernel-%{arch}.config kernel-%{some_feature}.config \
 #     > .config
 #
+# Authors:
+# - Przemysław Iskra <sparky at pld-linux.org>
+# 
 # TODO:
 #  - check value correctness, should allow only:
 #    y, m, n, -[0-9]+, 0x[0-9A-Fa-f]+, ".*"
 #  - 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
-#  - allow more multiarch configs
+
+# no:
+# CONFIG_SOMETHING=n		-- should warn
+# SOMETHING=n			-- should warn
+# CONFIG_SOMETHING all=n	-- should warn
+# SOMETHING all=n
+# # CONFIG_SOMETHING is not set	-- special case
+
+# yes/module/other
+# CONFIG_SOMETHING=y
+# SOMETHING=y			-- should warn
+# CONFIG_SOMETHING all=y	-- should warn
+# SOMETHING all=y
+
+
+# return actual file name (without path) and line number
+function fileLine() {
+	f = FILENAME
+	gsub( /^.*\//, "", f ) # strip path
+
+	return f " (" FNR ")"
+}
 
 function warn( msg ) {
-	print FILENAME " (" FNR "): " msg > "/dev/stderr"
+	print fileLine() ": " msg > "/dev/stderr"
 }
 
 BEGIN {
 	if ( ! arch ) {
-		warn( "arch= must be specified" )
+		print "arch= must be specified" > "/dev/stderr"
 		exit 1
 	}
-	firstfile = 1
 }
 
-{
-	# remember first file name
-	if ( ! file )
-		file = FILENAME
-
-	else if ( file != FILENAME ) { # second and following files
-		if ( match( $0, /CONFIG_[A-Za-z0-9_-]+/ ) ) {
-			option = substr( $0, RSTART, RLENGTH )
-			if ( $0 ~ "^" option "=.+$" || $0 ~ "^# " option " is not set$" ) {
-				if ( option in outputArray )
-					warn( option " already defined in: " outputArray[ option ] )
-				else {
-					print
-					outputArray[ option ] = FILENAME " (" FNR ")"
-				}
-			} else {
-				if ( ! /^#/ )
-					warn( "Incorrect line: " $0 )
-			}
-		} else if ( ! /^\s*$/ && ! /^#/ ) {
-			warn( "Incorrect line: " $0 )
-		}
-		next
-	}
+# convert special case:
+# # CONFIG_SOMETHING it not set
+# to:
+# SOMETHING all=n
+/^# CONFIG_[A-Za-z0-9_-]+ is not set$/ {
+	match( $0, /CONFIG_[A-Za-z0-9_-]+/ )
+	option = substr( $0, RSTART, RLENGTH)
+	$0 = option " all=n"
 }
 
-# multiarch file proxessing
-
+# ignore all the comments
 /^#/ || /^\s*$/ {
 	next
 }
 
-/^CONFIG_/ {
-	warn( "Options should not start with CONFIG_" )
-	gsub( /^CONFIG_/, "" )
+!/^CONFIG_/ {
+	$0 = "CONFIG_" $0
 }
 
 {
 	option = $1
 	line = $0
+	value = ""
 	if ( option ~ /=/ ) {
-		warn( $0 " should have explicit ` all='" )
 		gsub( /=.*$/, "", option )
 		gsub( /^[^=]*=/, "", line )
-		line = "all=" line
+		value = line
 	} else {
-		gsub( "^" option, "", line )
+		gsub( "^" option IFS, "", line )
+		split( line, archs )
+		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
+			}
+		}
 	}
-	split( line, archs )
 
-	dest = ""
-	for ( inx in archs ) {
-		split( archs[inx], opt, "=" );
-		if ( opt[1] == "all" )
-			dest = opt[2]
-
-		if ( opt[1] == arch ) {
-			dest = opt[2]
-			break
-		}
+	if ( option in outputArray ) {
+		warn( option " already defined in: " outputArray[ option ] )
+		next
 	}
-	if ( length( dest ) ) {
-		option = "CONFIG_" option
 
-		if ( dest == "n" )
+	if ( length( value ) ) {
+		if ( value == "n" )
 			out = "# " option " is not set"
 		else
-			out = option "=" dest
+			out = option "=" value
+	
 		print out
-
-		outputArray[ option ] = FILENAME " (" FNR ")"
+		outputArray[ option ] = fileLine()
 	}
 }
 
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/SOURCES/kernel-config.awk?r1=1.1&r2=1.2&f=u



More information about the pld-cvs-commit mailing list