[PATCH] make it possible to keep Config/Kbuild snippets in *.c files

Denys Vlasenko vda.linux at googlemail.com
Sun May 9 02:04:35 UTC 2010


Please review.
-- 
vda


diff -ad -urpN busybox.0/findutils/Config.in busybox.1/findutils/Config.in
--- busybox.0/findutils/Config.in	2010-04-09 20:01:59.000000000 +0200
+++ busybox.1/findutils/Config.in	1970-01-01 01:00:00.000000000 +0100
@@ -1,253 +0,0 @@
-#
-# For a description of the syntax of this configuration file,
-# see scripts/kbuild/config-language.txt.
-#
-
-menu "Finding Utilities"
-
-config FIND
-	bool "find"
-	default n
-	help
-	  find is used to search your system to find specified files.
-
-config FEATURE_FIND_PRINT0
-	bool "Enable -print0: NUL-terminated output"
-	default y
-	depends on FIND
-	help
-	  Causes output names to be separated by a NUL character
-	  rather than a newline. This allows names that contain
-	  newlines and other whitespace to be more easily
-	  interpreted by other programs.
-
-config FEATURE_FIND_MTIME
-	bool "Enable -mtime: modified time matching"
-	default y
-	depends on FIND
-	help
-	  Allow searching based on the modification time of
-	  files, in days.
-
-config FEATURE_FIND_MMIN
-	bool "Enable -mmin: modified time matching by minutes"
-	default y
-	depends on FIND
-	help
-	  Allow searching based on the modification time of
-	  files, in minutes.
-
-config FEATURE_FIND_PERM
-	bool "Enable -perm: permissions matching"
-	default y
-	depends on FIND
-	help
-	  Enable searching based on file permissions.
-
-config FEATURE_FIND_TYPE
-	bool "Enable -type: file type matching (file/dir/link/...)"
-	default y
-	depends on FIND
-	help
-	  Enable searching based on file type (file,
-	  directory, socket, device, etc.).
-
-config FEATURE_FIND_XDEV
-	bool "Enable -xdev: 'stay in filesystem'"
-	default y
-	depends on FIND
-	help
-	  This option allows find to restrict searches to a single filesystem.
-
-config FEATURE_FIND_MAXDEPTH
-	bool "Enable -maxdepth N"
-	default y
-	depends on FIND
-	help
-	  This option enables -maxdepth N option.
-
-config FEATURE_FIND_NEWER
-	bool "Enable -newer: compare file modification times"
-	default y
-	depends on FIND
-	help
-	  Support the 'find -newer' option for finding any files which have
-	  a modified time that is more recent than the specified FILE.
-
-config FEATURE_FIND_INUM
-	bool "Enable -inum: inode number matching"
-	default y
-	depends on FIND
-	help
-	  Support the 'find -inum' option for searching by inode number.
-
-config FEATURE_FIND_EXEC
-	bool "Enable -exec: execute commands"
-	default y
-	depends on FIND
-	help
-	  Support the 'find -exec' option for executing commands based upon
-	  the files matched.
-
-config FEATURE_FIND_USER
-	bool "Enable -user: username/uid matching"
-	default y
-	depends on FIND
-	help
-	  Support the 'find -user' option for searching by username or uid.
-
-config FEATURE_FIND_GROUP
-	bool "Enable -group: group/gid matching"
-	default y
-	depends on FIND
-	help
-	  Support the 'find -group' option for searching by group name or gid.
-
-config FEATURE_FIND_NOT
-	bool "Enable the 'not' (!) operator"
-	default y
-	depends on FIND
-	help
-	  Support the '!' operator to invert the test results.
-	  If 'Enable full-blown desktop' is enabled, then will also support
-	  the non-POSIX notation '-not'.
-
-config FEATURE_FIND_DEPTH
-	bool "Enable -depth"
-	default y
-	depends on FIND
-	help
-	  Process each directory's contents before the directory itself.
-
-config FEATURE_FIND_PAREN
-	bool "Enable parens in options"
-	default y
-	depends on FIND
-	help
-	  Enable usage of parens '(' to specify logical order of arguments.
-
-config FEATURE_FIND_SIZE
-	bool "Enable -size: file size matching"
-	default y
-	depends on FIND
-	help
-	  Support the 'find -size' option for searching by file size.
-
-config FEATURE_FIND_PRUNE
-	bool "Enable -prune: exclude subdirectories"
-	default y
-	depends on FIND
-	help
-	  If the file is a directory, dont descend into it. Useful for
-	  exclusion .svn and CVS directories.
-
-config FEATURE_FIND_DELETE
-	bool "Enable -delete: delete files/dirs"
-	default n
-	depends on FIND && FEATURE_FIND_DEPTH
-	help
-	  Support the 'find -delete' option for deleting files and directories.
-	  WARNING: This option can do much harm if used wrong. Busybox will not
-	  try to protect the user from doing stupid things. Use with care.
-
-config FEATURE_FIND_PATH
-	bool "Enable -path: match pathname with shell pattern"
-	default y
-	depends on FIND
-	help
-	  The -path option matches whole pathname instead of just filename.
-
-config FEATURE_FIND_REGEX
-	bool "Enable -regex: match pathname with regex"
-	default y
-	depends on FIND
-	help
-	  The -regex option matches whole pathname against regular expression.
-
-config FEATURE_FIND_CONTEXT
-	bool "Enable -context: security context matching"
-	default n
-	depends on FIND && SELINUX
-	help
-	  Support the 'find -context' option for matching security context.
-
-config FEATURE_FIND_LINKS
-	bool "Enable -links: link count matching"
-	default n
-	depends on FIND
-	help
-	  Support the 'find -links' option for matching number of links.
-
-config GREP
-	bool "grep"
-	default n
-	help
-	  grep is used to search files for a specified pattern.
-
-config FEATURE_GREP_EGREP_ALIAS
-	bool "Enable extended regular expressions (egrep & grep -E)"
-	default y
-	depends on GREP
-	help
-	  Enabled support for extended regular expressions. Extended
-	  regular expressions allow for alternation (foo|bar), grouping,
-	  and various repetition operators.
-
-config FEATURE_GREP_FGREP_ALIAS
-	bool "Alias fgrep to grep -F"
-	default y
-	depends on GREP
-	help
-	  fgrep sees the search pattern as a normal string rather than
-	  regular expressions.
-	  grep -F always works, this just creates the fgrep alias.
-
-config FEATURE_GREP_CONTEXT
-	bool "Enable before and after context flags (-A, -B and -C)"
-	default y
-	depends on GREP
-	help
-	  Print the specified number of leading (-B) and/or trailing (-A)
-	  context surrounding our matching lines.
-	  Print the specified number of context lines (-C).
-
-config XARGS
-	bool "xargs"
-	default n
-	help
-	  xargs is used to execute a specified command for
-	  every item from standard input.
-
-config FEATURE_XARGS_SUPPORT_CONFIRMATION
-	bool "Enable -p: prompt and confirmation"
-	default n
-	depends on XARGS
-	help
-	  Support -p: prompt the user whether to run each command
-	  line and read a line from the terminal.
-
-config FEATURE_XARGS_SUPPORT_QUOTES
-	bool "Enable single and double quotes and backslash"
-	default n
-	depends on XARGS
-	help
-	  Support quoting in the input.
-
-config FEATURE_XARGS_SUPPORT_TERMOPT
-	bool "Enable -x: exit if -s or -n is exceeded"
-	default n
-	depends on XARGS
-	help
-	  Support -x: exit if the command size (see the -s or -n option)
-	  is exceeded.
-
-config FEATURE_XARGS_SUPPORT_ZERO_TERM
-	bool "Enable -0: NUL-terminated input"
-	default n
-	depends on XARGS
-	help
-	  Support -0: input items are terminated by a NUL character
-	  instead of whitespace, and the quotes and backslash
-	  are not special.
-
-endmenu
diff -ad -urpN busybox.0/findutils/Config.src busybox.1/findutils/Config.src
--- busybox.0/findutils/Config.src	1970-01-01 01:00:00.000000000 +0100
+++ busybox.1/findutils/Config.src	2010-05-09 01:43:41.000000000 +0200
@@ -0,0 +1,10 @@
+#
+# For a description of the syntax of this configuration file,
+# see scripts/kbuild/config-language.txt.
+#
+
+menu "Finding Utilities"
+
+INSERT
+
+endmenu
diff -ad -urpN busybox.0/findutils/find.c busybox.1/findutils/find.c
--- busybox.0/findutils/find.c	2010-04-27 07:20:34.000000000 +0200
+++ busybox.1/findutils/find.c	2010-05-09 01:52:43.000000000 +0200
@@ -53,6 +53,181 @@
  * diff -u /tmp/std_find /tmp/bb_find && echo Identical
  */
 
