This stuff is part of the make machinery, so implement it in make
proper.
Avoids spurious, slow re-generation of the generated Config.in and
Kbuild files.

Signed-off-by: Bernhard Reutner-Fischer <[email protected]>
---
 Makefile                   |   61 ++++++++++++++++++++++++++++++++++++++------
 scripts/Kbuild.include     |    8 ++++++
 scripts/gen_build_files.sh |   60 -------------------------------------------
 3 files changed, 61 insertions(+), 68 deletions(-)
 delete mode 100755 scripts/gen_build_files.sh

diff --git a/Makefile b/Makefile
index c231092..de66535 100644
--- a/Makefile
+++ b/Makefile
@@ -298,6 +298,7 @@ STRIP               = $(CROSS_COMPILE)strip
 OBJCOPY                = $(CROSS_COMPILE)objcopy
 OBJDUMP                = $(CROSS_COMPILE)objdump
 AWK            = awk
+SED            = sed
 GENKSYMS       = scripts/genksyms/genksyms
 DEPMOD         = /sbin/depmod
 KALLSYMS       = scripts/kallsyms
@@ -329,7 +330,7 @@ KERNELVERSION = 
$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 
 export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION \
        ARCH CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC \
-       CPP AR NM STRIP OBJCOPY OBJDUMP MAKE AWK GENKSYMS PERL UTS_MACHINE \
+       CPP AR NM STRIP OBJCOPY OBJDUMP MAKE AWK SED GENKSYMS PERL UTS_MACHINE \
        HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS
 
 export CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS
@@ -377,11 +378,6 @@ 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
@@ -433,7 +429,56 @@ ifeq ($(config-targets),1)
 -include $(srctree)/arch/$(ARCH)/Makefile
 export KBUILD_DEFCONFIG
 
-config %config: scripts_basic outputmakefile gen_build_files FORCE
+busybox-alldirs := $(shell find $(srctree) -type f -name Kbuild.src)
+busybox-alldirs := $(foreach d,$(busybox-alldirs),$(dir $(d)))
+busybox-alldirs := $(patsubst $(srctree)/%/,%,$(busybox-alldirs))
+
+gen_build_files = $(addsuffix /Config.in,$(busybox-alldirs)) \
+       $(addsuffix /Kbuild,$(busybox-alldirs))
+
+define get_kbuild_str
+       $(shell $(SED) 's/\(["()]\)/\\\1/g;s...@^//kbuild:@\...@gp;d' -- 
$(subst $<,,$^))
+endef
+
+define get_config_str
+       $(shell $(SED) 's/\(["()]\)/\\\1/g;s...@^//config:@\...@gp;d' -- 
$(subst $<,,$^))
+endef
+
+define generate_kbuild
+       echo '# DO NOT EDIT. This file is generated from Kbuild.src' > 
[email protected]; \
+       $(SED) -e "/^INSERT/c\ $(call get_kbuild_str)" $< >> [email protected]; \
+       if cmp -s $@ [email protected]; \
+       then touch $@; \
+       else \
+               mv [email protected] $@; \
+       fi; \
+       rm -f [email protected]
+endef
+define generate_config_in
+       echo '# DO NOT EDIT. This file is generated from Config.src' > 
[email protected]; \
+       $(SED) -e "/^INSERT/c\ $(call get_config_str)" $< >> [email protected]; \
+       if cmp -s $@ [email protected]; \
+       then touch $@; \
+       else \
+               mv [email protected] $@; \
+       fi; \
+       rm -f [email protected]
+endef
+
+quiet_cmd_gen_config_in ?= GEN     $@
+brief_cmd_gen_config_in ?= GEN     $< + $(SED) 's...@^//config:@p;d' $(@D)/*.c 
-> $@
+      cmd_gen_config_in ?= $(generate_config_in)
+quiet_cmd_gen_kbuild    ?= GEN     $@
+brief_cmd_gen_kbuild    ?= GEN     $< + $(SED) 's...@^//kbuild:@p;d' $(@D)/*.c 
-> $@
+      cmd_gen_kbuild    ?= $(generate_kbuild)
+
+# This target generates Kbuild's and Config.in's from *.c files
+%/Config.in: %/Config.src %/*.c
+       $(call briefcmd,gen_config_in)
+%/Kbuild: %/Kbuild.src %/*.c
+       $(call briefcmd,gen_kbuild)
+
+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
@@ -448,7 +493,7 @@ ifeq ($(KBUILD_EXTMOD),)
 # Carefully list dependencies so we do not try to build scripts twice
 # in parrallel
 PHONY += scripts
-scripts: gen_build_files 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/scripts/Kbuild.include b/scripts/Kbuild.include
index 6ec1809..1e9f703 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -101,6 +101,10 @@ flags = $(foreach o,$($(1)),$(if $(filter -I%,$(o)),$(call 
addtree,$(o)),$(o)))
 # If quiet is set, only print short version of command
 cmd = @$(echo-cmd) $(cmd_$(1))
 
+# If quiet is set, only print short version of command
+# else print brief command, iff set
+briefcmd = @$(brief-cmd) $(cmd_$(1))
+
 # Add $(obj)/ for paths that is not absolute
 objectify = $(foreach o,$(1),$(if $(filter /%,$(o)),$(o),$(obj)/$(o)))
 
@@ -122,6 +126,10 @@ endif
 echo-cmd = $(if $($(quiet)cmd_$(1)), \
        echo '  $(call escsq,$($(quiet)cmd_$(1)))';)
 
+# echo command. Short version is $(quiet) equals quiet, otherwise brief command
+brief-cmd = $(if $(quiet),$(echo-cmd), \
+       $(if $(brief_cmd_$(1)), echo '  $(call escsq,$(brief_cmd_$(1)))';))
+
 make-cmd = $(subst \#,\\\#,$(subst $$,$$$$,$(call escsq,$(cmd_$(1)))))
 
 # function to only execute the passed command if necessary
diff --git a/scripts/gen_build_files.sh b/scripts/gen_build_files.sh
deleted file mode 100755
index b3aa132..0000000
--- a/scripts/gen_build_files.sh
+++ /dev/null
@@ -1,60 +0,0 @@
-#!/bin/sh
-
-test $# -ge 2 || { echo "Syntax: $0 SRCTREE OBJTREE"; exit 1; }
-
-# cd to objtree
-cd -- "$2" || { echo "Syntax: $0 SRCTREE OBJTREE"; exit 1; }
-
-srctree="$1"
-
-find -type d | while read -r d; do
-       d="${d#./}"
-       src="$srctree/$d/Kbuild.src"
-       dst="$d/Kbuild"
-       if test -f "$src"; then
-               #echo "  CHK     $dst"
-
-               s=`sed -n 's...@^//kbuild:@@p' -- "$srctree/$d"/*.c`
-               echo "# DO NOT EDIT. This file is generated from Kbuild.src" 
>"$dst.$$.tmp"
-
-               # Why "IFS='' read -r REPLY"??
-               # This atrocity is needed to read lines without mangling.
-               # IFS='' prevents whitespace trimming,
-               # -r suppresses backslash handling.
-               while IFS='' read -r REPLY; 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=`sed -n 's...@^//config:@@p' -- "$srctree/$d"/*.c`
-               echo "# DO NOT EDIT. This file is generated from Config.src" 
>"$dst.$$.tmp"
-
-               while IFS='' read -r REPLY; 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
-- 
1.7.1

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to