kernel source insight filelist

#!/bin/sh
###############################################################################
# File : collect-src
# Description: script to find all the compiled source file and header file
#
#       You must first compile the source and generate *.o files.
#
#       For kernel and busybox , the *.o.cmd file will be generated to find the header file.
#       For u-boot, the .depend file will be generated to find the header file.
#       Others, please concate with me for support!
#
###############################################################################
#
# Usage:
#
#     collect-src [-i list_file ]
#
# where:
#
#     -i list_file
#          Specifies the name of the file into which the list of files
#          to index is placed (default: src.list).
#
#     -f
#          Output full file path in the list_file
#
#
###############################################################################

DIR=.

obj_file=`echo $obj_file| sed 's/\n/ /g'`
src_list=src.list
tmp_mk=tmp_makefile.mk
full_path=false


while [ -n "$1" ]
do
    case $1 in
    -i)
        if [ "X$2" = "X" ]; then
            echo "$0: No list file specified" >&2
            exit 1
        fi
        src_list="$2"
        shift
        ;;
    -f)
        full_path=true
        ;;
    *)
        echo "Unsupport args $1"
        exit
        ;;
    esac
    shift
done

cd $DIR

cat <<EOF > $tmp_mk

src_list := $src_list
pwd := \$(shell pwd)


.PHONY: all

# make all is the first target
all:

define find_file
\$(shell find \$(1) \( -name "\$(2)" -a -type f \) | \\
     sed -e '/\/CVS\//d' -e '/\/RCS\//d' -e '/\.svn\//d' -e 's/^\.\///')
endef

define change1suffix
\$(foreach f,\$(1), \\
    \$(addprefix \$(dir \$(f)),\$(patsubst .%.o.cmd,%.o,\$(notdir \$(f)))))
endef

define _change2suffix
\$(wildcard \$(dir \$(1))\$(patsubst %.o,.%.\$(2),\$(notdir \$(1))))
endef

define change2suffix
\$(foreach f,\$(1), \\
    \$(call _change2suffix,\$(f),\$(2)))
endef

define _obj2src
\$(wildcard \$(patsubst %.o,%.\$(2),\$(1)))
endef

define obj2src
\$(eval _src_f := \$(call _obj2src,\$(1),c)) \\
\$(eval _src_f += \$(call _obj2src,\$(1),h)) \\
\$(eval _src_f += \$(call _obj2src,\$(1),l)) \\
\$(eval _src_f += \$(call _obj2src,\$(1),y)) \\
\$(eval _src_f += \$(call _obj2src,\$(1),S)) \\
\$(eval _src_f += \$(call _obj2src,\$(1),C)) \\
\$(eval _src_f += \$(call _obj2src,\$(1),cpp)) \\
\$(eval _src_f += \$(call _obj2src,\$(1),java)) \\
\$(_src_f)
endef

define get_src_from_var
\$(eval _all_files:=) \\
\$(foreach v,\$(1), \\
    \$(eval _files := \$(subst \$(pwd)/,,\$(\$(v)))) \\
    \$(eval _files := \$(patsubst /%,,\$(_files))) \\
    \$(eval _all_files := \$(sort \$(_all_files) \$(wildcard \$(_files))))) \\
\$(_all_files) \\
\$(eval _all_files:=)
endef

define get_one_src_from_var
\$(eval file:=) \\
\$(eval _file := \$(subst \$(pwd)/,,\$(\$(1)))) \\
\$(info 1111111111_file=\$(_file)) \\
\$(eval _file := \$(patsubst /%,,\$(_file))) \\
\$(info 2222222222 _file=\$(_file)) \\
\$(eval file := \$(sort \$(file) \$(wildcard \$(_file))))) \\
\$(file) \\
\$(eval file:=)
endef


DEP_FILE := \$(call find_file,.,*.o.cmd)
\$(if \$(DEP_FILE),, \\
    \$(eval DEP_FILE := \$(call find_file,.,.depend)) \\
    \$(eval nokernel := true))

ifneq (\$(nokernel),true)
################ Find all kernel source files ######################
dep_objs := \$(call change1suffix,\$(DEP_FILE))
dep_vars := \$(addprefix deps_,\$(dep_objs))
### New kernel ###
dep_vars += \$(addprefix source_,\$(dep_objs))

include \$(DEP_FILE)

######## Only find the kernel directory src and header files ####
autoconf_header := \$(shell test -d include && find include -name autoconf.h)
all_src_files := \$(autoconf_header)

all_src_files += \$(call get_src_from_var,\$(dep_vars))

else # \$(nokernel) == true
############### Not kernel ##########################################
O_SRC := \$(call find_file,.,*.o))
all_src_files := \$(call obj2src,\$(O_SRC))

#################### Find all source file by .depend ############
ifneq (\$(DEP_FILE),)
\$(foreach f,\$(DEP_FILE), \\
    \$(shell sed 's/\(^[a-zA-Z0-9_][a-zA-Z0-9_-]*\.o\):/\1:=/' \$(f) > \$(f).tmp))

dep_vars := \$(notdir \$(O_SRC))
include \$(addsuffix .tmp,\$(DEP_FILE))
all_src_files := \$(sort \$(all_src_files) \$(call get_src_from_var,\$(dep_vars)))
endif  # DEP_FILE

endif # end of nokernel


all:
 \$(foreach f,\$(all_src_files),\$(shell echo \$(f) >> \$(src_list)))
 @echo "----------- generate source file success ----------"

 

EOF

PWD=`pwd`

### collect files by Makefile
make -f $tmp_mk


all_src=`cat $src_list`

### remove tmp files
#rm -rf $tmp_mk

if [ "$full_path" = "true" ]; then
    rm -rf $src_list
    for f in $all_src; do
        echo $PWD/$f >> $src_list
    done
fi

# Generate cscope database with kernel mode
#cscope -k -b -i $src_list

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值