+// kbuild:lib-$(CONFIG_FIND) += find.o
+// config:
+// config:config FIND
+// config:	bool "find"
+// config:	default n
+// config:	help
+// config:	  find is used to search your system to find specified files.
+// config:
+// config:config FEATURE_FIND_PRINT0
+// config:	bool "Enable -print0: NUL-terminated output"
+// config:	default y
+// config:	depends on FIND
+// config:	help
+// config:	  Causes output names to be separated by a NUL character
+// config:	  rather than a newline. This allows names that contain
+// config:	  newlines and other whitespace to be more easily
+// config:	  interpreted by other programs.
+// config:
+// config:config FEATURE_FIND_MTIME
+// config:	bool "Enable -mtime: modified time matching"
+// config:	default y
+// config:	depends on FIND
+// config:	help
+// config:	  Allow searching based on the modification time of
+// config:	  files, in days.
+// config:
+// config:config FEATURE_FIND_MMIN
+// config:	bool "Enable -mmin: modified time matching by minutes"
+// config:	default y
+// config:	depends on FIND
+// config:	help
+// config:	  Allow searching based on the modification time of
+// config:	  files, in minutes.
+// config:
+// config:config FEATURE_FIND_PERM
+// config:	bool "Enable -perm: permissions matching"
+// config:	default y
+// config:	depends on FIND
+// config:	help
+// config:	  Enable searching based on file permissions.
+// config:
+// config:config FEATURE_FIND_TYPE
+// config:	bool "Enable -type: file type matching (file/dir/link/...)"
+// config:	default y
+// config:	depends on FIND
+// config:	help
+// config:	  Enable searching based on file type (file,
+// config:	  directory, socket, device, etc.).
+// config:
+// config:config FEATURE_FIND_XDEV
+// config:	bool "Enable -xdev: 'stay in filesystem'"
+// config:	default y
+// config:	depends on FIND
+// config:	help
+// config:	  This option allows find to restrict searches to a single filesystem.
+// config:
+// config:config FEATURE_FIND_MAXDEPTH
+// config:	bool "Enable -maxdepth N"
+// config:	default y
+// config:	depends on FIND
+// config:	help
+// config:	  This option enables -maxdepth N option.
+// config:
+// config:config FEATURE_FIND_NEWER
+// config:	bool "Enable -newer: compare file modification times"
+// config:	default y
+// config:	depends on FIND
+// config:	help
+// config:	  Support the 'find -newer' option for finding any files which have
+// config:	  a modified time that is more recent than the specified FILE.
+// config:
+// config:config FEATURE_FIND_INUM
+// config:	bool "Enable -inum: inode number matching"
+// config:	default y
+// config:	depends on FIND
+// config:	help
+// config:	  Support the 'find -inum' option for searching by inode number.
+// config:
+// config:config FEATURE_FIND_EXEC
+// config:	bool "Enable -exec: execute commands"
+// config:	default y
+// config:	depends on FIND
+// config:	help
+// config:	  Support the 'find -exec' option for executing commands based upon
+// config:	  the files matched.
+// config:
+// config:config FEATURE_FIND_USER
+// config:	bool "Enable -user: username/uid matching"
+// config:	default y
+// config:	depends on FIND
+// config:	help
+// config:	  Support the 'find -user' option for searching by username or uid.
+// config:
+// config:config FEATURE_FIND_GROUP
+// config:	bool "Enable -group: group/gid matching"
+// config:	default y
+// config:	depends on FIND
+// config:	help
+// config:	  Support the 'find -group' option for searching by group name or gid.
+// config:
+// config:config FEATURE_FIND_NOT
+// config:	bool "Enable the 'not' (!) operator"
+// config:	default y
+// config:	depends on FIND
+// config:	help
+// config:	  Support the '!' operator to invert the test results.
+// config:	  If 'Enable full-blown desktop' is enabled, then will also support
+// config:	  the non-POSIX notation '-not'.
+// config:
+// config:config FEATURE_FIND_DEPTH
+// config:	bool "Enable -depth"
+// config:	default y
+// config:	depends on FIND
+// config:	help
+// config:	  Process each directory's contents before the directory itself.
+// config:
+// config:config FEATURE_FIND_PAREN
+// config:	bool "Enable parens in options"
+// config:	default y
+// config:	depends on FIND
+// config:	help
+// config:	  Enable usage of parens '(' to specify logical order of arguments.
+// config:
+// config:config FEATURE_FIND_SIZE
+// config:	bool "Enable -size: file size matching"
+// config:	default y
+// config:	depends on FIND
+// config:	help
+// config:	  Support the 'find -size' option for searching by file size.
+// config:
+// config:config FEATURE_FIND_PRUNE
+// config:	bool "Enable -prune: exclude subdirectories"
+// config:	default y
+// config:	depends on FIND
+// config:	help
+// config:	  If the file is a directory, dont descend into it. Useful for
+// config:	  exclusion .svn and CVS directories.
+// config:
+// config:config FEATURE_FIND_DELETE
+// config:	bool "Enable -delete: delete files/dirs"
+// config:	default n
+// config:	depends on FIND && FEATURE_FIND_DEPTH
+// config:	help
+// config:	  Support the 'find -delete' option for deleting files and directories.
+// config:	  WARNING: This option can do much harm if used wrong. Busybox will not
+// config:	  try to protect the user from doing stupid things. Use with care.
+// config:
+// config:config FEATURE_FIND_PATH
+// config:	bool "Enable -path: match pathname with shell pattern"
+// config:	default y
+// config:	depends on FIND
+// config:	help
+// config:	  The -path option matches whole pathname instead of just filename.
+// config:
+// config:config FEATURE_FIND_REGEX
+// config:	bool "Enable -regex: match pathname with regex"
+// config:	default y
+// config:	depends on FIND
+// config:	help
+// config:	  The -regex option matches whole pathname against regular expression.
+// config:
+// config:config FEATURE_FIND_CONTEXT
+// config:	bool "Enable -context: security context matching"
+// config:	default n
+// config:	depends on FIND && SELINUX
+// config:	help
+// config:	  Support the 'find -context' option for matching security context.
+// config:
+// config:config FEATURE_FIND_LINKS
+// config:	bool "Enable -links: link count matching"
+// config:	default n
+// config:	depends on FIND
+// config:	help
+// config:	  Support the 'find -links' option for matching number of links.
+
 #include <fnmatch.h>
 #include "libbb.h"
 #if ENABLE_FEATURE_FIND_REGEX
