From 7fb68f199f037cb69363c8df5c934a27adc699f7 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 9 May 2010 04:22:48 +0200 Subject: [PATCH] make it possible to keep Config/Kbuild snippets in *.c files Signed-off-by: Denys Vlasenko --- Makefile | 9 +- findutils/Config.in | 253 ------------------------------- findutils/Config.src | 10 ++ findutils/{Kbuild => Kbuild.src} | 5 +- findutils/find.c | 175 +++++++++++++++++++++ findutils/grep.c | 35 +++++ findutils/xargs.c | 41 +++++ scripts/gen_build_files.sh | 55 +++++++ 8 files changed, 325 insertions(+), 258 deletions(-) delete mode 100644 findutils/Config.in create mode 100644 findutils/Config.src rename findutils/{Kbuild => Kbuild.src} (65%) create mode 100644 scripts/gen_build_files.sh diff --git a/Makefile b/Makefile index 1481f0100..da8f7d7b6 100644 --- a/Makefile +++ b/Makefile @@ -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 --git a/findutils/Config.in b/findutils/Config.in deleted file mode 100644 index 8582d6446..000000000 --- a/findutils/Config.in +++ /dev/null @@ -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 --git a/findutils/Config.src b/findutils/Config.src new file mode 100644 index 000000000..9ee71a845 --- /dev/null +++ b/findutils/Config.src @@ -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 --git a/findutils/Kbuild b/findutils/Kbuild.src similarity index 65% rename from findutils/Kbuild rename to findutils/Kbuild.src index 7b504bacf..771789ff5 100644 --- a/findutils/Kbuild +++ b/findutils/Kbuild.src @@ -5,6 +5,5 @@ # 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 + +INSERT diff --git a/findutils/find.c b/findutils/find.c index 30fb03dd1..9022867a2 100644 --- a/findutils/find.c +++ b/findutils/find.c @@ -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 #include "libbb.h" #if ENABLE_FEATURE_FIND_REGEX diff --git a/findutils/grep.c b/findutils/grep.c index 0f1c11abb..be290118f 100644 --- a/findutils/grep.c +++ b/findutils/grep.c @@ -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 --git a/findutils/xargs.c b/findutils/xargs.c index 3785f1ec0..c55ac5724 100644 --- a/findutils/xargs.c +++ b/findutils/xargs.c @@ -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 --git a/scripts/gen_build_files.sh b/scripts/gen_build_files.sh new file mode 100644 index 000000000..300d90c2a --- /dev/null +++ b/scripts/gen_build_files.sh @@ -0,0 +1,55 @@ +#!/bin/sh + +test $# -ge 2 || exit 1 + +# cd to objtree +cd "$2" || exit 1 + +srctree="$1" + +find -type d \ +| while read; do + d="$REPLY" + + src="$srctree/$d/Kbuild.src" + dst="$d/Kbuild" + if test -f "$src"; then + echo " CHK $dst" + + s=`grep -h '^//kbuild:' "$srctree/$d"/*.c | sed 's^//kbuild:^^'` + while read; do + test x"$REPLY" = x"INSERT" && REPLY="$s" + printf "%s\n" "$REPLY" + done <"$src" >"$dst.$$.tmp" + + if test -f "$dst" && cmp -s "$dst.$$.tmp" "$dst"; then + rm "$dst.$$.tmp" + else + echo " GEN $dst" + mv "$dst.$$.tmp" "$dst" + fi + fi + + src="$srctree/$d/Config.src" + dst="$d/Config.in" + if test -f "$src"; then + echo " CHK $dst" + + s=`grep -h '^//config:' "$srctree/$d"/*.c | sed 's^//config:^^'` + while read; do + test x"$REPLY" = x"INSERT" && REPLY="$s" + printf "%s\n" "$REPLY" + done <"$src" >"$dst.$$.tmp" + + if test -f "$dst" && cmp -s "$dst.$$.tmp" "$dst"; then + rm "$dst.$$.tmp" + else + echo " GEN $dst" + mv "$dst.$$.tmp" "$dst" + fi + fi + +done + +# Last read failed. This is normal. Don't exit with its error code: +exit 0