Linux内核Makefile cscope目标

6
当我使用make cscope来生成Linux内核cscope数据库时,我会得到一个数据库文件以及一列相对路径的文件列表。这对我来说是一个问题,因为后来当我从与内核不同的目录中附加外部内核数据库到vim编辑器中时,我可以轻松搜索特定的符号,我无法打开包含该符号的文件。
我编写了下面的bash脚本:
#!/bin/bash

SNAME="$0"
SNAME=${SNAME##*/}

function usage()
{
    echo Generate Linux kernel cscope database
    echo "Usage: $SNAME [PATH]"
    echo -n "You must provide this script with an ABSOLUTE path of your "
    echo "kernel's root directory"
}

if [[ -z "$1" ]]; then
    usage
    exit -1
fi

KDIR="$1"

echo -n "Collecting a list of files... "
if find "$KDIR" -path "${KDIR}/arch/*" ! -path "${KDIR}/arch/x86*" -prune -o \
        -path "${KDIR}/include/asm-*" \
        ! -path "${KDIR}/include/asm-generic*" \
        ! -path "${KDIR}/include/asm-x86*" -prune -o \
        -path "${KDIR}/tmp*" -prune -o \
        -path "${KDIR}/Documentation*" -prune -o \
        -path "${KDIR}/scripts*" -prune -o \
        -name "*.[chxsS]" -print > cscope.files; then
    echo done
else
    echo failed
fi

echo -n "Building cscope database... "
cscope -k -qb && echo done || echo failed

我创建了一个收集我需要的所有文件(x86 / x86_64架构)的目录,使用绝对路径,并且成功地手动构建了cscope数据库。但是我认为一定有更简单的方法来完成这个任务。也许有一些Makefile的目标,例如make cscope_absmake cscope_ext,但我尚未找到。

有什么建议吗?


+1 不知道它有一个 make cscope 选项。 - nom-mon-ir
1
我想到的一件事是:查看Makefile中如何调用cscope,如果存在变量,则可以在命令行中指定一些选项给cscope。 - Chnossos
4个回答

5

首先,按照以下方式创建特定于特定架构的cscope数据库更加简单:在Linux内核的顶层文件夹中运行以下命令:

ARCH=x86 make cscope

这将创建一个使用相对路径的cscope。现在你可以用以下两种方式之一让vim根据cscope.out文件的位置来解释这些路径: 方式1:使用cscoperelative。输入:help csre,可获得以下输出:
If 'cscoperelative' is set, then in absence of a prefix given to cscope
(prefix is the argument of -P option of cscope), basename of cscope.out
location (usually the project root directory) will be used as the prefix
to construct an absolute path.  The default is off.  Note: This option is
only effective when cscope (cscopeprg) is initialized without a prefix
path (-P).  Examples: >
    :set csre
    :set nocsre

方法2:(来自这个问题的Aaron Hs回答)在vim中添加cscope数据库时,指定基础位置。例如:

:cs add <base_location>/cscope.out <base_location>/

以下是vim的cscope add帮助页面的翻译:

USAGE   :cs add {file|dir} [pre-path] [flags]

    [pre-path] is the pathname used with the -P command to cscope.

3
make cscope

或者针对您的特定情况 -
ARCH=x86 make cscope

2
根据手册此处的描述:

-P path 在预先构建的交叉引用文件中为相对文件名添加路径,以便无需更改到构建交叉引用文件的目录。此选项仅适用于-d选项。

因此,我猜下面的命令从顶层内核目录应该可以解决问题(抱歉没有linux机器可用):
cscope -d -P `pwd`

我的看法是,


0
您可以在内核树的根目录中使用以下命令来生成绝对路径:
#> make O=. cscope

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接