diff -ad -urpN busybox.0/findutils/grep.c busybox.1/findutils/grep.c
--- busybox.0/findutils/grep.c	2010-04-30 09:30:10.000000000 +0200
+++ busybox.1/findutils/grep.c	2010-05-09 01:49:28.000000000 +0200
@@ -19,6 +19,41 @@
  * (C) 2006 Jac Goudsmit added -o option
  */
 
+// kbuild:lib-$(CONFIG_GREP) += grep.o
+// config:
+// config:config GREP
+// config:	bool "grep"
+// config:	default n
+// config:	help
+// config:	  grep is used to search files for a specified pattern.
+// config:
+// config:config FEATURE_GREP_EGREP_ALIAS
+// config:	bool "Enable extended regular expressions (egrep & grep -E)"
+// config:	default y
+// config:	depends on GREP
+// config:	help
+// config:	  Enabled support for extended regular expressions. Extended
+// config:	  regular expressions allow for alternation (foo|bar), grouping,
+// config:	  and various repetition operators.
+// config:
+// config:config FEATURE_GREP_FGREP_ALIAS
+// config:	bool "Alias fgrep to grep -F"
+// config:	default y
+// config:	depends on GREP
+// config:	help
+// config:	  fgrep sees the search pattern as a normal string rather than
+// config:	  regular expressions.
+// config:	  grep -F always works, this just creates the fgrep alias.
+// config:
+// config:config FEATURE_GREP_CONTEXT
+// config:	bool "Enable before and after context flags (-A, -B and -C)"
+// config:	default y
+// config:	depends on GREP
+// config:	help
+// config:	  Print the specified number of leading (-B) and/or trailing (-A)
+// config:	  context surrounding our matching lines.
+// config:	  Print the specified number of context lines (-C).
+
 #include "libbb.h"
 #include "xregex.h"
 
