kbuild: move tags support to a shell script
RFC PATCH 1/1 kbuild: move tags support to a shell script
As no-one else wanted to do so - I now moved the tags support to a shell script of its own.
The usage is the same: make {tags,TAGS,cscope}
The ALLSOURCE_ARCHS suppport was lost in the transition - is it actually used by anyone?
I have given the patch only some light testing.
Could those of you that actually sues tags/cscope plese give it a try.
My naive transformation to a shell script could benefit from a pair of critical eyes too.
I will await feedback on the script and ALLSOURCE_ARCHS before I push it out.
Sam
From b6083161ff0a4d4c2a8946c1b4fec7a23fce55a8 Mon Sep 17 00:00:00 2001
From: Sam Ravnborg <[email protected]>
Date: Sun, 23 Nov 2008 00:02:49 +0100
Subject: [PATCH] kbuild: move tags support to a shell script
tags and cscope support really belongs in a shell script as they do not benefit from the make functionality.
Moving the support to a shell script has several benefits:
- The code is much easier to read
- More people is able to extend the tags support
- We see less changes to the top-level Makefile
--- Makefile | 118 +------------------------------------------- scripts/tags.sh | 146 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+), 116 deletions(-) create mode 100644 scripts/tags.sh
scripts/tags.sh new file +146 -0
@@ -0,0 +1,146 @@ +#!/bin/sh +# Generate tags or cscope files +# Usage tags.sh <mode> +# +# mode may be any of: tags, TAGS, cscope +# +# Uses the following environment variables: +# ARCH, SUBARCH, srctree, src, obj + +# This is a duplicate of RCS_FIND_IGNORE without escaped '()' +ignore="( -name SCCS -o -name BitKeeper -o -name .svn -o \ + -name CVS -o -name .pc -o -name .hg -o \ + -name .git ) \ + -prune -o" + +# find sources in arch/$ARCH +find_arch_sources() +{ + find ${__srctree}arch/$1 $ignore \ + -wholename ${__srctree}arch/$1/include -type d -prune \ + -o -name $2 -print; +} + +# find sources in: +# include/asm-$ARCH +# arch/$ARCH/include +find_arch_include_sources() +{ + test -e ${__srctree}include/asm-$1 && \ + find ${__srctree}include/asm-$1 $ignore \ + -name $2 -print; + test -e ${__srctree}include/asm && \ + find ${__srctree}arch/$1/include/asm $ignore \ + -name $2 -print; +} + +find_include_sources() +{ + find ${__srctree}security/selinux/include $ignore \ + -name $1 -print; + + find ${__srctree}include $ignore \ + \( -name config -o -name 'asm-*' \) -prune \ + -o -name $1 -print; \ + + find ${__srctree}include/asm-generic $ignore \ + -name $1 -print; +} + +find_other_sources() +{ + find ${__srctree}* $ignore \ + \( -name include -o -name arch -o -name '.tmp_*' \) -prune -o \ + -name $1 -print; +} + +find_sources() +{ + for arch in $1; do + find_arch_sources $arch $2 + find_arch_include_sources $arch "$2" + done + + find_include_sources "$2" + find_other_sources "$2" +} + +all_sources() +{ + find_sources "${archs}" *.[chS] +} + +all_kconfigs() +{ + find_sources "${archs}" "Kconfig*" +} + +all_defconfigs() +{ + find_sources "${archs}" "defconfig" +} + +docscope() +{ + (echo \-k; echo \-q; all_sources) > cscope.files + echo " GEN cscope.out (from $(wc -l cscope.files | cut -d ' ' -f 1) files)" + cscope -b -f cscope.out +} + +xtags() +{ + if $1 --version 2>&1 | grep -iq exuberant; then + all_sources | xargs $1 -a \ + -I __initdata,__exitdata,__acquires,__releases \ + -I __read_mostly,____cacheline_aligned \ + -I ____cacheline_aligned_in_smp \ + -I ____cacheline_internodealigned_in_smp \ + -I EXPORT_SYMBOL,EXPORT_SYMBOL_GPL \ + --extra=+f --c-kinds=+px \ + --regex-asm='/^ENTRY\(([^)]*)\).*/\1/' + all_kconfigs | xargs $1 -a \ + --langdef=kconfig --language-force=kconfig \ + --regex-kconfig='/^[[:blank:]]*(menu|)config[[:blank:]]+([[:alnum:]_]+)/\2/'; \ + all_defconfigs | xargs -r $1 -a \ + --langdef=dotconfig --language-force=dotconfig \ + --regex-dotconfig='/^#?[[:blank:]]*(CONFIG_[[:alnum:]_]+)/\1/'; + elif $1 --version 2>&1 | grep -iq emacs; then + all_sources | xargs $1 -a; + all_kconfigs | xargs $1 -a \ + --regex='/^[ \t]*\(\(menu\)*config\)[ \t]+\([a-zA-Z0-9_]+\)/\3/'; + all_defconfigs | xargs -r $1 -a \ + --regex='/^#?[ \t]?\(CONFIG_[a-zA-Z0-9_]+\)/\1/'; + else + all_sources | xargs $1 -a; + fi +} + + +# Do not use full path is we do not use O=.. builds +if [ ${src} == ${obj} ]; then + x__srctree= +else + x__srctree=${srctree} +fi + +# Support um (which has SUBARCH) +# FIXME: add support for ALLSOURCE_ARCHS if really used +if [ "${ARCH}" == "${SUBARCH}" ]; then + archs="${ARCH} ${SUBARCH}" +else + archs="${SRCARCH}" +fi + +case "$1" in + "cscope") + docscope + ;; + + "tags") + xtags ctags + ;; + + "TAGS") + xtags etags + ;; +esac
Makefile +2 -116
124 lines not on this page · raw message
Signature · 1 line
1.5.6.GIT
Quoted 2 lines
My naive transformation to a shell script could benefit from a pair of critical eyes too.
And so I did.
Improved version follows.
Changes:
- Fixed several bugs compared to first version
- introduced a few more functions to improve readability
- simplified find logic based on patches previously submitted
by Ian Campbell <[email protected]>
- improved kconfig support based on patches previously submitted by Alexey Dobriyan <[email protected]>
- tried to squeze it into 80 char limit but the regexs did not fully allow that
Sam
From 915f5d850d6273c0c2a348a63a738f49fba712e8 Mon Sep 17 00:00:00 2001
From: Sam Ravnborg <[email protected]>
Date: Sun, 23 Nov 2008 09:41:23 +0100
Subject: [PATCH] kbuild: move tags support to a shell script
tags and cscope support really belongs in a shell script as they do not benefit from the make functionality.
Moving the support to a shell script has several benefits:
- The readability of the code has increased a lot
- More people is able to extend the tags support
- We see less changes to the top-level Makefile
The shell script version includes improvements from:
Alexey Dobriyan <[email protected]> (jump to kconfig symbols) Ian Campbell <[email protected]> (simplified find algorithms)
This version has a few caveats:
=> It does not support ALLSOURCE_ARCHS
- it is easy to add if it is really used
=> It assumes all archs have moved to arch/$ARCH/include
--- Makefile | 118 +------------------------------------------- scripts/tags.sh | 148 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 150 insertions(+), 116 deletions(-) create mode 100644 scripts/tags.sh
Makefile +2 -116
@@ -1409,122 +1409,8 @@ endif # KBUILD_EXTMOD # Generate tags for editors # --------------------------------------------------------------------------- - -#We want __srctree to totally vanish out when KBUILD_OUTPUT is not set -#(which is the most common case IMHO) to avoid unneeded clutter in the big tags file. -#Adding $(srctree) adds about 20M on i386 to the size of the output file! - -ifeq ($(src),$(obj)) -__srctree = -else -__srctree = $(srctree)/ -endif - -ifeq ($(ALLSOURCE_ARCHS),) -ifeq ($(ARCH),um) -ALLINCLUDE_ARCHS := $(ARCH) $(SUBARCH) -else -ALLINCLUDE_ARCHS := $(SRCARCH) -endif -else -#Allow user to specify only ALLSOURCE_PATHS on the command line, keeping existing behaviour. -ALLINCLUDE_ARCHS := $(ALLSOURCE_ARCHS) -endif - -ALLSOURCE_ARCHS := $(SRCARCH) - -define find-sources - ( for arch in $(ALLSOURCE_ARCHS) ; do \ - find $(__srctree)arch/$${arch} $(RCS_FIND_IGNORE) \ - -wholename $(__srctree)arch/$${arch}/include/asm -type d -prune \ - -o -name $1 -print; \ - done ; \ - find $(__srctree)security/selinux/include $(RCS_FIND_IGNORE) \ - -name $1 -print; \ - find $(__srctree)include $(RCS_FIND_IGNORE) \ - \( -name config -o -name 'asm-*' \) -prune \ - -o -name $1 -print; \ - for arch in $(ALLINCLUDE_ARCHS) ; do \ - test -e $(__srctree)include/asm-$${arch} && \ - find $(__srctree)include/asm-$${arch} $(RCS_FIND_IGNORE) \ - -name $1 -print; \ - test -e $(__srctree)arch/$${arch}/include/asm && \ - find $(__srctree)arch/$${arch}/include/asm $(RCS_FIND_IGNORE) \ - -name $1 -print; \ - done ; \ - find $(__srctree)include/asm-generic $(RCS_FIND_IGNORE) \ - -name $1 -print; \ - find $(__srctree) $(RCS_FIND_IGNORE) \ - \( -name include -o -name arch -o -name '.tmp_*' \) -prune -o \ - -name $1 -print; \ - ) -endef - -define all-sources - $(call find-sources,'*.[chS]') -endef -define all-kconfigs - $(call find-sources,'Kconfig*') -endef -define all-defconfigs - $(call find-sources,'defconfig') -endef - -define xtags - if $1 --version 2>&1 | grep -iq exuberant; then \ - $(all-sources) | xargs $1 -a \ - -I __initdata,__exitdata,__acquires,__releases \ - -I __read_mostly,____cacheline_aligned,____cacheline_aligned_in_smp,____cacheline_internodealigned_in_smp \ - -I EXPORT_SYMBOL,EXPORT_SYMBOL_GPL \ - --extra=+f --c-kinds=+px \ - --regex-asm='/^ENTRY\(([^)]*)\).*/\1/'; \ - $(all-kconfigs) | xargs $1 -a \ - --langdef=kconfig \ - --language-force=kconfig \ - --regex-kconfig='/^[[:blank:]]*(menu|)config[[:blank:]]+([[:alnum:]_]+)/\2/'; \ - $(all-defconfigs) | xargs -r $1 -a \ - --langdef=dotconfig \ - --language-force=dotconfig \ - --regex-dotconfig='/^#?[[:blank:]]*(CONFIG_[[:alnum:]_]+)/\1/'; \ - elif $1 --version 2>&1 | grep -iq emacs; then \ - $(all-sources) | xargs $1 -a; \ - $(all-kconfigs) | xargs $1 -a \ - --regex='/^[ \t]*\(\(menu\)*config\)[ \t]+\([a-zA-Z0-9_]+\)/\3/'; \ - $(all-defconfigs) | xargs -r $1 -a \ - --regex='/^#?[ \t]?\(CONFIG_[a-zA-Z0-9_]+\)/\1/'; \ - else \ - $(all-sources) | xargs $1 -a; \ - fi -endef - -quiet_cmd_cscope-file = FILELST cscope.files - cmd_cscope-file = (echo \-k; echo \-q; $(all-sources)) > cscope.files - -quiet_cmd_cscope = MAKE cscope.out - cmd_cscope = cscope -b -f cscope.out - -cscope: FORCE - $(call cmd,cscope-file) - $(call cmd,cscope) - -quiet_cmd_TAGS = MAKE $@ -define cmd_TAGS - rm -f $@; \ - $(call xtags,etags) -endef - -TAGS: FORCE - $(call cmd,TAGS) - -quiet_cmd_tags = MAKE $@ -define cmd_tags - rm -f $@; \ - $(call xtags,ctags) -endef - -tags: FORCE - $(call cmd,tags) - +tags TAGS cscope: FORCE + $(CONFIG_SHELL) $(srctree)/scripts/tags.sh $@ # Scripts to check various things for consistency # ---------------------------------------------------------------------------
scripts/tags.sh new file +148 -0
148 lines not on this page · raw message
Signature · 1 line
1.5.6.GIT
Quoted 5 lines · Sam Ravnborg
As no-one else wanted to do so - I now moved the tags support to a shell script of its own.
The usage is the same: make {tags,TAGS,cscope}The
ALLSOURCE_ARCHSsuppport was lost in the transition - is it actually used by anyone?
I'm the one who actually added it way back in a0674e88d9c150e016a69e78e735f48772314c53 and to be honest I don't use it anymore since I've changed jobs and only really do x86 now...
I can't say if anyone else is using it though.
Quoted 3 lines
I have given the patch only some light testing.
Could those of you that actually sues tags/cscope plese give it a try.
I tested your second patch from the subsequent email and functionally it seems fine, it currently includes include/asm-* for all architectures but I suppose they will all go away shortly.
The output was a bit odd though:
$ make cscope
/bin/sh /local/scratch/ianc/devel/linux-2.6.git/scripts/tags.sh cscope
GEN cscope.out (from 13251 files)
I guess I would have expected " GEN cscope.files" instead of the
first line or just " TAGS"?Ian.
Signature · 5 lines
Ian Campbell Current Noise: Nine Inch Nails - Where Is Everybody? "We came. We saw. We kicked its ass." -- Bill Murray, _Ghostbusters_
Sam Ravnborg
Tested-by Ian CampbellQuoted 21 lines · Ian Campbell
Quoted 5 lines · Sam Ravnborg
As no-one else wanted to do so - I now moved the tags support to a shell script of its own.
The usage is the same: make {tags,TAGS,cscope}The
ALLSOURCE_ARCHSsuppport was lost in the transition - is it actually used by anyone?I'm the one who actually added it way back in
a0674e88d9c150e016a69e78e735f48772314c53and to be honest I don't use it anymore since I've changed jobs and only really do x86 now...I can't say if anyone else is using it though.
Quoted 3 lines
I have given the patch only some light testing.
Could those of you that actually sues tags/cscope plese give it a try.
I tested your second patch from the subsequent email and functionally it seems fine, it currently includes
include/asm-*for all architectures but I suppose they will all go away shortly.
Quoted 6 lines
The output was a bit odd though:
$ make cscope /bin/sh /local/scratch/ianc/devel/linux-2.6.git/scripts/tags.sh cscope GEN cscope.out (from 13251 files) I guess I would have expected " GEN cscope.files" instead of the first line or just " TAGS"?
Thanks for testing Ian.
I will fix up the invocation line to something like
GEN {tags,TAGS,cscope}
And then I will drop the extra output from the shell script in the cscope case.
Is it OK that I add a:
to the patch?
Sam
Quoted 5 lines · Sam Ravnborg
Is it OK that I add a:
Tested-by Ian Campbell <[email protected]>to the patch?
Yes, sure.
Ian.
Signature · 5 lines
Ian Campbell Current Noise: Enslaved - Isa Keep the number of passes in a compiler to a minimum. -- D. Gries