diff -ad -urpN busybox.0/findutils/Kbuild busybox.1/findutils/Kbuild
--- busybox.0/findutils/Kbuild	2010-04-09 20:01:59.000000000 +0200
+++ busybox.1/findutils/Kbuild	1970-01-01 01:00:00.000000000 +0100
@@ -1,10 +0,0 @@
-# Makefile for busybox
-#
-# Copyright (C) 1999-2005 by Erik Andersen <andersen at codepoet.org>
-#
-# Licensed under the GPL v2, see the file LICENSE in this tarball.
-
-lib-y:=
-lib-$(CONFIG_FIND)	+= find.o
-lib-$(CONFIG_GREP)	+= grep.o
-lib-$(CONFIG_XARGS)	+= xargs.o
diff -ad -urpN busybox.0/findutils/Kbuild.src busybox.1/findutils/Kbuild.src
--- busybox.0/findutils/Kbuild.src	1970-01-01 01:00:00.000000000 +0100
+++ busybox.1/findutils/Kbuild.src	2010-05-09 03:54:53.000000000 +0200
@@ -0,0 +1,9 @@
+# Makefile for busybox
+#
+# Copyright (C) 1999-2005 by Erik Andersen <andersen at codepoet.org>
+#
+# Licensed under the GPL v2, see the file LICENSE in this tarball.
+
+lib-y:=
+
+INSERT
diff -ad -urpN busybox.0/findutils/xargs.c busybox.1/findutils/xargs.c
--- busybox.0/findutils/xargs.c	2010-04-09 20:01:59.000000000 +0200
+++ busybox.1/findutils/xargs.c	2010-05-09 01:49:25.000000000 +0200
@@ -17,6 +17,47 @@
  *
  */
 
+// kbuild:lib-$(CONFIG_XARGS) += xargs.o
+// config:
+// config:config XARGS
+// config:	bool "xargs"
+// config:	default n
+// config:	help
+// config:	  xargs is used to execute a specified command for
+// config:	  every item from standard input.
+// config:
+// config:config FEATURE_XARGS_SUPPORT_CONFIRMATION
+// config:	bool "Enable -p: prompt and confirmation"
+// config:	default n
+// config:	depends on XARGS
+// config:	help
+// config:	  Support -p: prompt the user whether to run each command
+// config:	  line and read a line from the terminal.
+// config:
+// config:config FEATURE_XARGS_SUPPORT_QUOTES
+// config:	bool "Enable single and double quotes and backslash"
+// config:	default n
+// config:	depends on XARGS
+// config:	help
+// config:	  Support quoting in the input.
+// config:
+// config:config FEATURE_XARGS_SUPPORT_TERMOPT
+// config:	bool "Enable -x: exit if -s or -n is exceeded"
+// config:	default n
+// config:	depends on XARGS
+// config:	help
+// config:	  Support -x: exit if the command size (see the -s or -n option)
+// config:	  is exceeded.
+// config:
+// config:config FEATURE_XARGS_SUPPORT_ZERO_TERM
+// config:	bool "Enable -0: NUL-terminated input"
+// config:	default n
+// config:	depends on XARGS
+// config:	help
+// config:	  Support -0: input items are terminated by a NUL character
+// config:	  instead of whitespace, and the quotes and backslash
+// config:	  are not special.
+
 #include "libbb.h"
 
 /* This is a NOEXEC applet. Be very careful! */
diff -ad -urpN busybox.0/Makefile busybox.1/Makefile
--- busybox.0/Makefile	2010-04-09 20:01:58.000000000 +0200
+++ busybox.1/Makefile	2010-05-09 03:53:15.000000000 +0200
@@ -377,6 +377,11 @@ ifneq ($(KBUILD_SRC),)
 	    $(srctree) $(objtree) $(VERSION) $(PATCHLEVEL)
 endif
 
+# This target generates Kbuild's and Config.in's from *.c files
+PHONY += gen_build_files
+gen_build_files:
+	$(Q)$(srctree)/scripts/gen_build_files.sh $(srctree) $(objtree)
+
 # To make sure we do not include .config for any of the *config targets
 # catch them early, and hand them over to scripts/kconfig/Makefile
 # It is allowed to specify more targets when calling make, including
@@ -428,7 +433,7 @@ ifeq ($(config-targets),1)
 -include $(srctree)/arch/$(ARCH)/Makefile
 export KBUILD_DEFCONFIG
 
-config %config: scripts_basic outputmakefile FORCE
+config %config: scripts_basic outputmakefile gen_build_files FORCE
 	$(Q)mkdir -p include
 	$(Q)$(MAKE) $(build)=scripts/kconfig $@
 	$(Q)$(MAKE) -C $(srctree) KBUILD_SRC= .kernelrelease
@@ -443,7 +448,7 @@ ifeq ($(KBUILD_EXTMOD),)
 # Carefully list dependencies so we do not try to build scripts twice
 # in parrallel
 PHONY += scripts
-scripts: scripts_basic include/config/MARKER
+scripts: gen_build_files scripts_basic include/config/MARKER
 	$(Q)$(MAKE) $(build)=$(@)
 
 scripts_basic: include/autoconf.h
diff -ad -urpN busybox.0/scripts/gen_build_files.sh busybox.1/scripts/gen_build_files.sh
--- busybox.0/scripts/gen_build_files.sh	1970-01-01 01:00:00.000000000 +0100
+++ busybox.1/scripts/gen_build_files.sh	2010-05-09 03:58:09.000000000 +0200
@@ -0,0 +1,51 @@
+#!/bin/sh
+
+test $# -ge 2 || exit 1
+
+# cd to objtree
+cd "$2" || exit 1
+
+srctree="$1"
+
+find -type d \
+| while read; do
+    d="$REPLY"
+
+    test -f "$srctree/$d"/Kbuild.src && {
+	echo "  CHK     $d/Kbuild"
+	s=`grep -h '^// kbuild:' "$d"/*.c | sed 's^// kbuild:^^'`
+	{
+	    while read; do
+		test x"$REPLY" = x"INSERT" && REPLY="$s"
+		printf "%s\n" "$REPLY"
+	    done <"$srctree/$d"/Kbuild.src
+	} >"$d"/Kbuild.$$.tmp
+	if cmp -s "$d"/Kbuild.$$.tmp "$d"/Kbuild; then
+	    rm "$d"/Kbuild.$$.tmp
+	else
+	    echo "  GEN     $d/Kbuild"
+	    mv "$d"/Kbuild.$$.tmp "$d"/Kbuild
+	fi
+    }
+
+    test -f "$srctree/$d"/Config.src && {
+	echo "  CHK     $d/Config.in"
+	s=`grep -h '^// config:' "$d"/*.c | sed 's^// config:^^'`
+	{
+	    while read; do
+		test x"$REPLY" = x"INSERT" && REPLY="$s"
+		printf "%s\n" "$REPLY"
+	    done <"$srctree/$d"/Config.src
+	} >"$d"/Config.in.$$.tmp
+	if cmp -s "$d"/Config.in.$$.tmp "$d"/Config.in; then
+	    rm "$d"/Config.in.$$.tmp
+	else
+	    echo "  GEN     $d/Config.in"
+	    mv "$d"/Config.in.$$.tmp "$d"/Config.in
+	fi
+    }
+
+done
+
+# Last read failed. This is normal. Don't exit with its error code:
+exit 0


More information about the busybox mailing list